blob: 2797e95e077f9025cccd0d878429a3888c7d62ce [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001#!/usr/bin/env python3
2# Copyright lowRISC contributors.
3# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4# SPDX-License-Identifier: Apache-2.0
Philipp Wagner14a3fee2019-11-21 10:07:02 +00005r"""Mako template to Hjson register description
lowRISC Contributors802543a2019-08-31 12:12:56 +01006"""
7import sys
8import argparse
9from io import StringIO
10
11from mako.template import Template
12
13
14def main():
15 parser = argparse.ArgumentParser(prog="reg_timer")
16 parser.add_argument(
17 'input',
18 nargs='?',
19 metavar='file',
20 type=argparse.FileType('r'),
21 default=sys.stdin,
22 help='input template file')
23 parser.add_argument('--harts', '-s', type=int, help='Number of Harts')
24 parser.add_argument(
25 '--timers',
26 '-t',
27 type=int,
28 default=1,
29 help='Number of Timers in a Hart. Maximum up to 32')
30
31 args = parser.parse_args()
32
33 if args.timers > 32:
34 raise Exception("OOB TIMERS")
35 # Determine output: if stdin then stdout if not then ??
36 out = StringIO()
37
38 reg_tpl = Template(args.input.read())
Eunchan Kim5ba11f22022-07-29 16:22:06 -070039 out.write(reg_tpl.render(harts=args.harts, timers=args.timers).rstrip())
lowRISC Contributors802543a2019-08-31 12:12:56 +010040
41 print(out.getvalue())
42
43 out.close()
44
45
46if __name__ == "__main__":
47 main()