added initial support for including libraries using flag -i and a relative path
This commit is contained in:
parent
1150113101
commit
325cbbff89
@ -5,57 +5,61 @@ import subprocess
|
|||||||
def getCfFileId(std: str):
|
def getCfFileId(std: str):
|
||||||
return "08" if std == "08" else "93" ## Weird behaviour from GHDL, but all vhdl versions besides 08 have [...]93.cf
|
return "08" if std == "08" else "93" ## Weird behaviour from GHDL, but all vhdl versions besides 08 have [...]93.cf
|
||||||
|
|
||||||
def ghdlEnvExists(std, relativePath="work"):
|
def ghdlEnvExists(std, lib):
|
||||||
## Check if work exists
|
## Check if work exists
|
||||||
try:
|
try:
|
||||||
os.lstat(relativePath)
|
os.lstat("work")
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
## Check that work is writable
|
## Check that work is writable
|
||||||
if not os.access(relativePath, os.W_OK):
|
if not os.access("work", os.W_OK):
|
||||||
print(f"{relativePath} is write-protected, please acquire correct permissions")
|
print("work is write-protected, please acquire correct permissions")
|
||||||
return False
|
return False
|
||||||
cfFileExists = False
|
cfFileExists = False
|
||||||
filesInWork = os.listdir(relativePath)
|
filesInWork = os.listdir("work")
|
||||||
cfFileId = getCfFileId(std)
|
cfFileId = getCfFileId(std)
|
||||||
for file in filesInWork:
|
for file in filesInWork:
|
||||||
if ".cf" in file and cfFileId in file:
|
if ".cf" in file and lib in file and cfFileId in file:
|
||||||
cfFileExists = True
|
cfFileExists = True
|
||||||
if not cfFileExists:
|
if not cfFileExists:
|
||||||
return False
|
return False
|
||||||
## Nothing bad, continue
|
## Nothing bad, continue
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def createBuildEnv(std: str):
|
def createBuildEnv(std: str, lib: str):
|
||||||
if ghdlEnvExists(std=std):
|
if ghdlEnvExists(std=std, lib=lib):
|
||||||
print("Build environment already exists, exiting...")
|
print("Build environment already exists, exiting...")
|
||||||
return -1
|
return -1
|
||||||
## Create build env
|
## Create build env
|
||||||
print("Initializing GHDL project in current directory...")
|
print("Initializing GHDL project in current directory...")
|
||||||
os.makedirs("work",exist_ok=True)
|
os.makedirs("work",exist_ok=True)
|
||||||
addAllVHDLFiles(std=std, init=True)
|
addAllVHDLFiles(std=std, lib=lib, init=True)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def addAllVHDLFiles(std: str, init=False):
|
def addAllVHDLFiles(std: str, lib: str, init=False):
|
||||||
## Ensure everything is ready for adding files
|
## Ensure everything is ready for adding files
|
||||||
## (init exception to avoid one if-case in ghdlEnvExists)
|
## (init exception to avoid one if-case in ghdlEnvExists)
|
||||||
if not ghdlEnvExists(std=std) and not init:
|
if not ghdlEnvExists(std=std, lib=lib) and not init:
|
||||||
return -1
|
return -1
|
||||||
vhdlFiles = []
|
vhdlFiles = []
|
||||||
currentlyAdded = []
|
currentlyAdded = []
|
||||||
|
absWorkDir = os.path.join(os.getcwd(), "work")
|
||||||
cfFileId = getCfFileId(std)
|
cfFileId = getCfFileId(std)
|
||||||
## Find already present files
|
## Find already present files
|
||||||
if not init:
|
if not init:
|
||||||
cfFileName = list(filter(lambda x: ".cf" in x and cfFileId in x, os.listdir("work")))[0]
|
cfFileName = list(filter(lambda x: ".cf" in x and lib in x and cfFileId in x, os.listdir(absWorkDir)))[0]
|
||||||
cfFilePath = os.path.join(os.getcwd(),f"work/{cfFileName}")
|
cfFilePath = os.path.join(absWorkDir,cfFileName)
|
||||||
currentlyAdded = getCurrentlyAddedFiles(cfFilePath)
|
currentlyAdded = getCurrentlyAddedFiles(cfFilePath)
|
||||||
|
print(currentlyAdded)
|
||||||
## Add files not added
|
## Add files not added
|
||||||
for file in os.listdir():
|
for file in os.listdir():
|
||||||
|
print(file)
|
||||||
|
print(currentlyAdded, file, file not in currentlyAdded)
|
||||||
if ".vhd" in file and file not in currentlyAdded:
|
if ".vhd" in file and file not in currentlyAdded:
|
||||||
vhdlFiles.append(file)
|
vhdlFiles.append(os.path.join(os.getcwd(), file))
|
||||||
if len(vhdlFiles) > 0:
|
if len(vhdlFiles) > 0:
|
||||||
print(f"Detected new files. Adding {vhdlFiles}")
|
print(f"Detected new files. Adding {vhdlFiles}")
|
||||||
command = ["ghdl", "-i", "--workdir=work", "--work=work", f"--std={std}"] + vhdlFiles
|
command = ["ghdl", "-i", "--workdir=work", f"--work={lib}", f"--std={std}"] + vhdlFiles
|
||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -64,5 +68,5 @@ def getCurrentlyAddedFiles(cfFilePath:str):
|
|||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
f.close()
|
f.close()
|
||||||
fileLines = filter(lambda x: "file" in x, lines)
|
fileLines = filter(lambda x: "file" in x, lines)
|
||||||
files = map(lambda x: split("\" \"",x)[1], fileLines)
|
files = map(lambda x: split("\"",x)[1], fileLines)
|
||||||
return list(files)
|
return list(files)
|
||||||
|
|||||||
@ -1,27 +1,35 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import build_env
|
import build_env
|
||||||
|
from typing import List
|
||||||
|
|
||||||
def elabDesign(topDef: str, arch: str, lib: str, std: str):
|
|
||||||
|
def generateIncludesForGHDL(includes: List[str]):
|
||||||
|
cmd = []
|
||||||
|
for inc in includes:
|
||||||
|
cmd.append(f"-P{os.path.join(os.getcwd(), f"{inc}/work")}")
|
||||||
|
return cmd
|
||||||
|
|
||||||
|
def elabDesign(topDef: str, arch: str, lib: str, std: str, includes: List[str]):
|
||||||
## Add all source files present in pwd
|
## Add all source files present in pwd
|
||||||
if build_env.addAllVHDLFiles(std) == -1:
|
if build_env.addAllVHDLFiles(std, lib) == -1:
|
||||||
print("Adding files failed. GHDL Build environment may be broken...")
|
print("Adding files failed. GHDL Build environment may be broken...")
|
||||||
return -1
|
return -1
|
||||||
|
incs = generateIncludesForGHDL(includes)
|
||||||
command = [
|
command = [
|
||||||
"ghdl", "-m", f"--workdir={lib}", f"--work={lib}", f"--std={std}",
|
"ghdl", "-m", "--workdir=work", f"--work={lib}", f"--std={std}"] + incs + ["-o", f"work/{topDef}-{arch}", f"work.{topDef}", f"{arch}"]
|
||||||
"-o", f"{lib}/{topDef}-{arch}", f"{lib}.{topDef}", f"{arch}"]
|
|
||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
|
|
||||||
def runDesign(topDef: str, arch: str, lib: str, std: str):
|
def runDesign(topDef: str, arch: str, lib: str, std: str, includes):
|
||||||
## elaborate first, then run
|
## elaborate first, then run
|
||||||
if elabDesign(topDef, arch, lib, std) == -1:
|
if elabDesign(topDef, arch, lib, std, includes) == -1:
|
||||||
print("Elaboration failed...")
|
print("Elaboration failed...")
|
||||||
return -1
|
return -1
|
||||||
os.makedirs("wave",exist_ok=True)
|
os.makedirs("wave",exist_ok=True)
|
||||||
wavePath = os.path.join(os.getcwd(), "wave")
|
wavePath = os.path.join(os.getcwd(), "wave")
|
||||||
|
incs = generateIncludesForGHDL(includes)
|
||||||
command = [ ## may add -v for verbose
|
command = [ ## may add -v for verbose
|
||||||
"ghdl", "--elab-run", f"--workdir={lib}", f"--work={lib}", f"--std={std}",
|
"ghdl", "--elab-run", f"--workdir=work", f"--work={lib}", f"--std={std}"] + incs + ["-o", f"work/{topDef}-{arch}", f"{topDef}", f"{arch}",
|
||||||
"-o", f"{lib}/{topDef}-{arch}", f"{topDef}", f"{arch}",
|
|
||||||
f"--wave=wave/{topDef}-{arch}.ghw" ##, "--read-wave-opt=<See"
|
f"--wave=wave/{topDef}-{arch}.ghw" ##, "--read-wave-opt=<See"
|
||||||
]
|
]
|
||||||
subprocess.run(command)
|
subprocess.run(command)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import typer
|
import typer
|
||||||
import elab as elaborate
|
import elab as elaborate
|
||||||
import build_env
|
import build_env
|
||||||
|
from typing import List, Optional
|
||||||
from typing_extensions import Annotated
|
from typing_extensions import Annotated
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
|
||||||
|
|
||||||
gantry_install_path = "/home/thesis2/exjobb-public/scripts"
|
gantry_install_path = "/home/thesis2/exjobb-public/scripts"
|
||||||
|
|
||||||
@ -21,42 +21,53 @@ def complete_vhdl_ver():
|
|||||||
|
|
||||||
@software.command(help="Initializes the GHDL build environment in a library named \"work\". Adds all files ending in \".vhd\" to the project")
|
@software.command(help="Initializes the GHDL build environment in a library named \"work\". Adds all files ending in \".vhd\" to the project")
|
||||||
def init(
|
def init(
|
||||||
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c"
|
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c",
|
||||||
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "defaultLib",
|
||||||
):
|
):
|
||||||
return build_env.createBuildEnv(std)
|
return build_env.createBuildEnv(std, library)
|
||||||
|
|
||||||
|
|
||||||
@software.command(help="Runs analysis and elaboration on the provided top definition and architecture using GHDL. Automatically adds new files not present in the project")
|
@software.command(help="Runs analysis and elaboration on the provided top definition and architecture using GHDL. Automatically adds new files not present in the project")
|
||||||
def elab(
|
def elab(
|
||||||
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
||||||
arch: Annotated[str, typer.Argument(help="Architecture to synthesize within the top definition provided")] = "",
|
arch: Annotated[str, typer.Argument(help="Architecture to synthesize within the top definition provided")] = "",
|
||||||
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "work",
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "defaultLib",
|
||||||
|
includes: Annotated[Optional[List[str]], typer.Option("--include", "-i", help="Which libraries to include in compile")] = None,
|
||||||
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c"
|
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c"
|
||||||
):
|
):
|
||||||
print(f"Elaborating {topdef} with arch {arch} in library {library}. VHDL {std}")
|
print(f"Elaborating {topdef} with arch {arch} in library {library}. VHDL {std}.")
|
||||||
return elaborate.elabDesign(topdef, arch, library, std)
|
if includes is not None:
|
||||||
|
print(f"Including libraries: {includes}")
|
||||||
|
else:
|
||||||
|
includes = []
|
||||||
|
return elaborate.elabDesign(topdef, arch, library, std, includes)
|
||||||
|
|
||||||
@software.command(help="Simulates elaborated design in GHDL and views waves in gtkwave. Automatically runs `gantry elab` on the same top def and arch.")
|
@software.command(help="Simulates elaborated design in GHDL and views waves in gtkwave. Automatically runs `gantry elab` on the same top def and arch.")
|
||||||
def run(
|
def run(
|
||||||
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
||||||
arch: Annotated[str, typer.Argument(help="Architecture to synthesize within the top definition provided")] = "",
|
arch: Annotated[str, typer.Argument(help="Architecture to synthesize within the top definition provided")] = "",
|
||||||
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "work",
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "defaultLib",
|
||||||
|
includes: Annotated[Optional[List[str]], typer.Option("--include", "-i", help="Which libraries to include in compile")] = None,
|
||||||
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c"
|
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c"
|
||||||
):
|
):
|
||||||
print(f"Running (and synthesizing if needed) {topdef} with arch {arch} in library {library}. VHDL {std}")
|
print(f"Running (and synthesizing if needed) {topdef} with arch {arch} in library {library}. VHDL {std}")
|
||||||
return elaborate.runDesign(topdef, arch, library, std)
|
if includes is not None:
|
||||||
|
print(f"Including libraries: {includes}")
|
||||||
|
else:
|
||||||
|
includes = []
|
||||||
|
return elaborate.runDesign(topdef, arch, library, std, includes)
|
||||||
|
|
||||||
@hardware.command(help="Synthesizes the provided top level design using NXPython. Make sure you run this with NXPython.")
|
@hardware.command(help="Synthesizes the provided top level design using NXPython. Make sure you run this with NXPython.")
|
||||||
def synth(
|
def synth(
|
||||||
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
||||||
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "work"
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "defaultLib"
|
||||||
):
|
):
|
||||||
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "synthDesign", library, topdef])
|
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "synthDesign", library, topdef])
|
||||||
|
|
||||||
@hardware.command(help="Places the provided top level design using NXPython. Make sure you run this with NXPython.")
|
@hardware.command(help="Places the provided top level design using NXPython. Make sure you run this with NXPython.")
|
||||||
def place(
|
def place(
|
||||||
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
||||||
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "work"
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "defaultLib"
|
||||||
):
|
):
|
||||||
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "placeDesign", library, topdef])
|
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "placeDesign", library, topdef])
|
||||||
|
|
||||||
@ -64,7 +75,7 @@ def place(
|
|||||||
@hardware.command(help="Routes the provided top level design using NXPython. Make sure you run this with NXPython.")
|
@hardware.command(help="Routes the provided top level design using NXPython. Make sure you run this with NXPython.")
|
||||||
def route(
|
def route(
|
||||||
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
||||||
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "work"
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "defaultLib"
|
||||||
):
|
):
|
||||||
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "routeDesign", library, topdef])
|
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "routeDesign", library, topdef])
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user