Clone of official tools

Committer:
theotherjimmy
Date:
Mon Nov 06 13:17:14 2017 -0600
Revision:
42:2cf3f29fece1
Parent:
41:2a77626a4c21
Child:
43:2a7da56ebd24
Update tools to 5.6.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:66f3b5499f7f 1 """
screamer 0:66f3b5499f7f 2 mbed SDK
screamer 0:66f3b5499f7f 3 Copyright (c) 2011-2013 ARM Limited
screamer 0:66f3b5499f7f 4
screamer 0:66f3b5499f7f 5 Licensed under the Apache License, Version 2.0 (the "License");
screamer 0:66f3b5499f7f 6 you may not use this file except in compliance with the License.
screamer 0:66f3b5499f7f 7 You may obtain a copy of the License at
screamer 0:66f3b5499f7f 8
screamer 0:66f3b5499f7f 9 http://www.apache.org/licenses/LICENSE-2.0
screamer 0:66f3b5499f7f 10
screamer 0:66f3b5499f7f 11 Unless required by applicable law or agreed to in writing, software
screamer 0:66f3b5499f7f 12 distributed under the License is distributed on an "AS IS" BASIS,
screamer 0:66f3b5499f7f 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
screamer 0:66f3b5499f7f 14 See the License for the specific language governing permissions and
screamer 0:66f3b5499f7f 15 limitations under the License.
screamer 0:66f3b5499f7f 16 """
screamer 0:66f3b5499f7f 17 import re
theotherjimmy 40:7d3fa6b99b2b 18 from copy import copy
The Other Jimmy 36:96847d42f010 19 from os.path import join, dirname, splitext, basename, exists
The Other Jimmy 36:96847d42f010 20 from os import makedirs, write
The Other Jimmy 36:96847d42f010 21 from tempfile import mkstemp
screamer 0:66f3b5499f7f 22
screamer 20:835f6355470d 23 from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS
screamer 0:66f3b5499f7f 24 from tools.hooks import hook_tool
theotherjimmy 40:7d3fa6b99b2b 25 from tools.utils import mkdir, NotSupportedException
screamer 0:66f3b5499f7f 26
screamer 0:66f3b5499f7f 27 class ARM(mbedToolchain):
screamer 0:66f3b5499f7f 28 LINKER_EXT = '.sct'
screamer 0:66f3b5499f7f 29 LIBRARY_EXT = '.ar'
screamer 0:66f3b5499f7f 30
screamer 0:66f3b5499f7f 31 STD_LIB_NAME = "%s.ar"
The Other Jimmy 35:da9c89f8be7d 32 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error|Fatal error): (?P<message>.+)')
screamer 21:4fdf0dd04f6f 33 INDEX_PATTERN = re.compile('(?P<col>\s*)\^')
screamer 0:66f3b5499f7f 34 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
theotherjimmy 40:7d3fa6b99b2b 35 SHEBANG = "#! armcc -E"
theotherjimmy 42:2cf3f29fece1 36 SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
theotherjimmy 42:2cf3f29fece1 37 "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD"]
screamer 0:66f3b5499f7f 38
The Other Jimmy 31:8ea194f6145b 39 @staticmethod
The Other Jimmy 31:8ea194f6145b 40 def check_executable():
The Other Jimmy 31:8ea194f6145b 41 """Returns True if the executable (armcc) location specified by the
The Other Jimmy 31:8ea194f6145b 42 user exists OR the executable can be found on the PATH.
The Other Jimmy 31:8ea194f6145b 43 Returns False otherwise."""
The Other Jimmy 31:8ea194f6145b 44 return mbedToolchain.generic_check_executable("ARM", 'armcc', 2, 'bin')
screamer 13:ab47a20b66f0 45
The Other Jimmy 31:8ea194f6145b 46 def __init__(self, target, notify=None, macros=None,
The Other Jimmy 36:96847d42f010 47 silent=False, extra_verbose=False, build_profile=None,
The Other Jimmy 36:96847d42f010 48 build_dir=None):
The Other Jimmy 31:8ea194f6145b 49 mbedToolchain.__init__(self, target, notify, macros, silent,
The Other Jimmy 36:96847d42f010 50 build_dir=build_dir,
The Other Jimmy 31:8ea194f6145b 51 extra_verbose=extra_verbose,
The Other Jimmy 31:8ea194f6145b 52 build_profile=build_profile)
theotherjimmy 42:2cf3f29fece1 53 if target.core not in self.SUPPORTED_CORES:
theotherjimmy 42:2cf3f29fece1 54 raise NotSupportedException(
theotherjimmy 42:2cf3f29fece1 55 "this compiler does not support the core %s" % target.core)
screamer 0:66f3b5499f7f 56
screamer 0:66f3b5499f7f 57 if target.core == "Cortex-M0+":
screamer 0:66f3b5499f7f 58 cpu = "Cortex-M0"
screamer 0:66f3b5499f7f 59 elif target.core == "Cortex-M4F":
screamer 0:66f3b5499f7f 60 cpu = "Cortex-M4.fp"
screamer 13:ab47a20b66f0 61 elif target.core == "Cortex-M7FD":
screamer 13:ab47a20b66f0 62 cpu = "Cortex-M7.fp.dp"
screamer 0:66f3b5499f7f 63 elif target.core == "Cortex-M7F":
screamer 0:66f3b5499f7f 64 cpu = "Cortex-M7.fp.sp"
screamer 0:66f3b5499f7f 65 else:
screamer 0:66f3b5499f7f 66 cpu = target.core
screamer 0:66f3b5499f7f 67
screamer 20:835f6355470d 68 ARM_BIN = join(TOOLCHAIN_PATHS['ARM'], "bin")
screamer 20:835f6355470d 69 ARM_INC = join(TOOLCHAIN_PATHS['ARM'], "include")
screamer 20:835f6355470d 70
screamer 0:66f3b5499f7f 71 main_cc = join(ARM_BIN, "armcc")
screamer 0:66f3b5499f7f 72
screamer 13:ab47a20b66f0 73 self.flags['common'] += ["--cpu=%s" % cpu]
screamer 0:66f3b5499f7f 74
The Other Jimmy 31:8ea194f6145b 75 self.asm = [main_cc] + self.flags['common'] + self.flags['asm']
The Other Jimmy 31:8ea194f6145b 76 self.cc = [main_cc] + self.flags['common'] + self.flags['c']
The Other Jimmy 31:8ea194f6145b 77 self.cppc = [main_cc] + self.flags['common'] + self.flags['c'] + self.flags['cxx']
screamer 0:66f3b5499f7f 78
theotherjimmy 40:7d3fa6b99b2b 79 self.ld = [join(ARM_BIN, "armlink")] + self.flags['ld']
screamer 0:66f3b5499f7f 80
screamer 0:66f3b5499f7f 81 self.ar = join(ARM_BIN, "armar")
screamer 0:66f3b5499f7f 82 self.elf2bin = join(ARM_BIN, "fromelf")
screamer 0:66f3b5499f7f 83
screamer 0:66f3b5499f7f 84 def parse_dependencies(self, dep_path):
screamer 0:66f3b5499f7f 85 dependencies = []
screamer 0:66f3b5499f7f 86 for line in open(dep_path).readlines():
screamer 0:66f3b5499f7f 87 match = ARM.DEP_PATTERN.match(line)
screamer 0:66f3b5499f7f 88 if match is not None:
screamer 21:4fdf0dd04f6f 89 #we need to append chroot, because when the .d files are generated the compiler is chrooted
screamer 21:4fdf0dd04f6f 90 dependencies.append((self.CHROOT if self.CHROOT else '') + match.group('file'))
screamer 0:66f3b5499f7f 91 return dependencies
theotherjimmy 40:7d3fa6b99b2b 92
screamer 0:66f3b5499f7f 93 def parse_output(self, output):
screamer 21:4fdf0dd04f6f 94 msg = None
screamer 0:66f3b5499f7f 95 for line in output.splitlines():
screamer 0:66f3b5499f7f 96 match = ARM.DIAGNOSTIC_PATTERN.match(line)
screamer 0:66f3b5499f7f 97 if match is not None:
screamer 21:4fdf0dd04f6f 98 if msg is not None:
screamer 21:4fdf0dd04f6f 99 self.cc_info(msg)
The Other Jimmy 31:8ea194f6145b 100 msg = None
screamer 21:4fdf0dd04f6f 101 msg = {
screamer 21:4fdf0dd04f6f 102 'severity': match.group('severity').lower(),
screamer 21:4fdf0dd04f6f 103 'file': match.group('file'),
screamer 21:4fdf0dd04f6f 104 'line': match.group('line'),
screamer 21:4fdf0dd04f6f 105 'col': match.group('column') if match.group('column') else 0,
screamer 21:4fdf0dd04f6f 106 'message': match.group('message'),
screamer 21:4fdf0dd04f6f 107 'text': '',
screamer 21:4fdf0dd04f6f 108 'target_name': self.target.name,
screamer 21:4fdf0dd04f6f 109 'toolchain_name': self.name
screamer 21:4fdf0dd04f6f 110 }
screamer 21:4fdf0dd04f6f 111 elif msg is not None:
screamer 24:25bff2709c20 112 # Determine the warning/error column by calculating the ^ position
screamer 21:4fdf0dd04f6f 113 match = ARM.INDEX_PATTERN.match(line)
screamer 21:4fdf0dd04f6f 114 if match is not None:
screamer 21:4fdf0dd04f6f 115 msg['col'] = len(match.group('col'))
screamer 21:4fdf0dd04f6f 116 self.cc_info(msg)
screamer 21:4fdf0dd04f6f 117 msg = None
screamer 21:4fdf0dd04f6f 118 else:
screamer 21:4fdf0dd04f6f 119 msg['text'] += line+"\n"
screamer 21:4fdf0dd04f6f 120
screamer 21:4fdf0dd04f6f 121 if msg is not None:
screamer 21:4fdf0dd04f6f 122 self.cc_info(msg)
screamer 0:66f3b5499f7f 123
screamer 0:66f3b5499f7f 124 def get_dep_option(self, object):
screamer 0:66f3b5499f7f 125 base, _ = splitext(object)
screamer 0:66f3b5499f7f 126 dep_path = base + '.d'
screamer 0:66f3b5499f7f 127 return ["--depend", dep_path]
screamer 0:66f3b5499f7f 128
screamer 20:835f6355470d 129 def get_config_option(self, config_header):
screamer 13:ab47a20b66f0 130 return ['--preinclude=' + config_header]
screamer 13:ab47a20b66f0 131
screamer 29:1210849dba19 132 def get_compile_options(self, defines, includes, for_asm=False):
screamer 21:4fdf0dd04f6f 133 opts = ['-D%s' % d for d in defines]
screamer 21:4fdf0dd04f6f 134 if self.RESPONSE_FILES:
screamer 21:4fdf0dd04f6f 135 opts += ['--via', self.get_inc_file(includes)]
screamer 21:4fdf0dd04f6f 136 else:
screamer 21:4fdf0dd04f6f 137 opts += ["-I%s" % i for i in includes]
screamer 21:4fdf0dd04f6f 138
screamer 29:1210849dba19 139 if not for_asm:
screamer 29:1210849dba19 140 config_header = self.get_config_header()
screamer 29:1210849dba19 141 if config_header is not None:
screamer 29:1210849dba19 142 opts = opts + self.get_config_option(config_header)
screamer 13:ab47a20b66f0 143 return opts
screamer 0:66f3b5499f7f 144
screamer 0:66f3b5499f7f 145 @hook_tool
screamer 0:66f3b5499f7f 146 def assemble(self, source, object, includes):
screamer 0:66f3b5499f7f 147 # Preprocess first, then assemble
screamer 0:66f3b5499f7f 148 dir = join(dirname(object), '.temp')
screamer 0:66f3b5499f7f 149 mkdir(dir)
screamer 0:66f3b5499f7f 150 tempfile = join(dir, basename(object) + '.E.s')
screamer 0:66f3b5499f7f 151
screamer 0:66f3b5499f7f 152 # Build preprocess assemble command
screamer 29:1210849dba19 153 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]
screamer 0:66f3b5499f7f 154
screamer 0:66f3b5499f7f 155 # Build main assemble command
screamer 0:66f3b5499f7f 156 cmd = self.asm + ["-o", object, tempfile]
screamer 0:66f3b5499f7f 157
screamer 0:66f3b5499f7f 158 # Call cmdline hook
screamer 0:66f3b5499f7f 159 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
screamer 0:66f3b5499f7f 160 cmd = self.hook.get_cmdline_assembler(cmd)
screamer 0:66f3b5499f7f 161
screamer 0:66f3b5499f7f 162 # Return command array, don't execute
screamer 0:66f3b5499f7f 163 return [cmd_pre, cmd]
screamer 0:66f3b5499f7f 164
screamer 0:66f3b5499f7f 165 @hook_tool
screamer 0:66f3b5499f7f 166 def compile(self, cc, source, object, includes):
screamer 0:66f3b5499f7f 167 # Build compile command
screamer 0:66f3b5499f7f 168 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
screamer 0:66f3b5499f7f 169
screamer 0:66f3b5499f7f 170 cmd.extend(self.get_dep_option(object))
screamer 0:66f3b5499f7f 171
screamer 0:66f3b5499f7f 172 cmd.extend(["-o", object, source])
screamer 0:66f3b5499f7f 173
screamer 0:66f3b5499f7f 174 # Call cmdline hook
screamer 0:66f3b5499f7f 175 cmd = self.hook.get_cmdline_compiler(cmd)
screamer 0:66f3b5499f7f 176
screamer 0:66f3b5499f7f 177 return [cmd]
screamer 0:66f3b5499f7f 178
screamer 0:66f3b5499f7f 179 def compile_c(self, source, object, includes):
screamer 0:66f3b5499f7f 180 return self.compile(self.cc, source, object, includes)
screamer 0:66f3b5499f7f 181
screamer 0:66f3b5499f7f 182 def compile_cpp(self, source, object, includes):
screamer 0:66f3b5499f7f 183 return self.compile(self.cppc, source, object, includes)
screamer 0:66f3b5499f7f 184
theotherjimmy 40:7d3fa6b99b2b 185 def correct_scatter_shebang(self, scatter_file):
theotherjimmy 40:7d3fa6b99b2b 186 """Correct the shebang at the top of a scatter file.
theotherjimmy 40:7d3fa6b99b2b 187
theotherjimmy 40:7d3fa6b99b2b 188 Positional arguments:
theotherjimmy 40:7d3fa6b99b2b 189 scatter_file -- the scatter file to correct
theotherjimmy 40:7d3fa6b99b2b 190
theotherjimmy 40:7d3fa6b99b2b 191 Return:
theotherjimmy 40:7d3fa6b99b2b 192 The location of the correct scatter file
screamer 0:66f3b5499f7f 193
theotherjimmy 40:7d3fa6b99b2b 194 Side Effects:
theotherjimmy 40:7d3fa6b99b2b 195 This method MAY write a new scatter file to disk
theotherjimmy 40:7d3fa6b99b2b 196 """
theotherjimmy 40:7d3fa6b99b2b 197 with open(scatter_file, "rb") as input:
theotherjimmy 40:7d3fa6b99b2b 198 lines = input.readlines()
theotherjimmy 40:7d3fa6b99b2b 199 if (lines[0].startswith(self.SHEBANG) or
theotherjimmy 40:7d3fa6b99b2b 200 not lines[0].startswith("#!")):
theotherjimmy 40:7d3fa6b99b2b 201 return scatter_file
theotherjimmy 40:7d3fa6b99b2b 202 else:
theotherjimmy 40:7d3fa6b99b2b 203 new_scatter = join(self.build_dir, ".link_script.sct")
theotherjimmy 40:7d3fa6b99b2b 204 if self.need_update(new_scatter, [scatter_file]):
theotherjimmy 40:7d3fa6b99b2b 205 with open(new_scatter, "wb") as out:
theotherjimmy 40:7d3fa6b99b2b 206 out.write(self.SHEBANG)
theotherjimmy 40:7d3fa6b99b2b 207 out.write("\n")
theotherjimmy 40:7d3fa6b99b2b 208 out.write("".join(lines[1:]))
theotherjimmy 40:7d3fa6b99b2b 209 return new_scatter
screamer 0:66f3b5499f7f 210
theotherjimmy 40:7d3fa6b99b2b 211 @hook_tool
theotherjimmy 40:7d3fa6b99b2b 212 def link(self, output, objects, libraries, lib_dirs, scatter_file):
theotherjimmy 40:7d3fa6b99b2b 213 base, _ = splitext(output)
theotherjimmy 40:7d3fa6b99b2b 214 map_file = base + ".map"
theotherjimmy 40:7d3fa6b99b2b 215 args = ["-o", output, "--info=totals", "--map", "--list=%s" % map_file]
theotherjimmy 40:7d3fa6b99b2b 216 args.extend(objects)
theotherjimmy 40:7d3fa6b99b2b 217 args.extend(libraries)
theotherjimmy 40:7d3fa6b99b2b 218 if lib_dirs:
theotherjimmy 40:7d3fa6b99b2b 219 args.extend(["--userlibpath", ",".join(lib_dirs)])
theotherjimmy 40:7d3fa6b99b2b 220 if scatter_file:
theotherjimmy 40:7d3fa6b99b2b 221 new_scatter = self.correct_scatter_shebang(scatter_file)
theotherjimmy 40:7d3fa6b99b2b 222 args.extend(["--scatter", new_scatter])
screamer 0:66f3b5499f7f 223
theotherjimmy 40:7d3fa6b99b2b 224 cmd_pre = self.ld + args
theotherjimmy 40:7d3fa6b99b2b 225 cmd = self.hook.get_cmdline_linker(cmd_pre)
screamer 0:66f3b5499f7f 226
screamer 21:4fdf0dd04f6f 227 if self.RESPONSE_FILES:
screamer 21:4fdf0dd04f6f 228 cmd_linker = cmd[0]
screamer 21:4fdf0dd04f6f 229 link_files = self.get_link_file(cmd[1:])
screamer 21:4fdf0dd04f6f 230 cmd = [cmd_linker, '--via', link_files]
screamer 0:66f3b5499f7f 231
screamer 21:4fdf0dd04f6f 232 self.cc_verbose("Link: %s" % ' '.join(cmd))
screamer 21:4fdf0dd04f6f 233 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 234
screamer 0:66f3b5499f7f 235 @hook_tool
screamer 0:66f3b5499f7f 236 def archive(self, objects, lib_path):
screamer 21:4fdf0dd04f6f 237 if self.RESPONSE_FILES:
screamer 22:9e85236d8716 238 param = ['--via', self.get_arch_file(objects)]
screamer 21:4fdf0dd04f6f 239 else:
screamer 21:4fdf0dd04f6f 240 param = objects
screamer 21:4fdf0dd04f6f 241 self.default_cmd([self.ar, '-r', lib_path] + param)
screamer 0:66f3b5499f7f 242
screamer 0:66f3b5499f7f 243 @hook_tool
screamer 0:66f3b5499f7f 244 def binary(self, resources, elf, bin):
The Other Jimmy 36:96847d42f010 245 _, fmt = splitext(bin)
The Other Jimmy 36:96847d42f010 246 bin_arg = {".bin": "--bin", ".hex": "--i32"}[fmt]
The Other Jimmy 36:96847d42f010 247 cmd = [self.elf2bin, bin_arg, '-o', bin, elf]
screamer 0:66f3b5499f7f 248 cmd = self.hook.get_cmdline_binary(cmd)
screamer 21:4fdf0dd04f6f 249 self.cc_verbose("FromELF: %s" % ' '.join(cmd))
screamer 0:66f3b5499f7f 250 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 251
The Other Jimmy 36:96847d42f010 252 @staticmethod
The Other Jimmy 36:96847d42f010 253 def name_mangle(name):
The Other Jimmy 36:96847d42f010 254 return "_Z%i%sv" % (len(name), name)
The Other Jimmy 36:96847d42f010 255
The Other Jimmy 36:96847d42f010 256 @staticmethod
The Other Jimmy 36:96847d42f010 257 def make_ld_define(name, value):
The Other Jimmy 36:96847d42f010 258 return "--predefine=\"-D%s=0x%x\"" % (name, value)
The Other Jimmy 36:96847d42f010 259
The Other Jimmy 36:96847d42f010 260 @staticmethod
The Other Jimmy 36:96847d42f010 261 def redirect_symbol(source, sync, build_dir):
The Other Jimmy 36:96847d42f010 262 if not exists(build_dir):
The Other Jimmy 36:96847d42f010 263 makedirs(build_dir)
The Other Jimmy 36:96847d42f010 264 handle, filename = mkstemp(prefix=".redirect-symbol.", dir=build_dir)
The Other Jimmy 36:96847d42f010 265 write(handle, "RESOLVE %s AS %s\n" % (source, sync))
The Other Jimmy 36:96847d42f010 266 return "--edit=%s" % filename
The Other Jimmy 36:96847d42f010 267
screamer 0:66f3b5499f7f 268
screamer 0:66f3b5499f7f 269 class ARM_STD(ARM):
theotherjimmy 41:2a77626a4c21 270 def __init__(self, target, notify=None, macros=None,
theotherjimmy 41:2a77626a4c21 271 silent=False, extra_verbose=False, build_profile=None,
theotherjimmy 41:2a77626a4c21 272 build_dir=None):
theotherjimmy 41:2a77626a4c21 273 ARM.__init__(self, target, notify, macros, silent,
theotherjimmy 41:2a77626a4c21 274 build_dir=build_dir, extra_verbose=extra_verbose,
theotherjimmy 41:2a77626a4c21 275 build_profile=build_profile)
theotherjimmy 41:2a77626a4c21 276 if "ARM" not in target.supported_toolchains:
theotherjimmy 41:2a77626a4c21 277 raise NotSupportedException("ARM compiler support is required for ARM build")
theotherjimmy 41:2a77626a4c21 278
screamer 0:66f3b5499f7f 279
screamer 0:66f3b5499f7f 280 class ARM_MICRO(ARM):
screamer 0:66f3b5499f7f 281 PATCHED_LIBRARY = False
theotherjimmy 41:2a77626a4c21 282 def __init__(self, target, notify=None, macros=None,
theotherjimmy 41:2a77626a4c21 283 silent=False, extra_verbose=False, build_profile=None,
theotherjimmy 41:2a77626a4c21 284 build_dir=None):
theotherjimmy 41:2a77626a4c21 285 ARM.__init__(self, target, notify, macros, silent,
theotherjimmy 41:2a77626a4c21 286 build_dir=build_dir, extra_verbose=extra_verbose,
theotherjimmy 41:2a77626a4c21 287 build_profile=build_profile)
theotherjimmy 41:2a77626a4c21 288 if not set(("ARM", "uARM")).intersection(set(target.supported_toolchains)):
theotherjimmy 41:2a77626a4c21 289 raise NotSupportedException("ARM/uARM compiler support is required for ARM build")
theotherjimmy 40:7d3fa6b99b2b 290
theotherjimmy 40:7d3fa6b99b2b 291 class ARMC6(ARM_STD):
theotherjimmy 40:7d3fa6b99b2b 292 SHEBANG = "#! armclang -E --target=arm-arm-none-eabi -x c"
theotherjimmy 42:2cf3f29fece1 293 SUPPORTED_CORES = ["Cortex-M0", "Cortex-M0+", "Cortex-M3", "Cortex-M4",
theotherjimmy 42:2cf3f29fece1 294 "Cortex-M4F", "Cortex-M7", "Cortex-M7F", "Cortex-M7FD",
theotherjimmy 42:2cf3f29fece1 295 "Cortex-M23", "Cortex-M23-NS", "Cortex-M33",
theotherjimmy 42:2cf3f29fece1 296 "CortexM33-NS"]
theotherjimmy 40:7d3fa6b99b2b 297 @staticmethod
theotherjimmy 40:7d3fa6b99b2b 298 def check_executable():
theotherjimmy 40:7d3fa6b99b2b 299 return mbedToolchain.generic_check_executable("ARMC6", "armclang", 1)
theotherjimmy 40:7d3fa6b99b2b 300
theotherjimmy 40:7d3fa6b99b2b 301 def __init__(self, target, *args, **kwargs):
theotherjimmy 40:7d3fa6b99b2b 302 mbedToolchain.__init__(self, target, *args, **kwargs)
theotherjimmy 42:2cf3f29fece1 303 if target.core not in self.SUPPORTED_CORES:
theotherjimmy 42:2cf3f29fece1 304 raise NotSupportedException(
theotherjimmy 42:2cf3f29fece1 305 "this compiler does not support the core %s" % target.core)
theotherjimmy 40:7d3fa6b99b2b 306
theotherjimmy 40:7d3fa6b99b2b 307 if not set(("ARM", "ARMC6")).intersection(set(target.supported_toolchains)):
theotherjimmy 40:7d3fa6b99b2b 308 raise NotSupportedException("ARM/ARMC6 compiler support is required for ARMC6 build")
theotherjimmy 40:7d3fa6b99b2b 309
theotherjimmy 40:7d3fa6b99b2b 310 if target.core.lower().endswith("fd"):
theotherjimmy 40:7d3fa6b99b2b 311 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-2])
theotherjimmy 40:7d3fa6b99b2b 312 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-2])
theotherjimmy 40:7d3fa6b99b2b 313 elif target.core.lower().endswith("f"):
theotherjimmy 40:7d3fa6b99b2b 314 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-1])
theotherjimmy 40:7d3fa6b99b2b 315 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-1])
theotherjimmy 40:7d3fa6b99b2b 316 elif target.core.lower().endswith("ns"):
theotherjimmy 40:7d3fa6b99b2b 317 self.flags['common'].append("-mcpu=%s" % target.core.lower()[:-3])
theotherjimmy 40:7d3fa6b99b2b 318 self.flags['ld'].append("--cpu=%s" % target.core.lower()[:-3])
theotherjimmy 40:7d3fa6b99b2b 319 else:
theotherjimmy 40:7d3fa6b99b2b 320 self.flags['common'].append("-mcpu=%s" % target.core.lower())
theotherjimmy 40:7d3fa6b99b2b 321 self.flags['ld'].append("--cpu=%s" % target.core.lower())
theotherjimmy 40:7d3fa6b99b2b 322
theotherjimmy 40:7d3fa6b99b2b 323 if target.core == "Cortex-M4F":
theotherjimmy 40:7d3fa6b99b2b 324 self.flags['common'].append("-mfpu=fpv4-sp-d16")
theotherjimmy 40:7d3fa6b99b2b 325 self.flags['common'].append("-mfloat-abi=hard")
theotherjimmy 40:7d3fa6b99b2b 326 elif target.core == "Cortex-M7F":
theotherjimmy 40:7d3fa6b99b2b 327 self.flags['common'].append("-mfpu=fpv5-sp-d16")
theotherjimmy 40:7d3fa6b99b2b 328 self.flags['common'].append("-mfloat-abi=softfp")
theotherjimmy 40:7d3fa6b99b2b 329 elif target.core == "Cortex-M7FD":
theotherjimmy 40:7d3fa6b99b2b 330 self.flags['common'].append("-mfpu=fpv5-d16")
theotherjimmy 40:7d3fa6b99b2b 331 self.flags['common'].append("-mfloat-abi=softfp")
theotherjimmy 40:7d3fa6b99b2b 332 elif target.core.startswith("Cortex-M23"):
theotherjimmy 40:7d3fa6b99b2b 333 self.flags['common'].append("-march=armv8-m.base")
theotherjimmy 40:7d3fa6b99b2b 334 elif target.core.startswith("Cortex-M33"):
theotherjimmy 40:7d3fa6b99b2b 335 self.flags['common'].append("-march=armv8-m.main")
theotherjimmy 40:7d3fa6b99b2b 336
theotherjimmy 40:7d3fa6b99b2b 337 if target.core == "Cortex-M23" or target.core == "Cortex-M33":
theotherjimmy 40:7d3fa6b99b2b 338 self.flags['common'].append("-mcmse")
theotherjimmy 40:7d3fa6b99b2b 339
theotherjimmy 40:7d3fa6b99b2b 340 asm_cpu = {
theotherjimmy 40:7d3fa6b99b2b 341 "Cortex-M0+": "Cortex-M0",
theotherjimmy 40:7d3fa6b99b2b 342 "Cortex-M4F": "Cortex-M4.fp",
theotherjimmy 40:7d3fa6b99b2b 343 "Cortex-M7F": "Cortex-M7.fp.sp",
theotherjimmy 40:7d3fa6b99b2b 344 "Cortex-M7FD": "Cortex-M7.fp.dp",
theotherjimmy 40:7d3fa6b99b2b 345 "Cortex-M23-NS": "Cortex-M23",
theotherjimmy 40:7d3fa6b99b2b 346 "Cortex-M33-NS": "Cortex-M33" }.get(target.core, target.core)
theotherjimmy 40:7d3fa6b99b2b 347
theotherjimmy 40:7d3fa6b99b2b 348 self.flags['asm'].append("--cpu=%s" % asm_cpu)
theotherjimmy 40:7d3fa6b99b2b 349
theotherjimmy 40:7d3fa6b99b2b 350 self.cc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
theotherjimmy 40:7d3fa6b99b2b 351 self.flags['common'] + self.flags['c'])
theotherjimmy 40:7d3fa6b99b2b 352 self.cppc = ([join(TOOLCHAIN_PATHS["ARMC6"], "armclang")] +
theotherjimmy 40:7d3fa6b99b2b 353 self.flags['common'] + self.flags['cxx'])
theotherjimmy 40:7d3fa6b99b2b 354 self.asm = [join(TOOLCHAIN_PATHS["ARMC6"], "armasm")] + self.flags['asm']
theotherjimmy 40:7d3fa6b99b2b 355 self.ld = [join(TOOLCHAIN_PATHS["ARMC6"], "armlink")] + self.flags['ld']
theotherjimmy 40:7d3fa6b99b2b 356 self.ar = [join(TOOLCHAIN_PATHS["ARMC6"], "armar")]
theotherjimmy 40:7d3fa6b99b2b 357 self.elf2bin = join(TOOLCHAIN_PATHS["ARMC6"], "fromelf")
theotherjimmy 40:7d3fa6b99b2b 358
theotherjimmy 40:7d3fa6b99b2b 359
theotherjimmy 40:7d3fa6b99b2b 360 def parse_dependencies(self, dep_path):
theotherjimmy 40:7d3fa6b99b2b 361 return mbedToolchain.parse_dependencies(self, dep_path)
theotherjimmy 40:7d3fa6b99b2b 362
theotherjimmy 40:7d3fa6b99b2b 363 def is_not_supported_error(self, output):
theotherjimmy 40:7d3fa6b99b2b 364 return "#error [NOT_SUPPORTED]" in output
theotherjimmy 40:7d3fa6b99b2b 365
theotherjimmy 40:7d3fa6b99b2b 366 def parse_output(self, output):
theotherjimmy 40:7d3fa6b99b2b 367 pass
theotherjimmy 40:7d3fa6b99b2b 368
theotherjimmy 40:7d3fa6b99b2b 369 def get_config_option(self, config_header):
theotherjimmy 40:7d3fa6b99b2b 370 return ["-include", config_header]
theotherjimmy 40:7d3fa6b99b2b 371
theotherjimmy 40:7d3fa6b99b2b 372 def get_compile_options(self, defines, includes, for_asm=False):
theotherjimmy 40:7d3fa6b99b2b 373 opts = ['-D%s' % d for d in defines]
theotherjimmy 40:7d3fa6b99b2b 374 opts.extend(["-I%s" % i for i in includes])
theotherjimmy 40:7d3fa6b99b2b 375 if for_asm:
theotherjimmy 40:7d3fa6b99b2b 376 return ["--cpreproc",
theotherjimmy 40:7d3fa6b99b2b 377 "--cpreproc_opts=%s" % ",".join(self.flags['common'] + opts)]
theotherjimmy 40:7d3fa6b99b2b 378 else:
theotherjimmy 40:7d3fa6b99b2b 379 config_header = self.get_config_header()
theotherjimmy 40:7d3fa6b99b2b 380 if config_header:
theotherjimmy 40:7d3fa6b99b2b 381 opts.extend(self.get_config_option(config_header))
theotherjimmy 40:7d3fa6b99b2b 382 return opts
theotherjimmy 40:7d3fa6b99b2b 383
theotherjimmy 40:7d3fa6b99b2b 384 @hook_tool
theotherjimmy 40:7d3fa6b99b2b 385 def assemble(self, source, object, includes):
theotherjimmy 40:7d3fa6b99b2b 386 cmd_pre = copy(self.asm)
theotherjimmy 40:7d3fa6b99b2b 387 cmd_pre.extend(self.get_compile_options(
theotherjimmy 40:7d3fa6b99b2b 388 self.get_symbols(True), includes, for_asm=True))
theotherjimmy 40:7d3fa6b99b2b 389 cmd_pre.extend(["-o", object, source])
theotherjimmy 40:7d3fa6b99b2b 390 return [self.hook.get_cmdline_assembler(cmd_pre)]
theotherjimmy 40:7d3fa6b99b2b 391
theotherjimmy 40:7d3fa6b99b2b 392 @hook_tool
theotherjimmy 40:7d3fa6b99b2b 393 def compile(self, cc, source, object, includes):
theotherjimmy 40:7d3fa6b99b2b 394 cmd = copy(cc)
theotherjimmy 40:7d3fa6b99b2b 395 cmd.extend(self.get_compile_options(self.get_symbols(), includes))
theotherjimmy 40:7d3fa6b99b2b 396 cmd.extend(["-o", object, source])
theotherjimmy 40:7d3fa6b99b2b 397 cmd = self.hook.get_cmdline_compiler(cmd)
theotherjimmy 40:7d3fa6b99b2b 398 return [cmd]