|
| 1 | +import re |
| 2 | +from os.path import join |
| 3 | + |
| 4 | +from workspace_tools.toolchains import mbedToolchain |
| 5 | +from workspace_tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB |
| 6 | + |
| 7 | + |
| 8 | +class ARM(mbedToolchain): |
| 9 | + LINKER_EXT = '.sct' |
| 10 | + LIBRARY_EXT = '.ar' |
| 11 | + |
| 12 | + STD_LIB_NAME = "%s.ar" |
| 13 | + DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)", line (?P<line>\d+): (?P<severity>Warning|Error): (?P<message>.+)') |
| 14 | + DEP_PATTERN = re.compile('\S+:\s(?P<file>.+)\n') |
| 15 | + |
| 16 | + def __init__(self, target, options=None, notify=None): |
| 17 | + mbedToolchain.__init__(self, target, options, notify) |
| 18 | + |
| 19 | + if target.core == "Cortex-M0+": |
| 20 | + cpu = "Cortex-M0" |
| 21 | + elif target.core == "Cortex-M4": |
| 22 | + cpu = "Cortex-M4.fp" |
| 23 | + else: |
| 24 | + cpu = target.core |
| 25 | + |
| 26 | + common = [join(ARM_BIN, "armcc"), "-c", |
| 27 | + "--cpu=%s" % cpu, "--gnu", |
| 28 | + "-Ospace", "--split_sections", "--apcs=interwork", |
| 29 | + "--brief_diagnostics", "--restrict" |
| 30 | + ] |
| 31 | + |
| 32 | + if "save-asm" in self.options: |
| 33 | + common.extend(["--asm", "--interleave"]) |
| 34 | +<<<<<<< HEAD |
| 35 | + elif "debug-info" in self.options: |
| 36 | + common.extend(["--debug"]) |
| 37 | +======= |
| 38 | + |
| 39 | + if "debug-info" in self.options: |
| 40 | + common.append("-g") |
| 41 | +>>>>>>> master |
| 42 | + |
| 43 | + common_c = [ |
| 44 | + "--md", "--no_depend_system_headers", |
| 45 | + '-I%s' % ARM_INC |
| 46 | + ] |
| 47 | + |
| 48 | + self.asm = common |
| 49 | + self.cc = common + common_c + ["--c99"] |
| 50 | + self.cppc = common + common_c + ["--cpp", "--no_rtti"] |
| 51 | + |
| 52 | + self.ld = [join(ARM_BIN, "armlink")] |
| 53 | + self.sys_libs = [] |
| 54 | + |
| 55 | + self.ar = join(ARM_BIN, "armar") |
| 56 | + self.elf2bin = join(ARM_BIN, "fromelf") |
| 57 | + |
| 58 | + def remove_option(self, option): |
| 59 | + for tool in [self.asm, self.cc, self.cppc]: |
| 60 | + if option in tool: |
| 61 | + tool.remove(option) |
| 62 | + |
| 63 | + def assemble(self, source, object): |
| 64 | + self.default_cmd(self.cc + ["-o", object, source]) |
| 65 | + |
| 66 | + def parse_dependencies(self, dep_path): |
| 67 | + dependencies = [] |
| 68 | + for line in open(dep_path).readlines(): |
| 69 | + match = ARM.DEP_PATTERN.match(line) |
| 70 | + if match is not None: |
| 71 | + dependencies.append(match.group('file')) |
| 72 | + return dependencies |
| 73 | + |
| 74 | + def parse_output(self, output): |
| 75 | + for line in output.splitlines(): |
| 76 | + match = ARM.DIAGNOSTIC_PATTERN.match(line) |
| 77 | + if match is not None: |
| 78 | + self.cc_info( |
| 79 | + match.group('severity').lower(), |
| 80 | + match.group('file'), |
| 81 | + match.group('line'), |
| 82 | + match.group('message') |
| 83 | + ) |
| 84 | + |
| 85 | + def archive(self, objects, lib_path): |
| 86 | + self.default_cmd([self.ar, '-r', lib_path] + objects) |
| 87 | + |
| 88 | + def link(self, output, objects, libraries, lib_dirs, mem_map): |
| 89 | + args = ["-o", output, "--userlibpath", ",".join(lib_dirs), "--info=totals", "--list=.link_totals.txt"] |
| 90 | + if mem_map: |
| 91 | + args.extend(["--scatter", mem_map]) |
| 92 | + |
| 93 | + self.default_cmd(self.ld + args + objects + libraries + self.sys_libs) |
| 94 | + |
| 95 | + def binary(self, elf, bin): |
| 96 | + self.default_cmd([self.elf2bin, '--bin', '-o', bin, elf]) |
| 97 | + |
| 98 | + |
| 99 | +class ARM_STD(ARM): |
| 100 | + def __init__(self, target, options=None, notify=None): |
| 101 | + ARM.__init__(self, target, options, notify) |
| 102 | + self.ld.append("--libpath=%s" % ARM_LIB) |
| 103 | + |
| 104 | + |
| 105 | +class ARM_MICRO(ARM): |
| 106 | + PATCHED_LIBRARY = True |
| 107 | + |
| 108 | + def __init__(self, target, options=None, notify=None): |
| 109 | + ARM.__init__(self, target, notify) |
| 110 | + |
| 111 | + # Compiler |
| 112 | + self.asm += ["-D__MICROLIB"] |
| 113 | + self.cc += ["--library_type=microlib", "-D__MICROLIB"] |
| 114 | + self.cppc += ["--library_type=microlib", "-D__MICROLIB"] |
| 115 | + |
| 116 | + # Linker |
| 117 | + self.ld.append("--library_type=microlib") |
| 118 | + |
| 119 | + # We had to patch microlib to add C++ support |
| 120 | + # In later releases this patch should have entered mainline |
| 121 | + if ARM_MICRO.PATCHED_LIBRARY: |
| 122 | + self.ld.append("--noscanlib") |
| 123 | + |
| 124 | + # System Libraries |
| 125 | + self.sys_libs.extend([join(MY_ARM_CLIB, lib+".l") for lib in ["mc_p", "mf_p", "m_ps"]]) |
| 126 | + |
| 127 | + if target.core == "Cortex-M3": |
| 128 | + self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ws", "cpprt_w"]]) |
| 129 | + |
| 130 | + elif target.core in ["Cortex-M0", "Cortex-M0+"]: |
| 131 | + self.sys_libs.extend([join(ARM_CPPLIB, lib+".l") for lib in ["cpp_ps", "cpprt_p"]]) |
| 132 | + else: |
| 133 | + self.ld.append("--libpath=%s" % ARM_LIB) |
0 commit comments