python-3.x - Lattice Diamond 命令行工具不知道 'synthesis' 命令

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

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

然后我从我的 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")

最佳答案

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

window

syntheseses.exe 必须使用所有必需的 Lattice 环境变量从命令 shell 运行。环境由 bin/nt64 目录中名为 pnwrap.exe 的可执行文件设置。在您的示例中,必须从 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 打开一个新的命令 shell 窗口来设置环境。因此,无法通过管道重定向输出。但是,日志也会在 .prj 文件中指定的日志文件中找到。

Linux

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

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

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

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)

关于python-3.x - Lattice Diamond 命令行工具不知道 'synthesis' 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36604066/

相关文章:

python - 如何在 pandas 数据框中的列中填充字母数字系列?

python - 在脚本当前目录中从 Python 运行子进程 bash 脚本

c++ - Tcl 脚本非检测调试器使用 Tcl 库和/或 Tcl 内部?

c++ - 如何将整数数组从 Tcl 传递到 C++?

python - 如何在Python中比较两行并通过索引获取结果?

python - 覆盖析构函数而不调用他们的 parent

python - 切片数组,但 Python 中重叠间隔

python : WindowsError: [Error 6] The handle is invalid

python - subprocess.check_output 因错误 127 而失败

python - 在没有 root 访问权限的情况下安装 Tkinter