10Script to generate MSP430 definitions from TI's devices.csv
12Download the devices.csv from [1] using the link "Header and Support Files".
14[1]: https://www.ti.com/tool/MSP430-GCC-OPENSOURCE#downloads
23MULTIPLIER_HW_16 = (
"1",
"2")
24MULTIPLIER_HW_32 = (
"4",
"8")
26PREFIX =
"""//===--- MSP430Target.def - MSP430 Feature/Processor Database----*- C++ -*-===//
28// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
29// See https://llvm.org/LICENSE.txt for license information.
30// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
32//===----------------------------------------------------------------------===//
34// This file defines the MSP430 devices and their features.
36// Generated from TI's devices.csv in version {} using the script in
37// Target/MSP430/gen-msp430-def.py - use this tool rather than adding
40//===----------------------------------------------------------------------===//
42#ifndef MSP430_MCU_FEAT
43#define MSP430_MCU_FEAT(NAME, HWMULT) MSP430_MCU(NAME)
47#define MSP430_MCU(NAME)
54MSP430_MCU("msp430i2xxgeneric")
63 Parse the devices.csv file at the given path, generate the definitions and
64 write them to the given path.
66 :param csv_path: Path to the devices.csv to parse
68 :param def_path: Path to the output file to write the definitions to
72 mcus_multiplier_sw = []
73 mcus_multiplier_hw_16 = []
74 mcus_multiplier_hw_32 = []
77 with open(csv_path)
as csv_file:
78 csv_reader = csv.reader(csv_file)
80 row = next(csv_reader)
81 if len(row) < MULTIPLIER_COLUMN:
84 if row[DEVICE_COLUMN] ==
"# Device Name":
85 assert row[MULTIPLIER_COLUMN] ==
"MPY_TYPE",
"File format changed"
88 if row[0] ==
"Version:":
91 for row
in csv_reader:
92 if row[DEVICE_COLUMN].endswith(
"generic"):
94 if row[MULTIPLIER_COLUMN] == MULTIPLIER_SW:
95 mcus_multiplier_sw.append(row[DEVICE_COLUMN])
96 elif row[MULTIPLIER_COLUMN]
in MULTIPLIER_HW_16:
97 mcus_multiplier_hw_16.append(row[DEVICE_COLUMN])
98 elif row[MULTIPLIER_COLUMN]
in MULTIPLIER_HW_32:
99 mcus_multiplier_hw_32.append(row[DEVICE_COLUMN])
101 assert 0,
"Unknown multiplier type"
103 with open(def_path,
"w")
as def_file:
104 def_file.write(PREFIX.format(version))
106 for mcu
in mcus_multiplier_sw:
107 def_file.write(f
'MSP430_MCU("{mcu}")\n')
109 def_file.write(
"\n// With 16-bit hardware multiplier\n")
111 for mcu
in mcus_multiplier_hw_16:
112 def_file.write(f
'MSP430_MCU_FEAT("{mcu}", "16bit")\n')
114 def_file.write(
"\n// With 32-bit hardware multiplier\n")
116 for mcu
in mcus_multiplier_hw_32:
117 def_file.write(f
'MSP430_MCU_FEAT("{mcu}", "32bit")\n')
119 def_file.write(SUFFIX)
122if __name__ ==
"__main__":
123 if len(sys.argv) != 3:
124 sys.exit(f
"Usage: {sys.argv[0]} <CSV_FILE> <DEF_FILE>")
126 csv2def(sys.argv[1], sys.argv[2])
def csv2def(csv_path, def_path)