Skip to content

Commit

Permalink
cfgparse: add support for polymorphism in json cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
saursin committed Nov 26, 2023
1 parent f5ad5e9 commit 7e47e23
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
26 changes: 7 additions & 19 deletions rtl/config/hydrogensoc_minimal.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
{
"name": "hydrogensoc_minimal",
"vtopmodule": "HydrogenSoC",
"vdefines": [
"ENABLE_RISCV_EMBEDDED"
],
"vsrcs": [
"${RVATOM}/rtl/soc/hydrogensoc/HydrogenSoC.v"
],
"vincdirs": [
"${RVATOM}/rtl/soc/hydrogensoc"
],
"includes": [
"atomrv_wb",
"wbcomponents",
"uart",
"gpio",
"spi",
"timer",
"mem"
]
"extends": "hydrogensoc",
"params": {
"en_embedded": true,
"en_compressed": false,
"en_csr": false,
"en_exceptions": false
}
}
20 changes: 20 additions & 0 deletions scripts/cfgparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,26 @@ def add_searchdir(self, dir: str):
self.search_dirs = [dir] + self.search_dirs

def parse(self):
# check if extends
def chk_extends(cfg:Config):
if 'extends' in cfg.json.keys():
import copy
bak = copy.deepcopy(cfg)
parent_cfg = cfg.json['extends']
parent_cfg_file = search_file(parent_cfg+'.json', self.search_dirs)
assert parent_cfg_file is not None, f'Cannot find parent "{parent_cfg}" for "{cfg.get_name()}"\n\tSearched in {str(self.search_dirs)}'
with open(parent_cfg_file, 'r') as cf:
cfg.json = json.load(cf)
# override name
cfg.json['name'] = bak.get_name()
# override params
for param in bak.get_params().keys():
cfg.json['params'][param] = bak.get_params()[param] # updates, adds if not presents
print(cfg.get_params())
for dep in cfg.deps:
chk_extends(dep)
chk_extends(self.cfg)

def resolve_config_deps(cfg: Config):
# resolve deps in current config
for inc_cfg_name in cfg.get_includes():
Expand Down

0 comments on commit 7e47e23

Please sign in to comment.