f4pga/flows: use proper pinmap CSV for qlf_k4n8 (#649)

diff --git a/docs/getting-started.rst b/docs/getting-started.rst
index 63593dd..0aef85e 100644
--- a/docs/getting-started.rst
+++ b/docs/getting-started.rst
@@ -68,7 +68,7 @@
 -------------------
 
 .. IMPORTANT::
-  Dure to size constraints, Architecture Definition packages cannot be distributed through Conda.
+  Due to size constraints, Architecture Definition packages cannot be distributed through Conda.
   Hence, installing a functional F4PGA system is a two step process: bootstraping the conda environment and getting the
   tarballs (or vice versa).
   In the future, getting and managing the tarballs might be handled by F4PGA.
diff --git a/f4pga/flows/cache.py b/f4pga/flows/cache.py
index 690e8db..96ad566 100755
--- a/f4pga/flows/cache.py
+++ b/f4pga/flows/cache.py
@@ -24,13 +24,6 @@
 from f4pga.flows.common import sfprint
 
 
-def _get_hash(path: Path):
-    if not path.is_dir():
-        with path.open("rb") as rfptr:
-            return zlib_adler32(rfptr.read())
-    return 0  # Directories always get '0' hash.
-
-
 class F4Cache:
     """
     `F4Cache` is used to track changes among dependencies and keep the status of the files on a persistent storage.
@@ -76,7 +69,13 @@
     def process_file(self, path: Path):
         """Process file for tracking with f4cache."""
 
-        hash = _get_hash(path)
+        if path.is_dir():
+            # Directories always get '0' hash.
+            hash = 0
+        else:
+            with path.open("rb") as rfptr:
+                hash = zlib_adler32(rfptr.read())
+
         self.current_hashes[path.as_posix()] = hash
 
     def update(self, path: Path, consumer: str):
diff --git a/f4pga/flows/common.py b/f4pga/flows/common.py
index fb89da2..35c7bd0 100644
--- a/f4pga/flows/common.py
+++ b/f4pga/flows/common.py
@@ -95,44 +95,6 @@
     return d
 
 
-class VprArgs:
-    """
-    Represents argument list for VPR (Versatile Place and Route).
-    """
-
-    arch_dir: str
-    arch_def: str
-    lookahead: str
-    rr_graph: str
-    place_delay: str
-    device_name: str
-    eblif: str
-    optional: list
-
-    def __init__(
-        self,
-        share: str,
-        eblif,
-        arch_def,
-        lookahead,
-        rr_graph,
-        place_delay,
-        device_name,
-        vpr_options={},
-        sdc_file: "str | None" = None,
-    ):
-        self.arch_dir = str(Path(share) / "arch")
-        self.arch_def = arch_def
-        self.lookahead = lookahead
-        self.rr_graph = rr_graph
-        self.place_delay = place_delay
-        self.device_name = device_name
-        self.eblif = str(Path(eblif).resolve())
-        self.optional = options_dict_to_list(vpr_options)
-        if sdc_file is not None:
-            self.optional += ["--sdc_file", sdc_file]
-
-
 class SubprocessException(Exception):
     return_code: int
 
@@ -152,48 +114,6 @@
     return out.stdout
 
 
-def vpr(mode: str, vprargs: VprArgs, cwd=None):
-    """
-    Execute `vpr`.
-    """
-    return sub(
-        *(
-            [
-                "vpr",
-                vprargs.arch_def,
-                vprargs.eblif,
-                "--device",
-                vprargs.device_name,
-                "--read_rr_graph",
-                vprargs.rr_graph,
-                "--read_router_lookahead",
-                vprargs.lookahead,
-                "--read_placement_delay_lookup",
-                vprargs.place_delay,
-            ]
-            + ([f"--{mode}"] if mode in ["pack", "place", "route", "analysis"] else [])
-            + vprargs.optional
-        ),
-        cwd=cwd,
-        print_stdout_on_fail=True,
-    )
-
-
-_vpr_specific_values = [
-    "arch_def",
-    "rr_graph_lookahead_bin",
-    "rr_graph_real_bin",
-    "vpr_place_delay",
-    "vpr_grid_layout_name",
-    "vpr_options?",
-]
-
-
-def vpr_specific_values():
-    global _vpr_specific_values
-    return _vpr_specific_values
-
-
 def options_dict_to_list(opt_dict: dict):
     """
     Converts a dictionary of named options for CLI program to a list.
@@ -215,13 +135,6 @@
     environ["OUR_NOISY_WARNINGS"] = f"noisy_warnings-{device}_pack.log"
 
 
-def save_vpr_log(filename, build_dir=""):
-    """
-    Save VPR logic (moves the default output file into a desired path).
-    """
-    sh_mv(str(Path(build_dir) / "vpr_stdout.log"), filename)
-
-
 def fatal(code, message):
     """
     Print a message informing about an error that has occured and terminate program with a given return code.
diff --git a/f4pga/flows/flow_config.py b/f4pga/flows/flow_config.py
index f2977f8..0e1210f 100644
--- a/f4pga/flows/flow_config.py
+++ b/f4pga/flows/flow_config.py
@@ -31,7 +31,7 @@
         return json_load(rfptr)
 
 
-def _get_ovs_raw(dict_name: str, flow_cfg, part: "str | None", stage: "str | None"):
+def p_get_ovs_raw(dict_name: str, flow_cfg, part: "str | None", stage: "str | None"):
     vals = flow_cfg.get(dict_name)
     if vals is None:
         vals = {}
@@ -55,11 +55,6 @@
     return False
 
 
-def _is_kword(w: str):
-    kwords = {"dependencies", "values", "default_platform", "default_target"}
-    return w in kwords
-
-
 class FlowDefinition:
     stages: "dict[str, Stage]"  # stage name -> module path mapping
     r_env: ResolutionEnv
@@ -80,6 +75,9 @@
         return self.stages.keys()
 
 
+KWORDS = {"dependencies", "values", "default_platform", "default_target"}
+
+
 class ProjectFlowConfig:
     flow_cfg: dict
     path: str
@@ -90,7 +88,7 @@
 
     def parts(self):
         for part in self.flow_cfg.keys():
-            if not _is_kword(part):
+            if part not in KWORDS:
                 yield part
 
     def get_default_part(self) -> "str | None":
@@ -103,13 +101,13 @@
         """
         Get dependencies without value resolution applied.
         """
-        return _get_ovs_raw("dependencies", self.flow_cfg, part, None)
+        return p_get_ovs_raw("dependencies", self.flow_cfg, part, None)
 
     def get_values_raw(self, part: "str | None" = None, stage: "str | None" = None):
         """
         Get values without value resolution applied.
         """
-        return _get_ovs_raw("values", self.flow_cfg, part, stage)
+        return p_get_ovs_raw("values", self.flow_cfg, part, stage)
 
     def get_stage_value_overrides(self, part: str, stage: str):
         stage_vals_ovds = {}
@@ -155,7 +153,7 @@
             p_dependencies.update(cli_p_dependencies)
 
         for stage_name, cli_stage_cfg in part_cfg.items():
-            if _is_kword(stage_name):
+            if stage_name in KWORDS:
                 continue
 
             stage_cfg = part_cfg.get(stage_name)
diff --git a/f4pga/flows/inspector.py b/f4pga/flows/inspector.py
index 7ed4ea6..7f8a83b 100644
--- a/f4pga/flows/inspector.py
+++ b/f4pga/flows/inspector.py
@@ -23,18 +23,18 @@
 from f4pga.flows.common import decompose_depname
 
 
-def _get_if_qualifier(deplist: "list[str]", qualifier: str):
+def p_get_if_qualifier(deplist: "list[str]", qualifier: str):
     for dep_name in deplist:
         name, q = decompose_depname(dep_name)
         if q == qualifier:
             yield f"● {Style.BRIGHT}{name}{Style.RESET_ALL}"
 
 
-def _list_if_qualifier(deplist: "list[str]", qualifier: str, indent: int = 4):
+def p_list_if_qualifier(deplist: "list[str]", qualifier: str, indent: int = 4):
     indent_str = "".join([" " for _ in range(0, indent)])
     r = ""
 
-    for line in _get_if_qualifier(deplist, qualifier):
+    for line in p_get_if_qualifier(deplist, qualifier):
         r += indent_str + line + "\n"
 
     return r
@@ -44,18 +44,18 @@
     r = ""
     r += f"Module `{Style.BRIGHT}{module.name}{Style.RESET_ALL}`:\n"
     r += "Inputs:\n  Required:\n    Dependencies\n"
-    r += _list_if_qualifier(module.takes, "req", indent=6)
+    r += p_list_if_qualifier(module.takes, "req", indent=6)
     r += "    Values:\n"
-    r += _list_if_qualifier(module.values, "req", indent=6)
+    r += p_list_if_qualifier(module.values, "req", indent=6)
     r += "  Optional:\n    Dependencies:\n"
-    r += _list_if_qualifier(module.takes, "maybe", indent=6)
+    r += p_list_if_qualifier(module.takes, "maybe", indent=6)
     r += "    Values:\n"
-    r += _list_if_qualifier(module.values, "maybe", indent=6)
+    r += p_list_if_qualifier(module.values, "maybe", indent=6)
     r += "Outputs:\n  Guaranteed:\n"
-    r += _list_if_qualifier(module.produces, "req", indent=4)
+    r += p_list_if_qualifier(module.produces, "req", indent=4)
     r += "  On-demand:\n"
-    r += _list_if_qualifier(module.produces, "demand", indent=4)
+    r += p_list_if_qualifier(module.produces, "demand", indent=4)
     r += "  Not guaranteed:\n"
-    r += _list_if_qualifier(module.produces, "maybe", indent=4)
+    r += p_list_if_qualifier(module.produces, "maybe", indent=4)
 
     return r
diff --git a/f4pga/flows/modules/analysis.py b/f4pga/flows/modules/analysis.py
index 40d2115..0f4fadd 100644
--- a/f4pga/flows/modules/analysis.py
+++ b/f4pga/flows/modules/analysis.py
@@ -19,30 +19,22 @@
 
 from pathlib import Path
 
-from f4pga.flows.common import vpr_specific_values, vpr as common_vpr, VprArgs
+from f4pga.flows.tools.vpr import vpr_specific_values, vpr, VprArgs
 from f4pga.flows.module import Module, ModuleContext
 
 
-def analysis_merged_post_implementation_file(ctx: ModuleContext):
-    return str(Path(ctx.takes.eblif).with_suffix("")) + "_merged_post_implementation.v"
-
-
-def analysis_post_implementation_file(ctx: ModuleContext):
-    return str(Path(ctx.takes.eblif).with_suffix("")) + "_post_synthesis.v"
-
-
 class analysisModule(Module):
     def map_io(self, ctx: ModuleContext):
         return {
-            "merged_post_implementation_v": analysis_merged_post_implementation_file(ctx),
-            "post_implementation_v": analysis_post_implementation_file(ctx),
+            "merged_post_implementation_v": p_analysis_merged_post_implementation_file(ctx),
+            "post_implementation_v": p_analysis_post_implementation_file(ctx),
         }
 
     def execute(self, ctx: ModuleContext):
         build_dir = Path(ctx.takes.eblif).parent
 
         yield "Analysis with VPR..."
-        common_vpr(
+        vpr(
             "analysis",
             VprArgs(
                 share=ctx.share,
@@ -59,10 +51,10 @@
         )
 
         if ctx.is_output_explicit("merged_post_implementation_v"):
-            Path(analysis_merged_post_implementation_file(ctx)).rename(ctx.outputs.merged_post_implementation_v)
+            Path(p_analysis_merged_post_implementation_file(ctx)).rename(ctx.outputs.merged_post_implementation_v)
 
         if ctx.is_output_explicit("post_implementation_v"):
-            Path(analysis_post_implementation_file(ctx)).rename(ctx.outputs.post_implementation_v)
+            Path(p_analysis_post_implementation_file(ctx)).rename(ctx.outputs.post_implementation_v)
 
         yield "Saving log..."
         save_vpr_log("analysis.log", build_dir=build_dir)
@@ -72,7 +64,15 @@
         self.no_of_phases = 2
         self.takes = ["eblif", "route", "sdc?"]
         self.produces = ["merged_post_implementation_v", "post_implementation_v", "analysis_log"]
-        self.values = ["device", "vpr_options?"] + vpr_specific_values()
+        self.values = ["device", "vpr_options?"] + vpr_specific_values
 
 
 ModuleClass = analysisModule
+
+
+def p_analysis_merged_post_implementation_file(ctx: ModuleContext):
+    return str(Path(ctx.takes.eblif).with_suffix("")) + "_merged_post_implementation.v"
+
+
+def p_analysis_post_implementation_file(ctx: ModuleContext):
+    return str(Path(ctx.takes.eblif).with_suffix("")) + "_post_synthesis.v"
diff --git a/f4pga/flows/modules/fasm.py b/f4pga/flows/modules/fasm.py
index 3ac06bb..79f7d24 100644
--- a/f4pga/flows/modules/fasm.py
+++ b/f4pga/flows/modules/fasm.py
@@ -19,7 +19,8 @@
 
 from pathlib import Path
 
-from f4pga.flows.common import vpr_specific_values, VprArgs, get_verbosity_level, sub as common_sub
+from f4pga.flows.common import get_verbosity_level, sub as common_sub
+from f4pga.flows.tools.vpr import vpr_specific_values, VprArgs
 from f4pga.flows.module import Module, ModuleContext
 
 
@@ -81,7 +82,7 @@
         self.no_of_phases = 2
         self.takes = ["eblif", "net", "place", "route", "fasm_extra?", "sdc?"]
         self.produces = ["fasm"]
-        self.values = ["device", "top", "pnr_corner?"] + vpr_specific_values()
+        self.values = ["device", "top", "pnr_corner?"] + vpr_specific_values
         self.prod_meta = {"fasm": "FPGA assembly file"}
 
 
diff --git a/f4pga/flows/modules/io_rename.py b/f4pga/flows/modules/io_rename.py
index 25c5787..6043b3d 100644
--- a/f4pga/flows/modules/io_rename.py
+++ b/f4pga/flows/modules/io_rename.py
@@ -48,7 +48,7 @@
 from f4pga.flows.runner import get_module
 
 
-def _switch_keys(d: "dict[str, ]", renames: "dict[str, str]") -> "dict[str, ]":
+def p_switch_keys(d: "dict[str, ]", renames: "dict[str, str]") -> "dict[str, ]":
     newd = {}
     for k, v in d.items():
         r = renames.get(k)
@@ -59,7 +59,7 @@
     return newd
 
 
-def _switchback_attrs(d: Namespace, renames: "dict[str, str]") -> SimpleNamespace:
+def p_switchback_attrs(d: Namespace, renames: "dict[str, str]") -> SimpleNamespace:
     newn = SimpleNamespace()
     for k, v in vars(d).items():
         setattr(newn, k, v)
@@ -71,7 +71,7 @@
     return newn
 
 
-def _switch_entries(l: "list[str]", renames: "dict[str, str]") -> "list[str]":
+def p_switch_entries(l: "list[str]", renames: "dict[str, str]") -> "list[str]":
     newl = []
     for e in l:
         r = renames.get(e)
@@ -83,7 +83,7 @@
     return newl
 
 
-def _or_empty_dict(d: "dict | None"):
+def p_or_empty_dict(d: "dict | None"):
     return d if d is not None else {}
 
 
@@ -95,16 +95,16 @@
 
     def map_io(self, ctx: ModuleContext):
         newctx = ctx.shallow_copy()
-        newctx.takes = _switchback_attrs(ctx.takes, self.rename_takes)
-        newctx.values = _switchback_attrs(ctx.values, self.rename_values)
+        newctx.takes = p_switchback_attrs(ctx.takes, self.rename_takes)
+        newctx.values = p_switchback_attrs(ctx.values, self.rename_values)
         r = self.module.map_io(newctx)
-        return _switch_keys(r, self.rename_produces)
+        return p_switch_keys(r, self.rename_produces)
 
     def execute(self, ctx: ModuleContext):
         newctx = ctx.shallow_copy()
-        newctx.takes = _switchback_attrs(ctx.takes, self.rename_takes)
-        newctx.values = _switchback_attrs(ctx.values, self.rename_values)
-        newctx.outputs = _switchback_attrs(ctx.produces, self.rename_produces)
+        newctx.takes = p_switchback_attrs(ctx.takes, self.rename_takes)
+        newctx.values = p_switchback_attrs(ctx.values, self.rename_values)
+        newctx.outputs = p_switchback_attrs(ctx.produces, self.rename_produces)
         print(newctx.takes)
         return self.module.execute(newctx)
 
@@ -113,18 +113,18 @@
         module_class = get_module(mod_path)
         module: Module = module_class(params.get("params"))
 
-        self.rename_takes = _or_empty_dict(params.get("rename_takes"))
-        self.rename_produces = _or_empty_dict(params.get("rename_produces"))
-        self.rename_values = _or_empty_dict(params.get("rename_values"))
+        self.rename_takes = p_or_empty_dict(params.get("rename_takes"))
+        self.rename_produces = p_or_empty_dict(params.get("rename_produces"))
+        self.rename_values = p_or_empty_dict(params.get("rename_values"))
 
         self.module = module
         self.name = f"{module.name}-io_renamed"
         self.no_of_phases = module.no_of_phases
-        self.takes = _switch_entries(module.takes, self.rename_takes)
-        self.produces = _switch_entries(module.produces, self.rename_produces)
-        self.values = _switch_entries(module.values, self.rename_values)
+        self.takes = p_switch_entries(module.takes, self.rename_takes)
+        self.produces = p_switch_entries(module.produces, self.rename_produces)
+        self.values = p_switch_entries(module.values, self.rename_values)
         if hasattr(module, "prod_meta"):
-            self.prod_meta = _switch_keys(module.prod_meta, self.rename_produces)
+            self.prod_meta = p_switch_keys(module.prod_meta, self.rename_produces)
 
 
 ModuleClass = IORenameModule
diff --git a/f4pga/flows/modules/nextpnr_ice40.py b/f4pga/flows/modules/nextpnr_ice40.py
index 03d97f5..17844d3 100644
--- a/f4pga/flows/modules/nextpnr_ice40.py
+++ b/f4pga/flows/modules/nextpnr_ice40.py
@@ -20,7 +20,7 @@
 import pathlib
 from f4pga.flows.common import ResolutionEnv
 from f4pga.flows.module import ModuleContext
-from f4pga.flows.modules.nextpnr import NextPnrBaseModule
+from f4pga.flows.tools.nextpnr import NextPnrBaseModule
 
 import re
 from pathlib import Path
diff --git a/f4pga/flows/modules/pack.py b/f4pga/flows/modules/pack.py
index 4c01dae..49a8019 100644
--- a/f4pga/flows/modules/pack.py
+++ b/f4pga/flows/modules/pack.py
@@ -19,7 +19,8 @@
 
 from pathlib import Path
 
-from f4pga.flows.common import vpr_specific_values, noisy_warnings, vpr as common_vpr, VprArgs
+from f4pga.flows.common import noisy_warnings
+from f4pga.flows.tools.vpr import vpr_specific_values, vpr, VprArgs
 from f4pga.flows.module import Module, ModuleContext
 
 
@@ -42,7 +43,7 @@
         build_dir = Path(ctx.outputs.net).parent
 
         yield "Packing with VPR..."
-        common_vpr(
+        vpr(
             "pack",
             VprArgs(
                 share=ctx.share,
@@ -77,9 +78,7 @@
         self.no_of_phases = 2
         self.takes = ["eblif", "sdc?"]
         self.produces = ["net", "util_rpt", "timing_rpt", "pack_log!"]
-        self.values = [
-            "device",
-        ] + vpr_specific_values()
+        self.values = ["device"] + vpr_specific_values
 
 
 ModuleClass = PackModule
diff --git a/f4pga/flows/modules/place.py b/f4pga/flows/modules/place.py
index e3f5aab..9136613 100644
--- a/f4pga/flows/modules/place.py
+++ b/f4pga/flows/modules/place.py
@@ -20,25 +20,17 @@
 from pathlib import Path
 from re import match as re_match
 
-from f4pga.flows.common import vpr_specific_values, vpr as common_vpr, VprArgs, save_vpr_log
+from f4pga.flows.tools.vpr import vpr_specific_values, vpr, VprArgs, save_vpr_log
 from f4pga.flows.module import Module, ModuleContext
 
 
-def default_output_name(eblif):
-    return str(Path(eblif).with_suffix(".place"))
-
-
-def place_constraints_file(ctx: ModuleContext):
-    if ctx.takes.place_constraints:
-        return ctx.takes.place_constraints, False
-    if ctx.takes.io_place:
-        return ctx.takes.io_place, False
-    return str(Path(ctx.takes.eblif).with_suffix(".place"))
+def p_default_output_name(eblif):
+    return Path(eblif).with_suffix(".place")
 
 
 class PlaceModule(Module):
     def map_io(self, ctx: ModuleContext):
-        return {"place": default_output_name(ctx.takes.eblif)}
+        return {"place": str(p_default_output_name(ctx.takes.eblif))}
 
     def execute(self, ctx: ModuleContext):
         build_dir = ctx.takes.build_dir
@@ -48,7 +40,7 @@
             vpr_options.update({"fix_clusters": ctx.takes.place_constraints})
 
         yield "Running VPR..."
-        common_vpr(
+        vpr(
             "place",
             VprArgs(
                 share=ctx.share,
@@ -72,7 +64,7 @@
         # modules may produce some temporary files with names that differ from
         # the ones in flow configuration.
         if ctx.is_output_explicit("place"):
-            Path(default_output_name(ctx.takes.eblif)).rename(ctx.outputs.place)
+            p_default_output_name(ctx.takes.eblif).rename(ctx.outputs.place)
 
         yield "Saving log..."
         save_vpr_log("place.log", build_dir=build_dir)
@@ -82,7 +74,7 @@
         self.no_of_phases = 2
         self.takes = ["build_dir", "eblif", "sdc?", "place_constraints?", "io_place?"]
         self.produces = ["place"]
-        self.values = ["device", "vpr_options?"] + vpr_specific_values()
+        self.values = ["device", "vpr_options?"] + vpr_specific_values
 
 
 ModuleClass = PlaceModule
diff --git a/f4pga/flows/modules/place_constraints.py b/f4pga/flows/modules/place_constraints.py
index 1eababf..d5577ba 100644
--- a/f4pga/flows/modules/place_constraints.py
+++ b/f4pga/flows/modules/place_constraints.py
@@ -19,7 +19,7 @@
 
 from pathlib import Path
 
-from f4pga.flows.common import sub as common_sub
+from f4pga.flows.common import sub as common_sub, options_dict_to_list
 from f4pga.flows.module import Module, ModuleContext
 
 
diff --git a/f4pga/flows/modules/route.py b/f4pga/flows/modules/route.py
index 5d08582..1938466 100644
--- a/f4pga/flows/modules/route.py
+++ b/f4pga/flows/modules/route.py
@@ -19,23 +19,23 @@
 
 from pathlib import Path
 
-from f4pga.flows.common import vpr_specific_values, vpr as common_vpr, VprArgs, options_dict_to_list, save_vpr_log
+from f4pga.flows.tools.vpr import vpr_specific_values, vpr, VprArgs, save_vpr_log
 from f4pga.flows.module import Module, ModuleContext
 
 
-def route_place_file(ctx: ModuleContext):
+def p_route_place_file(ctx: ModuleContext):
     return Path(ctx.takes.eblif).with_suffix(".route")
 
 
 class RouteModule(Module):
     def map_io(self, ctx: ModuleContext):
-        return {"route": str(route_place_file(ctx))}
+        return {"route": str(p_route_place_file(ctx))}
 
     def execute(self, ctx: ModuleContext):
         build_dir = Path(ctx.takes.eblif).parent
 
         yield "Routing with VPR..."
-        common_vpr(
+        vpr(
             "route",
             VprArgs(
                 share=ctx.share,
@@ -52,7 +52,7 @@
         )
 
         if ctx.is_output_explicit("route"):
-            route_place_file(ctx).rename(ctx.outputs.route)
+            p_route_place_file(ctx).rename(ctx.outputs.route)
 
         yield "Saving log..."
         save_vpr_log("route.log", build_dir=build_dir)
@@ -62,7 +62,7 @@
         self.no_of_phases = 2
         self.takes = ["eblif", "place", "sdc?"]
         self.produces = ["route"]
-        self.values = ["device", "vpr_options?"] + vpr_specific_values()
+        self.values = ["device", "vpr_options?"] + vpr_specific_values
 
 
 ModuleClass = RouteModule
diff --git a/f4pga/flows/modules/nextpnr.py b/f4pga/flows/tools/nextpnr.py
similarity index 100%
rename from f4pga/flows/modules/nextpnr.py
rename to f4pga/flows/tools/nextpnr.py
diff --git a/f4pga/flows/tools/vpr.py b/f4pga/flows/tools/vpr.py
new file mode 100644
index 0000000..ffe1add
--- /dev/null
+++ b/f4pga/flows/tools/vpr.py
@@ -0,0 +1,106 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2022 F4PGA Authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+
+
+from pathlib import Path
+from shutil import move as sh_mv
+
+from f4pga.flows.common import sub as common_sub, options_dict_to_list
+
+
+class VprArgs:
+    """
+    Represents argument list for VPR (Versatile Place and Route).
+    """
+
+    arch_dir: str
+    arch_def: str
+    lookahead: str
+    rr_graph: str
+    place_delay: str
+    device_name: str
+    eblif: str
+    optional: list
+
+    def __init__(
+        self,
+        share: str,
+        eblif,
+        arch_def,
+        lookahead,
+        rr_graph,
+        place_delay,
+        device_name,
+        vpr_options={},
+        sdc_file: "str | None" = None,
+    ):
+        self.arch_dir = str(Path(share) / "arch")
+        self.arch_def = arch_def
+        self.lookahead = lookahead
+        self.rr_graph = rr_graph
+        self.place_delay = place_delay
+        self.device_name = device_name
+        self.eblif = str(Path(eblif).resolve())
+        self.optional = options_dict_to_list(vpr_options)
+        if sdc_file is not None:
+            self.optional += ["--sdc_file", sdc_file]
+
+
+def vpr(mode: str, vprargs: VprArgs, cwd=None):
+    """
+    Execute `vpr`.
+    """
+    return common_sub(
+        *(
+            [
+                "vpr",
+                vprargs.arch_def,
+                vprargs.eblif,
+                "--device",
+                vprargs.device_name,
+                "--read_rr_graph",
+                vprargs.rr_graph,
+                "--read_router_lookahead",
+                vprargs.lookahead,
+                "--read_placement_delay_lookup",
+                vprargs.place_delay,
+            ]
+            + ([f"--{mode}"] if mode in ["pack", "place", "route", "analysis"] else [])
+            + vprargs.optional
+        ),
+        cwd=cwd,
+        print_stdout_on_fail=True,
+    )
+
+
+vpr_specific_values = [
+    "arch_def",
+    "rr_graph_lookahead_bin",
+    "rr_graph_real_bin",
+    "vpr_place_delay",
+    "vpr_grid_layout_name",
+    "vpr_options?",
+]
+
+
+def save_vpr_log(filename, build_dir=""):
+    """
+    Save VPR logic (moves the default output file into a desired path).
+    """
+    sh_mv(str(Path(build_dir) / "vpr_stdout.log"), filename)