1#----------------------------------------------------------------------------
2# Project:  Horizon
3# File:     commondefs.cctype.RVCT.om
4#
5# Copyright (C)2009-2011 Nintendo Co., Ltd.  All rights reserved.
6#
7# These coded instructions, statements, and computer programs contain
8# proprietary information of Nintendo of America Inc. and/or Nintendo
9# Company Ltd., and are protected by Federal copyright law. They may
10# not be disclosed to third parties or copied or duplicated in any form,
11# in whole or in part, without the prior written consent of Nintendo.
12#
13# $Rev: 35731 $
14#----------------------------------------------------------------------------
15
16# Version of RVCT supported
17private.SUOPPORT_RVCT_VER[] =
18    RVCT40
19    ARMCC41
20
21global.RVCT_DIAG_STYLE          = arm
22global.EXCLUSION_SCATTER        = false
23global.EXT_CG                   = .txt
24
25# If CTRSDK_RVCT_VER is not defined, set the RVCT version for which SDK operations have been verified
26
27
28if $(not $(defined CTRSDK_RVCT_VER))
29    CTRSDK_RVCT_VER = 40
30    export CTRSDK_RVCT_VER
31    if $(defined-env CTRSDK_RVCT_VER)
32        CTRSDK_RVCT_VER = $(getenv CTRSDK_RVCT_VER)
33
34global.RVCT_ENV_PREFIX =
35    if $(equal $(CTRSDK_RVCT_VER),40)
36        value RVCT40
37    else
38        if $(equal $(CTRSDK_RVCT_VER),41)
39            value ARMCC41
40        else
41            value ARMCC$(CTRSDK_RVCT_VER)
42
43
44# If a RVCT version for which SDK operations have been verified has been installed, it is used
45# If not installed, the most recent supported version of the RVCT installed by the user is used
46#
47if $(defined-env $(RVCT_ENV_PREFIX)BIN)
48    RVCT_BINDIR = $(getenv $"$(RVCT_ENV_PREFIX)BIN")$(DIRSEP)
49    export
50else
51    foreach(rvct_version, $(SUOPPORT_RVCT_VER))
52        if $(defined-env $(rvct_version)BIN)
53            RVCT_BINDIR     = $(getenv $"$(rvct_version)BIN")$(DIRSEP)
54            RVCT_ENV_PREFIX = $(rvct_version)
55            break()
56            export
57        RVCT_BINDIR =
58        export
59    export
60
61if $(defined-env HORIZON_RVCT_DIAG_STYLE)
62    RVCT_DIAG_STYLE     = $(getenv HORIZON_RVCT_DIAG_STYLE)
63    export
64
65
66
67
68
69
70#----------------------------------------------------------------------------
71# Class definitions
72#----------------------------------------------------------------------------
73
74CompilerRVCT. =
75    extends $(Compiler)
76    class CompilerRVCT
77
78    #----------------------------------------------------------------------------
79    # Constant definitions
80    #----------------------------------------------------------------------------
81
82    this.CC             = $"$(RVCT_BINDIR)armcc.exe"
83    this.CXX            = $"$(RVCT_BINDIR)armcc.exe"
84    this.CPP            = $"$(RVCT_BINDIR)armcc.exe" -E
85    this.AR             = $"$(RVCT_BINDIR)armar.exe"
86    this.LD             = $"$(RVCT_BINDIR)armlink.exe"
87    this.AS             = $"$(RVCT_BINDIR)armasm.exe"
88
89    this.STRIP          = $"$(RVCT_BINDIR)fromelf.exe" --strip debug,comment,symbols --elf
90    this.DISAS          = $"$(RVCT_BINDIR)fromelf.exe" --32x1 -cd
91
92    this.CCFLAGS_MACRO  =
93
94    #------------------------------------------------------------------------
95    # The following warnings are suppressed
96    #
97    #    186: pointless comparison of unsigned integer with zero
98    #    340: value copied to temporary, reference to temporary used
99    #    401: destructor for base class "<class name>" is not virtual
100    #   1256: "<type name>" would have been promoted to "int" when passed
101    #   1297: Header file not guarded against multiple inclusion
102    #   1568: nonstandard reinterpret_cast
103    #   1764: SWP instructions are deprecated in architecture ARMv6 and above
104    #   1786: This instruction using SP is deprecated
105    #   1788: Explicit use of PC in this instruction is deprecated
106    #   2523: use of inline assembler is deprecated
107
108    #------------------------------------------------------------------------
109    # The following comments are suppressed
110    #
111    #     96: a translation unit must contain at least one declaration
112    #   1794: Error encountered parsing expansion routine
113    #   1801: Optimization: Function expanded (xxx)
114    #   2442: Could not inline: Cannot remove function from expression
115
116    #------------------------------------------------------------------------
117    # The following warnings are handled as errors
118    #
119    #     68: integer conversion resulted in a change of sign
120    #     88: assignment in condition
121    #    174: expression has no effect
122    #    188: enumerated type mixed with another type
123    #    223: function "<foo>" declared implicitly
124    #   3017: <foo> may be used before being set
125
126    #------------------------------------------------------------------------
127    # The following comments are handled as warnings
128    #
129    #    177: variable "xxx" was declared but never referenced
130    #    193: zero used for undefined preprocessing identifier "xxx"
131    #    228: trailing comma is nonstandard
132    #    550: variable "xxx" was set but never used
133    #    826: parameter "<parameter>" was never referenced
134    #   1301: padding inserted in <struct>
135
136    this.CCFLAGS_WARNING= --diag_suppress 186,340,401,1256,1297     \
137                          --diag_suppress 1568,1764,1786,1788,2523  \
138                          --diag_suppress 96,1794,1801,2442,3017    \
139                          --diag_error 68,88,174,188,223            \
140                          --diag_warning 177,193,228,550,826,1301   \
141                          --diag_suppress=optimizations
142
143    this.CCFLAGS_DEV_OPT= -O0 --retain=calls
144
145    private.ccflags_must1    = \
146        --multibyte_chars \
147        --signed_chars \
148
149    private.ccflags_must2    = \
150        --dollar \
151        --littleend \
152        --wchar \
153        --wchar16 \
154
155    private.ccflags_may     = \
156        --apcs /interwork \
157        --data_reorder \
158        --debug \
159        --diag_style=$(RVCT_DIAG_STYLE) \
160        --dwarf3 \
161        --no_debug_macros \
162        --remove_unneeded_entities \
163        --split_sections \
164
165    private.ccflags_var     = \
166        --debug_info=line_inlining_extensions \
167        --force_new_nothrow \
168        --fpmode=fast \
169        --no_exceptions \
170        --no_rtti \
171        --remarks \
172        --vfe \
173        $`(uniq_diag_flags $(CCFLAGS_WARNING)) \
174        $`(if $(and $(USE_GNU_EXTENTIONS), $(not $(equal $(config.buildtype), Debug))), --gnu)
175
176    this.CCFLAGS        = $(ccflags_var) $(ccflags_may) $(ccflags_must2) $(ccflags_must1)
177
178    this.CFLAGS         = --c99
179    this.CXXFLAGS       = --cpp
180    this.CSCANFLAGS     = -M --no_depend_system_headers
181    # omake bugzilla #654 --ignore_missing_headers --phony_targets
182
183    #------------------------------------------------------------------------
184    # Demote the following linker warnings to suppresses:
185    #
186    #   L6314W: No section matches pattern
187    #   L6329W: Pattern * only matches removed unused sections
188
189    this.LDFLAGS_WARNING= --diag_suppress L6314W,L6329W
190    this.ASFLAGS        = --cpreproc
191    this.ARFLAGS        = -rcuT
192    this.RANLIB         = echo ranlib
193    this.INCLUDES_OPT   = -I
194    this.YACC           = echo yacc
195    this.LEX            = echo lex
196
197    # Option to generate .map files or call graph files
198    # These are unnecessary when generating a feedback file
199    this.LDFLAGS_INFO   = $`(if $(and $(defined MAPFILE), $(MAPFILE)),\
200                             --list=$(MAPFILE) \
201                             --callgraph_file=$(removesuffix $(MAPFILE))$(EXT_CG) \
202                             --callgraph --callgraph_output=text \
203                             --verbose --map --symbols --xref --unmangled \
204                             --info=$(concat $",",\
205                                            architecture \
206                                            exceptions \
207                                            inline \
208                                            inputs \
209                                            libraries \
210                                            merge \
211                                            sizes \
212                                            stack \
213                                            summarysizes \
214                                            summarystack \
215                                            tailreorder \
216                                            totals \
217                                            unused \
218                                            unusedsymbols \
219                                            veneerpools \
220                                            veneers \
221                                            veneercallers \
222                                            visibility)) \
223
224    private.ldflags_must1   = \
225        $`(if $(not $(EXCLUSION_SCATTER)), --scatter $`(LDSCRIPT)) \
226        --datacompressor off \
227
228    private.ldflags_must2   = \
229        --entry=$`(ENTRYPOINT) \
230        --keep=nnMain \
231        --startup=$`(ENTRYPOINT) \
232
233    private.ldflags_may     = \
234        --debug \
235        --diag_style=$(RVCT_DIAG_STYLE) \
236        --largeregions \
237        --merge \
238        --no_eager_load_debug \
239        --pad 0xFF \
240        --remove \
241        --strict \
242
243    private.ldflags_var     = \
244        --exceptions_tables=nocreate \
245        --no_exceptions \
246        --scanlib \
247        --userlibpath=$`(LIBDIR) \
248        --vfemode=force \
249        $(LDFLAGS_INFO) \
250        $`(LDFLAGS_WARNING) \
251
252    this.LDFLAGS        = $(ldflags_var) $(ldflags_may) $(ldflags_must2) $(ldflags_must1)
253
254    this.LDRESP         = --via
255    this.CCOUT          = -o
256    this.LDOUT          = -o
257    this.ASOUT          = -o
258
259
260
261
262    #----------------------------------------------------------------------------
263    # Function definitions
264    #----------------------------------------------------------------------------
265
266    #-------------------------------------------------------
267    # New.
268    #
269    # Overview
270    #   |
271    #
272    # Global variable that is referenced
273    #   None.
274    #-------------------------------------------------------
275    new() =
276        return $(this)
277
278    #-------------------------------------------------------
279    # getLDFlagsDebug
280    #
281    # Overview
282    #   |
283    #
284    # Global variable that is referenced
285    #   None.
286    #-------------------------------------------------------
287    getLDFlagsDebug(config) =
288        switch($(config.buildtype))
289        case $"Debug"
290            return --bestdebug
291        case $"Development"
292            return --bestdebug
293        case $"Release"
294            return --no_bestdebug --inline --tailreorder
295        return
296
297    #-------------------------------------------------------
298    # getCCFlagsCPU
299    #
300    # Overview
301    #   |
302    #
303    # Global variable that is referenced
304    #   None.
305    #-------------------------------------------------------
306    getCCFlagsCPU(config) =
307        private.flags =
308            switch($(config.processor))
309            case MPCore
310                value --cpu MPCore
311            case ARM946ES
312                value --cpu ARM946E-S
313            case ARM7TDMI
314                value --cpu ARM7TDMI
315
316        switch($(config.effort))
317        case fast
318            return $(flags) --arm
319        case small
320            return $(flags) --thumb
321
322    #-------------------------------------------------------
323    # getASFlagsCPU
324    #
325    # Overview
326    #   |
327    #
328    # Global variable that is referenced
329    #   None.
330    #-------------------------------------------------------
331    getASFlagsCPU(config) =
332        private.flags =
333            switch($(config.processor))
334            case MPCore
335                value --cpu MPCore
336            case ARM946ES
337                value --cpu ARM946E-S
338            case ARM7TDMI
339                value --cpu ARM7TDMI
340
341        return $(flags) --arm
342
343    #-------------------------------------------------------
344    # getCCFlagsLtcg
345    #
346    # Overview
347    #   |
348    #
349    # Global variable that is referenced
350    #   None.
351    #-------------------------------------------------------
352    getCCFlagsLtcg(config) =
353        if $(and $(not $(equal $(config.systemname),Process)),$(equal $(config.buildtype),Release))
354            return $(EMPTY)  #--ltcg
355        else
356            return $(EMPTY)
357
358    #-------------------------------------------------------
359    # getLDFlagsLtcg
360    #
361    # Overview
362    #   |
363    #
364    # Global variable that is referenced
365    #   None.
366    #-------------------------------------------------------
367    getLDFlagsLtcg(config) =
368        if $(and $(not $(equal $(config.systemname),Process)),$(equal $(config.buildtype),Release))
369            return $(EMPTY)  #--ltcg
370        else
371            return $(EMPTY)
372
373    #-------------------------------------------------------
374    # getMacroFlags
375    #
376    # Overview
377    #   |
378    #
379    # Global variable that is referenced
380    #   None.
381    #-------------------------------------------------------
382    getMacroFlags(config) =
383        private.flags = -DNN_COMPILER_RVCT -DNN_COMPILER_RVCT_VERSION_MAJOR=4 -DNN_COMPILER_RVCT_VERSION_MINOR=0
384        flags += $(config.getMacroFlags)
385        flags += $(Compiler::getMacroFlags $(config))
386
387        switch($(config.effort))
388        case fast
389            flags += -DNN_COMPILER_OPTION_ARM
390            export flags
391
392        return $(flags)
393
394
395
396
397#----------------------------------------------------------------------------
398# Function definitions
399#----------------------------------------------------------------------------
400
401#-------------------------------------------------------
402# uniq_diag_flags
403#
404# Overview
405#   |
406#
407# Global variable that is referenced
408#   None.
409#-------------------------------------------------------
410uniq_diag_flags(flags) =
411    private.flags = $(gsub $(flags), $' +', $' ')
412    private.numbers_map = $(Map)
413    lex($(open-in-string $(flags)))
414    default
415        # empty
416    case $'\(A?[[:digit:]]+W?\)' g
417        private.count = 1
418        if $(numbers_map.mem $0)
419            count = $(add $(numbers_map.find $0), 1)
420            export count
421        numbers_map = $(numbers_map.add $0, $(count))
422        export numbers_map
423
424    private.outstr = $(EMPTY)
425    lex($(open-in-string $(flags)))
426    case $'\(A?[[:digit:]]+W?\)\(,| |$\)' g
427        export outstr numbers_map
428        private.count = $(numbers_map.find $1)
429        if $(gt $(count), 1)
430            if $(equal $2,$" ")
431                outstr += $2
432        else
433            outstr += $(0)
434        numbers_map = $(numbers_map.add $1, $(sub $(count), 1))
435    default
436        outstr += $0
437        export outstr
438
439    private.flags_tmp = $(split $' ', $(concat $(EMPTY), $(outstr)))
440    private.flags =
441        foreach(flag, $(flags_tmp))
442            value $(flag)
443
444    flags = $(gsub $(concat $" ",$(flags)), $', ', $' ')
445
446    # If there is an empty option such as '--diag_warning   --diag_suppress', an error occurs, so it is removed
447    #
448    flags = $(gsub $(flags), $'(--diag_(suppress|error|warning)[[:space:]]*)+--', $'--')
449    flags = $(gsub $(flags), $'--diag_(suppress|error|warning)[[:space:]]*$', $(EMPTY))
450
451    return $(flags)
452
453
454
455