Skip to content

Commit

Permalink
Finished Lattice Diamond flow. Improved error reporting. README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabeltud committed May 13, 2016
1 parent e923e64 commit e1e3eec
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 148 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ cd <PoCRoot>
**Note:** The configuration process can be re-run at every time to add, remove
or update choices made.

If you want to check your installation, you can run one of our testbenches as described in [tb/README.md][tb_readme]

[tb_readme]: tb/README.md

## 6 Integrating PoC into Projects

**The PoC-Library** is meant to be integrated into HDL projects. Therefore it's
Expand Down
21 changes: 16 additions & 5 deletions py/Base/Compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,22 @@ def _PrepareCompilerEnvironment(self, device):
self._LogVerbose("Creating temporary directory for synthesizer files.")
self._LogDebug("Temporary directory: {0!s}".format(self.Directories.Working))
if (self.Directories.Working.exists()):
shutil.rmtree(str(self.Directories.Working))
self.Directories.Working.mkdir(parents=True)

try:
shutil.rmtree(str(self.Directories.Working))
except OSError as ex:
raise CompilerException("Error while deleting '{0!s}'.".format(self.Directories.Working)) from ex
try:
self.Directories.Working.mkdir(parents=True)
except OSError as ex:
raise CompilerException("Error while creating '{0!s}'.".format(self.Directories.Working)) from ex

# change working directory to temporary iSim path
self._LogVerbose("Changing working directory to temporary directory.")
self._LogDebug("cd \"{0!s}\"".format(self.Directories.Working))
chdir(str(self.Directories.Working))
try:
chdir(str(self.Directories.Working))
except OSError as ex:
raise CompilerException("Error while changing to '{0!s}'.".format(self.Directories.Working)) from ex

# create output directory for CoreGen if not existent
if (not self.Directories.Destination.exists()) :
Expand Down Expand Up @@ -282,7 +290,10 @@ def _ExecuteCopyTasks(self, tasks, text):
task.DestinationPath.parent.mkdir(parents=True)

self._LogDebug("{0}-copying '{1!s}'.".format(text, task.SourcePath))
shutil.copy(str(task.SourcePath), str(task.DestinationPath))
try:
shutil.copy(str(task.SourcePath), str(task.DestinationPath))
except OSError as ex:
raise CompilerException("Error while copying '{0!s}'.".format(task.SourcePath)) from ex

def _RunPostDelete(self, netlist):
self._LogVerbose("copy generated files into netlist directory...")
Expand Down
34 changes: 22 additions & 12 deletions py/Base/Logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,41 @@

@unique
class Severity(Enum):
Fatal = 30
Error = 25
Quiet = 20
Warning = 15
Fatal = 30
Error = 25
Quiet = 20
Warning = 15
Info = 10
Normal = 4
Verbose = 2
Debug = 1
All = 0


def __init__(self, *_):
"""Patch the embedded MAP dictionary"""
for k,v in self.__class__.__VHDL_SEVERITY_LEVEL_MAP__.items():
if ((not isinstance(v, self.__class__)) and (v == self.value)):
self.__class__.__VHDL_SEVERITY_LEVEL_MAP__[k] = self
break

def __eq__(self, other): return self.value == other.value
def __ne__(self, other): return self.value != other.value
def __lt__(self, other): return self.value < other.value
def __le__(self, other): return self.value <= other.value
def __gt__(self, other): return self.value > other.value
def __ge__(self, other): return self.value >= other.value

__VHDL_SEVERITY_LEVEL_MAP__ = {
"failure": Fatal,
"error": Error,
"warning": Warning,
"note": Info
}

@classmethod
def fromVhdlLevel(cls, severity, fallback = None):
return {
"failure": cls.Fatal,
"error": cls.Error,
"warning": cls.Warning,
"note": cls.Info
}.get(severity, fallback)
def ParseVHDLSeverityLevel(cls, severity, fallback=None):
return cls.__VHDL_SEVERITY_LEVEL_MAP__.get(severity, fallback)


class LogEntry:
def __init__(self, message, severity=Severity.Normal, indent=0):
Expand Down
19 changes: 16 additions & 3 deletions py/Base/Simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def __init__(self, host):
def Host(self): return self.__host
@property
def Directories(self): return self._directories
@property
def PoCProject(self): return self._pocProject
@property
def TestSuite(self): return self._testSuite

def _GetTimeDeltaSinceLastEvent(self):
now = datetime.now()
Expand All @@ -143,13 +147,22 @@ def _PrepareSimulationEnvironment(self):
self._LogVerbose("Creating fresh temporary directory for simulator files.")
self._LogDebug("Temporary directory: {0!s}".format(self.Directories.Working))
if (self.Directories.Working.exists()):
shutil.rmtree(str(self.Directories.Working))
self.Directories.Working.mkdir(parents=True)
try:
shutil.rmtree(str(self.Directories.Working))
except OSError as ex:
raise SimulatorException("Error while deleting '{0!s}'.".format(self.Directories.Working)) from ex
try:
self.Directories.Working.mkdir(parents=True)
except OSError as ex:
raise SimulatorException("Error while creating '{0!s}'.".format(self.Directories.Working)) from ex

# change working directory to temporary path
self._LogVerbose("Changing working directory to temporary directory.")
self._LogDebug("cd \"{0!s}\"".format(self.Directories.Working))
chdir(str(self.Directories.Working))
try:
chdir(str(self.Directories.Working))
except OSError as ex:
raise SimulatorException("Error while changing to '{0!s}'.".format(self.Directories.Working)) from ex

def RunAll(self, fqnList, *args, **kwargs):
"""Run a list of testbenches. Expand wildcards to all selected testbenches."""
Expand Down
53 changes: 33 additions & 20 deletions py/Compiler/LSECompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# ==============================================================================
#
# entry point
from Base.Exceptions import PlatformNotSupportedException


