Skip to content

Commit

Permalink
util: Adding a Python/ispTcl interface library
Browse files Browse the repository at this point in the history
Signed-off-by: David Shah <davey1576@gmail.com>
  • Loading branch information
gatecat committed May 12, 2018
1 parent dcad9c1 commit 0e3faaf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
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
14 changes: 14 additions & 0 deletions diamond_tcl.sh
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
51 changes: 51 additions & 0 deletions util/common/isptcl.py
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()

0 comments on commit 0e3faaf

Please sign in to comment.