Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

iar.py 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import re
  15. from os import remove
  16. from os.path import join, exists
  17. from workspace_tools.toolchains import mbedToolchain
  18. from workspace_tools.settings import IAR_PATH
  19. from workspace_tools.settings import GOANNA_PATH
  20. from workspace_tools.hooks import hook_tool
  21. class IAR(mbedToolchain):
  22. LIBRARY_EXT = '.a'
  23. LINKER_EXT = '.icf'
  24. STD_LIB_NAME = "%s.a"
  25. DIAGNOSTIC_PATTERN = re.compile('"(?P<file>[^"]+)",(?P<line>[\d]+)\s+(?P<severity>Warning|Error)(?P<message>.+)')
  26. def __init__(self, target, options=None, notify=None, macros=None, silent=False):
  27. mbedToolchain.__init__(self, target, options, notify, macros, silent)
  28. c_flags = [
  29. "--cpu=%s" % target.core, "--thumb",
  30. "--dlib_config", join(IAR_PATH, "inc", "c", "DLib_Config_Full.h"),
  31. "-e", # Enable IAR language extension
  32. "--no_wrap_diagnostics",
  33. # Pa050: No need to be notified about "non-native end of line sequence"
  34. # Pa084: Pointless integer comparison -> checks for the values of an enum, but we use values outside of the enum to notify errors (ie: NC).
  35. # Pa093: Implicit conversion from float to integer (ie: wait_ms(85.4) -> wait_ms(85))
  36. # Pa082: Operation involving two values from two registers (ie: (float)(*obj->MR)/(float)(LPC_PWM1->MR0))
  37. "--diag_suppress=Pa050,Pa084,Pa093,Pa082",
  38. ]
  39. if "debug-info" in self.options:
  40. c_flags.append("-r")
  41. c_flags.append("-On")
  42. else:
  43. c_flags.append("-Oh")
  44. IAR_BIN = join(IAR_PATH, "bin")
  45. main_cc = join(IAR_BIN, "iccarm")
  46. self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", target.core]
  47. if not "analyze" in self.options:
  48. self.cc = [main_cc] + c_flags
  49. self.cppc = [main_cc, "--c++", "--no_rtti", "--no_exceptions"] + c_flags
  50. else:
  51. self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + c_flags
  52. 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
  53. self.ld = join(IAR_BIN, "ilinkarm")
  54. self.ar = join(IAR_BIN, "iarchive")
  55. self.elf2bin = join(IAR_BIN, "ielftool")
  56. def parse_output(self, output):
  57. for line in output.splitlines():
  58. match = IAR.DIAGNOSTIC_PATTERN.match(line)
  59. if match is not None:
  60. self.cc_info(
  61. match.group('severity').lower(),
  62. match.group('file'),
  63. match.group('line'),
  64. match.group('message'),
  65. target_name=self.target.name,
  66. toolchain_name=self.name
  67. )
  68. match = self.goanna_parse_line(line)
  69. if match is not None:
  70. self.cc_info(
  71. match.group('severity').lower(),
  72. match.group('file'),
  73. match.group('line'),
  74. match.group('message')
  75. )
  76. def get_dep_opt(self, dep_path):
  77. return ["--dependencies", dep_path]
  78. def cc_extra(self, base):
  79. return ["-l", base + '.s']
  80. def parse_dependencies(self, dep_path):
  81. return [path.strip() for path in open(dep_path).readlines()
  82. if (path and not path.isspace())]
  83. def assemble(self, source, object, includes):
  84. 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])]
  85. def archive(self, objects, lib_path):
  86. if exists(lib_path):
  87. remove(lib_path)
  88. self.default_cmd([self.ar, lib_path] + objects)
  89. def link(self, output, objects, libraries, lib_dirs, mem_map):
  90. args = [self.ld, "-o", output, "--config", mem_map, "--skip_dynamic_initialization"]
  91. self.default_cmd(self.hook.get_cmdline_linker(args + objects + libraries))
  92. @hook_tool
  93. def binary(self, resources, elf, bin):
  94. self.default_cmd(self.hook.get_cmdline_binary([self.elf2bin, '--bin', elf, bin]))