Brian Daniels / mbed-tools

Fork of mbed-tools by Morpheus

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers iar.py Source File

iar.py

00001 """
00002 mbed SDK
00003 Copyright (c) 2011-2013 ARM Limited
00004 
00005 Licensed under the Apache License, Version 2.0 (the "License");
00006 you may not use this file except in compliance with the License.
00007 You may obtain a copy of the License at
00008 
00009     http://www.apache.org/licenses/LICENSE-2.0
00010 
00011 Unless required by applicable law or agreed to in writing, software
00012 distributed under the License is distributed on an "AS IS" BASIS,
00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014 See the License for the specific language governing permissions and
00015 limitations under the License.
00016 """
00017 import re
00018 from os import remove
00019 from os.path import join, exists
00020 
00021 from tools.toolchains import mbedToolchain
00022 from tools.settings import IAR_PATH
00023 from tools.settings import GOANNA_PATH
00024 from tools.hooks import hook_tool
00025 
00026 class IAR(mbedToolchain):
00027     LIBRARY_EXT = '.a'
00028     LINKER_EXT = '.icf'
00029     STD_LIB_NAME = "%s.a"
00030 
00031     DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
00032 
00033     def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
00034         mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
00035         if target.core == "Cortex-M7F":
00036             cpuchoice = "Cortex-M7"
00037         else:
00038             cpuchoice = target.core
00039         c_flags = [
00040             "--cpu=%s" % cpuchoice, "--thumb",
00041             "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
00042             "-e", # Enable IAR language extension
00043             "--no_wrap_diagnostics",
00044             # Pa050: No need to be notified about "non-native end of line sequence"
00045             # Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC).
00046             # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
00047             # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
00048             "--diag_suppress=Pa050,Pa084,Pa093,Pa082",
00049         ]
00050 
00051         if target.core == "Cortex-M7F":
00052             c_flags.append("--fpu=VFPv5_sp")
00053                 
00054 
00055         if "debug-info" in self.options:
00056             c_flags.append("-r")
00057             c_flags.append("-On")
00058         else:
00059             c_flags.append("-Oh")
00060 
00061         IAR_BIN = join(IAR_PATH, "bin")
00062         main_cc = join(IAR_BIN, "iccarm")
00063         self.asm  = [join(IAR_BIN, "iasmarm")] + ["--cpu", cpuchoice]
00064         if not "analyze" in self.options:
00065             self.cc   = [main_cc] + c_flags
00066             self.cppc = [main_cc, "--c++",  "--no_rtti", "--no_exceptions"] + c_flags
00067         else:
00068             self.cc   = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + c_flags
00069             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
00070         self.ld   = join(IAR_BIN, "ilinkarm")
00071         self.ar = join(IAR_BIN, "iarchive")
00072         self.elf2bin = join(IAR_BIN, "ielftool")
00073 
00074     def parse_output(self, output):
00075         for line in output.splitlines():
00076             match = IAR.DIAGNOSTIC_PATTERN.match(line)
00077             if match is not None:
00078                 self.cc_info(
00079                     match.group('severity').lower(),
00080                     match.group('file'),
00081                     match.group('line'),
00082                     match.group('message'),
00083                     target_name=self.target.name,
00084                     toolchain_name=self.name
00085                 )
00086             match = self.goanna_parse_line(line)
00087             if match is not None:
00088                 self.cc_info(
00089                     match.group('severity').lower(),
00090                     match.group('file'),
00091                     match.group('line'),
00092                     match.group('message')
00093                 )
00094 
00095     def get_dep_opt(self, dep_path):
00096         return ["--dependencies", dep_path]
00097 
00098     def cc_extra(self, base):
00099         return ["-l", base + '.s']
00100 
00101     def parse_dependencies(self, dep_path):
00102         return [path.strip() for path in open(dep_path).readlines()
00103                 if (path and not path.isspace())]
00104 
00105     def assemble(self, source, object, includes):
00106         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])]
00107 
00108     def archive(self, objects, lib_path):
00109         if exists(lib_path):
00110             remove(lib_path)
00111         self.default_cmd([self.ar, lib_path] + objects)
00112 
00113     def link(self, output, objects, libraries, lib_dirs, mem_map):
00114         args = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"]
00115         self.default_cmd(self.hook.get_cmdline_linker(args + objects + libraries))
00116 
00117     @hook_tool
00118     def binary(self, resources, elf, bin):
00119         self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, '--bin', elf, bin]))