Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symbiyosys: honour include paths #371

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 52 additions & 6 deletions edalize/symbiyosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class Symbiyosys(Edatool):
# A list of task names to pass to sby. Defaults to empty (in which case
# sby will run each task in the .sby file)
- my_proof
extra_options:
# A list of extra command line arguments to sby. Defaults to empty.
- -d
- build

The SymbiYosys tool expects a configuration file telling it what to do. This
file includes a list of all the source files, together with various flags which
Expand Down Expand Up @@ -108,8 +112,10 @@ class Symbiyosys(Edatool):
"lists": {
# A list of tasks to run from the .sby file. Passed on the sby
# command line.
"tasknames": "String"
}
"tasknames": "String",
# A list of extra arguments to the sby command.
"extra_options": "String",
},
}

def __init__(self, edam=None, work_root=None, eda_api=None, verbose=True):
Expand All @@ -126,6 +132,10 @@ def __init__(self, edam=None, work_root=None, eda_api=None, verbose=True):
# configure time by _get_file_names)
self.incdirs = None

# The list of include files in the fileset (populated at
# configure time)
self.includes = None

# The name of the interpolated .sby file that we create in the work
# root
self.sby_name = "test.sby"
Expand All @@ -143,15 +153,46 @@ def get_doc(api_ver):
"A list of the .sby file's tasks to run. "
"Passed on the sby command line."
),
}
},
{
"name": "extra_options",
"type": "String",
"desc": (
"A list of extra arguments. "
"Passed on the sby command line."
),
},
],
}

def _get_include_files(self, force_slash=False):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the include file name, no just the include directory

class Include:
def __init__(self, name, rel_name):
self.name = name
self.rel_name = rel_name

includes = []
for f in self.files:
if f.get("is_include_file"):
# The fully-qualified name
_name = f["name"]
# The working set base directory
_incdir = f.get("include_path") or os.path.dirname(f["name"]) or "."
if force_slash:
_incdir = _incdir.replace("\\", "/")
_name = _incdir.replace("\\", "/")
# The path to copy the include to in the working set
_rel_name = _name.removeprefix(_incdir)
_rel_name = _rel_name.removeprefix("/")
includes.append(Include(_name, _rel_name))
return includes

def _get_file_names(self):
"""Read the fileset to get our file names"""
assert self.rtl_paths is None

src_files, self.incdirs = self._get_fileset_files()
self.includes = self._get_include_files()
self.rtl_paths = []
bn_to_path = {}
sby_names = []
Expand Down Expand Up @@ -205,7 +246,6 @@ def _get_read_flags(self):
"-D{}={}".format(key, self._param_value_str(value))
for key, value in self.vlogdefine.items()
]
+ ["-I{}".format(inc) for inc in self.incdirs]
Copy link
Author

@ollie-etl ollie-etl Mar 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer do includes with flags. This doesn't work

)

def _get_chparam(self):
Expand Down Expand Up @@ -275,7 +315,7 @@ def _interpolate_sby(self, src):
"as a Jinja2 template: {}.".format(src_path, err)
)

files = "\n".join(self.rtl_paths)
files = "\n".join(map(lambda x: f"{x.rel_name} {x.name}", self.includes)) + "\n" + "\n".join(self.rtl_paths)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the files template to contain include files in dst src form


template_ctxt = {
"chparam": self._get_chparam(),
Expand Down Expand Up @@ -317,5 +357,11 @@ def run_main(self):
'"tasknames" tool option should be '
"a list of strings. Got {!r}.".format(tasknames)
)
extra_options = self.tool_options.get("extra_options", [])
if not isinstance(extra_options, list):
raise RuntimeError(
'"extra_options" tool option should be '
"a list of strings. Got {!r}.".format(extra_options)
)

self._run_tool("sby", ["-d", "build", self.sby_name] + tasknames)
self._run_tool("sby", extra_options + [self.sby_name] + tasknames)
1 change: 1 addition & 0 deletions tests/test_symbiyosys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def test_symbiyosys(make_edalize_test):
param_types=["vlogdefine", "vlogparam"],
tool_options={
"tasknames": ["task0", "task1"],
"extra_options": ["-d", "build"],
},
)

Expand Down