Skip to content

Commit 26c08d0

Browse files
fix: addBelsToPrim does not trim bel prefixes, remove local import and make it available for VHDL fabrics
Signed-off-by: Jonas K. <[email protected]>
1 parent 8355d42 commit 26c08d0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

FABulous/fabric_generator/gen_fabric/fabric_automation.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,10 @@ def addBelsToPrim(
414414
# check if its first port, to not set a comma before
415415
first = True
416416

417-
shared_ports = [p for p, _ in bel.sharedPort]
418-
419-
# external ports contain the bel prefix, but this is not needed in the prims file
417+
# ports contain the bel prefix, but this is not needed in the prims file
418+
inputs = [p.removeprefix(bel.prefix) for p in bel.inputs]
419+
outputs = [p.removeprefix(bel.prefix) for p in bel.outputs]
420+
shared_ports = [p.removeprefix(bel.prefix) for p, _ in bel.sharedPort]
420421
external_inputs: list[str] = []
421422
external_outputs: list[str] = []
422423
for external_port in bel.externalInput:
@@ -466,16 +467,17 @@ def addBelsToPrim(
466467

467468
modline += f" {direction} {port}"
468469
else: # No vector support
469-
ports = bel.inputs + bel.outputs + external_ports + shared_ports
470+
ports = inputs + outputs + external_ports + shared_ports
470471

472+
# we iterate through all ports to make the handling of the commas easier
471473
for port in ports:
472474
if not first:
473475
modline += ",\n"
474476
else:
475477
first = False
476-
if port in bel.inputs:
478+
if port in inputs:
477479
modline += f" input {port}"
478-
if port in bel.outputs:
480+
if port in outputs:
479481
modline += f" output {port}"
480482
if port in external_ports:
481483
modline += " (* iopad_external_pin *)\n"

FABulous/fabric_generator/parser/parse_csv.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from FABulous.fabric_definition.Gen_IO import Gen_IO
1818
from FABulous.fabric_definition.SuperTile import SuperTile
1919
from FABulous.fabric_definition.Tile import Tile
20+
from FABulous.fabric_generator.gen_fabric.fabric_automation import addBelsToPrim
2021
from FABulous.fabric_generator.parser.parse_hdl import parseBelFile
2122
from FABulous.fabric_generator.parser.parse_switchmatrix import (
2223
parseList,
@@ -140,19 +141,16 @@ def parseTilesCSV(fileName: Path) -> tuple[list[Tile], list[tuple[str, str]]]:
140141
bels.append(parseBelFile(belFilePath, bel_prefix, "vhdl"))
141142
elif temp[1].endswith(".v") or temp[1].endswith(".sv"):
142143
bels.append(parseBelFile(belFilePath, bel_prefix, "verilog"))
143-
if "ADD_AS_CUSTOM_PRIM" in temp[4:]:
144-
# local import to avoid circular import
145-
from FABulous.fabric_generator.gen_fabric.fabric_automation import (
146-
addBelsToPrim,
147-
)
148-
149-
primsFile = proj_dir.joinpath("user_design/custom_prims.v")
150-
logger.info(f"Adding bels to custom prims file: {primsFile}")
151-
addBelsToPrim(primsFile, [bels[-1]])
152144
else:
153145
raise InvalidFileType(
154146
f"File {belFilePath} is not a .vhdl or .v file. Please check the BEL file."
155147
)
148+
149+
if "ADD_AS_CUSTOM_PRIM" in temp[3:]:
150+
primsFile = proj_dir.joinpath("user_design/custom_prims.v")
151+
logger.info(f"Adding bels to custom prims file: {primsFile}")
152+
addBelsToPrim(primsFile, [bels[-1]])
153+
156154
elif temp[0] == "GEN_IO":
157155
configBit = 0
158156
configAccess = False

0 commit comments

Comments
 (0)