3

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

然后我pnmainc.exe从我的 PowerShell 开始并执行: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报告为未知命令。它没有在帮助中列出。我想,那是因为综合.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")
4

1 回答 1

3

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

视窗

synthesises.exe必须从带有所有必需的 Lattice 环境变量的命令 shell 运行。环境由目录中调用的可执行文件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参数指定要在 Lattice 环境中运行的可执行文件。以下所有参数都传递给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打开一个新的命令外壳窗口来设置环境。因此,输出不能通过管道重定向。但是,日志也将在文件中指定的日志文件中找到.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)
于 2016-05-13T14:47:41.550 回答