-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1461e0f
commit 3b0e8e3
Showing
9 changed files
with
277 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from pathlib import Path | ||
import re | ||
import fire | ||
from mako.template import Template | ||
|
||
|
||
def super_define(sv_file): | ||
with open(sv_file, "r") as file: | ||
content = file.read() | ||
pattern = r"""\/\* super_define\((?:.*)\).*\*\/""" | ||
matches = re.findall(pattern, content, re.DOTALL) | ||
|
||
if matches: | ||
for match in matches: | ||
lines = match.split("\n") | ||
result = re.match(r".*\((.*)\).*", lines[0]) | ||
lines = lines[1:-1] | ||
t = Template("\n".join(lines)) | ||
generated_code = t.render() if not result.group(1) else f'`include "{result.group(1)}"\n' | ||
new_string = f"{match}\n// super_define generate begin\n{generated_code}// super_define generate end" | ||
pattern = r"""\/\* super_define\(.*\).*super_define generate end|\/\* super_define\(.*\).*\*\/""" | ||
content = re.sub(pattern, new_string, content, 1, re.DOTALL) | ||
|
||
if result.group(1): | ||
inc_file = Path(sv_file).parent.joinpath(result.group(1)) | ||
with open(inc_file, "w") as f_inc, open(sv_file, "w") as f_src: | ||
f_inc.write(t.render()) | ||
f_src.write(content) | ||
print(f"super_define generate in '{inc_file}'.") | ||
else: | ||
with open(sv_file, "w") as file: | ||
file.write(content) | ||
print(f"super_define generate in '{sv_file}'.") | ||
else: | ||
print(f"Pattern '{pattern}' not found in file '{sv_file}'.") | ||
|
||
|
||
def main(): | ||
fire.Fire(super_define) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
int cfg_1; | ||
int cfg_2; | ||
int cfg_3; | ||
int cfg_4; | ||
int cfg_5; | ||
int cfg_6; | ||
int cfg_7; | ||
int cfg_8; | ||
int cfg_9; | ||
int cfg_10; | ||
|
||
`uvm_object_utils_begin(mycfg) | ||
`uvm_field_int(cfg_1, UVM_DEFAULT) | ||
`uvm_field_int(cfg_2, UVM_DEFAULT) | ||
`uvm_field_int(cfg_3, UVM_DEFAULT) | ||
`uvm_field_int(cfg_4, UVM_DEFAULT) | ||
`uvm_field_int(cfg_5, UVM_DEFAULT) | ||
`uvm_field_int(cfg_6, UVM_DEFAULT) | ||
`uvm_field_int(cfg_7, UVM_DEFAULT) | ||
`uvm_field_int(cfg_8, UVM_DEFAULT) | ||
`uvm_field_int(cfg_9, UVM_DEFAULT) | ||
`uvm_field_int(cfg_10, UVM_DEFAULT) | ||
`uvm_object_utils_end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* super_define(cfg_inc.svh) | ||
<% | ||
%>\ | ||
% for i in range(1, 11): | ||
int cfg_${i}; | ||
% endfor | ||
`uvm_object_utils_begin(mycfg) | ||
% for i in range(1, 11): | ||
`uvm_field_int(cfg_${i}, UVM_DEFAULT) | ||
% endfor | ||
`uvm_object_utils_end | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* super_define(cfg_inc.svh) | ||
<% | ||
%>\ | ||
% for i in range(1, 11): | ||
int cfg_${i}; | ||
% endfor | ||
`uvm_object_utils_begin(mycfg) | ||
% for i in range(1, 11): | ||
`uvm_field_int(cfg_${i}, UVM_DEFAULT) | ||
% endfor | ||
`uvm_object_utils_end | ||
*/ | ||
// super_define generate begin | ||
`include "cfg_inc.svh" | ||
// super_define generate end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* super_define() | ||
<% | ||
%>\ | ||
% for i in range(1, 11): | ||
int cfg_${i}; | ||
% endfor | ||
`uvm_object_utils_begin(mycfg) | ||
% for i in range(1, 11): | ||
`uvm_field_int(cfg_${i}, UVM_DEFAULT) | ||
% endfor | ||
`uvm_object_utils_end | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* super_define() | ||
<% | ||
%>\ | ||
% for i in range(1, 11): | ||
int cfg_${i}; | ||
% endfor | ||
`uvm_object_utils_begin(mycfg) | ||
% for i in range(1, 11): | ||
`uvm_field_int(cfg_${i}, UVM_DEFAULT) | ||
% endfor | ||
`uvm_object_utils_end | ||
*/ | ||
// super_define generate begin | ||
int cfg_1; | ||
int cfg_2; | ||
int cfg_3; | ||
int cfg_4; | ||
int cfg_5; | ||
int cfg_6; | ||
int cfg_7; | ||
int cfg_8; | ||
int cfg_9; | ||
int cfg_10; | ||
|
||
`uvm_object_utils_begin(mycfg) | ||
`uvm_field_int(cfg_1, UVM_DEFAULT) | ||
`uvm_field_int(cfg_2, UVM_DEFAULT) | ||
`uvm_field_int(cfg_3, UVM_DEFAULT) | ||
`uvm_field_int(cfg_4, UVM_DEFAULT) | ||
`uvm_field_int(cfg_5, UVM_DEFAULT) | ||
`uvm_field_int(cfg_6, UVM_DEFAULT) | ||
`uvm_field_int(cfg_7, UVM_DEFAULT) | ||
`uvm_field_int(cfg_8, UVM_DEFAULT) | ||
`uvm_field_int(cfg_9, UVM_DEFAULT) | ||
`uvm_field_int(cfg_10, UVM_DEFAULT) | ||
`uvm_object_utils_end | ||
// super_define generate end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import filecmp | ||
from pathlib import Path | ||
from uvmgen.super_define import super_define | ||
|
||
base_json_paths = Path(__file__).parent.joinpath("json/base_pkg").iterdir() | ||
|
||
|
||
def test_super_define_inline(): | ||
test_file = Path(__file__).parent.joinpath("super_define_data/sudef_inline.sv") | ||
exp_file = Path(__file__).parent.joinpath("super_define_data/sudef_inline_exp.sv") | ||
super_define(test_file) | ||
assert filecmp.cmp(test_file, exp_file) | ||
|
||
|
||
def test_super_define_inc(): | ||
test_file = Path(__file__).parent.joinpath("super_define_data/sudef_inc.sv") | ||
exp_file = Path(__file__).parent.joinpath("super_define_data/sudef_inc_exp.sv") | ||
inc_file = Path(__file__).parent.joinpath("super_define_data/cfg_inc.svh") | ||
inc_exp_file = Path(__file__).parent.joinpath("super_define_data/cfg_inc_exp.svh") | ||
super_define(test_file) | ||
assert filecmp.cmp(test_file, exp_file) | ||
assert filecmp.cmp(inc_file, inc_exp_file) |