Clone of official tools

Committer:
screamer
Date:
Fri May 20 22:56:45 2016 +0100
Revision:
5:f45a4ca92830
Parent:
2:07730b0f452c
Child:
7:5af61d55adbe
Fixed ARMCC compile error and re-activate ARM_STD and ARM_MICRO profiles

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
screamer 0:66f3b5499f7f 18 from os.path import join, dirname, splitext, basename, exists
screamer 0:66f3b5499f7f 19
screamer 0:66f3b5499f7f 20 from tools.toolchains import mbedToolchain
screamer 0:66f3b5499f7f 21 from tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB, GOANNA_PATH
screamer 0:66f3b5499f7f 22 from tools.hooks import hook_tool
screamer 0:66f3b5499f7f 23 from tools.utils import mkdir
screamer 0:66f3b5499f7f 24
screamer 0:66f3b5499f7f 25 class ARM(mbedToolchain):
screamer 2:07730b0f452c 26 PROFILE = {}
screamer 0:66f3b5499f7f 27 LINKER_EXT = '.sct'
screamer 0:66f3b5499f7f 28 LIBRARY_EXT = '.ar'
screamer 0:66f3b5499f7f 29
screamer 0:66f3b5499f7f 30 STD_LIB_NAME = "%s.ar"
screamer 0:66f3b5499f7f 31 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+)( \(column (?P<column>\d+)\)|): (?P<severity>Warning|Error): (?P<message>.+)')
screamer 0:66f3b5499f7f 32 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
screamer 0:66f3b5499f7f 33
screamer 2:07730b0f452c 34 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None):
screamer 2:07730b0f452c 35 mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile)
screamer 0:66f3b5499f7f 36
screamer 0:66f3b5499f7f 37 if target.core == "Cortex-M0+":
screamer 0:66f3b5499f7f 38 cpu = "Cortex-M0"
screamer 0:66f3b5499f7f 39 elif target.core == "Cortex-M4F":
screamer 0:66f3b5499f7f 40 cpu = "Cortex-M4.fp"
screamer 0:66f3b5499f7f 41 elif target.core == "Cortex-M7F":
screamer 0:66f3b5499f7f 42 cpu = "Cortex-M7.fp.sp"
screamer 0:66f3b5499f7f 43 else:
screamer 0:66f3b5499f7f 44 cpu = target.core
screamer 0:66f3b5499f7f 45
screamer 0:66f3b5499f7f 46 main_cc = join(ARM_BIN, "armcc")
screamer 2:07730b0f452c 47 common = self.PROFILE.get('COMMON_FLAGS', ["-c", "--gnu", "-O3",
screamer 0:66f3b5499f7f 48 "-Otime", "--split_sections", "--apcs=interwork",
screamer 2:07730b0f452c 49 ])
screamer 2:07730b0f452c 50 common.extend(["--cpu=%s" % cpu, "--brief_diagnostics", "--restrict", "--multibyte_chars"])
screamer 2:07730b0f452c 51 common.extend(['-I%s' % ARM_INC])
screamer 0:66f3b5499f7f 52
screamer 0:66f3b5499f7f 53 if "save-asm" in self.options:
screamer 0:66f3b5499f7f 54 common.extend(["--asm", "--interleave"])
screamer 0:66f3b5499f7f 55
screamer 0:66f3b5499f7f 56 if "debug-info" in self.options:
screamer 0:66f3b5499f7f 57 common.append("-O0")
screamer 0:66f3b5499f7f 58 else:
screamer 0:66f3b5499f7f 59 common.append("-O3")
screamer 2:07730b0f452c 60
screamer 0:66f3b5499f7f 61 # add debug symbols for all builds
screamer 0:66f3b5499f7f 62 common.append("-g")
screamer 0:66f3b5499f7f 63
screamer 2:07730b0f452c 64 common_c = self.PROFILE.get('COMMON_C_FLAGS', ["--no_depend_system_headers"]) + ['--md']
screamer 0:66f3b5499f7f 65
screamer 2:07730b0f452c 66 self.asm = [main_cc] + common
screamer 2:07730b0f452c 67 self.cc = [main_cc] + common + common_c + self.PROFILE.get('COMMON_CC_FLAGS', ["--c99"])
screamer 2:07730b0f452c 68 self.cppc = [main_cc] + common + common_c + self.PROFILE.get('COMMON_CPP_FLAGS', ["--cpp", "--no_rtti"])
screamer 5:f45a4ca92830 69 self.ld = [join(ARM_BIN, "armlink")] + self.PROFILE.get('COMMON_LD_FLAGS', [])
screamer 0:66f3b5499f7f 70 self.sys_libs = []
screamer 0:66f3b5499f7f 71
screamer 0:66f3b5499f7f 72 self.ar = join(ARM_BIN, "armar")
screamer 0:66f3b5499f7f 73 self.elf2bin = join(ARM_BIN, "fromelf")
screamer 0:66f3b5499f7f 74
screamer 0:66f3b5499f7f 75 def parse_dependencies(self, dep_path):
screamer 0:66f3b5499f7f 76 dependencies = []
screamer 0:66f3b5499f7f 77 for line in open(dep_path).readlines():
screamer 0:66f3b5499f7f 78 match = ARM.DEP_PATTERN.match(line)
screamer 0:66f3b5499f7f 79 if match is not None:
screamer 0:66f3b5499f7f 80 dependencies.append(match.group('file'))
screamer 0:66f3b5499f7f 81 return dependencies
screamer 0:66f3b5499f7f 82
screamer 0:66f3b5499f7f 83 def parse_output(self, output):
screamer 0:66f3b5499f7f 84 for line in output.splitlines():
screamer 0:66f3b5499f7f 85 match = ARM.DIAGNOSTIC_PATTERN.match(line)
screamer 0:66f3b5499f7f 86 if match is not None:
screamer 0:66f3b5499f7f 87 self.cc_info(
screamer 0:66f3b5499f7f 88 match.group('severity').lower(),
screamer 0:66f3b5499f7f 89 match.group('file'),
screamer 0:66f3b5499f7f 90 match.group('line'),
screamer 0:66f3b5499f7f 91 match.group('message'),
screamer 0:66f3b5499f7f 92 target_name=self.target.name,
screamer 0:66f3b5499f7f 93 toolchain_name=self.name
screamer 0:66f3b5499f7f 94 )
screamer 0:66f3b5499f7f 95 match = self.goanna_parse_line(line)
screamer 0:66f3b5499f7f 96 if match is not None:
screamer 0:66f3b5499f7f 97 self.cc_info(
screamer 0:66f3b5499f7f 98 match.group('severity').lower(),
screamer 0:66f3b5499f7f 99 match.group('file'),
screamer 0:66f3b5499f7f 100 match.group('line'),
screamer 0:66f3b5499f7f 101 match.group('message')
screamer 0:66f3b5499f7f 102 )
screamer 0:66f3b5499f7f 103
screamer 0:66f3b5499f7f 104 def get_dep_option(self, object):
screamer 0:66f3b5499f7f 105 base, _ = splitext(object)
screamer 0:66f3b5499f7f 106 dep_path = base + '.d'
screamer 0:66f3b5499f7f 107 return ["--depend", dep_path]
screamer 0:66f3b5499f7f 108
screamer 0:66f3b5499f7f 109 def get_compile_options(self, defines, includes):
screamer 0:66f3b5499f7f 110 return ['-D%s' % d for d in defines] + ['--via', self.get_inc_file(includes)]
screamer 0:66f3b5499f7f 111
screamer 0:66f3b5499f7f 112 @hook_tool
screamer 0:66f3b5499f7f 113 def assemble(self, source, object, includes):
screamer 0:66f3b5499f7f 114 # Preprocess first, then assemble
screamer 0:66f3b5499f7f 115 dir = join(dirname(object), '.temp')
screamer 0:66f3b5499f7f 116 mkdir(dir)
screamer 0:66f3b5499f7f 117 tempfile = join(dir, basename(object) + '.E.s')
screamer 0:66f3b5499f7f 118
screamer 0:66f3b5499f7f 119 # Build preprocess assemble command
screamer 0:66f3b5499f7f 120 cmd_pre = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-E", "-o", tempfile, source]
screamer 0:66f3b5499f7f 121
screamer 0:66f3b5499f7f 122 # Build main assemble command
screamer 0:66f3b5499f7f 123 cmd = self.asm + ["-o", object, tempfile]
screamer 0:66f3b5499f7f 124
screamer 0:66f3b5499f7f 125 # Call cmdline hook
screamer 0:66f3b5499f7f 126 cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
screamer 0:66f3b5499f7f 127 cmd = self.hook.get_cmdline_assembler(cmd)
screamer 0:66f3b5499f7f 128
screamer 0:66f3b5499f7f 129 # Return command array, don't execute
screamer 0:66f3b5499f7f 130 return [cmd_pre, cmd]
screamer 0:66f3b5499f7f 131
screamer 0:66f3b5499f7f 132 @hook_tool
screamer 0:66f3b5499f7f 133 def compile(self, cc, source, object, includes):
screamer 0:66f3b5499f7f 134 # Build compile command
screamer 0:66f3b5499f7f 135 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
screamer 0:66f3b5499f7f 136
screamer 0:66f3b5499f7f 137 cmd.extend(self.get_dep_option(object))
screamer 0:66f3b5499f7f 138
screamer 0:66f3b5499f7f 139 cmd.extend(["-o", object, source])
screamer 0:66f3b5499f7f 140
screamer 0:66f3b5499f7f 141 # Call cmdline hook
screamer 0:66f3b5499f7f 142 cmd = self.hook.get_cmdline_compiler(cmd)
screamer 0:66f3b5499f7f 143
screamer 0:66f3b5499f7f 144 return [cmd]
screamer 0:66f3b5499f7f 145
screamer 0:66f3b5499f7f 146 def compile_c(self, source, object, includes):
screamer 0:66f3b5499f7f 147 return self.compile(self.cc, source, object, includes)
screamer 0:66f3b5499f7f 148
screamer 0:66f3b5499f7f 149 def compile_cpp(self, source, object, includes):
screamer 0:66f3b5499f7f 150 return self.compile(self.cppc, source, object, includes)
screamer 0:66f3b5499f7f 151
screamer 0:66f3b5499f7f 152 @hook_tool
screamer 0:66f3b5499f7f 153 def link(self, output, objects, libraries, lib_dirs, mem_map):
screamer 0:66f3b5499f7f 154 if len(lib_dirs):
screamer 0:66f3b5499f7f 155 args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--list=.link_totals.txt"]
screamer 0:66f3b5499f7f 156 else:
screamer 0:66f3b5499f7f 157 args = ["-o", output, "--info=totals", "--list=.link_totals.txt"]
screamer 0:66f3b5499f7f 158
screamer 0:66f3b5499f7f 159 if mem_map:
screamer 0:66f3b5499f7f 160 args.extend(["--scatter", mem_map])
screamer 0:66f3b5499f7f 161
screamer 0:66f3b5499f7f 162 # Build linker command
screamer 0:66f3b5499f7f 163 cmd = self.ld + args + objects + libraries + self.sys_libs
screamer 0:66f3b5499f7f 164
screamer 0:66f3b5499f7f 165 # Call cmdline hook
screamer 0:66f3b5499f7f 166 cmd = self.hook.get_cmdline_linker(cmd)
screamer 0:66f3b5499f7f 167
screamer 0:66f3b5499f7f 168 # Split link command to linker executable + response file
screamer 0:66f3b5499f7f 169 link_files = join(dirname(output), ".link_files.txt")
screamer 0:66f3b5499f7f 170 with open(link_files, "wb") as f:
screamer 0:66f3b5499f7f 171 cmd_linker = cmd[0]
screamer 0:66f3b5499f7f 172 cmd_list = []
screamer 0:66f3b5499f7f 173 for c in cmd[1:]:
screamer 0:66f3b5499f7f 174 if c:
screamer 0:66f3b5499f7f 175 cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
screamer 0:66f3b5499f7f 176 string = " ".join(cmd_list).replace("\\", "/")
screamer 0:66f3b5499f7f 177 f.write(string)
screamer 0:66f3b5499f7f 178
screamer 0:66f3b5499f7f 179 # Exec command
screamer 0:66f3b5499f7f 180 self.default_cmd([cmd_linker, '--via', link_files])
screamer 0:66f3b5499f7f 181
screamer 0:66f3b5499f7f 182 @hook_tool
screamer 0:66f3b5499f7f 183 def archive(self, objects, lib_path):
screamer 0:66f3b5499f7f 184 archive_files = join(dirname(lib_path), ".archive_files.txt")
screamer 0:66f3b5499f7f 185 with open(archive_files, "wb") as f:
screamer 0:66f3b5499f7f 186 o_list = []
screamer 0:66f3b5499f7f 187 for o in objects:
screamer 0:66f3b5499f7f 188 o_list.append('"%s"' % o)
screamer 0:66f3b5499f7f 189 string = " ".join(o_list).replace("\\", "/")
screamer 0:66f3b5499f7f 190 f.write(string)
screamer 0:66f3b5499f7f 191
screamer 0:66f3b5499f7f 192 # Exec command
screamer 0:66f3b5499f7f 193 self.default_cmd([self.ar, '-r', lib_path, '--via', archive_files])
screamer 0:66f3b5499f7f 194
screamer 0:66f3b5499f7f 195 @hook_tool
screamer 0:66f3b5499f7f 196 def binary(self, resources, elf, bin):
screamer 0:66f3b5499f7f 197 # Build binary command
screamer 0:66f3b5499f7f 198 cmd = [self.elf2bin, '--bin', '-o', bin, elf]
screamer 0:66f3b5499f7f 199
screamer 0:66f3b5499f7f 200 # Call cmdline hook
screamer 0:66f3b5499f7f 201 cmd = self.hook.get_cmdline_binary(cmd)
screamer 0:66f3b5499f7f 202
screamer 0:66f3b5499f7f 203 # Exec command
screamer 0:66f3b5499f7f 204 self.default_cmd(cmd)
screamer 0:66f3b5499f7f 205
screamer 0:66f3b5499f7f 206
screamer 0:66f3b5499f7f 207 class ARM_STD(ARM):
screamer 2:07730b0f452c 208 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None):
screamer 2:07730b0f452c 209 ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile)
screamer 0:66f3b5499f7f 210 self.cc += ["-D__ASSERT_MSG"]
screamer 0:66f3b5499f7f 211 self.cppc += ["-D__ASSERT_MSG"]
screamer 0:66f3b5499f7f 212 self.ld.extend(["--libpath", ARM_LIB])
screamer 0:66f3b5499f7f 213
screamer 0:66f3b5499f7f 214
screamer 0:66f3b5499f7f 215 class ARM_MICRO(ARM):
screamer 0:66f3b5499f7f 216 PATCHED_LIBRARY = False
screamer 0:66f3b5499f7f 217
screamer 2:07730b0f452c 218 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None):
screamer 2:07730b0f452c 219 ARM.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile)
screamer 0:66f3b5499f7f 220
screamer 0:66f3b5499f7f 221 # Compiler
screamer 0:66f3b5499f7f 222 self.asm += ["-D__MICROLIB"]
screamer 0:66f3b5499f7f 223 self.cc += ["--library_type=microlib", "-D__MICROLIB", "-D__ASSERT_MSG"]
screamer 0:66f3b5499f7f 224 self.cppc += ["--library_type=microlib", "-D__MICROLIB", "-D__ASSERT_MSG"]
screamer 0:66f3b5499f7f 225
screamer 0:66f3b5499f7f 226 # Linker
screamer 0:66f3b5499f7f 227 self.ld.append("--library_type=microlib")
screamer 0:66f3b5499f7f 228
screamer 0:66f3b5499f7f 229 # We had to patch microlib to add C++ support
screamer 0:66f3b5499f7f 230 # In later releases this patch should have entered mainline
screamer 0:66f3b5499f7f 231 if ARM_MICRO.PATCHED_LIBRARY:
screamer 0:66f3b5499f7f 232 self.ld.append("--noscanlib")
screamer 0:66f3b5499f7f 233
screamer 0:66f3b5499f7f 234 # System Libraries
screamer 0:66f3b5499f7f 235 self.sys_libs.extend([join(MY_ARM_CLIB, lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
screamer 0:66f3b5499f7f 236
screamer 0:66f3b5499f7f 237 if target.core == "Cortex-M3":
screamer 0:66f3b5499f7f 238 self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
screamer 0:66f3b5499f7f 239
screamer 0:66f3b5499f7f 240 elif target.core in ["Cortex-M0", "Cortex-M0+"]:
screamer 0:66f3b5499f7f 241 self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
screamer 0:66f3b5499f7f 242 else:
screamer 0:66f3b5499f7f 243 self.ld.extend(["--libpath", ARM_LIB])