xc16.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Copyright 2012-2019 The Meson development team
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. # Unless required by applicable law or agreed to in writing, software
  7. # distributed under the License is distributed on an "AS IS" BASIS,
  8. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. # See the License for the specific language governing permissions and
  10. # limitations under the License.
  11. """Representations specific to the Microchip XC16 C compiler family."""
  12. import os
  13. import typing as T
  14. from ...mesonlib import EnvironmentException
  15. if T.TYPE_CHECKING:
  16. from ...environment import Environment
  17. xc16_buildtype_args = {
  18. 'plain': [],
  19. 'debug': [],
  20. 'debugoptimized': [],
  21. 'release': [],
  22. 'minsize': [],
  23. 'custom': [],
  24. } # type: T.Dict[str, T.List[str]]
  25. xc16_optimization_args = {
  26. '0': ['-O0'],
  27. 'g': ['-O0'],
  28. '1': ['-O1'],
  29. '2': ['-O2'],
  30. '3': ['-O3'],
  31. 's': ['-Os']
  32. } # type: T.Dict[str, T.List[str]]
  33. xc16_debug_args = {
  34. False: [],
  35. True: []
  36. } # type: T.Dict[bool, T.List[str]]
  37. class Xc16Compiler:
  38. def __init__(self):
  39. if not self.is_cross:
  40. raise EnvironmentException('xc16 supports only cross-compilation.')
  41. self.id = 'xc16'
  42. # Assembly
  43. self.can_compile_suffixes.add('s')
  44. default_warn_args = [] # type: T.List[str]
  45. self.warn_args = {'0': [],
  46. '1': default_warn_args,
  47. '2': default_warn_args + [],
  48. '3': default_warn_args + []}
  49. def get_always_args(self) -> T.List[str]:
  50. return []
  51. def get_pic_args(self) -> T.List[str]:
  52. # PIC support is not enabled by default for xc16,
  53. # if users want to use it, they need to add the required arguments explicitly
  54. return []
  55. def get_buildtype_args(self, buildtype: str) -> T.List[str]:
  56. return xc16_buildtype_args[buildtype]
  57. def get_pch_suffix(self) -> str:
  58. return 'pch'
  59. def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
  60. return []
  61. # Override CCompiler.get_dependency_gen_args
  62. def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]:
  63. return []
  64. def thread_flags(self, env: 'Environment') -> T.List[str]:
  65. return []
  66. def get_coverage_args(self) -> T.List[str]:
  67. return []
  68. def get_no_stdinc_args(self) -> T.List[str]:
  69. return ['-nostdinc']
  70. def get_no_stdlib_link_args(self) -> T.List[str]:
  71. return ['--nostdlib']
  72. def get_optimization_args(self, optimization_level: str) -> T.List[str]:
  73. return xc16_optimization_args[optimization_level]
  74. def get_debug_args(self, is_debug: bool) -> T.List[str]:
  75. return xc16_debug_args[is_debug]
  76. @classmethod
  77. def unix_args_to_native(cls, args: T.List[str]) -> T.List[str]:
  78. result = []
  79. for i in args:
  80. if i.startswith('-D'):
  81. i = '-D' + i[2:]
  82. if i.startswith('-I'):
  83. i = '-I' + i[2:]
  84. if i.startswith('-Wl,-rpath='):
  85. continue
  86. elif i == '--print-search-dirs':
  87. continue
  88. elif i.startswith('-L'):
  89. continue
  90. result.append(i)
  91. return result
  92. def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str], build_dir: str) -> T.List[str]:
  93. for idx, i in enumerate(parameter_list):
  94. if i[:9] == '-I':
  95. parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:]))
  96. return parameter_list