if __name__ != "__main__":
# place library initialization code here
pass
Expand All @@ -44,10 +47,11 @@
# load dependencies
from pathlib import Path

from Base.Project import ToolChain, Tool
from Base.Compiler import Compiler as BaseCompiler, CompilerException, SkipableCompilerException
from Base.Project import ToolChain, Tool
from PoC.Entity import WildCard
from ToolChains.Lattice.Diamond import Diamond, SynthesisArgumentFile
from ToolChains.Lattice.Lattice import LatticeException


class Compiler(BaseCompiler):
Expand All @@ -68,7 +72,13 @@ def __init__(self, host, dryRun, noCleanUp):
def _PrepareCompiler(self):
self._LogVerbose("Preparing Lattice Synthesis Engine (LSE).")
diamondSection = self.Host.PoCConfig['INSTALL.Lattice.Diamond']
binaryPath = Path(diamondSection['BinaryDirectory'])
if (self.Host.Platform == "Linux"):
binaryPath = Path(diamondSection['BinaryDirectory2'])
elif (self.Host.Platform == "Windows"):
binaryPath = Path(diamondSection['BinaryDirectory'])
else:
raise PlatformNotSupportedException(self.Host.Platform)

version = diamondSection['Version']
self._toolChain = Diamond(self.Host.Platform, binaryPath, version, logger=self.Logger)

Expand All @@ -87,37 +97,40 @@ def Run(self, netlist, board):

netlist.PrjFile = self.Directories.Working / (netlist.ModuleName + ".prj")

self._WriteLSEProjectFile(netlist)
lseArgumentFile = self._WriteLSEProjectFile(netlist, board)

self._LogNormal("Executing pre-processing tasks...")
self._RunPreCopy(netlist)
self._RunPreReplace(netlist)

self._LogNormal("Running Lattice Diamond LSE...")
self._RunCompile(netlist)
self._RunCompile(netlist, lseArgumentFile) # attach to netlist

self._LogNormal("Executing post-processing tasks...")
self._RunPostCopy(netlist)
self._RunPostReplace(netlist)
self._RunPostDelete(netlist)

def _WriteLSEProjectFile(self, netlist):
def _WriteLSEProjectFile(self, netlist, board):
device = board.Device
argumentFile = SynthesisArgumentFile(netlist.PrjFile)
argumentFile.Architecture = "\"ECP5UM\""
argumentFile.TopLevel = netlist.ModuleName
argumentFile.Architecture = "\"{0}\"".format(device.Series)
argumentFile.Device = "\"{0}\"".format(device.ShortName)
argumentFile.SpeedGrade = str(device.SpeedGrade)
argumentFile.Package = "{0!s}{1!s}".format(device.Package, device.PinCount)
argumentFile.TopLevel = netlist.ModuleName
argumentFile.LogFile = self.Directories.Working / (netlist.ModuleName + ".lse.log")

argumentFile.Write(self.PoCProject)

def _RunCompile(self, netlist):
tclShell = self._toolChain.GetTclShell()

# raise NotImplementedError("Next: implement interactive shell")
self._LogWarning("Execution skipped due to Tcl shell problems.")
# tclShell.Run()
# try:
# q2map.Compile()
# except QuartusException as ex:
# raise CompilerException("Error while compiling '{0!s}'.".format(netlist)) from ex
# if q2map.HasErrors:
# raise SkipableCompilerException("Error while compiling '{0!s}'.".format(netlist))
return argumentFile

def _RunCompile(self, netlist, lseArgumentFile):
synth = self._toolChain.GetSynthesizer()
synth.Parameters[synth.SwitchProjectFile] = netlist.ModuleName + ".prj"

try:
synth.Compile(lseArgumentFile.LogFile)
except LatticeException as ex:
raise CompilerException("Error while compiling '{0!s}'.".format(netlist)) from ex
if synth.HasErrors:
raise SkipableCompilerException("Error while compiling '{0!s}'.".format(netlist))
18 changes: 12 additions & 6 deletions py/Compiler/XCOCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@

# load dependencies
import shutil
from os import chdir
from os import chdir
from pathlib import Path
from textwrap import dedent
from textwrap import dedent

from Base.Project import ToolChain, Tool
from Base.Project import ToolChain, Tool
from Base.Compiler import Compiler as BaseCompiler, CompilerException, SkipableCompilerException
from PoC.Entity import WildCard
from PoC.Entity import WildCard
from ToolChains.Xilinx.ISE import ISE, ISEException


Expand Down Expand Up @@ -173,11 +173,17 @@ def _RunCompile(self, netlist, device):
# copy xco file into temporary directory
self._LogVerbose("Copy CoreGen xco file to '{0}'.".format(xcoFilePath))
self._LogDebug("cp {0!s} {1!s}".format(xcoInputFilePath, self.Directories.Working))
shutil.copy(str(xcoInputFilePath), str(xcoFilePath), follow_symlinks=True)
try:
shutil.copy(str(xcoInputFilePath), str(xcoFilePath), follow_symlinks=True)
except OSError as ex:
raise CompilerException("Error while copying '{0!s}'.".format(xcoInputFilePath)) from ex

# change working directory to temporary CoreGen path
self._LogDebug("cd {0!s}".format(self.Directories.Working))
chdir(str(self.Directories.Working))
try:
chdir(str(self.Directories.Working))
except OSError as ex:
raise CompilerException("Error while changing to '{0!s}'.".format(self.Directories.Working)) from ex

# running CoreGen
# ==========================================================================
Expand Down
Loading

0 comments on commit e1e3eec

Please sign in to comment.