regmap.type_ref = regtypename
-def main():
- regdb_filename = sys.argv[1]
- with open(regdb_filename, 'r') as filp:
- regdb = RegisterDatabase.from_json(json.load(filp))
+def json_canonicalize(filp, chips = None):
+ regdb = RegisterDatabase.from_json(json.load(filp))
- if len(sys.argv) > 2:
+ if chips is not None:
for regmap in regdb.register_mappings():
assert not hasattr(regmap, 'chips')
- regmap.chips = [sys.argv[2]]
+ regmap.chips = [chips]
deduplicate_enums(regdb)
deduplicate_register_types(regdb)
deduce_missing_register_types(regdb)
regdb.garbage_collect()
- print(regdb.encode_json_pretty())
+ return regdb.encode_json_pretty()
+
+def main():
+ print(json_canonicalize(open(sys.argv[1], 'r'), sys.argv[2]))
if __name__ == '__main__':
main()