Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ generate_register_group(
stdx
INCLUDES
"stdx/tuple.hpp"
"stdx/compiler.hpp"
BUS
"groov::mmio_bus<>"
NAMESPACE
Expand Down
2 changes: 2 additions & 0 deletions test/tools/test_regs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import groov

def test_parse(t):
return {
"test_regs": groov.Group(
Expand Down
21 changes: 17 additions & 4 deletions tools/regs2groov.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import argparse
import groov
import importlib.util
from pathlib import Path
import sys


def select_name_func(choice):
Expand All @@ -15,7 +18,6 @@ def keep(s):
return dict(keep=keep, lower=to_lower, upper=to_upper)[choice]


# def generate_groups(groups, ):
def generate_groups(groups, config):
namespace = config.namespace
name_func = select_name_func(config.naming)
Expand Down Expand Up @@ -52,11 +54,13 @@ def generate_group(g):

with open(f"{config.output}", "w") as f:
print("#pragma once", file=f)
print("", file=f)
for include in includes:
print(f"#include <{include}>", file=f)

print("", file=f)
print("#include <groov/mmio_bus.hpp>", file=f)
print("#include <groov/config.hpp>", file=f)
print("", file=f)
print("#include <cstdint>", file=f)
print("", file=f)

Expand All @@ -66,9 +70,17 @@ def generate_group(g):
print(f"}} // namespace {namespace}", file=f)


def import_parser_modules(modules):
for m in modules:
module_name = Path(m).stem
spec = importlib.util.spec_from_file_location(module_name, m)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
globals().update(vars(module))


def generate(config):
for f in config.parser_modules:
exec(open(f).read())
parse_fn = eval(config.parse_fn)
groups = parse_fn(config.input)
generate_groups(groups, config)
Expand Down Expand Up @@ -139,6 +151,7 @@ def parse_cmdline():

def main():
args = parse_cmdline()
import_parser_modules(args.parser_modules)
generate(args)


Expand Down