Skip to content

Commit

Permalink
Common get_file_type function (#401)
Browse files Browse the repository at this point in the history
Add common function for stripping version from file_type

---------

Co-authored-by: Paul Gatewood <[email protected]>
  • Loading branch information
paul-gatewood and Paul Gatewood authored Nov 19, 2023
1 parent c3e9a54 commit 0dad9a4
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 18 deletions.
3 changes: 2 additions & 1 deletion edalize/design_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess

from edalize.edatool import Edatool
from edalize.utils import get_file_type
from edalize.yosys import Yosys
from importlib import import_module

Expand Down Expand Up @@ -142,7 +143,7 @@ def src_file_filter(self, f):
"SDC": "source",
}

_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)
if _file_type in file_types:
cmd = ""
cmd += file_types[_file_type] + " "
Expand Down
3 changes: 2 additions & 1 deletion edalize/diamond.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys

from edalize.edatool import Edatool
from edalize.utils import get_file_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -128,7 +129,7 @@ def _vhdl_source(f):
"tclSource": "source",
"SDC": "prj_src add -format SDC",
}
_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)
if _file_type in file_types:
return file_types[_file_type] + " " + f.name
elif _file_type in ["user", "LPF"]:
Expand Down
3 changes: 2 additions & 1 deletion edalize/genus.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import subprocess

from edalize.edatool import Edatool
from edalize.utils import get_file_type
from edalize.yosys import Yosys
from importlib import import_module

Expand Down Expand Up @@ -128,7 +129,7 @@ def src_file_filter(self, f):
# Note: we do not add an SDC source here as the constraint files are
# referenced inside the MMMC view file on a per corner base
}
_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)

if _file_type in file_types:
cmd = ""
Expand Down
7 changes: 4 additions & 3 deletions edalize/libero.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from collections import defaultdict
from edalize.edatool import Edatool
from edalize.utils import get_file_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -141,7 +142,7 @@ def configure_main(self):
verilogFiles = 0
VHDLFiles = 0
for f in src_files:
t = f.file_type.split("-")[0]
t = get_file_type(f)
if t == "verilogSource" or t == "systemVerilogSource":
verilogFiles += 1
elif t == "vhdlSource":
Expand Down Expand Up @@ -179,7 +180,7 @@ def src_file_filter(self, f):
"FDC": "-net_fdc {",
"NDC": "-ndc {",
}
_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)
if _file_type in file_types:
# Do not return library files here
if f.logical_name:
Expand All @@ -191,7 +192,7 @@ def tcl_file_filter(self, f):
file_types = {
"tclSource": "source ",
}
_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)
if _file_type in file_types:
return file_types[_file_type] + f.name
return ""
Expand Down
9 changes: 3 additions & 6 deletions edalize/quartus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import xml.etree.ElementTree as ET
from functools import partial
from edalize.edatool import Edatool
from edalize.utils import get_file_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -169,15 +170,11 @@ def configure_main(self):
"quartus-project.tcl.j2", escaped_name + ".tcl", template_vars
)

# Helper to extract file type
def file_type(self, f):
return f.file_type.split("-")[0]

# Filter for just QSYS files. This verifies that they are compatible
# with the identified Quartus version
def qsys_file_filter(self, f):
name = ""
if self.file_type(f) == "QSYS":
if get_file_type(f) == "QSYS":
# Compatibility checks
try:
qsysTree = ET.parse(os.path.join(self.work_root, f.name))
Expand Down Expand Up @@ -242,7 +239,7 @@ def _handle_tcl(f):
"tclSource": partial(_handle_tcl),
}

_file_type = self.file_type(f)
_file_type = get_file_type(f)
if _file_type in file_mapping:
return file_mapping[_file_type](f)
elif _file_type == "user":
Expand Down
3 changes: 2 additions & 1 deletion edalize/radiant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os.path

from edalize.edatool import Edatool
from edalize.utils import get_file_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -114,7 +115,7 @@ def _work_source(f):
"vhdlSource": "prj_add_source ",
"PDC": "prj_add_source ",
}
_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)
if _file_type in file_types:
return file_types[_file_type] + f.name + _work_source(f)
elif _file_type == "tclSource":
Expand Down
3 changes: 2 additions & 1 deletion edalize/spyglass.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import OrderedDict

from edalize.edatool import Edatool
from edalize.utils import get_file_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -136,7 +137,7 @@ def _vhdl_source(f):
"waiver": "read_file -type waiver",
"awl": "read_file -type awl",
}
_file_type = f.file_type.split("-")[0]
_file_type = get_file_type(f)
if _file_type in file_types:
return file_types[_file_type] + " " + f.name
elif _file_type == "user":
Expand Down
12 changes: 12 additions & 0 deletions edalize/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,15 @@ def write(self, outfile):
f.write(
f"\t$(EDALIZE_LAUNCHER) {env_prefix}{' '.join([str(x) for x in c.command])}\n"
)


# Helper function to strip potential version from the end of a file_type (for example, converting
# vhdlSource-2008 -> vhdlSource)
def get_file_type(file_obj):
file_type = file_obj.file_type

for i, c in enumerate(file_type):
if c == "-":
return file_type[0:i]

return file_type
6 changes: 2 additions & 4 deletions edalize/vunit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
from collections import OrderedDict
from edalize.edatool import Edatool
from edalize.utils import get_file_type

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -103,16 +104,13 @@ def src_file_vhdl_standard_filter(self, f):
return fragments[1]

def src_file_filter(self, f):
def _get_file_type(f):
return f.file_type.split("-")[0]

file_mapping = {
"verilogSource": lambda f: f.name,
"systemVerilogSource": lambda f: f.name,
"vhdlSource": lambda f: f.name,
}

_file_type = _get_file_type(f)
_file_type = get_file_type(f)
if _file_type in file_mapping:
return file_mapping[_file_type](f)
elif _file_type == "user":
Expand Down

0 comments on commit 0dad9a4

Please sign in to comment.