f4pga: style

Signed-off-by: Unai Martinez-Corral <umartinezcorral@antmicro.com>
This commit is contained in:
Unai Martinez-Corral 2022-08-18 21:39:25 +02:00
parent b161b69048
commit 2ccbbbe4e4
6 changed files with 66 additions and 78 deletions

View File

@ -198,7 +198,7 @@ def vpr(mode: str, vprargs: VprArgs, cwd=None):
+ modeargs
+ vprargs.optional
),
cwd=str(cwd),
cwd=cwd,
)

View File

@ -60,15 +60,14 @@ class SynthModule(Module):
extra_products: "list[str]"
def map_io(self, ctx: ModuleContext):
mapping = {}
top = Path(ctx.takes.build_dir) / ctx.values.top if ctx.takes.build_dir else Path(ctx.values.top)
top = ctx.values.top
if ctx.takes.build_dir:
top = str(Path(ctx.takes.build_dir) / top)
mapping["eblif"] = top + ".eblif"
mapping["fasm_extra"] = top + "_fasm_extra.fasm"
mapping["json"] = top + ".json"
mapping["synth_json"] = top + "_io.json"
mapping = {
"eblif": f"{top!s}.eblif",
"fasm_extra": f"{top!s}_fasm_extra.fasm",
"json": f"{top!s}.json",
"synth_json": f"{top!s}_io.json",
}
for extra in self.extra_products:
name, spec = decompose_depname(extra)
@ -77,8 +76,8 @@ class SynthModule(Module):
f"Yosys synth extra products can't use 'maybe\ "
f"(?) specifier. Product causing this error: `{extra}`."
)
elif spec == 'req':
mapping[name] = str(Path(top).parent / f'{ctx.values.device}_{name}.{name}')
elif spec == "req":
mapping[name] = str(top.parent / f"{ctx.values.device}_{name}.{name}")
return mapping

View File

@ -239,12 +239,13 @@ class Flow:
def _build_dep(self, dep):
paths = self.dep_paths.get(dep)
provider = self.os_map.get(dep)
run = (provider.name in self.run_stages) if provider else False
if not paths:
sfprint(2, f"Dependency {dep} is unresolved.")
return False
provider = self.os_map.get(dep)
run = (provider.name in self.run_stages) if provider else False
if p_req_exists(paths) and not run:
return True
else:

View File

@ -73,9 +73,7 @@ class FlowDefinition:
if global_vals is not None:
self.r_env.add_values(global_vals)
stages_d = flow_def["stages"]
for stage_name, stage_def in stages_d.items():
for stage_name, stage_def in flow_def["stages"].items():
self.stages[stage_name] = Stage(stage_name, stage_def)
def stage_names(self):
@ -142,14 +140,13 @@ class FlowConfig:
def __init__(self, project_config: ProjectFlowConfig, platform_def: FlowDefinition, part: str):
self.r_env = platform_def.r_env
platform_vals = project_config.get_values_raw(part)
self.r_env.add_values(platform_vals)
self.r_env.add_values(project_config.get_values_raw(part))
self.stages = platform_def.stages
self.part = part
raw_project_deps = project_config.get_dependencies_raw(part)
self.dependencies_explicit = deep(lambda p: str(Path(p).resolve()))(self.r_env.resolve(raw_project_deps))
self.dependencies_explicit = deep(lambda p: str(Path(p).resolve()))(
self.r_env.resolve(project_config.get_dependencies_raw(part))
)
for stage_name, stage in platform_def.stages.items():
project_val_ovds = project_config.get_stage_value_overrides(part, stage_name)

View File

@ -25,8 +25,7 @@ from f4pga.flows.runner import get_module, module_io
class StageIO:
"""
Stage dependency input/output.
TODO: Solve the inconsistecy between usage of that and usage of
`decompose_depname` with an unprocessed string.
TODO: Solve the inconsistecy between usage of that and usage of `decompose_depname` with an unprocessed string.
"""
name: str # A symbolic name given to the dependency
@ -47,49 +46,41 @@ class StageIO:
class Stage:
"""
Represents a single stage in a flow. I.e an instance of a module with a
local set of values.
Represents a single stage in a flow.
I.e an instance of a module with a local set of values.
"""
name: str # Name of the stage (module's name)
takes: "list[StageIO]" # List of symbolic names of dependencies used by
# the stage
produces: "list[StageIO]" # List of symbolic names of dependencies
# produced by the stage
value_overrides: "dict[str, ]" # Stage-specific values
module: Module
meta: "dict[str, str]" # Stage's metadata extracted from module's
# output.
# Name of the stage (module's name)
name: str
# List of symbolic names of dependencies used by the stage
takes: "list[StageIO]"
# List of symbolic names of dependencies produced by the stage
produces: "list[StageIO]"
# Stage-specific values
value_overrides: "dict[str, ]"
# Stage's metadata extracted from module's output.
meta: "dict[str, str]"
def __init__(self, name: str, stage_def: "dict[str, ]"):
self.name = name
if stage_def is None:
stage_def = {}
modstr = stage_def["module"]
module_path = resolve_modstr(modstr)
ModuleClass = get_module(module_path)
self.module = ModuleClass(stage_def.get("params"))
self.module = get_module(resolve_modstr(stage_def["module"]))(stage_def.get("params"))
values = stage_def.get("values")
if values is not None:
self.value_overrides = values
else:
self.value_overrides = {}
self.value_overrides = values if values is not None else {}
mod_io = module_io(self.module)
self.name = name
self.takes = []
for input in mod_io["takes"]:
io = StageIO(input)
self.takes.append(io)
self.produces = []
for input in mod_io["produces"]:
io = StageIO(input)
self.produces.append(io)
self.takes = [StageIO(input) for input in mod_io["takes"]]
self.produces = [StageIO(input) for input in mod_io["produces"]]
self.meta = mod_io["meta"]
def __repr__(self) -> str: