Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

126 lignes
3.4 KiB

  1. #!/usr/bin/env python
  2. # This python program generates parameters for the linker script generator feature.
  3. # This file is part of the libopencm3 project.
  4. #
  5. # 2017 George-Cristian Jiglau <noonien>
  6. #
  7. # This library is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with this library. If not, see <http://www.gnu.org/licenses/>.
  19. from __future__ import print_function
  20. import fnmatch
  21. import sys
  22. import re
  23. import os
  24. if len(sys.argv) != 4:
  25. print("usage: %s <device-data-file> <device> <mode>" % sys.argv[0], file=sys.stderr)
  26. sys.exit(1)
  27. data_file_path = sys.argv[1]
  28. find = sys.argv[2].lower()
  29. mode = sys.argv[3].upper()
  30. device = {
  31. 'info': {},
  32. 'defs': [],
  33. 'family': [],
  34. }
  35. # open device data file
  36. with open(data_file_path, 'r') as data_file:
  37. # iterate lines
  38. for line in data_file:
  39. # strip whitespace from the beginning and end of line
  40. line = line.strip()
  41. # skip empty lines and comments
  42. if line == '' or line.startswith('#'):
  43. continue
  44. # split line into it's parts: <pattern> <parent> <data..>
  45. parts = line.split()
  46. pattern, parent, data = parts[0], parts[1], parts[2:]
  47. # skip line if pattern did not match first element
  48. if not fnmatch.fnmatch(find, pattern):
  49. continue
  50. # extract data
  51. for d in data:
  52. # split into K=V
  53. try:
  54. (k, v) = d.split('=')
  55. except:
  56. continue
  57. # skip invalid datas
  58. if not re.match('^[A-Z0-9_]+$', k):
  59. continue
  60. # add FPU and CPU to info, not defs
  61. if k in ('FPU', 'CPU'):
  62. device['info'][k.lower()] = v
  63. continue
  64. device['defs'].append((k, v))
  65. # if parent is +, there's more data for this pattern
  66. if parent == '+':
  67. continue
  68. # device family
  69. device['family'].append(find)
  70. # break if this was the last line in this chain
  71. if parent == 'END':
  72. break
  73. # look for the parent
  74. find = parent
  75. # reverse device list
  76. device['family'] = device['family'][::-1]
  77. # device was not found
  78. if len(device['family']) == 0:
  79. sys.exit(1)
  80. # for CPPFLAGS and DEFS, define device family
  81. if mode in ('CPPFLAGS', 'DEFS'):
  82. sys.stdout.write(' '.join('-D%s' % d.upper() for d in device['family']))
  83. # defines
  84. if mode == 'DEFS':
  85. if len(device['defs']) > 0:
  86. defs = ' '.join('-D_%s=%s' % d for d in device['defs'])
  87. sys.stdout.write(' ' + defs)
  88. # device family
  89. elif mode == 'FAMILY':
  90. if len(device['family']) > 0:
  91. sys.stdout.write(device['family'][0])
  92. # device subfamily
  93. elif mode == 'SUBFAMILY':
  94. if len(device['family']) > 1:
  95. sys.stdout.write(device['family'][1])
  96. # device info
  97. else:
  98. info = mode.lower()
  99. if info in device['info']:
  100. sys.stdout.write(device['info'][info])
  101. sys.stdout.flush()