Eunchan Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 1 | # 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 | """ |
| 6 | import logging as log |
| 7 | |
Eunchan Kim | 837c796 | 2020-04-30 12:15:49 -0700 | [diff] [blame] | 8 | from reggen.validate import val_types |
Weicai Yang | 53b0d4d | 2020-11-30 15:28:33 -0800 | [diff] [blame] | 9 | |
Eunchan Kim | 837c796 | 2020-04-30 12:15:49 -0700 | [diff] [blame] | 10 | from .validate import root |
Eunchan Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 11 | |
| 12 | doc_intro = """ |
| 13 | |
Eunchan Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 14 | The tables describe each key and the type of the value. The following |
| 15 | types are used: |
| 16 | |
| 17 | Type | Description |
| 18 | ---- | ----------- |
| 19 | """ |
| 20 | |
Eunchan Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 21 | |
| 22 | def 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 += """ |
| 37 | Field | 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 | |
| 74 | def selfdoc(heading, cmd=""): |
Philipp Wagner | 14a3fee | 2019-11-21 10:07:02 +0000 | [diff] [blame] | 75 | # heading : Markdown header depth |
Eunchan Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 76 | # value type |
Rupert Swarbrick | 0b0d498 | 2021-03-11 08:21:10 +0000 | [diff] [blame] | 77 | outstr = doc_intro |
Eunchan Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 78 | |
| 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 Kim | 266b3a5 | 2019-10-09 14:31:57 -0700 | [diff] [blame] | 86 | |
| 87 | return outstr |