lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 1 | #!/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 Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 5 | r"""Mako template to Hjson register description |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 6 | """ |
| 7 | import sys |
| 8 | import argparse |
| 9 | from io import StringIO |
| 10 | |
| 11 | from mako.template import Template |
| 12 | |
| 13 | |
| 14 | def 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 Kim | 5ba11f2 | 2022-07-29 16:22:06 -0700 | [diff] [blame] | 39 | out.write(reg_tpl.render(harts=args.harts, timers=args.timers).rstrip()) |
lowRISC Contributors | 802543a | 2019-08-31 12:12:56 +0100 | [diff] [blame] | 40 | |
| 41 | print(out.getvalue()) |
| 42 | |
| 43 | out.close() |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | main() |