Skip to content

Commit

Permalink
Added ensure function to check if flow_args was None or a dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
yonnorc42 committed Nov 15, 2023
1 parent a458c7d commit 63eb71f
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 17 deletions.
8 changes: 0 additions & 8 deletions bfasst/ninja_flows/flow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from bfasst.paths import NINJA_BUILD_PATH

from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth


def get_flows():
"""Get all flows in the flows directory"""
Expand All @@ -32,9 +30,3 @@ def create_build_file():
"""Overwrite the build.ninja file when running generation and build steps separately"""
with open(NINJA_BUILD_PATH, "w") as f:
f.write("# This file is autogenerated by bfasst\n\n")


def configure_vivado_synth_tool(design, flow_args, ooc=False):
if isinstance(flow_args, dict) and "synth" in flow_args:
return VivadoSynth(design, flow_args["synth"], ooc)
return VivadoSynth(design, ooc=ooc)
4 changes: 3 additions & 1 deletion bfasst/ninja_flows/ninja_flow_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def __init__(self):

def create_flows(self, flow_name, designs, flow_args=None):
"""Create the ninja flows for the given designs."""
if flow_args is None:
flow_args = {}
self.flow_name = flow_name
self.flows = []
self.designs = []
Expand Down Expand Up @@ -101,7 +103,7 @@ def get_design_basenames(designs):
if parsed_args.flow_args:
FLOW_ARGS_DICT = json.loads(parsed_args.flow_args.replace("'", '"'))
else:
FLOW_ARGS_DICT = {}
FLOW_ARGS_DICT = None

flow_manager = NinjaFlowManager()
flow_manager.create_flows(
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from bfasst.ninja_tools.vivado.impl.vivado_impl import VivadoImpl
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class Vivado(Flow):
Expand All @@ -11,7 +12,7 @@ class Vivado(Flow):
def __init__(self, design, flow_args=None, ooc=False):
super().__init__(design)
self.ooc = ooc
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"), ooc=ooc)
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"), ooc)
self.vivado_impl_tool = VivadoImpl(design, ooc)

def create_rule_snippets(self):
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_bit_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
from bfasst.ninja_tools.transform.netlist_cleanup import NetlistCleanupTool
from bfasst.ninja_tools.transform.netlist_phys_to_logical import NetlistPhysToLogicalTool
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class VivadoBitAnalysis(Flow):
"""Flow to reverse a netlist from a bitstream using x-ray."""

def __init__(self, design, flow_args=None):
super().__init__(design)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.xrev_tool = XrevTool(design)
self.netlist_cleanup_tool = NetlistCleanupTool(design)
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_conformal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.types import Vendor
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class VivadoConformal(Flow):
"""Run vivado, phys_netlist, reverse with xray, then compare with conformal."""

def __init__(self, design, flow_args=None):
super().__init__(design)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.xrev_tool = Xray(design)
self.conformal_tool = Conformal(design)
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_phys_netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from bfasst.ninja_tools.transform.phys_netlist import PhysNetlist
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class VivadoPhysNetlist(Flow):
"""Creates a Vivado netlist that has only physical primitives."""

def __init__(self, design, flow_args=None):
super().__init__(design)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.phys_netlist_tool = PhysNetlist(design)

Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_phys_netlist_cmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from bfasst.ninja_tools.transform.phys_netlist import PhysNetlist
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class VivadoPhysNetlistCmp(Flow):
"""Structural Comparison of physical netlist and reversed netlist"""

def __init__(self, design, flow_args=None):
super().__init__(design)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.phys_netlist_tool = PhysNetlist(design)
self.xray_tool = Xray(design)
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_phys_netlist_xrev.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from bfasst.ninja_tools.transform.phys_netlist import PhysNetlist
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class VivadoPhysNetlistXrev(Flow):
"""Flow that combines vivado phys netlist and xray/f2b reversal."""

def __init__(self, design, flow_args=None):
super().__init__(design)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.phys_netlist_tool = PhysNetlist(design)
self.xrev_tool = Xray(design)
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_structural_error_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bfasst.ninja_tools.transform.phys_netlist import PhysNetlist
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure

from bfasst.ninja_utils.error_injector import ErrorType

Expand All @@ -20,7 +21,7 @@ class VivadoStructuralErrorInjection(Flow):
def __init__(self, design, flow_args=None):
super().__init__(design)
random.seed(0)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.phys_netlist_tool = PhysNetlist(design)
self.xrev_tool = Xray(design)
Expand Down
3 changes: 2 additions & 1 deletion bfasst/ninja_flows/vivado_yosys_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from bfasst.ninja_tools.rev_bit.xray import Xray
from bfasst.paths import NINJA_FLOWS_PATH
from bfasst.ninja_tools.vivado.synth.vivado_synth import VivadoSynth
from bfasst.utils.general import ensure


class VivadoYosysImpl(Flow):
"""Flow to compare reversed netlist to original using yosys."""

def __init__(self, design, flow_args=None):
super().__init__(design)
self.vivado_synth_tool = VivadoSynth(design, flow_args.get("synth"))
self.vivado_synth_tool = VivadoSynth(design, ensure(flow_args, {}).get("synth"))
self.vivado_impl_tool = VivadoImpl(design)
self.xrev_tool = Xray(design)
self.yosys_tool = Yosys(design)
Expand Down
7 changes: 7 additions & 0 deletions bfasst/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,10 @@ def ensure_tuple(x):
if isinstance(x, list):
return tuple(x)
return (x,)


def ensure(x, y):
"""Compensates for how python deals with default reference objects"""
if x is None:
return y
return x

0 comments on commit 63eb71f

Please sign in to comment.