blob: 6747df084a9f38a2ee9afce812eefd7041e7cbfe [file] [log] [blame]
Eunchan Kim266b3a52019-10-09 14:31:57 -07001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4"""TileLink-Uncached Lightweight Xbar self document
5"""
6import logging as log
7
Eunchan Kim837c7962020-04-30 12:15:49 -07008from reggen.validate import val_types
Weicai Yang53b0d4d2020-11-30 15:28:33 -08009
Eunchan Kim837c7962020-04-30 12:15:49 -070010from .validate import root
Eunchan Kim266b3a52019-10-09 14:31:57 -070011
12doc_intro = """
13
Eunchan Kim266b3a52019-10-09 14:31:57 -070014The tables describe each key and the type of the value. The following
15types are used:
16
17Type | Description
18---- | -----------
19"""
20
Eunchan Kim266b3a52019-10-09 14:31:57 -070021
22def print_control(control, heading):
23 """Print a control group and its subgroup recursively
24 """
25 subgroup = [] # added if the field hit sub control group
26
27 outstr = '#' * heading + ' ' + control['name'] + '\n'
28 outstr += '\n'
29
30 outstr += control['description']
31 outstr += '\n\n'
32
33 items = {**control['required'], **control['optional'], **control['added']}
34
35 if len(items) > 0:
36 outstr += """
37Field | Kind | Type | Description
38----- | ---- | ---- | ------------
39"""
40 for k, v in items.items():
41 if k in control['required']:
42 kind = "required"
43 elif k in control['optional']:
44 kind = "optional"
45 else:
46 kind = "added by tool"
47
48 v_type = val_types[v[0]][0]
49
50 if v[0] == 'lg':
51 subgroup.append(v[1])
52 log.error(val_types[v[0]])
53 outstr += '{} | {} | {} | List of {} group\n'.format(
54 k, kind, v_type, k)
55 continue
56 elif v[0] == 'g':
57 if not isinstance(v[1], str):
58 subgroup.append(v[1])
59 outstr += '{} | {} | {} | {} group\n'.format(
60 k, kind, v_type, k)
61 continue
62
63 # Generic string print
64 outstr += '{} | {} | {} | {}\n'.format(k, kind, v_type, v[1])
65
66 outstr += "\n\n"
67 # recursive subgroup
68 for e in subgroup:
69 outstr += print_control(e, heading)
70
71 return outstr
72
73
74def selfdoc(heading, cmd=""):
Philipp Wagner14a3fee2019-11-21 10:07:02 +000075 # heading : Markdown header depth
Eunchan Kim266b3a52019-10-09 14:31:57 -070076 # value type
Rupert Swarbrick0b0d4982021-03-11 08:21:10 +000077 outstr = doc_intro
Eunchan Kim266b3a52019-10-09 14:31:57 -070078
79 for k, v in val_types.items():
80 outstr += v[0] + " | " + v[1] + "\n"
81
82 # root + subgroup
83 outstr += print_control(root, heading)
84
85 # connections: Needs custom as the key are hosts (can vary)
Eunchan Kim266b3a52019-10-09 14:31:57 -070086
87 return outstr