blob: 66bbb9b7b1565bc58054763b146e253215b0078e [file] [log] [blame]
Lei YU43082e72020-03-09 10:32:48 +08001#!/usr/bin/env python3
Brandon Wyman34e257b2019-03-28 17:39:18 -05002
3import os
Patrick Williamsa93243d2022-12-05 09:20:34 -06004import sys
Brandon Wyman34e257b2019-03-28 17:39:18 -05005from argparse import ArgumentParser
Patrick Williamsa93243d2022-12-05 09:20:34 -06006
7import yaml
Brandon Wyman34e257b2019-03-28 17:39:18 -05008from mako.lookup import TemplateLookup
9
Patrick Williamsa93243d2022-12-05 09:20:34 -060010if __name__ == "__main__":
Brandon Wyman34e257b2019-03-28 17:39:18 -050011 parser = ArgumentParser(
Patrick Williamsa93243d2022-12-05 09:20:34 -060012 description="Power sequencer UCD90160 definition parser"
13 )
Brandon Wyman34e257b2019-03-28 17:39:18 -050014
Patrick Williamsa93243d2022-12-05 09:20:34 -060015 parser.add_argument(
16 "-i",
17 "--input_yaml",
18 dest="input_yaml",
19 default="example/ucd90160.yaml",
20 help="UCD90160 definitions YAML",
21 )
Brandon Wyman34e257b2019-03-28 17:39:18 -050022
Patrick Williamsa93243d2022-12-05 09:20:34 -060023 parser.add_argument(
24 "-o",
25 "--output_dir",
26 dest="output_dir",
27 default=".",
28 help="output directory",
29 )
Brandon Wyman34e257b2019-03-28 17:39:18 -050030
31 args = parser.parse_args()
32
33 if not args.input_yaml or not args.output_dir:
34 parser.print_usage()
35 sys.exit(1)
36
Patrick Williamsa93243d2022-12-05 09:20:34 -060037 with open(args.input_yaml, "r") as ucd90160_input:
Brandon Wyman34e257b2019-03-28 17:39:18 -050038 ucd90160_data = yaml.safe_load(ucd90160_input) or {}
39
40 templates_dir = os.path.join(
Patrick Williamsa93243d2022-12-05 09:20:34 -060041 os.path.dirname(os.path.realpath(__file__)), "templates"
42 )
Brandon Wyman34e257b2019-03-28 17:39:18 -050043
44 output_file = os.path.join(args.output_dir, "ucd90160_defs.cpp")
45
Patrick Williamsa93243d2022-12-05 09:20:34 -060046 mylookup = TemplateLookup(directories=templates_dir.split())
47 mytemplate = mylookup.get_template("ucd90160_defs.mako.cpp")
Brandon Wyman34e257b2019-03-28 17:39:18 -050048
Patrick Williamsa93243d2022-12-05 09:20:34 -060049 with open(output_file, "w") as output:
Brandon Wyman34e257b2019-03-28 17:39:18 -050050 output.write(mytemplate.render(ucd90160s=ucd90160_data))