Skip to content

Commit 4cef2c9

Browse files
authored
Merge pull request #1 from screamerbg/split_symbols
Differentiate ASM and CXX symbols
2 parents a6ffdd4 + 88564a9 commit 4cef2c9

File tree

4 files changed

+60
-48
lines changed

4 files changed

+60
-48
lines changed

tools/toolchains/__init__.py

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ def __init__(self, target, options=None, notify=None, macros=None, silent=False,
230230
self.macros = macros or []
231231

232232
# Macros generated from toolchain and target rules/features
233-
self.symbols = None
233+
self.asm_symbols = None
234+
self.cxx_symbols = None
234235

235236
# Labels generated from toolchain and target rules/features (used for selective build)
236237
self.labels = None
@@ -372,36 +373,50 @@ def notify(self, event):
372373
event['toolchain'] = self
373374
return self.notify_fun(event, self.silent)
374375

375-
def get_symbols(self):
376-
if self.symbols is None:
377-
# Target and Toolchain symbols
378-
labels = self.get_labels()
379-
self.symbols = ["TARGET_%s" % t for t in labels['TARGET']]
380-
self.symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
381-
382-
# Cortex CPU symbols
383-
if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
384-
self.symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
385-
386-
# Symbols defined by the on-line build.system
387-
self.symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
388-
if MBED_ORG_USER:
389-
self.symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
390-
391-
# Add target's symbols
392-
self.symbols += self.target.macros
393-
# Add target's hardware
394-
self.symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
395-
# Add target's features
396-
self.symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
397-
# Add extra symbols passed via 'macros' parameter
398-
self.symbols += self.macros
399-
400-
# Form factor variables
401-
if hasattr(self.target, 'supported_form_factors'):
402-
self.symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
403-
404-
return list(set(self.symbols)) # Return only unique symbols
376+
def get_symbols(self, for_asm=False):
377+
if for_asm:
378+
if self.asm_symbols is None:
379+
self.asm_symbols = []
380+
381+
# Cortex CPU symbols
382+
if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
383+
self.asm_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
384+
385+
# Add target's symbols
386+
self.asm_symbols += self.target.macros
387+
# Add extra symbols passed via 'macros' parameter
388+
self.asm_symbols += self.macros
389+
return list(set(self.asm_symbols)) # Return only unique symbols
390+
else:
391+
if self.cxx_symbols is None:
392+
# Target and Toolchain symbols
393+
labels = self.get_labels()
394+
self.cxx_symbols = ["TARGET_%s" % t for t in labels['TARGET']]
395+
self.cxx_symbols.extend(["TOOLCHAIN_%s" % t for t in labels['TOOLCHAIN']])
396+
397+
# Cortex CPU symbols
398+
if self.target.core in mbedToolchain.CORTEX_SYMBOLS:
399+
self.cxx_symbols.extend(mbedToolchain.CORTEX_SYMBOLS[self.target.core])
400+
401+
# Symbols defined by the on-line build.system
402+
self.cxx_symbols.extend(['MBED_BUILD_TIMESTAMP=%s' % self.timestamp, 'TARGET_LIKE_MBED', '__MBED__=1'])
403+
if MBED_ORG_USER:
404+
self.cxx_symbols.append('MBED_USERNAME=' + MBED_ORG_USER)
405+
406+
# Add target's symbols
407+
self.cxx_symbols += self.target.macros
408+
# Add target's hardware
409+
self.cxx_symbols += ["DEVICE_" + data + "=1" for data in self.target.device_has]
410+
# Add target's features
411+
self.cxx_symbols += ["FEATURE_" + data + "=1" for data in self.target.features]
412+
# Add extra symbols passed via 'macros' parameter
413+
self.cxx_symbols += self.macros
414+
415+
# Form factor variables
416+
if hasattr(self.target, 'supported_form_factors'):
417+
self.cxx_symbols.extend(["TARGET_FF_%s" % t for t in self.target.supported_form_factors])
418+
419+
return list(set(self.cxx_symbols)) # Return only unique symbols
405420

406421
# Extend the internal list of macros
407422
def add_macros(self, new_macros):

tools/toolchains/arm.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,17 @@ def get_dep_option(self, object):
128128
def get_config_option(self, config_header):
129129
return ['--preinclude=' + config_header]
130130

131-
def get_compile_options(self, defines, includes):
131+
def get_compile_options(self, defines, includes, for_asm=False):
132132
opts = ['-D%s' % d for d in defines]
133133
if self.RESPONSE_FILES:
134134
opts += ['--via', self.get_inc_file(includes)]
135135
else:
136136
opts += ["-I%s" % i for i in includes]
137137

138-
config_header = self.get_config_header()
139-
if config_header is not None:
140-
opts = opts + self.get_config_option(config_header)
138+
if not for_asm:
139+
config_header = self.get_config_header()
140+
if config_header is not None:
141+
opts = opts + self.get_config_option(config_header)
141142
return opts
142143

143144
@hook_tool
@@ -148,7 +149,7 @@ def assemble(self, source, object, includes):
148149
tempfile = join(dir, basename(object) + '.E.s')
149150

150151
# Build preprocess assemble command
151-
cmd_pre = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-E", "-o", tempfile, source]
152+
cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
152153

153154
# Build main assemble command
154155
cmd = self.asm + ["-o", object, tempfile]

tools/toolchains/gcc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,23 @@ def get_dep_option(self, object):
170170
def get_config_option(self, config_header):
171171
return ['-include', config_header]
172172

173-
def get_compile_options(self, defines, includes):
173+
def get_compile_options(self, defines, includes, for_asm=False):
174174
opts = ['-D%s' % d for d in defines]
175175
if self.RESPONSE_FILES:
176176
opts += ['@%s' % self.get_inc_file(includes)]
177177
else:
178178
opts += ["-I%s" % i for i in includes]
179179

180-
config_header = self.get_config_header()
181-
if config_header is not None:
182-
opts = opts + self.get_config_option(config_header)
180+
if not for_asm:
181+
config_header = self.get_config_header()
182+
if config_header is not None:
183+
opts = opts + self.get_config_option(config_header)
183184
return opts
184185

185186
@hook_tool
186187
def assemble(self, source, object, includes):
187188
# Build assemble command
188-
cmd = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-o", object, source]
189+
cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-o", object, source]
189190

190191
# Call cmdline hook
191192
cmd = self.hook.get_cmdline_assembler(cmd)

tools/toolchains/iar.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
151151
else:
152152
opts += ["-I%s" % i for i in includes]
153153

154-
config_header = self.get_config_header()
155-
if for_asm:
156-
# The assembler doesn't support '--preinclude', so we need to add
157-
# the macros directly
158-
opts = opts + ['-D%s' % d for d in self.get_config_macros()]
159-
else:
154+
if not for_asm:
160155
config_header = self.get_config_header()
161156
if config_header is not None:
162157
opts = opts + self.get_config_option(config_header)
@@ -165,7 +160,7 @@ def get_compile_options(self, defines, includes, for_asm=False):
165160
@hook_tool
166161
def assemble(self, source, object, includes):
167162
# Build assemble command
168-
cmd = self.asm + self.get_compile_options(self.get_symbols(), includes, for_asm=True) + ["-o", object, source]
163+
cmd = self.asm + self.get_compile_options(self.get_symbols(True), includes, True) + ["-o", object, source]
169164

170165
# Call cmdline hook
171166
cmd = self.hook.get_cmdline_assembler(cmd)

0 commit comments

Comments
 (0)