Lattice Diamond命令行工具不知道合成'命令

时间:2016-04-13 16:12:23

标签: python-3.x subprocess tcl lattice-diamond

我在Windows 7上安装了(免费)Lattice Diamond 3.7,我想从命令行运行综合作业。我生成了一个* .prj文件,其中包含所有相关的命令行选项,例如part,toplevel和所有源文件。

然后我从PowerShell启动pnmainc.exe并执行:synthesis -f arith_prng.prj

-a "ECP5UM"
-top arith_prng
-logfile D:\git\PoC\temp\lattice\arith_prng.lse.log
-lib poc
-vhd D:/git/PoC/tb/common/my_project.vhdl
-vhd D:/git/PoC/tb/common/my_config_KC705.vhdl
-vhd D:/git/PoC/src/common/utils.vhdl
-vhd D:/git/PoC/src/common/config.vhdl
-vhd D:/git/PoC/src/common/math.vhdl
-vhd D:/git/PoC/src/common/strings.vhdl
-vhd D:/git/PoC/src/common/vectors.vhdl
-vhd D:/git/PoC/src/common/physical.vhdl
-vhd D:/git/PoC/src/common/components.vhdl
-vhd D:/git/PoC/src/arith/arith.pkg.vhdl
-vhd D:/git/PoC/src/arith/arith_prng.vhdl

合成过程开始并完成。接下来,我尝试使用包装Python脚本实现相同的行为,控制子进程的STDIN和STDOUT。

我可以执行一些命令,但synthesis报告为未知命令。它没有在帮助中列出。我认为,那是因为synthesis.exe是一个外部程序。

例如,如果我发送help,则会显示所有帮助主题。

如何从Python运行Diamond的Tcl命令?

这是我用于在Tcl-Shell包装器上进行实验的Python代码。

from subprocess      import Popen    as Subprocess_Popen
from subprocess      import PIPE      as Subprocess_Pipe
from subprocess      import STDOUT    as Subprocess_StdOut

class Executable:
  _POC_BOUNDARY = "====== POC BOUNDARY ======"

  def __init__(self, executablePath):
    self._process =    None
    self._executablePath =    executablePath

  @property
  def Path(self):
    return self._executablePath

  def StartProcess(self, parameterList):
    parameterList.insert(0, str(self._executablePath))
    self._process = Subprocess_Popen(parameterList, stdin=Subprocess_Pipe, stdout=Subprocess_Pipe, stderr=Subprocess_StdOut, universal_newlines=True, bufsize=16, shell=True)

  def Send(self, line):
    print("  sending command: {0}".format(line))
    self._process.stdin.write(line + "\n")
    self._process.stdin.flush()

  def SendBoundary(self):
    print("  sending boundary")
    self.Send("puts \"{0}\"\n".format(self._POC_BOUNDARY))

  def GetReader(self):
    for line in iter(self._process.stdout.readline, ""):
      yield line[:-1]

tclShell = Executable(r"D:\Lattice\diamond\3.7_x64\bin\nt64\pnmainc.exe")
print("starting process: {0!s}".format(tclShell.Path))
tclShell.StartProcess([])
reader = tclShell.GetReader()
iterator = iter(reader)

# send boundary and wait until pnmainc.exe is ready
tclShell.SendBoundary()
for line in iterator:
  print(line)
  if (line == tclShell._POC_BOUNDARY):
    break
print("pnmainc.exe is ready...")

tclShell.Send("help")
tclShell.SendBoundary()
for line in iterator:
  print(line)
  if (line == tclShell._POC_BOUNDARY):
    break
print("pnmainc.exe is ready...")

tclShell.Send("synthesis -f arith_prng.prj")
tclShell.SendBoundary()
for line in iterator:
  print(line)
  if (line == tclShell._POC_BOUNDARY):
    break
print("pnmainc.exe is ready...")

print("exit program")
tclShell.Send("exit")
print("reading output")
for line in iterator:
  print(line)

print("done")

1 个答案:

答案 0 :(得分:2)

要运行综合,不需要使用pnmainc进行TCL脚本编写。您可以按如下方式直接运行合成器二进制文件。

必须从包含所有必需的莱迪思环境变量的命令shell运行synthesises.exe。环境由pnwrap.exe目录中名为bin/nt64的可执行文件设置。在您的示例中,必须从shell中调用此可执行文件:

D:\Lattice\diamond\3.7_x64\bin\nt64\pnwrap.exe -exec D:\Lattice\diamond\3.7_x64\ispfpga\bin\nt64\synthesis.exe -f arith_prng.prj

-exec参数指定要在莱迪思环境中运行的可执行文件。以下所有参数都传递给synthesis.exe

在Python中,您可以使用(使用Executable类)运行合成器:

exe = Executable(r"D:\Lattice\diamond\3.7_x64\bin\nt64\pnwrap.exe")
parameterList = ['-exec', r"D:\Lattice\diamond\3.7_x64\ispfpga\bin\nt64\synthesis.exe", '-f', 'arith_prng']
exe.StartProcess(parameterList)

不幸的是,pnwrap.exe打开了一个新的命令shell窗口来设置环境。因此,输出不能通过管道重定向。但是,日志也可以在.prj文件中指定的日志文件中找到。

的Linux

首先,您必须加载Lattice Diamond环境以设置所有必要的环境变量。使用Bash语法,这将是:

bindir=/opt/lattice/diamond/3.7_x64/bin/lin64
source $bindir/diamond_env

然后,您可以使用命令行直接从synthesis目录执行ispfpga/bin/lin64,如下例所示:

synthesis -f arith_prng.prj

synthesis可执行文件位于$PATH

在Python中,您可以使用(使用Executable类)运行合成器:

exe = Executable('/opt/lattice/diamond/3.7_x64/ispfpga/bin/lin64/synthesis')
parameterList = ['-f', 'arith_prng']
exe.StartProcess(parameterList)