Skip to content

Commit

Permalink
generate-mocserver-json.py: Support JSON input format only
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-holenko committed Aug 4, 2021
1 parent a4b7073 commit 9cbced3
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions generate-mocserver-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
import collections
import json

from litex_renode.configuration import Configuration

configuration = None


def mk_obj():
def mk_obj(csr):
"""
Makes an object of dicts and lists from the registers var
Expand All @@ -27,11 +23,17 @@ def set_path(d, path, value):
d[path[-1]]['value'] = 0

the_dict = make_dict()
for register in configuration.registers:
for name, val in csr['csr_registers'].items():
reg_dict = { 'name': name, 'address': val['addr'] }
reg_dict.update(val)
reg_dict['r'] = val['type']
del(reg_dict['type'])
del(reg_dict['addr'])
reg_dict['shadowed_address'] = None
set_path(
the_dict,
register.split('_'),
configuration.registers[register],
name.split('_'),
reg_dict,
)

return the_dict
Expand Down Expand Up @@ -67,18 +69,19 @@ def crawl(d):
d[k].append(v)


def mk_json(filepath):
def mk_json(csr, filepath):
""" writes json file for the moc server to serve.
Args:
csr (dict): LiteX configuration
filepath (string): path to the file lines should be written to
or '-' to write to a standard output
the module's registers var data is turned into an object
and serialized to a .json file.
"""

o = mk_obj()
o = mk_obj(csr)
crawl(o)

with open(filepath, 'w') as f:
Expand All @@ -88,7 +91,7 @@ def mk_json(filepath):
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('conf_file',
help='CSV configuration generated by LiteX')
help='JSON configuration generated by LiteX')
parser.add_argument('--json-file', action='store',
help='Output json file for moc server')
args = parser.parse_args()
Expand All @@ -97,13 +100,13 @@ def parse_args():


def main():
global configuration
args = parse_args()

configuration = Configuration(args.conf_file)
with open(args.conf_file) as f:
csr = json.load(f)

if args.json_file:
mk_json(args.json_file)
mk_json(csr, args.json_file)


if __name__ == '__main__':
Expand Down

0 comments on commit 9cbced3

Please sign in to comment.