Clone of official tools

Revision:
13:ab47a20b66f0
Parent:
7:5af61d55adbe
Child:
20:835f6355470d
diff -r f2e8a005c7d3 -r ab47a20b66f0 toolchains/iar.py
--- a/toolchains/iar.py	Tue Jun 14 11:33:06 2016 +0100
+++ b/toolchains/iar.py	Thu Jul 14 20:21:19 2016 +0100
@@ -30,41 +30,78 @@
 
     DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
 
-    def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False, profile=None):
-        mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose, profile=profile)
-        if target.core == "Cortex-M7F":
-            cpu = "Cortex-M7"
-        else:
-            cpu = target.core
-
-        c_flags = [
-            "--cpu=%s" % cpu, "--thumb",
-            "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
-            "-e", # Enable IAR language extension
+    DEFAULT_FLAGS = {
+        'common': [
             "--no_wrap_diagnostics",
             # Pa050: No need to be notified about "non-native end of line sequence"
             # Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC).
             # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
             # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
-            "--diag_suppress=Pa050,Pa084,Pa093,Pa082",
-        ]
+            "-e", # Enable IAR language extension
+            "--diag_suppress=Pa050,Pa084,Pa093,Pa082"],
+        'asm': [],
+        'c': ["--vla"],
+        'cxx': ["--guard_calls"],
+        'ld': ["--skip_dynamic_initialization", "--threaded_lib"],
+    }
 
-        if target.core == "Cortex-M7F":
-            c_flags.append("--fpu=VFPv5_sp")
+    def __init__(self, target, options=None, notify=None, macros=None, silent=False, extra_verbose=False):
+        mbedToolchain.__init__(self, target, options, notify, macros, silent, extra_verbose=extra_verbose)
+        if target.core == "Cortex-M7F" or target.core == "Cortex-M7FD":
+            cpuchoice = "Cortex-M7"
+        else:
+            cpuchoice = target.core
+        # flags_cmd are used only by our scripts, the project files have them already defined,
+        # using this flags results in the errors (duplication)
+        # asm accepts --cpu Core or --fpu FPU, not like c/c++ --cpu=Core
+        if target.core == "Cortex-M4F":
+          asm_flags_cmd = [
+              "--cpu", "Cortex-M4F"
+          ]
+        else:
+          asm_flags_cmd = [
+              "--cpu", cpuchoice
+          ]
+        # custom c flags
+        if target.core == "Cortex-M4F":
+          c_flags_cmd = [
+              "--cpu", "Cortex-M4F",
+              "--thumb", "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")
+          ]
+        else:
+          c_flags_cmd = [
+              "--cpu", cpuchoice,
+              "--thumb", "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h")
+          ]
+        # custom c++ cmd flags
+        cxx_flags_cmd = [
+            "--c++", "--no_rtti", "--no_exceptions"
+        ]
+        if target.core == "Cortex-M7FD":
+            asm_flags_cmd += ["--fpu", "VFPv5"]
+            c_flags_cmd.append("--fpu=VFPv5")
+        elif target.core == "Cortex-M7F":
+            asm_flags_cmd += ["--fpu", "VFPv5_sp"]
+            c_flags_cmd.append("--fpu=VFPv5_sp")
 
         if "debug-info" in self.options:
-            c_flags.append("-On")
+            c_flags_cmd.append("-r")
+            c_flags_cmd.append("-On")
         else:
-            c_flags.append("-Oh")
-
-        # add debug symbols for all builds
-        c_flags.append("-r")
+            c_flags_cmd.append("-Oh")
 
         IAR_BIN = join(IAR_PATH, "bin")
         main_cc = join(IAR_BIN, "iccarm")
-        self.asm  = [join(IAR_BIN, "iasmarm")] + ["--cpu", cpu]
-        self.cc   = [main_cc] + c_flags
-        self.cppc = [main_cc, "--c++",  "--no_rtti", "--no_exceptions"] + c_flags
+
+        self.asm  = [join(IAR_BIN, "iasmarm")] + asm_flags_cmd + self.flags["asm"]
+        if not "analyze" in self.options:
+            self.cc   = [main_cc]
+            self.cppc = [main_cc]
+        else:
+            self.cc   = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
+            self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT]
+        self.cc += self.flags["common"] + c_flags_cmd + self.flags["c"]
+        self.cppc += self.flags["common"] + c_flags_cmd + cxx_flags_cmd + self.flags["cxx"]
         self.ld   = join(IAR_BIN, "ilinkarm")
         self.ar = join(IAR_BIN, "iarchive")
         self.elf2bin = join(IAR_BIN, "ielftool")
@@ -101,15 +138,28 @@
 
     def cc_extra(self, object):
         base, _ = splitext(object)
-        return ["-l", base + '.s']
+        return ["-l", base + '.s.txt']
+
+    def get_config_option(self, config_header):
+        return ['--preinclude=' + config_header]
 
-    def get_compile_options(self, defines, includes):
-        return ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
+    def get_compile_options(self, defines, includes, for_asm=False):
+        opts = ['-D%s' % d for d in defines] + ['-f', self.get_inc_file(includes)]
+        config_header = self.get_config_header()
+        if for_asm:
+            # The assembler doesn't support '--preinclude', so we need to add
+            # the macros directly
+            opts = opts + ['-D%s' % d for d in self.get_config_macros()]
+        else:
+            config_header = self.get_config_header()
+            if config_header is not None:
+                opts = opts + self.get_config_option(config_header)
+        return opts
 
     @hook_tool
     def assemble(self, source, object, includes):
         # Build assemble command
-        cmd = self.asm + self.get_compile_options(self.get_symbols(), includes) + ["-o", object, source]
+        cmd = self.asm + self.get_compile_options(self.get_symbols(), includes, for_asm=True) + ["-o", object, source]
 
         # Call cmdline hook
         cmd = self.hook.get_cmdline_assembler(cmd)
@@ -143,7 +193,7 @@
     def link(self, output, objects, libraries, lib_dirs, mem_map):
         # Build linker command
         map_file = splitext(output)[0] + ".map"
-        cmd = [self.ld, "-o", output, "--skip_dynamic_initialization", "--map=%s" % map_file] + objects + libraries
+        cmd = [self.ld, "-o", output, "--map=%s" % map_file] + objects + libraries + self.flags['ld']
 
         if mem_map:
             cmd.extend(["--config", mem_map])