[reggen] Define a class wrapping the top-level IP block
The bulk of this patch is in ip_block.py, which defines the IpBlock class.
This object replaces the top-level dictionary that we were parsing.
Client code then replaces something like this:
obj = hjson.load(hjson_file.open('r'),
use_decimal=True,
object_pairs_hook=OrderedDict)
if validate.validate(obj, params=[]) != 0:
log.info("Parsing %s configuration failed." % hjson_file)
sys.exit(1)
with
obj = IpBlock.from_path(str(hjson_file), [])
where obj is now an IpBlock object instead of a dict.
Other than some pesky rewrites in the various gen_FOO scripts and
template files, the other big change on the reggen side was to replace
the hierarchical "Block" class that was defined in data.py. Now, we
have a Top class (created by topgen code) and a Top can contain
multiple blocks. We've also now got some validation logic to make sure
that the sub-blocks and memories don't overlap: I'm not sure that was
there before.
As well as changing how we load files (as described above), topgen
also needed a bit of work. We now have to convert various objects to
dicts in the merge stage. (Before, we cloned the dictionaries and
added some keys; now we construct the new dictionary explicitly).
The idea is that in time we'll start to generate objects instead of
dicts in topgen as well. As a bonus, we should be able to get rid of
some of the spurious "dump & load" logic found there.
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/util/reggen/gen_selfdoc.py b/util/reggen/gen_selfdoc.py
index 8e46ac9..5f38404 100644
--- a/util/reggen/gen_selfdoc.py
+++ b/util/reggen/gen_selfdoc.py
@@ -7,7 +7,7 @@
"""
from .access import SWACCESS_PERMITTED, HWACCESS_PERMITTED
from reggen import (validate,
- enum_entry, field,
+ ip_block, enum_entry, field,
register, multi_register, window)
@@ -248,12 +248,10 @@
outfile, "\n\nThe top level of the JSON is a group containing "
"the following keys:\n")
doc_tbl_head(outfile, 1)
- for x in validate.top_required:
- doc_tbl_line(outfile, x, 'r', validate.top_required[x])
- for x in validate.top_optional:
- doc_tbl_line(outfile, x, 'o', validate.top_optional[x])
- for x in validate.top_added:
- doc_tbl_line(outfile, x, 'a', validate.top_added[x])
+ for k, v in ip_block.REQUIRED_FIELDS.items():
+ doc_tbl_line(outfile, k, 'r', v)
+ for k, v in ip_block.OPTIONAL_FIELDS.items():
+ doc_tbl_line(outfile, k, 'o', v)
genout(outfile, top_example)
genout(