Skip to content

Commit

Permalink
Prepending generated core files (#636)
Browse files Browse the repository at this point in the history
* added a possibility to prepend generated cores

* added tests for posisiton prepend + fixed syntax

---------

Co-authored-by: Mykyta Haranko <mykyta.haranko@zhinst.com>
  • Loading branch information
garankonic and Mykyta Haranko authored Nov 17, 2023
1 parent 456c2ae commit dba68ff
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fusesoc/capi2/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@
"type": "string"
},
"position": {
"description": "Where to insert the generated core. Legal values are *first*, *append* or *last*. *append* will insert core after the core that called the generator",
"description": "Where to insert the generated core. Legal values are *first*, *prepend*, *append* or *last*. *prepend* (*append*) will insert core before (after) the core that called the generator",
"type": "string",
"pattern": "^first|append|last$"
"pattern": "^first|prepend|append|last$"
},
"parameters": {
"description": "Generator-specific parameters. ``fusesoc gen show $generator`` might show available parameters. ",
Expand Down
2 changes: 2 additions & 0 deletions fusesoc/edalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ def create_edam(self):
first_snippets.append(snippet)
elif core.pos == "last":
last_snippets.append(snippet)
elif core.pos == "prepend" and len(snippets) > 0:
snippets.insert(len(snippets) - 1, snippet)
else:
snippets.append(snippet)
else:
Expand Down
7 changes: 7 additions & 0 deletions tests/capi2_cores/deptree/generated_child_a.core
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ generate:
parameters:
filename: generated-child-a.sv

generated-child-a-generate-position-prepend:
generator: generated-child-a-generator
parameters:
filename: generated-child-a-prepend.sv
position: prepend

generated-child-a-generate-position-append:
generator: generated-child-a-generator
parameters:
Expand Down Expand Up @@ -49,6 +55,7 @@ targets:
- fs1
generate:
- generated-child-a-generate
- generated-child-a-generate-position-prepend
- generated-child-a-generate-position-append
- generated-child-a-generate-position-last
- generated-child-a-generate-position-first
2 changes: 2 additions & 0 deletions tests/test_coremanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ def test_deptree(tmp_path):
# This is because generated files are often dependent on files
# that are not generated, and it convenient to be able to
# include them in the same core.
# However, for peculiar cases when non-generated files actually depend on generated, "position: prepend" is also available
"child-a2.sv",
"generated-child-a-prepend.sv",
"generated-child-a.sv",
"generated-child-a-append.sv",
),
Expand Down

0 comments on commit dba68ff

Please sign in to comment.