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