21
21
22
22
from tools .targets import CORE_ARCH
23
23
from tools .toolchains .mbed_toolchain import mbedToolchain , TOOLCHAIN_PATHS
24
- from tools .utils import run_cmd , NotSupportedException
24
+ from tools .utils import run_cmd
25
+
25
26
26
27
class IAR (mbedToolchain ):
27
28
OFFICIALLY_SUPPORTED = True
@@ -30,20 +31,29 @@ class IAR(mbedToolchain):
30
31
STD_LIB_NAME = "%s.a"
31
32
32
33
DIAGNOSTIC_PATTERN = re .compile ('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error|Fatal error)(?P<message>.+)' )
33
- INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
34
+ INDEX_PATTERN = re .compile ('(?P<col>\s*)\^' )
34
35
IAR_VERSION_RE = re .compile (b"IAR ANSI C/C\+\+ Compiler V(\d+\.\d+)" )
35
36
IAR_VERSION = LooseVersion ("8.32" )
36
37
37
38
@staticmethod
38
39
def check_executable ():
39
40
"""Returns True if the executable (arm-none-eabi-gcc) location
40
- specified by the user exists OR the executable can be found on the PATH.
41
- Returns False otherwise."""
42
- return mbedToolchain .generic_check_executable ("IAR" , 'iccarm' , 2 , "bin" )
41
+ specified by the user exists OR the executable can be found on the
42
+ PATH. Returns False otherwise."""
43
+ return mbedToolchain .generic_check_executable (
44
+ "IAR" , 'iccarm' , 2 , "bin"
45
+ )
43
46
44
47
def __init__ (self , target , notify = None , macros = None , build_profile = None ,
45
48
build_dir = None ):
46
- mbedToolchain .__init__ (self , target , notify , macros , build_dir = build_dir , build_profile = build_profile )
49
+ mbedToolchain .__init__ (
50
+ self ,
51
+ target ,
52
+ notify ,
53
+ macros ,
54
+ build_dir = build_dir ,
55
+ build_profile = build_profile
56
+ )
47
57
core = target .core
48
58
if CORE_ARCH [target .core ] == 8 :
49
59
# Add linking time preprocessor macro DOMAIN_NS
@@ -65,8 +75,8 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
65
75
"Cortex-M33F" : "Cortex-M33.fp.no_dsp" ,
66
76
"Cortex-M33FE" : "Cortex-M33.fp" }.get (core , core )
67
77
68
- # flags_cmd are used only by our scripts, the project files have them already defined,
69
- # using this flags results in the errors (duplication)
78
+ # flags_cmd are used only by our scripts, the project files have them
79
+ # already defined, using this flags results in the errors (duplication)
70
80
# asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core
71
81
asm_flags_cmd = ["--cpu" , cpu ]
72
82
# custom c flags
@@ -83,13 +93,22 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
83
93
IAR_BIN = join (TOOLCHAIN_PATHS ['IAR' ], "bin" )
84
94
main_cc = join (IAR_BIN , "iccarm" )
85
95
86
- self .asm = [join (IAR_BIN , "iasmarm" )] + asm_flags_cmd + self .flags ["asm" ]
87
- self .cc = [main_cc ]
96
+ self .asm = [join (IAR_BIN , "iasmarm" )]
97
+ self .asm += asm_flags_cmd
98
+ self .asm += self .flags ["asm" ]
99
+
100
+ self .cc = [main_cc ]
101
+ self .cc += self .flags ["common" ]
102
+ self .cc += c_flags_cmd
103
+ self .cc += self .flags ["c" ]
104
+
88
105
self .cppc = [main_cc ]
89
- self .cc += self .flags ["common" ] + c_flags_cmd + self .flags ["c" ]
90
- self .cppc += self .flags ["common" ] + c_flags_cmd + cxx_flags_cmd + self .flags ["cxx" ]
91
-
92
- self .ld = [join (IAR_BIN , "ilinkarm" )] + self .flags ['ld' ]
106
+ self .cppc += self .flags ["common" ]
107
+ self .cppc += c_flags_cmd
108
+ self .cppc += cxx_flags_cmd
109
+ self .cppc += self .flags ["cxx" ]
110
+
111
+ self .ld = [join (IAR_BIN , "ilinkarm" )] + self .flags ['ld' ]
93
112
self .ar = join (IAR_BIN , "iarchive" )
94
113
self .elf2bin = join (IAR_BIN , "ielftool" )
95
114
@@ -113,10 +132,16 @@ def version_check(self):
113
132
"severity" : "Warning" ,
114
133
})
115
134
135
+ def _inner_parse_deps (self , dep_path ):
136
+ for path in open (dep_path ).readlines ():
137
+ if path and not path .isspace ():
138
+ if self .CHROOT :
139
+ yield self .CHROOT + path .strip ()
140
+ else :
141
+ yield path .strip ()
116
142
117
143
def parse_dependencies (self , dep_path ):
118
- return [(self .CHROOT if self .CHROOT else '' )+ path .strip () for path in open (dep_path ).readlines ()
119
- if (path and not path .isspace ())]
144
+ return list (self ._inner_parse_deps (dep_path ))
120
145
121
146
def parse_output (self , output ):
122
147
msg = None
@@ -137,7 +162,8 @@ def parse_output(self, output):
137
162
'toolchain_name' : self .name
138
163
}
139
164
elif msg is not None :
140
- # Determine the warning/error column by calculating the ^ position
165
+ # Determine the warning/error column by calculating the '^'
166
+ # position
141
167
match = IAR .INDEX_PATTERN .match (line )
142
168
if match is not None :
143
169
msg ['col' ] = len (match .group ('col' ))
@@ -165,7 +191,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
165
191
opts = ['-D%s' % d for d in defines ]
166
192
if for_asm :
167
193
config_macros = self .config .get_config_data_macros ()
168
- macros_cmd = ['"-D%s"' % d for d in config_macros if not '"' in d ]
194
+ macros_cmd = ['"-D%s"' % d for d in config_macros if '"' not in d ]
169
195
if self .RESPONSE_FILES :
170
196
via_file = self .make_option_file (
171
197
macros_cmd , "asm_macros_{}.xcl" )
@@ -186,21 +212,19 @@ def get_compile_options(self, defines, includes, for_asm=False):
186
212
187
213
def assemble (self , source , object , includes ):
188
214
# Build assemble command
189
- cmd = self .asm + self .get_compile_options (self .get_symbols (True ), includes , True ) + ["-o" , object , source ]
215
+ cmd = self .asm + self .get_compile_options (
216
+ self .get_symbols (True ), includes , True
217
+ ) + ["-o" , object , source ]
190
218
191
219
# Return command array, don't execute
192
220
return [cmd ]
193
221
194
222
def compile (self , cc , source , object , includes ):
195
223
# Build compile command
196
- cmd = cc + self .get_compile_options (self .get_symbols (), includes )
197
-
224
+ cmd = cc + self .get_compile_options (self .get_symbols (), includes )
198
225
cmd .extend (self .get_dep_option (object ))
199
-
200
226
cmd .extend (self .cc_extra (object ))
201
-
202
227
cmd .extend (["-o" , object , source ])
203
-
204
228
return [cmd ]
205
229
206
230
def compile_c (self , source , object , includes ):
@@ -212,7 +236,9 @@ def compile_cpp(self, source, object, includes):
212
236
def link (self , output , objects , libraries , lib_dirs , mem_map ):
213
237
# Build linker command
214
238
map_file = splitext (output )[0 ] + ".map"
215
- cmd = self .ld + [ "-o" , output , "--map=%s" % map_file ] + objects + libraries
239
+ cmd = self .ld + ["-o" , output , "--map=%s" % map_file ]
240
+ cmd += objects
241
+ cmd += libraries
216
242
217
243
if mem_map :
218
244
cmd .extend (["--config" , mem_map ])
0 commit comments