Clone of official tools
toolchains/iar.py@7:5af61d55adbe, 2016-06-07 (annotated)
- Committer:
- screamer
- Date:
- Tue Jun 07 11:21:44 2016 +0100
- Revision:
- 7:5af61d55adbe
- Parent:
- 2:07730b0f452c
- Child:
- 13:ab47a20b66f0
Ported changes and config system from workspace tools
Who changed what in which revision?
User | Revision | Line number | New 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 | 2:07730b0f452c | 33 | def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None): |
screamer | 2:07730b0f452c | 34 | mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile) |
screamer | 0:66f3b5499f7f | 35 | if target.core == "Cortex-M7F": |
screamer | 2:07730b0f452c | 36 | cpu = "Cortex-M7" |
screamer | 0:66f3b5499f7f | 37 | else: |
screamer | 2:07730b0f452c | 38 | cpu = target.core |
screamer | 2:07730b0f452c | 39 | |
screamer | 0:66f3b5499f7f | 40 | c_flags = [ |
screamer | 2:07730b0f452c | 41 | "--cpu=%s" % cpu, "--thumb", |
screamer | 0:66f3b5499f7f | 42 | "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"), |
screamer | 0:66f3b5499f7f | 43 | "-e", # Enable IAR language extension |
screamer | 0:66f3b5499f7f | 44 | "--no_wrap_diagnostics", |
screamer | 0:66f3b5499f7f | 45 | # Pa050: No need to be notified about "non-native end of line sequence" |
screamer | 0:66f3b5499f7f | 46 | # 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 | 47 | # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85)) |
screamer | 0:66f3b5499f7f | 48 | # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0)) |
screamer | 0:66f3b5499f7f | 49 | "--diag_suppress=Pa050,Pa084,Pa093,Pa082", |
screamer | 0:66f3b5499f7f | 50 | ] |
screamer | 0:66f3b5499f7f | 51 | |
screamer | 0:66f3b5499f7f | 52 | if target.core == "Cortex-M7F": |
screamer | 0:66f3b5499f7f | 53 | c_flags.append("--fpu=VFPv5_sp") |
screamer | 0:66f3b5499f7f | 54 | |
screamer | 0:66f3b5499f7f | 55 | if "debug-info" in self.options: |
screamer | 0:66f3b5499f7f | 56 | c_flags.append("-On") |
screamer | 0:66f3b5499f7f | 57 | else: |
screamer | 0:66f3b5499f7f | 58 | c_flags.append("-Oh") |
screamer | 2:07730b0f452c | 59 | |
screamer | 0:66f3b5499f7f | 60 | # add debug symbols for all builds |
screamer | 0:66f3b5499f7f | 61 | c_flags.append("-r") |
screamer | 0:66f3b5499f7f | 62 | |
screamer | 0:66f3b5499f7f | 63 | IAR_BIN = join(IAR_PATH, "bin") |
screamer | 0:66f3b5499f7f | 64 | main_cc = join(IAR_BIN, "iccarm") |
screamer | 2:07730b0f452c | 65 | self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", cpu] |
screamer | 2:07730b0f452c | 66 | self.cc = [main_cc] + c_flags |
screamer | 2:07730b0f452c | 67 | self.cppc = [main_cc, "--c++", "--no_rtti", "--no_exceptions"] + c_flags |
screamer | 0:66f3b5499f7f | 68 | self.ld = join(IAR_BIN, "ilinkarm") |
screamer | 0:66f3b5499f7f | 69 | self.ar = join(IAR_BIN, "iarchive") |
screamer | 0:66f3b5499f7f | 70 | self.elf2bin = join(IAR_BIN, "ielftool") |
screamer | 0:66f3b5499f7f | 71 | |
screamer | 0:66f3b5499f7f | 72 | def parse_dependencies(self, dep_path): |
screamer | 0:66f3b5499f7f | 73 | return [path.strip() for path in open(dep_path).readlines() |
screamer | 0:66f3b5499f7f | 74 | if (path and not path.isspace())] |
screamer | 0:66f3b5499f7f | 75 | |
screamer | 0:66f3b5499f7f | 76 | def parse_output(self, output): |
screamer | 0:66f3b5499f7f | 77 | for line in output.splitlines(): |
screamer | 0:66f3b5499f7f | 78 | match = IAR.DIAGNOSTIC_PATTERN.match(line) |
screamer | 0:66f3b5499f7f | 79 | if match is not None: |
screamer | 0:66f3b5499f7f | 80 | self.cc_info( |
screamer | 0:66f3b5499f7f | 81 | match.group('severity').lower(), |
screamer | 0:66f3b5499f7f | 82 | match.group('file'), |
screamer | 0:66f3b5499f7f | 83 | match.group('line'), |
screamer | 0:66f3b5499f7f | 84 | match.group('message'), |
screamer | 0:66f3b5499f7f | 85 | target_name=self.target.name, |
screamer | 0:66f3b5499f7f | 86 | toolchain_name=self.name |
screamer | 0:66f3b5499f7f | 87 | ) |
screamer | 0:66f3b5499f7f | 88 | match = self.goanna_parse_line(line) |
screamer | 0:66f3b5499f7f | 89 | if match is not None: |
screamer | 0:66f3b5499f7f | 90 | self.cc_info( |
screamer | 0:66f3b5499f7f | 91 | match.group('severity').lower(), |
screamer | 0:66f3b5499f7f | 92 | match.group('file'), |
screamer | 0:66f3b5499f7f | 93 | match.group('line'), |
screamer | 0:66f3b5499f7f | 94 | match.group('message') |
screamer | 0:66f3b5499f7f | 95 | ) |
screamer | 0:66f3b5499f7f | 96 | |
screamer | 0:66f3b5499f7f | 97 | def get_dep_option(self, object): |
screamer | 0:66f3b5499f7f | 98 | base, _ = splitext(object) |
screamer | 0:66f3b5499f7f | 99 | dep_path = base + '.d' |
screamer | 0:66f3b5499f7f | 100 | return ["--dependencies", dep_path] |
screamer | 0:66f3b5499f7f | 101 | |
screamer | 0:66f3b5499f7f | 102 | def cc_extra(self, object): |
screamer | 0:66f3b5499f7f | 103 | base, _ = splitext(object) |
screamer | 0:66f3b5499f7f | 104 | return ["-l", base + '.s'] |
screamer | 0:66f3b5499f7f | 105 | |
screamer | 0:66f3b5499f7f | 106 | def get_compile_options(self, defines, includes): |
screamer | 0:66f3b5499f7f | 107 | return ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)] |
screamer | 0:66f3b5499f7f | 108 | |
screamer | 0:66f3b5499f7f | 109 | @hook_tool |
screamer | 0:66f3b5499f7f | 110 | def assemble(self, source, object, includes): |
screamer | 0:66f3b5499f7f | 111 | # Build assemble command |
screamer | 0:66f3b5499f7f | 112 | cmd = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-o", object, source] |
screamer | 0:66f3b5499f7f | 113 | |
screamer | 0:66f3b5499f7f | 114 | # Call cmdline hook |
screamer | 0:66f3b5499f7f | 115 | cmd = self.hook.get_cmdline_assembler(cmd) |
screamer | 0:66f3b5499f7f | 116 | |
screamer | 0:66f3b5499f7f | 117 | # Return command array, don't execute |
screamer | 0:66f3b5499f7f | 118 | return [cmd] |
screamer | 0:66f3b5499f7f | 119 | |
screamer | 0:66f3b5499f7f | 120 | @hook_tool |
screamer | 0:66f3b5499f7f | 121 | def compile(self, cc, source, object, includes): |
screamer | 0:66f3b5499f7f | 122 | # Build compile command |
screamer | 0:66f3b5499f7f | 123 | cmd = cc + self.get_compile_options(self.get_symbols(), includes) |
screamer | 0:66f3b5499f7f | 124 | |
screamer | 0:66f3b5499f7f | 125 | cmd.extend(self.get_dep_option(object)) |
screamer | 0:66f3b5499f7f | 126 | |
screamer | 0:66f3b5499f7f | 127 | cmd.extend(self.cc_extra(object)) |
screamer | 0:66f3b5499f7f | 128 | |
screamer | 0:66f3b5499f7f | 129 | cmd.extend(["-o", object, source]) |
screamer | 0:66f3b5499f7f | 130 | |
screamer | 0:66f3b5499f7f | 131 | # Call cmdline hook |
screamer | 0:66f3b5499f7f | 132 | cmd = self.hook.get_cmdline_compiler(cmd) |
screamer | 0:66f3b5499f7f | 133 | |
screamer | 0:66f3b5499f7f | 134 | return [cmd] |
screamer | 0:66f3b5499f7f | 135 | |
screamer | 0:66f3b5499f7f | 136 | def compile_c(self, source, object, includes): |
screamer | 0:66f3b5499f7f | 137 | return self.compile(self.cc, source, object, includes) |
screamer | 0:66f3b5499f7f | 138 | |
screamer | 0:66f3b5499f7f | 139 | def compile_cpp(self, source, object, includes): |
screamer | 0:66f3b5499f7f | 140 | return self.compile(self.cppc, source, object, includes) |
screamer | 0:66f3b5499f7f | 141 | |
screamer | 0:66f3b5499f7f | 142 | @hook_tool |
screamer | 0:66f3b5499f7f | 143 | def link(self, output, objects, libraries, lib_dirs, mem_map): |
screamer | 0:66f3b5499f7f | 144 | # Build linker command |
screamer | 7:5af61d55adbe | 145 | map_file = splitext(output)[0] + ".map" |
screamer | 7:5af61d55adbe | 146 | cmd = [self.ld, "-o", output, "--skip_dynamic_initialization", "--map=%s" % map_file] + objects + libraries |
screamer | 0:66f3b5499f7f | 147 | |
screamer | 0:66f3b5499f7f | 148 | if mem_map: |
screamer | 7:5af61d55adbe | 149 | cmd.extend(["--config", mem_map]) |
screamer | 0:66f3b5499f7f | 150 | |
screamer | 0:66f3b5499f7f | 151 | # Call cmdline hook |
screamer | 0:66f3b5499f7f | 152 | cmd = self.hook.get_cmdline_linker(cmd) |
screamer | 0:66f3b5499f7f | 153 | |
screamer | 0:66f3b5499f7f | 154 | # Split link command to linker executable + response file |
screamer | 0:66f3b5499f7f | 155 | link_files = join(dirname(output), ".link_files.txt") |
screamer | 0:66f3b5499f7f | 156 | with open(link_files, "wb") as f: |
screamer | 0:66f3b5499f7f | 157 | cmd_linker = cmd[0] |
screamer | 0:66f3b5499f7f | 158 | cmd_list = [] |
screamer | 0:66f3b5499f7f | 159 | for c in cmd[1:]: |
screamer | 0:66f3b5499f7f | 160 | if c: |
screamer | 0:66f3b5499f7f | 161 | cmd_list.append(('"%s"' % c) if not c.startswith('-') else c) |
screamer | 0:66f3b5499f7f | 162 | string = " ".join(cmd_list).replace("\\", "/") |
screamer | 0:66f3b5499f7f | 163 | f.write(string) |
screamer | 0:66f3b5499f7f | 164 | |
screamer | 0:66f3b5499f7f | 165 | # Exec command |
screamer | 0:66f3b5499f7f | 166 | self.default_cmd([cmd_linker, '-f', link_files]) |
screamer | 0:66f3b5499f7f | 167 | |
screamer | 0:66f3b5499f7f | 168 | @hook_tool |
screamer | 0:66f3b5499f7f | 169 | def archive(self, objects, lib_path): |
screamer | 0:66f3b5499f7f | 170 | archive_files = join(dirname(lib_path), ".archive_files.txt") |
screamer | 0:66f3b5499f7f | 171 | with open(archive_files, "wb") as f: |
screamer | 0:66f3b5499f7f | 172 | o_list = [] |
screamer | 0:66f3b5499f7f | 173 | for o in objects: |
screamer | 0:66f3b5499f7f | 174 | o_list.append('"%s"' % o) |
screamer | 0:66f3b5499f7f | 175 | string = " ".join(o_list).replace("\\", "/") |
screamer | 0:66f3b5499f7f | 176 | f.write(string) |
screamer | 0:66f3b5499f7f | 177 | |
screamer | 0:66f3b5499f7f | 178 | if exists(lib_path): |
screamer | 0:66f3b5499f7f | 179 | remove(lib_path) |
screamer | 0:66f3b5499f7f | 180 | |
screamer | 0:66f3b5499f7f | 181 | self.default_cmd([self.ar, lib_path, '-f', archive_files]) |
screamer | 0:66f3b5499f7f | 182 | |
screamer | 0:66f3b5499f7f | 183 | @hook_tool |
screamer | 0:66f3b5499f7f | 184 | def binary(self, resources, elf, bin): |
screamer | 0:66f3b5499f7f | 185 | # Build binary command |
screamer | 0:66f3b5499f7f | 186 | cmd = [self.elf2bin, "--bin", elf, bin] |
screamer | 0:66f3b5499f7f | 187 | |
screamer | 0:66f3b5499f7f | 188 | # Call cmdline hook |
screamer | 0:66f3b5499f7f | 189 | cmd = self.hook.get_cmdline_binary(cmd) |
screamer | 0:66f3b5499f7f | 190 | |
screamer | 0:66f3b5499f7f | 191 | # Exec command |
screamer | 0:66f3b5499f7f | 192 | self.default_cmd(cmd) |