From dba68ffe6204748f8931652f8d99203a2b6b62e5 Mon Sep 17 00:00:00 2001 From: Mykyta Haranko Date: Fri, 17 Nov 2023 12:13:55 +0100 Subject: [PATCH] Prepending generated core files (#636) * added a possibility to prepend generated cores * added tests for posisiton prepend + fixed syntax --------- Co-authored-by: Mykyta Haranko --- fusesoc/capi2/json_schema.py | 4 ++-- fusesoc/edalizer.py | 2 ++ tests/capi2_cores/deptree/generated_child_a.core | 7 +++++++ tests/test_coremanager.py | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/fusesoc/capi2/json_schema.py b/fusesoc/capi2/json_schema.py index f38da7b6..8ff1564c 100644 --- a/fusesoc/capi2/json_schema.py +++ b/fusesoc/capi2/json_schema.py @@ -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. ", diff --git a/fusesoc/edalizer.py b/fusesoc/edalizer.py index 8fa4d1e1..1c2a5142 100644 --- a/fusesoc/edalizer.py +++ b/fusesoc/edalizer.py @@ -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: diff --git a/tests/capi2_cores/deptree/generated_child_a.core b/tests/capi2_cores/deptree/generated_child_a.core index a08061de..c92b5cd1 100644 --- a/tests/capi2_cores/deptree/generated_child_a.core +++ b/tests/capi2_cores/deptree/generated_child_a.core @@ -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: @@ -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 diff --git a/tests/test_coremanager.py b/tests/test_coremanager.py index e1fa672f..84d4ad5d 100644 --- a/tests/test_coremanager.py +++ b/tests/test_coremanager.py @@ -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", ),