Skip to content

Commit e3b9def

Browse files
theotherjimmy0xc0170
authored andcommitted
Refactors all toolchains to have flags api
1 parent 3a0d561 commit e3b9def

File tree

4 files changed

+60
-38
lines changed

4 files changed

+60
-38
lines changed

tools/toolchains/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from shutil import copyfile
2525
from os.path import join, splitext, exists, relpath, dirname, basename, split, abspath
2626
from inspect import getmro
27+
from copy import deepcopy
2728

2829
from multiprocessing import Pool, cpu_count
2930
from tools.utils import run_cmd, mkdir, rel_path, ToolException, NotSupportedException, split_path
@@ -242,6 +243,7 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
242243

243244
if 'UVISOR_PRESENT=1' in self.macros:
244245
self.target.core = re.sub(r"F$", '', self.target.core)
246+
self.flags = deepcopy(self.DEFAULT_FLAGS)
245247

246248
def get_output(self):
247249
return self.output

tools/toolchains/arm.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
5656

5757
main_cc = join(ARM_BIN, "armcc")
5858

59-
self.flags = copy.deepcopy(self.DEFAULT_FLAGS)
6059
self.flags['common'] += ["--cpu=%s" % cpu]
6160
if "save-asm" in self.options:
6261
self.flags['common'].extend(["--asm", "--interleave"])

tools/toolchains/gcc.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ class GCC(mbedToolchain):
2929
STD_LIB_NAME = "lib%s.a"
3030
DIAGNOSTIC_PATTERN = re.compile('((?P<file>[^:]+):(?P<line>\d+):)(\d+:)? (?P<severity>warning|error): (?P<message>.+)')
3131

32+
DEFAULT_FLAGS = {
33+
'common': ["-c", "-Wall", "-Wextra",
34+
"-Wno-unused-parameter", "-Wno-missing-field-initializers",
35+
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
36+
"-ffunction-sections", "-fdata-sections",
37+
"-MMD", "-fno-delete-null-pointer-checks", "-fomit-frame-pointer"
38+
],
39+
'asm': ["-x", "assembler-with-cpp"],
40+
'c': ["-std=gnu99"],
41+
'cxx': ["-std=gnu++98", "-fno-rtti"],
42+
'ld': ["-Wl,--gc-sections", "-Wl,--wrap,main",
43+
"-Wl,--wrap,_malloc_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r"],
44+
}
45+
3246
def __init__(self, target, options=None, notify=None, macros=None, silent=False, tool_path="", extra_verbose=False):
3347
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
3448

@@ -63,33 +77,31 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
6377

6478
# Note: We are using "-O2" instead of "-Os" to avoid this known GCC bug:
6579
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46762
66-
common_flags = ["-c", "-Wall", "-Wextra",
67-
"-Wno-unused-parameter", "-Wno-missing-field-initializers",
68-
"-fmessage-length=0", "-fno-exceptions", "-fno-builtin",
69-
"-ffunction-sections", "-fdata-sections",
70-
"-fno-delete-null-pointer-checks", "-fomit-frame-pointer"
71-
] + self.cpu
80+
self.flags["common"] += self.cpu
7281

7382
if "save-asm" in self.options:
74-
common_flags.append("-save-temps")
83+
self.flags["common"].append("-save-temps")
7584

7685
if "debug-info" in self.options:
77-
common_flags.append("-g")
78-
common_flags.append("-O0")
86+
self.flags["common"].append("-g")
87+
self.flags["common"].append("-O0")
7988
else:
80-
common_flags.append("-O2")
89+
self.flags["common"].append("-O2")
8190

8291
main_cc = join(tool_path, "arm-none-eabi-gcc")
8392
main_cppc = join(tool_path, "arm-none-eabi-g++")
84-
self.asm = [main_cc, "-x", "assembler-with-cpp"] + common_flags
93+
self.asm = [main_cc] + self.flags['asm'] + self.flags["common"]
8594
if not "analyze" in self.options:
86-
self.cc = [main_cc, "-std=gnu99"] + common_flags
87-
self.cppc =[main_cppc, "-std=gnu++98", "-fno-rtti"] + common_flags
95+
self.cc = [main_cc]
96+
self.cppc =[main_cppc]
8897
else:
89-
self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "-std=gnu99", "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT] + common_flags
90-
self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cppc.replace('\\', '/'), "-std=gnu++98", "-fno-rtti", "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT] + common_flags
98+
self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT]
99+
self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cppc.replace('\\', '/'), "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT]
100+
self.cc += self.flags['c'] + self.flags['common']
101+
self.cppc += self.flags['cxx'] + self.flags['common']
91102

