Skip to content

Commit 01dd541

Browse files
DavidAntliffdantliff-sqcamykyta3
authored
Add --reverse-fields option to show register fields in LSB to MSB order. (#60)
* Add --reverse-fields option to show register fields in LSB to MSB order. * Add PeakRDL TOML config for 'reverse-fields' feature. * Simplify reverse_fields logic --------- Co-authored-by: David Antliff <david.antliff@sqc.com.au> Co-authored-by: Alex Mykyta <amykyta3@users.noreply.github.com>
1 parent 007aac2 commit 01dd541

4 files changed

Lines changed: 47 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Constructor for the HTML exporter class
6363
* Additional context variables to load into the template namespace.
6464
* `show_signals`
6565
* Show signal components. Default is False
66+
* `reverse-fields`
67+
* Show fields in reverse order (LSB to MSB). Default is False
6668
* `extra_doc_properties`
6769
* List of properties to explicitly document.
6870

src/peakrdl_html/__peakrdl__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Exporter(ExporterSubcommandPlugin):
1919
"user_static_dir": schema.DirectoryPath(),
2020
"extra_doc_properties": [schema.String()],
2121
"generate_source_links": schema.Boolean(),
22+
"reverse_fields": schema.Boolean(),
2223
}
2324

2425

@@ -46,14 +47,24 @@ def add_exporter_arguments(self, arg_group: 'argparse.ArgumentParser') -> None:
4647
help="Show signal components in generated doc pages"
4748
)
4849

50+
arg_group.add_argument(
51+
"--reverse-fields",
52+
dest="reverse_fields",
53+
default=False,
54+
action="store_true",
55+
help="Show fields in reverse order (LSB to MSB)"
56+
)
4957

5058
def do_export(self, top_node: 'AddrmapNode', options: 'argparse.Namespace') -> None:
5159
generate_source_links = self.cfg['generate_source_links']
5260
if generate_source_links is None:
5361
generate_source_links = True
5462

63+
reverse_fields = options.reverse_fields or self.cfg['reverse_fields']
64+
5565
html = HTMLExporter(
5666
show_signals=options.show_signals,
67+
reverse_fields=reverse_fields,
5768
user_template_dir=self.cfg['user_template_dir'],
5869
user_static_dir=self.cfg['user_static_dir'],
5970
extra_doc_properties=self.cfg['extra_doc_properties'],

src/peakrdl_html/exporter.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ def __init__(self, **kwargs: 'Any') -> None:
4545
Additional context variables to load into the template namespace.
4646
show_signals: bool
4747
Show signal components. Default is False
48+
reverse_fields: bool
49+
(optional) Control whether register fields are displayed in reverse
50+
bit order (LSB to MSB). Default is False
4851
extra_doc_properties: List[str]
4952
List of properties to explicitly document.
5053
Nodes that have a property explicitly set will show its value in a
@@ -60,10 +63,12 @@ def __init__(self, **kwargs: 'Any') -> None:
6063
self.title = "" # type: str
6164
self.home_url = None # type: Optional[str]
6265
self.skip_not_present = True
66+
self.reverse_fields = False
6367
self.current_top_node = None # type: AddrmapNode
6468

6569
self.user_static_dir = kwargs.pop("user_static_dir", None) # type: Optional[str]
6670
self.show_signals = kwargs.pop("show_signals", False)
71+
self.reverse_fields = kwargs.pop("reverse_fields", False)
6772
self.user_context = kwargs.pop("user_context", {})
6873
markdown_inst = kwargs.pop("markdown_inst", None) # type: Optional[markdown.Markdown]
6974
self.extra_properties = kwargs.pop("extra_doc_properties", []) # type: List[str]
@@ -299,6 +304,12 @@ def write_ral_data(self) -> None:
299304

300305
def write_page(self, this_id: int, node: Node, children: 'Dict[int, Node]') -> None:
301306

307+
def field_order(x):
308+
if not self.reverse_fields:
309+
return reversed(x)
310+
else:
311+
return x
312+
302313
view_source_url, view_source_filename= self.get_view_source_info(node)
303314
context = {
304315
'this_id': this_id,
@@ -318,13 +329,14 @@ def write_page(self, this_id: int, node: Node, children: 'Dict[int, Node]') -> N
318329
'FieldNode': FieldNode,
319330
'AddressableNode': AddressableNode,
320331
'PropertyReference': rdltypes.PropertyReference,
321-
'reversed': reversed,
332+
'reversed': field_order,
322333
'isinstance': isinstance,
323334
'list': list,
324335
'view_source_url': view_source_url,
325336
'view_source_filename': view_source_filename,
326337
'reg_fields_are_low_to_high': reg_fields_are_low_to_high,
327-
'skip_not_present': self.skip_not_present
338+
'skip_not_present': self.skip_not_present,
339+
'highest_fields_first': not self.reverse_fields
328340
}
329341
context.update(self.user_context)
330342

src/peakrdl_html/templates/reg_base.html

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,16 @@
3030
<th></th>
3131
</tr>
3232
{%- for field in reversed(list(node.fields(skip_not_present=skip_not_present))) %}
33-
{%- if loop.first and field.high < (node.get_property('regwidth') - 1) %}
34-
{{reserved_field(node.get_property('regwidth') - 1, field.high + 1, reg_fields_are_low_to_high(node))}}
33+
{%- if loop.first %}
34+
{%- if highest_fields_first %}
35+
{%- if field.high < (node.get_property('regwidth') - 1) %}
36+
{{ reserved_field(node.get_property('regwidth') - 1, field.high + 1, reg_fields_are_low_to_high(node))}}
37+
{%- endif %}
38+
{%- else %}
39+
{%- if field.low > 0 %}
40+
{{ reserved_field(0, field.low - 1, reg_fields_are_low_to_high(node))}}
41+
{%- endif %}
42+
{%- endif %}
3543
{%- elif (not loop.first) and field.high < loop.previtem.low - 1 %}
3644
{{reserved_field(loop.previtem.low - 1, field.high + 1, reg_fields_are_low_to_high(node))}}
3745
{%- endif %}
@@ -89,8 +97,16 @@
8997
<a class="headerlink" href="#{{field.inst_name}}" title="Permalink to this row"></a>
9098
</td>
9199
</tr>
92-
{%- if loop.last and field.low != 0 %}
93-
{{reserved_field(field.low - 1, 0, reg_fields_are_low_to_high(node))}}
100+
{%- if loop.last %}
101+
{%- if highest_fields_first %}
102+
{%- if field.low != 0 %}
103+
{{ reserved_field(field.low - 1, 0, reg_fields_are_low_to_high(node))}}
104+
{%- endif %}
105+
{%- else %}
106+
{%- if field.high != node.get_property('regwidth') - 1 %}
107+
{{ reserved_field(node.get_property('regwidth') - 1, field.high + 1, reg_fields_are_low_to_high(node))}}
108+
{%- endif %}
109+
{%- endif %}
94110
{%- endif %}
95111
{%- endfor %}
96112
</table>

0 commit comments

Comments
 (0)