forked from YosysHQ/prjtrellis
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: Adding a Python/ispTcl interface library
Signed-off-by: David Shah <davey1576@gmail.com>
- Loading branch information
Showing
3 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
__pycache__/ | ||
*.pyc | ||
/user_environment.sh | ||
ispTcl.log | ||
ispTcl.log.* | ||
ispTcl.tcl | ||
ispTcl.tcl.* | ||
.ispTcl.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
# Script to start a Diamond ispTcl consoke | ||
diamonddir="${DIAMONDDIR:-/usr/local/diamond/3.10_x64}" | ||
export FOUNDRY="${diamonddir}/ispfpga" | ||
bindir="${diamonddir}/bin/lin64" | ||
LSC_DIAMOND=true | ||
export LSC_DIAMOND | ||
export NEOCAD_MAXLINEWIDTH=32767 | ||
export TCL_LIBRARY="${diamonddir}/tcltk/lib/tcl8.5" | ||
export fpgabindir=${FOUNDRY}/bin/lin64 | ||
export LD_LIBRARY_PATH="${bindir}:${fpgabindir}" | ||
export LM_LICENSE_FILE="${diamonddir}/license/license.dat" | ||
$FOUNDRY/userware/unix/bin/lin64/ispTcl $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
Interface between Python fuzzer scripts and Lattice Diamond ispTcl | ||
""" | ||
|
||
import database | ||
import subprocess | ||
import tempfile | ||
from os import path | ||
|
||
|
||
def tcl_run(commands): | ||
"""Run a list of Tcl commands, returning the output as a string""" | ||
dtcl_path = path.join(database.get_trellis_root(), "diamond_tcl.sh") | ||
workdir = tempfile.mkdtemp() | ||
scriptfile = path.join(workdir, "script.tcl") | ||
with open(scriptfile, 'w') as f: | ||
f.write('source $::env(FOUNDRY)/data/tcltool/IspTclDev.tcl\n') | ||
f.write('source $::env(FOUNDRY)/data/tcltool/IspTclCmd.tcl\n') | ||
for c in commands: | ||
f.write(c + '\n') | ||
result = subprocess.run(["bash", dtcl_path, scriptfile], cwd=workdir).returncode | ||
assert result == 0, "ispTcl returned non-zero status code {}".format(result) | ||
outfile = path.join(workdir, 'ispTcl.log') | ||
with open(outfile, 'r') as f: | ||
output = f.read() | ||
# Strip Lattice header | ||
delimiter = "-" * 80 | ||
output = output[output.rindex(delimiter)+81:].strip() | ||
# Strip Lattice pleasantry | ||
pleasantry = "Thank you for using ispTcl." | ||
output = output.replace(pleasantry, "").strip() | ||
return output | ||
|
||
|
||
def tcl_run_ncd_prf(ncdfile, prffile, commands): | ||
""" | ||
Run a list of Tcl commands after loading given .ncd and .prf files | ||
""" | ||
run_cmds = [ | ||
"des_read_ncd {}".format(ncdfile), | ||
"des_read_prf {}".format(prffile) | ||
] + commands | ||
return tcl_run(run_cmds) | ||
|
||
|
||
def main(): | ||
print(tcl_run([])) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |