blob: 367587cdce7c9deae6143415a10c008f1583a76a [file] [log] [blame]
Dhruvaraj Subhashchandranc1f5ed62023-07-09 04:31:28 -05001#!/usr/bin/env python3
2
3import argparse
4import os
5
6import yaml
7from mako.template import Template
8
9
10def main():
11 parser = argparse.ArgumentParser(
12 description="OpenPOWER map code generator"
13 )
14
15 parser.add_argument(
16 "-i",
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -050017 "--input_dump_type_yaml",
18 dest="input_dump_type_yaml",
19 default="example_dump_types.yaml",
20 help="input dump type yaml file to parse",
21 )
22
23 parser.add_argument(
24 "-j",
25 "--input_error_type_yaml",
26 dest="input_error_type_yaml",
27 default="example_errors_watch.yaml",
28 help="input error type yaml file to parse",
Dhruvaraj Subhashchandranc1f5ed62023-07-09 04:31:28 -050029 )
30
31 parser.add_argument(
32 "-t",
33 "--template",
34 dest="template",
35 default="template.mako.cpp",
36 help="mako template file to use",
37 )
38
39 parser.add_argument(
40 "-o",
41 "--output_file",
42 dest="output_file",
43 default="output.cpp",
44 help="output cpp file",
45 )
46
Dhruvaraj Subhashchandranc1f5ed62023-07-09 04:31:28 -050047 args = parser.parse_args()
48
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -050049 with open(os.path.join(script_dir, args.input_dump_type_yaml), "r") as fd:
50 yaml_dict1 = yaml.safe_load(fd)
51
52 with open(os.path.join(script_dir, args.input_error_type_yaml), "r") as fd:
53 yaml_dict2 = yaml.safe_load(fd)
Dhruvaraj Subhashchandranc1f5ed62023-07-09 04:31:28 -050054
55 template = os.path.join(script_dir, args.template)
56 t = Template(filename=template)
57 with open(args.output_file, "w") as fd:
Dhruvaraj Subhashchandranaa0937f2023-07-22 23:50:40 -050058 fd.write(
59 t.render(DUMP_TYPE_TABLE=yaml_dict1, ERROR_TYPE_DICT=yaml_dict2)
60 )
Dhruvaraj Subhashchandranc1f5ed62023-07-09 04:31:28 -050061
62
63if __name__ == "__main__":
64 script_dir = os.path.dirname(os.path.realpath(__file__))
65 main()