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.
18 from os.path import join
20 from workspace_tools.toolchains import mbedToolchain
21 from workspace_tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB
22 from workspace_tools.hooks import hook_tool
23 from workspace_tools.settings import GOANNA_PATH
25 class ARM(mbedToolchain):
29 STD_LIB_NAME = "%s.ar"
30 DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)')
31 DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n')
33 def __init__(self, target, options=None, notify=None, macros=None, silent=False):
34 mbedToolchain.__init__(self, target, options, notify, macros, silent)
36 if target.core == "Cortex-M0+":
38 elif target.core == "Cortex-M4F":
40 elif target.core == "Cortex-M7F":
41 cpu = "Cortex-M7.fp.sp"
45 main_cc = join(ARM_BIN, "armcc")
47 "--cpu=%s" % cpu, "--gnu",
48 "-Otime", "--split_sections", "--apcs=interwork",
49 "--brief_diagnostics", "--restrict", "--multibyte_chars"
52 if "save-asm" in self.options:
53 common.extend(["--asm", "--interleave"])
55 if "debug-info" in self.options:
62 "--md", "--no_depend_system_headers",
66 self.asm = [main_cc] + common + ['-I%s' % ARM_INC]
67 if not "analyze" in self.options:
68 self.cc = [main_cc] + common + common_c + ["--c99"]
69 self.cppc = [main_cc] + common + common_c + ["--cpp", "--no_rtti"]
71 self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + common + common_c + ["--c99"]
72 self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + common + common_c + ["--cpp", "--no_rtti"]
74 self.ld = [join(ARM_BIN, "armlink")]
77 self.ar = join(ARM_BIN, "armar")
78 self.elf2bin = join(ARM_BIN, "fromelf")
80 def remove_option(self, option):
81 for tool in [self.asm, self.cc, self.cppc]:
85 def assemble(self, source, object, includes):
86 # Preprocess first, then assemble
87 tempfile = object + '.E.s'
89 self.asm + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-E", "-o", tempfile, source],
90 self.hook.get_cmdline_assembler(self.asm + ["-o", object, tempfile])
93 def parse_dependencies(self, dep_path):
95 for line in open(dep_path).readlines():
96 match = ARM.DEP_PATTERN.match(line)
98 dependencies.append(match.group('file'))
101 def parse_output(self, output):
102 for line in output.splitlines():
103 match = ARM.DIAGNOSTIC_PATTERN.match(line)
104 if match is not None:
106 match.group('severity').lower(),
109 match.group('message'),
110 target_name=self.target.name,
111 toolchain_name=self.name
113 match = self.goanna_parse_line(line)
114 if match is not None:
116 match.group('severity').lower(),
119 match.group('message')
122 def get_dep_opt(self, dep_path):
123 return ["--depend", dep_path]
125 def archive(self, objects, lib_path):
126 self.default_cmd([self.ar, '-r', lib_path] + objects)
128 def link(self, output, objects, libraries, lib_dirs, mem_map):
130 args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--list=.link_totals.txt"]
132 args = ["-o", output, "--info=totals", "--list=.link_totals.txt"]
135 args.extend(["--scatter", mem_map])
137 if hasattr(self.target, "link_cmdline_hook"):
138 args = self.target.link_cmdline_hook(self.__class__.__name__, args)
140 self.default_cmd(self.ld + args + objects + libraries + self.sys_libs)
143 def binary(self, resources, elf, bin):
144 args = [self.elf2bin, '--bin', '-o', bin, elf]
146 if hasattr(self.target, "binary_cmdline_hook"):
147 args = self.target.binary_cmdline_hook(self.__class__.__name__, args)
149 self.default_cmd(args)
152 def __init__(self, target, options=None, notify=None, macros=None, silent=False):
153 ARM.__init__(self, target, options, notify, macros, silent)
154 self.cc += ["-D__ASSERT_MSG"]
155 self.cppc += ["-D__ASSERT_MSG"]
156 self.ld.append("--libpath=%s" % ARM_LIB)
159 class ARM_MICRO(ARM):
160 PATCHED_LIBRARY = False
162 def __init__(self, target, options=None, notify=None, macros=None, silent=False):
163 ARM.__init__(self, target, options, notify, macros, silent)
166 self.asm += ["-D__MICROLIB"]
167 self.cc += ["--library_type=microlib", "-D__MICROLIB", "-D__ASSERT_MSG"]
168 self.cppc += ["--library_type=microlib", "-D__MICROLIB", "-D__ASSERT_MSG"]
171 self.ld.append("--library_type=microlib")
173 # We had to patch microlib to add C++ support
174 # In later releases this patch should have entered mainline
175 if ARM_MICRO.PATCHED_LIBRARY:
176 self.ld.append("--noscanlib")
179 self.sys_libs.extend([join(MY_ARM_CLIB, lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]])
181 if target.core == "Cortex-M3":
182 self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ws", "cpprt_w"]])
184 elif target.core in ["Cortex-M0", "Cortex-M0+"]:
185 self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]])
187 self.ld.append("--libpath=%s" % ARM_LIB)