92-
self.ld = [join(tool_path, "arm-none-eabi-gcc"), "-Wl,--gc-sections", "-Wl,--wrap,main", "-Wl,--wrap,_malloc_r", "-Wl,--wrap,_free_r", "-Wl,--wrap,_realloc_r"] + self.cpu
103+
self.flags['ld'] += self.cpu
104+
self.ld = [join(tool_path, "arm-none-eabi-gcc")] + self.flags['ld']
93105
self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"]
94106

95107
self.ar = join(tool_path, "arm-none-eabi-ar")

tools/toolchains/iar.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,56 @@ class IAR(mbedToolchain):
3030

3131
DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
3232

33+
DEFAULT_FLAGS = {
34+
'common': [
35+
"--no_wrap_diagnostics",
36+
# Pa050: No need to be notified about "non-native end of line sequence"
37+
# Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC).
38+
# Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
39+
# Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
40+
"-e", # Enable IAR language extension
41+
"--diag_suppress=Pa050,Pa084,Pa093,Pa082"],
42+
'asm': [],
43+
'c': [],
44+
'cxx': ["--c++", "--no_rtti", "--no_exceptions", "--guard_calls"],
45+
'ld': [],
46+
}
47+
3348
def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
3449
mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
3550
if target.core == "Cortex-M7F":
3651
cpuchoice = "Cortex-M7"
3752
else:
3853
cpuchoice = target.core
39-
c_flags = [
54+
self.flags["common"] += [
4055
"--cpu=%s" % cpuchoice, "--thumb",
4156
"--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
42-
"-e", # Enable IAR language extension
43-
"--no_wrap_diagnostics",
44-
# Pa050: No need to be notified about "non-native end of line sequence"
45-
# Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC).
46-
# Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
47-
# Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
48-
"--diag_suppress=Pa050,Pa084,Pa093,Pa082",
4957
]
5058

5159
if target.core == "Cortex-M7F":
52-
c_flags.append("--fpu=VFPv5_sp")
53-
60+
self.flags["common"].append("--fpu=VFPv5_sp")
5461

5562
if "debug-info" in self.options:
56-
c_flags.append("-r")
57-
c_flags.append("-On")
63+
self.flags["common"].append("-r")
64+
self.flags["common"].append("-On")
5865
else:
59-
c_flags.append("-Oh")
66+
self.flags["common"].append("-Oh")
6067

6168
IAR_BIN = join(IAR_PATH, "bin")
6269
main_cc = join(IAR_BIN, "iccarm")
63-
70+
71+
self.flags["asm"] += ["--cpu", cpuchoice]
6472
if target.core == "Cortex-M7F":
65-
self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", cpuchoice] + ["--fpu", "VFPv5_sp"]
66-
else:
67-
self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", cpuchoice]
73+
self.flags["asm"] += ["--fpu", "VFPv5_sp"]
74+
self.asm = [join(IAR_BIN, "iasmarm")] + self.flags["asm"]
6875
if not "analyze" in self.options:
69-
self.cc = [main_cc, "--vla"] + c_flags
70-
self.cppc = [main_cc, "--c++", "--no_rtti", "--no_exceptions"] + c_flags
76+
self.cc = [main_cc]
77+
self.cppc = [main_cc]
7178
else:
72-
self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT, "--vla"] + c_flags
73-
self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + ["--c++", "--no_rtti", "--no_exceptions"] + c_flags
79+
self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
80+
self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
81+
self.cc += self.flags["common"] + self.flags["c"]
82+
self.cppc += self.flags["common"] + self.flags["cxx"]
7483
self.ld = join(IAR_BIN, "ilinkarm")
7584
self.ar = join(IAR_BIN, "iarchive")
7685
self.elf2bin = join(IAR_BIN, "ielftool")

0 commit comments

Comments
 (0)