3 Copyright (c) 2011-2013 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
19 from os.path import join, exists
21 from workspace_tools.toolchains import mbedToolchain
22 from workspace_tools.settings import IAR_PATH
23 from workspace_tools.settings import GOANNA_PATH
24 from workspace_tools.hooks import hook_tool
26 class IAR(mbedToolchain):
31 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
33 def __init__(self, target, options=None, notify=None, macros=None, silent=False):
34 mbedToolchain.__init__(self, target, options, notify, macros, silent)
37 "--cpu=%s" % target.core, "--thumb",
38 "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
39 "-e", # Enable IAR language extension
40 "--no_wrap_diagnostics",
41 # Pa050: No need to be notified about "non-native end of line sequence"
42 # Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC).
43 # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
44 # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
45 "--diag_suppress=Pa050,Pa084,Pa093,Pa082",
48 if "debug-info" in self.options:
54 IAR_BIN = join(IAR_PATH, "bin")
55 main_cc = join(IAR_BIN, "iccarm")
56 self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", target.core]
57 if not "analyze" in self.options:
58 self.cc = [main_cc] + c_flags
59 self.cppc = [main_cc, "--c++", "--no_rtti", "--no_exceptions"] + c_flags
61 self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + c_flags
62 self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + ["--c++", "--no_rtti", "--no_exceptions"] + c_flags
63 self.ld = join(IAR_BIN, "ilinkarm")
64 self.ar = join(IAR_BIN, "iarchive")
65 self.elf2bin = join(IAR_BIN, "ielftool")
67 def parse_output(self, output):
68 for line in output.splitlines():
69 match = IAR.DIAGNOSTIC_PATTERN.match(line)
72 match.group('severity').lower(),
75 match.group('message'),
76 target_name=self.target.name,
77 toolchain_name=self.name
79 match = self.goanna_parse_line(line)
82 match.group('severity').lower(),
85 match.group('message')
88 def get_dep_opt(self, dep_path):
89 return ["--dependencies", dep_path]
91 def cc_extra(self, base):
92 return ["-l", base + '.s']
94 def parse_dependencies(self, dep_path):
95 return [path.strip() for path in open(dep_path).readlines()
96 if (path and not path.isspace())]
98 def assemble(self, source, object, includes):
99 return [self.hook.get_cmdline_assembler(self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source])]
101 def archive(self, objects, lib_path):
104 self.default_cmd([self.ar, lib_path] + objects)
106 def link(self, output, objects, libraries, lib_dirs, mem_map):
107 args = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"]
108 self.default_cmd(self.hook.get_cmdline_linker(args + objects + libraries))
111 def binary(self, resources, elf, bin):
112 self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, '--bin', elf, bin]))