40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
import os
|
|
import subprocess
|
|
import build_env
|
|
from typing import List
|
|
|
|
|
|
def generateIncludesForGHDL(includes: List[str]):
|
|
cmd = []
|
|
for inc in includes:
|
|
cmd.append(f"-P{inc}/work")
|
|
return cmd
|
|
|
|
def elabDesign(topDef: str, arch: str, lib: str, std: str, includes: List[str]):
|
|
## Add all source files present in pwd
|
|
if build_env.addAllVHDLFiles(std, lib) == -1:
|
|
print("Adding files failed. GHDL Build environment may be broken...")
|
|
return -1
|
|
incs = generateIncludesForGHDL(includes)
|
|
command = [
|
|
"ghdl", "-m", "--workdir=work", f"--work={lib}", f"--std={std}"] + incs + ["-o", f"work/{topDef}-{arch}", f"work.{topDef}", f"{arch}"]
|
|
subprocess.run(command)
|
|
|
|
def runDesign(topDef: str, arch: str, lib: str, std: str, includes):
|
|
## elaborate first, then run
|
|
if elabDesign(topDef, arch, lib, std, includes) == -1:
|
|
print("Elaboration failed...")
|
|
return -1
|
|
os.makedirs("wave",exist_ok=True)
|
|
wavePath = "wave"
|
|
incs = generateIncludesForGHDL(includes)
|
|
command = [ ## may add -v for verbose
|
|
"ghdl", "--elab-run", f"--workdir=work", f"--work={lib}", f"--std={std}"] + incs + ["-o", f"work/{topDef}-{arch}", f"{topDef}", f"{arch}",
|
|
f"--wave=wave/{topDef}-{arch}.ghw" ##, "--read-wave-opt=<See"
|
|
]
|
|
subprocess.run(command)
|
|
command = [
|
|
"gtkwave", f"{topDef}-{arch}.ghw", "--rcvar",
|
|
"do_initial_zoom_fit yes"]
|
|
subprocess.run(command, cwd=wavePath)
|