Clone of official tools

Committer:
screamer
Date:
Thu Jul 14 20:21:19 2016 +0100
Revision:
13:ab47a20b66f0
Parent:
7:5af61d55adbe
Child:
20:835f6355470d
Apply latest tools

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 import remove
screamer 0:66f3b5499f7f 19 from os.path import join, exists, dirname, splitext, exists
screamer 0:66f3b5499f7f 20
screamer 0:66f3b5499f7f 21 from tools.toolchains import mbedToolchain
screamer 0:66f3b5499f7f 22 from tools.settings import IAR_PATH
screamer 0:66f3b5499f7f 23 from tools.settings import GOANNA_PATH
screamer 0:66f3b5499f7f 24 from tools.hooks import hook_tool
screamer 0:66f3b5499f7f 25
screamer 0:66f3b5499f7f 26 class IAR(mbedToolchain):
screamer 0:66f3b5499f7f 27 LIBRARY_EXT = '.a'
screamer 0:66f3b5499f7f 28 LINKER_EXT = '.icf'
screamer 0:66f3b5499f7f 29 STD_LIB_NAME = "%s.a"
screamer 0:66f3b5499f7f 30
screamer 0:66f3b5499f7f 31 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
screamer 0:66f3b5499f7f 32
screamer 13:ab47a20b66f0 33 DEFAULT_FLAGS = {
screamer 13:ab47a20b66f0 34 'common': [
screamer 0:66f3b5499f7f 35 "--no_wrap_diagnostics",
screamer 0:66f3b5499f7f 36 # Pa050: No need to be notified about "non-native end of line sequence"
screamer 0:66f3b5499f7f 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).
screamer 0:66f3b5499f7f 38 # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
screamer 0:66f3b5499f7f 39 # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
screamer 13:ab47a20b66f0 40 "-e", # Enable IAR language extension
screamer 13:ab47a20b66f0 41 "--diag_suppress=Pa050,Pa084,Pa093,Pa082"],
screamer 13:ab47a20b66f0 42 'asm': [],
screamer 13:ab47a20b66f0 43 'c': ["--vla"],
screamer 13:ab47a20b66f0 44 'cxx': ["--guard_calls"],
screamer 13:ab47a20b66f0 45 'ld': ["--skip_dynamic_initialization", "--threaded_lib"],
screamer 13:ab47a20b66f0 46 }
screamer 0:66f3b5499f7f 47
screamer 13:ab47a20b66f0 48 def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
screamer 13:ab47a20b66f0 49 mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
screamer 13:ab47a20b66f0 50 if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD":
screamer 13:ab47a20b66f0 51 cpuchoice = "Cortex-M7"
screamer 13:ab47a20b66f0 52 else:
screamer 13:ab47a20b66f0 53 cpuchoice = target.core
screamer 13:ab47a20b66f0 54 # flags_cmd are used only by our scripts, the project files have them already defined,
screamer 13:ab47a20b66f0 55 # using this flags results in the errors (duplication)
screamer 13:ab47a20b66f0 56 # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core
screamer 13:ab47a20b66f0 57 if target.core == "Cortex-M4F":
screamer 13:ab47a20b66f0 58 asm_flags_cmd = [
screamer 13:ab47a20b66f0 59 "--cpu", "Cortex-M4F"
screamer 13:ab47a20b66f0 60 ]
screamer 13:ab47a20b66f0 61 else:
screamer 13:ab47a20b66f0 62 asm_flags_cmd = [
screamer 13:ab47a20b66f0 63 "--cpu", cpuchoice
screamer 13:ab47a20b66f0 64 ]
screamer 13:ab47a20b66f0 65 # custom c flags
screamer 13:ab47a20b66f0 66 if target.core == "Cortex-M4F":
screamer 13:ab47a20b66f0 67 c_flags_cmd = [
screamer 13:ab47a20b66f0 68 "--cpu", "Cortex-M4F",
screamer 13:ab47a20b66f0 69 "--thumb", "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")
screamer 13:ab47a20b66f0 70 ]
screamer 13:ab47a20b66f0 71 else:
screamer 13:ab47a20b66f0 72 c_flags_cmd = [
screamer 13:ab47a20b66f0 73 "--cpu", cpuchoice,
screamer 13:ab47a20b66f0 74 "--thumb", "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")
screamer 13:ab47a20b66f0 75 ]
screamer 13:ab47a20b66f0 76 # custom c++ cmd flags
screamer 13:ab47a20b66f0 77 cxx_flags_cmd = [
screamer 13:ab47a20b66f0 78 "--c++", "--no_rtti", "--no_exceptions"
screamer 13:ab47a20b66f0 79 ]
screamer 13:ab47a20b66f0 80 if target.core == "Cortex-M7FD":
screamer 13:ab47a20b66f0 81 asm_flags_cmd += ["--fpu", "VFPv5"]
screamer 13:ab47a20b66f0 82 c_flags_cmd.append("--fpu=VFPv5")
screamer 13:ab47a20b66f0 83 elif target.core == "Cortex-M7F":
screamer 13:ab47a20b66f0 84 asm_flags_cmd += ["--fpu", "VFPv5_sp"]
screamer 13:ab47a20b66f0 85 c_flags_cmd.append("--fpu=VFPv5_sp")
screamer 0:66f3b5499f7f 86
screamer 0:66f3b5499f7f 87 if "debug-info" in self.options:
screamer 13:ab47a20b66f0 88 c_flags_cmd.append("-r")
screamer 13:ab47a20b66f0 89 c_flags_cmd.append("-On")
screamer 0:66f3b5499f7f 90 else:
screamer 13:ab47a20b66f0 91 c_flags_cmd.append("-Oh")
screamer 0:66f3b5499f7f 92
screamer 0:66f3b5499f7f 93 IAR_BIN = join(IAR_PATH, "bin")
screamer 0:66f3b5499f7f 94 main_cc = join(IAR_BIN, "iccarm")
screamer 13:ab47a20b66f0 95
screamer 13:ab47a20b66f0 96 self.asm = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"]
screamer 13:ab47a20b66f0 97 if not "analyze" in self.options:
screamer 13:ab47a20b66f0 98 self.cc = [main_cc]
screamer 13:ab47a20b66f0 99 self.cppc = [main_cc]
screamer 13:ab47a20b66f0 100 else:
screamer 13:ab47a20b66f0 101 self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
screamer 13:ab47a20b66f0 102 self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
screamer 13:ab47a20b66f0 103 self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"]
screamer 13:ab47a20b66f0 104 self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"]
screamer 0:66f3b5499f7f 105 self.ld = join(IAR_BIN, "ilinkarm")
screamer 0:66f3b5499f7f 106 self.ar = join(IAR_BIN, "iarchive")
screamer 0:66f3b5499f7f 107 self.elf2bin = join(IAR_BIN, "ielftool")
screamer 0:66f3b5499f7f 108
screamer 0:66f3b5499f7f 109 def parse_dependencies(self, dep_path):
screamer 0:66f3b5499f7f 110 return [path.strip() for path in open(dep_path).readlines()
screamer 0:66f3b5499f7f 111 if (path and not path.isspace())]
screamer 0:66f3b5499f7f 112
screamer 0:66f3b5499f7f 113 def parse_output(self, output):
screamer 0:66f3b5499f7f 114 for line in output.splitlines():
screamer 0:66f3b5499f7f 115 match = IAR.DIAGNOSTIC_PATTERN.match(line)
screamer 0:66f3b5499f7f 116 if match is not None:
screamer 0:66f3b5499f7f 117 self.cc_info(
screamer 0:66f3b5499f7f 118 match.group('severity').lower(),
screamer 0:66f3b5499f7f 119 match.group('file'),
screamer 0:66f3b5499f7f 120 match.group('line'),
screamer 0:66f3b5499f7f 121 match.group('message'),
screamer 0:66f3b5499f7f 122 target_name=self.target.name,
screamer 0:66f3b5499f7f 123 toolchain_name=self.name
screamer 0:66f3b5499f7f 124 )
screamer 0:66f3b5499f7f 125 match = self.goanna_parse_line(line)
screamer 0:66f3b5499f7f 126 if match is not None:
screamer 0:66f3b5499f7f 127 self.cc_info(
screamer 0:66f3b5499f7f 128 match.group('severity').lower(),
screamer 0:66f3b5499f7f 129 match.group('file'),
screamer 0:66f3b5499f7f 130 match.group('line'),
screamer 0:66f3b5499f7f 131 match.group('message')
screamer 0:66f3b5499f7f 132 )
screamer 0:66f3b5499f7f 133
screamer 0:66f3b5499f7f 134 def get_dep_option(self, object):
screamer 0:66f3b5499f7f 135 base, _ = splitext(object)
screamer 0:66f3b5499f7f 136 dep_path = base + '.d'
screamer 0:66f3b5499f7f 137 return ["--dependencies", dep_path]
screamer 0:66f3b5499f7f 138
screamer 0:66f3b5499f7f 139 def cc_extra(self, object):
screamer 0:66f3b5499f7f 140 base, _ = splitext(object)
screamer 13:ab47a20b66f0 141 return ["-l", base + '.s.txt']
screamer 13:ab47a20b66f0 142
screamer 13:ab47a20b66f0 143 def get_config_option(self, config_header):
screamer 13:ab47a20b66f0 144 return ['--preinclude=' + config_header]
screamer 0:66f3b5499f7f 145
screamer 13:ab47a20b66f0 146 def get_compile_options(self, defines, includes, for_asm=False):
screamer 13:ab47a20b66f0 147 opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
screamer 13:ab47a20b66f0 148 config_header = self.get_config_header()
screamer 13:ab47a20b66f0 149 if for_asm:
screamer 13:ab47a20b66f0 150 # The assembler doesn't support '--preinclude', so we need to add
screamer 13:ab47a20b66f0 151 # the macros directly
screamer 13:ab47a20b66f0 152 opts = opts + ['-D%s' % d for d in self.get_config_macros()]
screamer 13:ab47a20b66f0 153 else:
screamer 13:ab47a20b66f0 154 config_header = self.get_config_header()
screamer 13:ab47a20b66f0 155 if config_header is not None:
screamer 13:ab47a20b66f0 156 opts = opts + self.get_config_option(config_header)
screamer 13:ab47a20b66f0 157 return opts
screamer 0:66f3b5499f7f 158
screamer 0:66f3b5499f7f 159 @hook_tool
screamer 0:66f3b5499f7f 160 def assemble(self, source, object, includes):
screamer 0:66f3b5499f7f 161 # Build assemble command
screamer 13:ab47a20b66f0 162 cmd = self.asm + self.get_compile_options(self.get_symbols(), includes, for_asm=True) + ["-o", object, source]
screamer 0:66f3b5499f7f 163
screamer 0:66f3b5499f7f 164 # Call cmdline hook
screamer 0:66f3b5499f7f 165 cmd = self.hook.get_cmdline_assembler(cmd)
screamer 0:66f3b5499f7f 166
screamer 0:66f3b5499f7f 167 # Return command array, don't execute
screamer 0:66f3b5499f7f 168 return [cmd]
screamer 0:66f3b5499f7f 169
screamer 0:66f3b5499f7f 170 @hook_tool
screamer 0:66f3b5499f7f 171 def compile(self, cc, source, object, includes):
screamer 0:66f3b5499f7f 172 # Build compile command
screamer 0:66f3b5499f7f 173 cmd = cc + self.get_compile_options(self.get_symbols(), includes)
screamer 0:66f3b5499f7f 174
screamer 0:66f3b5499f7f 175 cmd.extend(self.get_dep_option(object))
screamer 0:66f3b5499f7f 176
screamer 0:66f3b5499f7f 177 cmd.extend(self.cc_extra(object))
screamer 0:66f3b5499f7f 178
screamer 0:66f3b5499f7f 179 cmd.extend(["-o", object, source])
screamer 0:66f3b5499f7f 180
screamer 0:66f3b5499f7f 181 # Call cmdline hook
screamer 0:66f3b5499f7f 182 cmd = self.hook.get_cmdline_compiler(cmd)
screamer 0:66f3b5499f7f 183
screamer 0:66f3b5499f7f 184 return [cmd]
screamer 0:66f3b5499f7f 185
screamer 0:66f3b5499f7f 186 def compile_c(self, source, object, includes):
screamer 0:66f3b5499f7f 187 return self.compile(self.cc, source, object, includes)
screamer 0:66f3b5499f7f 188
screamer 0:66f3b5499f7f 189 def compile_cpp(self, source, object, includes):
screamer 0:66f3b5499f7f 190 return self.compile(self.cppc, source, object, includes)
screamer 0:66f3b5499f7f 191
screamer 0:66f3b5499f7f 192 @hook_tool
screamer 0:66f3b5499f7f 193 def link(self, output, objects, libraries, lib_dirs, mem_map):
screamer 0:66f3b5499f7f 194 # Build linker command
screamer 7:5af61d55adbe 195 map_file = splitext(output)[0] + ".map"
screamer 13:ab47a20b66f0 196 cmd = [self.ld, "-o", output, "--map=%s" % map_file] + objects + libraries + self.flags['ld']
screamer 0:66f3b5499f7f 197
screamer 0:66f3b5499f7f 198 if mem_map:
screamer 7:5af61d55adbe 199 cmd.extend(["--config", mem_map])
screamer 0:66f3b5499f7f 200
screamer 0:66f3b5499f7f 201 # Call cmdline hook
screamer 0:66f3b5499f7f 202 cmd = self.hook.get_cmdline_linker(cmd)
screamer 0:66f3b5499f7f 203
screamer 0:66f3b5499f7f 204 # Split link command to linker executable + response file
screamer 0:66f3b5499f7f 205 link_files = join(dirname(output), ".link_files.txt")
screamer 0:66f3b5499f7f 206 with open(link_files, "wb") as f:
screamer 0:66f3b5499f7f 207 cmd_linker = cmd[0]
screamer 0:66f3b5499f7f 208 cmd_list = []
screamer 0:66f3b5499f7f 209 for c in cmd[1:]:
screamer 0:66f3b5499f7f 210 if c:
screamer 0:66f3b5499f7f 211 cmd_list.append(('"%s"' % c) if not c.startswith('-') else c)
screamer 0:66f3b5499f7f 212 string = " ".join(cmd_list).replace("\\", "/")
screamer 0:66f3b5499f7f 213 f.write(string)
screamer 0:66f3b5499f7f 214
screamer 0:66f3b5499f7f 215 # Exec command
screamer 0:66f3b5499f7f 216 self.default_cmd([cmd_linker, '-f', link_files])
screamer 0:66f3b5499f7f 217
screamer 0:66f3b5499f7f 218 @hook_tool
screamer 0:66f3b5499f7f 219 def archive(self, objects, lib_path):
screamer 0:66f3b5499f7f 220 archive_files = join(dirname(lib_path), ".archive_files.txt")
screamer 0:66f3b5499f7f 221 with open(archive_files, "wb") as f:
screamer 0:66f3b5499f7f 222 o_list = []
screamer 0:66f3b5499f7f 223 for o in objects:
screamer 0:66f3b5499f7f 224 o_list.append('"%s"' % o)
screamer 0:66f3b5499f7f 225 string = " ".join(o_list).replace("\\", "/")
screamer 0:66f3b5499f7f 226 f.write(string)
screamer 0:66f3b5499f7f 227
screamer 0:66f3b5499f7f 228 if exists(lib_path):
screamer 0:66f3b5499f7f 229 remove(lib_path)
screamer 0:66f3b5499f7f 230
screamer 0:66f3b5499f7f 231 self.default_cmd([self.ar, lib_path, '-f', archive_files])
screamer 0:66f3b5499f7f 232
screamer 0:66f3b5499f7f 233 @hook_tool
screamer 0:66f3b5499f7f 234 def binary(self, resources, elf, bin):
screamer 0:66f3b5499f7f 235 # Build binary command
screamer 0:66f3b5499f7f 236 cmd = [self.elf2bin, "--bin", elf, bin]
screamer 0:66f3b5499f7f 237
screamer 0:66f3b5499f7f 238 # Call cmdline hook
screamer 0:66f3b5499f7f 239 cmd = self.hook.get_cmdline_binary(cmd)
screamer 0:66f3b5499f7f 240
screamer 0:66f3b5499f7f 241 # Exec command
screamer 0:66f3b5499f7f 242 self.default_cmd(cmd)