Skip to content

Commit

Permalink
[PyCDE] Refactor ESI collateral packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
teqdruid committed Sep 21, 2023
1 parent 6b1f86c commit 4cfa7cf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
25 changes: 11 additions & 14 deletions frontends/PyCDE/src/bsp/cosim.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ..module import Module, generator
from ..system import System
from ..types import types
from .. import esi

from ..circt import ir
from ..circt.dialects import esi as raw_esi
Expand All @@ -32,6 +33,7 @@ def build(ports):
impl_type=ir.StringAttr.get("cosim"),
inputs=[ports.clk.value, ports.rst.value])

System.current().add_packaging_step(esi.package)
System.current().add_packaging_step(top.package)

@staticmethod
Expand All @@ -40,37 +42,32 @@ def package(sys: System):

# When pycde is installed through a proper install, all of the collateral
# files are under a dir called "collateral".
hw_src = sys.hw_output_dir
collateral_dir = __root_dir__ / "collateral"
if collateral_dir.exists():
bin_dir = collateral_dir
lib_dir = collateral_dir
esi_inc_dir = collateral_dir
esi_lib_dir = collateral_dir
else:
# Build we also want to allow pycde to work in-tree for developers. The
# necessary files are screwn around the build tree.
build_dir = __root_dir__.parents[4]
bin_dir = build_dir / "bin"
lib_dir = build_dir / "lib"
circt_inc_dir = build_dir / "tools" / "circt" / "include" / "circt"
esi_inc_dir = circt_inc_dir / "Dialect" / "ESI"
circt_lib_dir = build_dir / "tools" / "circt" / "lib"
esi_lib_dir = circt_lib_dir / "Dialect" / "ESI"

shutil.copy(bin_dir / "driver.cpp", hw_src)
shutil.copy(bin_dir / "driver.sv", hw_src)
shutil.copy(esi_lib_dir / "cosim" / "Cosim_DpiPkg.sv", hw_src)
shutil.copy(esi_lib_dir / "cosim" / "Cosim_Endpoint.sv", hw_src)

hw_src = sys.hw_output_dir
for f in lib_dir.glob("*.so"):
shutil.copy(f, hw_src)
for f in lib_dir.glob("*.dll"):
shutil.copy(f, hw_src)

if not collateral_dir.exists():
shutil.copy(bin_dir / "driver.cpp", hw_src)
shutil.copy(bin_dir / "driver.sv", hw_src)
shutil.copy(esi_inc_dir / "ESIPrimitives.sv", hw_src)
shutil.copy(esi_inc_dir / "cosim" / "Cosim_DpiPkg.sv", hw_src)
shutil.copy(esi_inc_dir / "cosim" / "Cosim_Endpoint.sv", hw_src)

shutil.copy(__root_dir__ / "Makefile.cosim", sys.output_directory)
shutil.copy(sys.hw_output_dir / "schema.capnp", sys.runtime_output_dir)

# Copy everything from the 'runtime' directory
shutil.copytree(esi_inc_dir, sys.runtime_output_dir, dirs_exist_ok=True)

return top
2 changes: 2 additions & 0 deletions frontends/PyCDE/src/bsp/xrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ..module import Module, generator
from ..system import System
from ..types import bit, types, Bits
from .. import esi

import glob
from io import FileIO
Expand Down Expand Up @@ -221,6 +222,7 @@ def construct(ports):

# Copy additional sources
sys: System = System.current()
sys.add_packaging_step(esi.package)
sys.add_packaging_step(top.package)

@staticmethod
Expand Down
34 changes: 34 additions & 0 deletions frontends/PyCDE/src/esi.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,3 +501,37 @@ def param(name: str, type: Type = None):
else:
type_attr = ir.TypeAttr.get(type._type)
esi.ESIPureModuleParamOp(name, type_attr)


def package(sys: System):
"""Package all ESI collateral."""

import os
import shutil
__root_dir__ = Path(__file__).parent

# When pycde is installed through a proper install, all of the collateral
# files are under a dir called "collateral".
collateral_dir = __root_dir__ / "collateral"
if collateral_dir.exists():
esi_lib_dir = collateral_dir
else:
# Build we also want to allow pycde to work in-tree for developers. The
# necessary files are screwn around the build tree.
build_dir = __root_dir__.parents[4]
circt_lib_dir = build_dir / "tools" / "circt" / "lib"
esi_lib_dir = circt_lib_dir / "Dialect" / "ESI"
shutil.copy(esi_lib_dir / "ESIPrimitives.sv", sys.hw_output_dir)

# Copy everything from the 'runtime' directory
for root, dir, files in os.walk(esi_lib_dir / "runtime"):
if ".dir" in dir:
continue
for file in files:
if ".cmake" in file or file.endswith(".o"):
continue
to_dir = sys.runtime_output_dir
if len(dir) > 0:
to_dir = to_dir / os.path.join(*dir)
to_dir.mkdir(parents=True, exist_ok=True)
shutil.copyfile(os.path.join(root, file), to_dir / file)

0 comments on commit 4cfa7cf

Please sign in to comment.