]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/workspace_tools/toolchains/iar.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / workspace_tools / toolchains / iar.py
1 """
2 mbed SDK
3 Copyright (c) 2011-2013 ARM Limited
4
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
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
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.
16 """
17 import re
18 from os import remove
19 from os.path import join, exists
20
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
25
26 class IAR(mbedToolchain):
27 LIBRARY_EXT = '.a'
28 LINKER_EXT = '.icf'
29 STD_LIB_NAME = "%s.a"
30
31 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
32
33 def __init__(self, target, options=None, notify=None, macros=None, silent=False):
34 mbedToolchain.__init__(self, target, options, notify, macros, silent)
35
36 c_flags = [
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",
46 ]
47
48 if "debug-info" in self.options:
49 c_flags.append("-r")
50 c_flags.append("-On")
51 else:
52 c_flags.append("-Oh")
53
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
60 else:
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")
66
67 def parse_output(self, output):
68 for line in output.splitlines():
69 match = IAR.DIAGNOSTIC_PATTERN.match(line)
70 if match is not None:
71 self.cc_info(
72 match.group('severity').lower(),
73 match.group('file'),
74 match.group('line'),
75 match.group('message'),
76 target_name=self.target.name,
77 toolchain_name=self.name
78 )
79 match = self.goanna_parse_line(line)
80 if match is not None:
81 self.cc_info(
82 match.group('severity').lower(),
83 match.group('file'),
84 match.group('line'),
85 match.group('message')
86 )
87
88 def get_dep_opt(self, dep_path):
89 return ["--dependencies", dep_path]
90
91 def cc_extra(self, base):
92 return ["-l", base + '.s']
93
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())]
97
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])]
100
101 def archive(self, objects, lib_path):
102 if exists(lib_path):
103 remove(lib_path)
104 self.default_cmd([self.ar, lib_path] + objects)
105
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))
109
110 @hook_tool
111 def binary(self, resources, elf, bin):
112 self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, '--bin', elf, bin]))
Imprint / Impressum