Example #1
0
class GitSCM(Executable, ToolMixIn):
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "git.exe"
        elif (self._platform == "Linux"):
            executablePath = self._binaryDirectoryPath / "git"
        elif (self._platform == "Darwin"):
            executablePath = self._binaryDirectoryPath / "git"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    def Clear(self):
        for param in self.Parameters:
            if (param is not self.Executable):
                self.Parameters[param] = None

    class Executable(metaclass=ExecutableArgument):
        pass

    class Switch_Version(metaclass=LongFlagArgument):
        _name = "version"

    Parameters = CommandLineArgumentList(Executable, Switch_Version)
Example #2
0
class GitConfig(GitSCM):
    def Clear(self):
        super().Clear()
        for param in self.ConfigParameters:
            # if isinstance(param, ExecutableArgument):
            # print("{0}".format(param.Value))
            # elif isinstance(param, NamedCommandLineArgument):
            # print("{0}".format(param.Name))
            if (param is not self.Command):
                # print("  clearing: {0} = {1} to None".format(param.Name, param.Value))
                self.ConfigParameters[param] = None

    class Command(metaclass=CommandArgument):
        _name = "config"

    class SwitchUnset(metaclass=LongFlagArgument):
        _name = "unset"

    class SwitchRemoveSection(metaclass=LongFlagArgument):
        _name = "remove-section"

    class ValueFilterClean(metaclass=ValuedFlagArgument):
        _name = "clean"
        _pattern = "filter.{1}.{0}"

    class ValueFilterSmudge(metaclass=ValuedFlagArgument):
        _name = "smudge"
        _pattern = "filter.{1}.{0}"

    class ValueFilterParameters(metaclass=StringArgument):
        pass

    ConfigParameters = CommandLineArgumentList(Command, SwitchUnset,
                                               SwitchRemoveSection,
                                               ValueFilterClean,
                                               ValueFilterSmudge,
                                               ValueFilterParameters)

    def Execute(self):
        parameterList = self.Parameters.ToArgumentList()
        parameterList += self.ConfigParameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GitException("Failed to launch Git.") from ex

        # FIXME: Replace GetReader with a shorter call to e.g. GetLine and/or GetLines
        output = ""
        for line in self.GetReader():
            output += line

        return output
Example #3
0
class GitRevParse(GitSCM):
    def Clear(self):
        super().Clear()
        for param in self.RevParseParameters:
            # if isinstance(param, ExecutableArgument):
            # 	print("{0}".format(param.Value))
            # elif isinstance(param, NamedCommandLineArgument):
            # 	print("{0}".format(param.Name))
            if (param is not self.Command):
                # print("  clearing: {0} = {1} to None".format(param.Name, param.Value))
                self.RevParseParameters[param] = None

    class Command(metaclass=CommandArgument):
        _name = "rev-parse"

    class SwitchInsideWorkingTree(metaclass=LongFlagArgument):
        _name = "is-inside-work-tree"

    class SwitchShowTopLevel(metaclass=LongFlagArgument):
        _name = "show-toplevel"

    class SwitchGitDir(metaclass=LongFlagArgument):
        _name = "git-dir"

    RevParseParameters = CommandLineArgumentList(Command,
                                                 SwitchInsideWorkingTree,
                                                 SwitchShowTopLevel,
                                                 SwitchGitDir)

    def Execute(self):
        parameterList = self.Parameters.ToArgumentList()
        parameterList += self.RevParseParameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GitException("Failed to launch Git.") from ex

        # FIXME: Replace GetReader with a shorter call to e.g. GetLine and/or GetLines
        output = ""
        for line in self.GetReader():
            output += line

        return output
Example #4
0
class Cmd(Executable):
    def __init__(self, platform, dryrun, logger=None):
        if (platform == "Windows"):
            executablePath = Path("C:\Windows\System32\cmd.exe")
        else:
            raise PlatformNotSupportedException(platform)
        super().__init__(platform, dryrun, executablePath, logger=logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        pass

    class SwitchCommand(metaclass=WindowsTupleArgument):
        _name = "C"

    Parameters = CommandLineArgumentList(Executable, SwitchCommand)

    def GetEnvironment(self, settingsFile=None):
        if (settingsFile is None):
            self.Parameters[self.SwitchCommand] = "set"
        else:
            self.Parameters[
                self.SwitchCommand] = "{settingsFile!s} && set".format(
                    settingsFile=settingsFile)

        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise WindowsException("Failed to launch cmd.exe.") from ex

        env = Environment()
        iterator = iter(self.GetReader())
        for line in iterator:
            try:
                var, value = line.split("=", 1)
                env.Variables[var] = value
            except Exception as ex:
                raise WindowsException(
                    "Error while reading output from cmd.exe.") from ex

        return env
Example #5
0
class Bash(Executable):
    def __init__(self, platform, dryrun, logger=None):
        if (platform == "Linux"): executablePath = Path("/bin/bash")
        else: raise PlatformNotSupportedException(platform)
        super().__init__(platform, dryrun, executablePath, logger=logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        pass

    class SwitchCommand(metaclass=ShortTupleArgument):
        _name = "c"

    Parameters = CommandLineArgumentList(Executable, SwitchCommand)

    def GetEnvironment(self, settingsFile=None, variables=""):
        if (settingsFile is None):
            self.Parameters[self.SwitchCommand] = "env"
        else:
            self.Parameters[
                self.
                SwitchCommand] = "{variables}source {settingsFile!s} && env".format(
                    settingsFile=settingsFile, variables=variables)

        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GNUException("Failed to launch /bin/bash.") from ex

        env = Environment()
        iterator = iter(self.GetReader())
        for line in iterator:
            try:
                var, value = line.split("=", 1)
                env.Variables[var] = value
            except Exception as ex:
                raise GNUException(
                    "Error while reading output from /bin/bash.") from ex

        return env
Example #6
0
class GitDescribe(GitSCM):
    def Clear(self):
        super().Clear()
        for param in self.DescribeParameters:
            # if isinstance(param, ExecutableArgument):
            # 	print("{0}".format(param.Value))
            # elif isinstance(param, NamedCommandLineArgument):
            # 	print("{0}".format(param.Name))
            if (param is not self.Command):
                # print("  clearing: {0} = {1} to None".format(param.Name, param.Value))
                self.DescribeParameters[param] = None

    class Command(metaclass=CommandArgument):
        _name = "describe"

    class SwitchAbbrev(metaclass=LongValuedFlagArgument):
        _name = "abbrev"

    class SwitchTags(metaclass=LongTupleArgument):
        _name = "tags"

    DescribeParameters = CommandLineArgumentList(Command, SwitchAbbrev,
                                                 SwitchTags)

    def Execute(self):
        parameterList = self.Parameters.ToArgumentList()
        parameterList += self.DescribeParameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GitException("Failed to launch Git.") from ex

        # FIXME: Replace GetReader with a shorter call to e.g. GetLine and/or GetLines
        output = ""
        for line in self.GetReader():
            output += line

        return output
Example #7
0
class LCov(Executable):
    def __init__(self, platform, dryrun, logger=None):
        if (platform == "Linux"): executablePath = Path("/usr/bin/lcov")
        else: raise PlatformNotSupportedException(platform)
        super().__init__(platform, dryrun, executablePath, logger=logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        pass

    class FlagCapture(metaclass=LongFlagArgument):
        _name = "capture"

    class SwitchDirectory(metaclass=LongTupleArgument):
        _name = "directory"

    class SwitchOutputFile(metaclass=LongTupleArgument):
        _name = "output-file"

    Parameters = CommandLineArgumentList(Executable, FlagCapture,
                                         SwitchDirectory, SwitchOutputFile)

    def Execute(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GNUException("Failed to launch /usr/bin/lcov.") from ex

        iterator = iter(self.GetReader())
        for line in iterator:
            print(line)
Example #8
0
class VHDLLibraryTool(OutputFilteredExecutable, ToolMixIn):
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vlib.exe"
        elif (self._platform == "Linux"):
            executablePath = self._binaryDirectoryPath / "vlib"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        pass

    class SwitchLibraryName(metaclass=StringArgument):
        pass

    Parameters = CommandLineArgumentList(Executable, SwitchLibraryName)

    def CreateLibrary(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise ModelSimException("Failed to launch vlib run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        try:
            iterator = iter(VLibFilter(self.GetReader()))

            line = next(iterator)
            line.IndentBy(self.Logger.BaseIndent + 1)
            self._hasOutput = True
            self.LogNormal("vlib messages for '{0}'".format(
                self.Parameters[self.SwitchLibraryName]),
                           indent=1)
            self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2), indent=1)
            self.Log(line)

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line = next(iterator)
                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)

        except DryRunException:
            pass
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2),
                               indent=1)
Example #9
0
class CoreGenerator(OutputFilteredExecutable, ToolMixIn):
	def __init__(self, toolchain : ToolMixIn):
		ToolMixIn.__init__(
			self, toolchain._platform, toolchain._dryrun, toolchain._binaryDirectoryPath, toolchain._version,
			toolchain._logger)

		if (self._platform == "Windows"):      executablePath = self._binaryDirectoryPath / "coregen.exe"
		elif (self._platform == "Linux"):      executablePath = self._binaryDirectoryPath / "coregen"
		else:                            raise PlatformNotSupportedException(self._platform)
		super().__init__(self._platform, self._dryrun, executablePath, environment=toolchain._environment, logger=self._logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):        pass

	class FlagRegenerate(metaclass=ShortFlagArgument):
		_name = "r"

	class SwitchProjectFile(metaclass=ShortTupleArgument):
		_name = "p"

	class SwitchBatchFile(metaclass=ShortTupleArgument):
		_name = "b"

	Parameters = CommandLineArgumentList(
		Executable,
		FlagRegenerate,
		SwitchProjectFile,
		SwitchBatchFile
	)

	def Generate(self):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise ISEException("Failed to launch corgen.") from ex

		self._hasOutput =   False
		self._hasWarnings = False
		self._hasErrors =   False
		try:
			iterator = iter(CoreGeneratorFilter(self.GetReader()))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  coregen messages for '{0}'".format(self.Parameters[self.SwitchProjectFile]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |=  (line.Severity is Severity.Warning)
				self._hasErrors |=    (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			pass
		except StopIteration:
			pass
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))
Example #10
0
class ISESimulator(OutputFilteredExecutable):
	def __init__(self, platform, dryrun, executablePath, environment, logger=None):
		super().__init__(platform, dryrun, executablePath, environment=environment, logger=logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):      pass

	class SwitchLogFile(metaclass=ShortTupleArgument):
		_name =    "log"

	class FlagGuiMode(metaclass=ShortFlagArgument):
		_name =    "gui"

	class SwitchTclBatchFile(metaclass=ShortTupleArgument):
		_name =    "tclbatch"

	class SwitchWaveformFile(metaclass=ShortTupleArgument):
		_name =    "view"

	Parameters = CommandLineArgumentList(
		Executable,
		SwitchLogFile,
		FlagGuiMode,
		SwitchTclBatchFile,
		SwitchWaveformFile
	)

	def Simulate(self):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise ISEException("Failed to launch isim.") from ex

		self._hasOutput =   False
		self._hasWarnings = False
		self._hasErrors =   False
		simulationResult =  CallByRefParam(SimulationResult.Error)
		try:
			iterator = iter(PoCSimulationResultFilter(SimulatorFilter(self.GetReader()), simulationResult))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  isim messages for '{0}'".format(self.Parameters[self.Executable]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |= (line.Severity is Severity.Warning)
				self._hasErrors |= (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			simulationResult <<= SimulationResult.DryRun
		except StopIteration:
			pass
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

		return simulationResult.value
Example #11
0
class Fuse(OutputFilteredExecutable, ToolMixIn):
	def __init__(self, toolchain : ToolMixIn):
		ToolMixIn.__init__(
			self, toolchain._platform, toolchain._dryrun, toolchain._binaryDirectoryPath, toolchain._version,
			toolchain._logger)

		if (self._platform == "Windows"):    executablePath = self._binaryDirectoryPath / "fuse.exe"
		elif (self._platform == "Linux"):    executablePath = self._binaryDirectoryPath / "fuse"
		else:                          raise PlatformNotSupportedException(self._platform)
		super().__init__(self._platform, self._dryrun, executablePath, environment=toolchain._environment, logger=self._logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):            pass

	class FlagIncremental(metaclass=ShortFlagArgument):
		_name =    "incremental"

	# FlagIncremental = ShortFlagArgument(_name="incremntal")

	class FlagRangeCheck(metaclass=ShortFlagArgument):
		_name =    "rangecheck"

	class SwitchMultiThreading(metaclass=ShortTupleArgument):
		_name =    "mt"

	class SwitchTimeResolution(metaclass=ShortTupleArgument):
		_name =    "timeprecision_vhdl"

	class SwitchProjectFile(metaclass=ShortTupleArgument):
		_name =    "prj"

	class SwitchOutputFile(metaclass=ShortTupleArgument):
		_name =    "o"

	class ArgTopLevel(metaclass=StringArgument):          pass

	Parameters = CommandLineArgumentList(
		Executable,
		FlagIncremental,
		FlagRangeCheck,
		SwitchMultiThreading,
		SwitchTimeResolution,
		SwitchProjectFile,
		SwitchOutputFile,
		ArgTopLevel
	)

	def Link(self):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise ISEException("Failed to launch fuse.") from ex

		self._hasOutput =   False
		self._hasWarnings = False
		self._hasErrors =   False
		try:
			iterator = iter(FuseFilter(self.GetReader()))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  fuse messages for '{0}'".format(self.Parameters[self.SwitchProjectFile]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |= (line.Severity is Severity.Warning)
				self._hasErrors |= (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			pass
		except StopIteration:
			pass
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))
Example #12
0
class Synth(OutputFilteredExecutable, ToolMixIn):
	def __init__(self, toolchain : ToolMixIn):
		ToolMixIn.__init__(
			self, toolchain._platform, toolchain._dryrun, toolchain._binaryDirectoryPath, toolchain._version,
			toolchain._logger)

		if (self._platform == "Windows"):    executablePath = self._binaryDirectoryPath / "synthesis.exe"
		elif (self._platform == "Linux"):    executablePath = self._binaryDirectoryPath / "synthesis"
		else:                          raise PlatformNotSupportedException(self._platform)
		super().__init__(self._platform, self._dryrun, executablePath, environment=toolchain._environment, logger=self._logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):
		pass

	class SwitchProjectFile(metaclass=ShortTupleArgument):
		_name = "f"
		_value = None

	Parameters = CommandLineArgumentList(
		Executable,
		SwitchProjectFile
	)

	@staticmethod
	def GetLogFileReader(logFile):
		while True:
			if logFile.exists(): break
			time.sleep(5)							# FIXME: implement a 'tail -f' functionality

		with logFile.open('r') as logFileHandle:
			for line in logFileHandle:
				yield line[:-1]

	def Compile(self, logFile):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		if (self._dryrun):
			self.LogDryRun("Start process: {0}".format(" ".join(parameterList)))
			return

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise LatticeException("Failed to launch LSE.") from ex

		self._hasOutput = False
		self._hasWarnings = False
		self._hasErrors = False
		try:
			iterator = iter(CompilerFilter(self.GetReader()))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  LSE messages for '{0}'".format(self.Parameters[self.SwitchProjectFile]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |= (line.Severity is Severity.Warning)
				self._hasErrors |= (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			pass
		except StopIteration:
			pass
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))
Example #13
0
class VHDLSimulator(OutputFilteredExecutable, ToolMixIn):
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vsim.exe"
        elif (self._platform == "Linux"):
            executablePath = self._binaryDirectoryPath / "vsim"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        """The executable to launch."""
        _value = None

    class SwitchBatchCommand(metaclass=ShortTupleArgument):
        """Specify a Tcl batch script for the batch mode."""
        _name = "do"
        _value = None

    class FlagCommandLineMode(metaclass=ShortFlagArgument):
        """Run simulation in command line mode."""
        _name = "c"
        _value = None

    class SwitchTimeResolution(metaclass=ShortTupleArgument):
        """Set simulation time resolution."""
        _name = "t"  # -t [1|10|100]fs|ps|ns|us|ms|sec  Time resolution limit
        _value = None

    class SwitchTopLevel(metaclass=StringArgument):
        """The top-level for simulation."""
        _value = None

    #: Specify all accepted command line arguments
    Parameters = CommandLineArgumentList(Executable, SwitchBatchCommand,
                                         FlagCommandLineMode,
                                         SwitchTimeResolution, SwitchTopLevel)

    def Simulate(self):
        """Start a simulation."""
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise RivieraPROException("Failed to launch vsim run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        simulationResult = CallByRefParam(SimulationResult.Error)
        try:
            iterator = iter(
                PoCSimulationResultFilter(VSimFilter(self.GetReader()),
                                          simulationResult))

            line = next(iterator)
            line.IndentBy(self.Logger.BaseIndent + 1)
            self._hasOutput = True
            self.LogNormal("vsim messages for '{0}'".format(
                self.Parameters[self.SwitchTopLevel]),
                           indent=1)
            self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2), indent=1)
            self.Log(line)

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line = next(iterator)
                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)

        except DryRunException:
            simulationResult <<= SimulationResult.DryRun
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2),
                               indent=1)

        return simulationResult.value
Example #14
0
class Synth(OutputFilteredExecutable, ToolMixIn):
	def __init__(self, toolchain : ToolMixIn):
		ToolMixIn.__init__(
			self, toolchain._platform, toolchain._dryrun, toolchain._binaryDirectoryPath, toolchain._version,
			toolchain._logger)

		if (self._platform == "Windows"):    executablePath = self._binaryDirectoryPath / "vivado.bat"
		elif (self._platform == "Linux"):    executablePath = self._binaryDirectoryPath / "vivado"
		else:                                            raise PlatformNotSupportedException(self._platform)
		super().__init__(self._platform, self._dryrun, executablePath, environment=toolchain._environment, logger=self._logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):
		_value =  None

	class SwitchLogFile(metaclass=ShortTupleArgument):
		_name =    "log"
		_value =  None

	class SwitchSourceFile(metaclass=ShortTupleArgument):
		_name =    "source"
		_value =  None

	class SwitchMode(metaclass=ShortTupleArgument):
		_name =    "mode"
		_value =  "batch"


	Parameters = CommandLineArgumentList(
		Executable,
		SwitchLogFile,
		SwitchSourceFile,
		SwitchMode
	)

	def Compile(self):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise VivadoException("Failed to launch vivado.") from ex

		self._hasOutput = False
		self._hasWarnings = False
		self._hasErrors = False
		try:
			iterator = iter(CompilerFilter(self.GetReader()))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  vivado messages for '{0}'".format(self.Parameters[self.SwitchSourceFile]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |= (line.Severity is Severity.Warning)
				self._hasErrors |= (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			pass
		except StopIteration:
			pass
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))
Example #15
0
class XElab(OutputFilteredExecutable, ToolMixIn):
	def __init__(self, toolchain : ToolMixIn):
		ToolMixIn.__init__(
			self, toolchain._platform, toolchain._dryrun, toolchain._binaryDirectoryPath, toolchain._version,
			toolchain._logger)

		if (self._platform == "Windows"):    executablePath = self._binaryDirectoryPath / "xelab.bat"
		elif (self._platform == "Linux"):    executablePath = self._binaryDirectoryPath / "xelab"
		else:                                            raise PlatformNotSupportedException(self._platform)
		super().__init__(self._platform, self._dryrun, executablePath, environment=toolchain._environment, logger=self._logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):
		_value =  None

	class FlagRangeCheck(metaclass=ShortFlagArgument):
		_name =    "rangecheck"
		_value =  None

	class SwitchMultiThreading(metaclass=ShortTupleArgument):
		_name =    "mt"
		_value =  None

	class SwitchVerbose(metaclass=ShortTupleArgument):
		_name =    "verbose"
		_value =  None

	class SwitchDebug(metaclass=ShortTupleArgument):
		_name =    "debug"
		_value =  None

	# class SwitchVHDL2008(metaclass=ShortFlagArgument):
	# 	_name =    "vhdl2008"
	# 	_value =  None

	class SwitchOptimization(metaclass=ShortValuedFlagArgument):
		_pattern = "--{0}{1}"
		_name =    "O"
		_value =  None

	class SwitchTimeResolution(metaclass=ShortTupleArgument):
		_name =    "timeprecision_vhdl"
		_value =  None

	class SwitchProjectFile(metaclass=ShortTupleArgument):
		_name =    "prj"
		_value =  None

	class SwitchLogFile(metaclass=ShortTupleArgument):
		_name =    "log"
		_value =  None

	class SwitchSnapshot(metaclass=ShortTupleArgument):
		_name =    "s"
		_value =  None

	class ArgTopLevel(metaclass=StringArgument):
		_value =  None

	Parameters = CommandLineArgumentList(
		Executable,
		FlagRangeCheck,
		SwitchMultiThreading,
		SwitchTimeResolution,
		SwitchVerbose,
		SwitchDebug,
		# SwitchVHDL2008,
		SwitchOptimization,
		SwitchProjectFile,
		SwitchLogFile,
		SwitchSnapshot,
		ArgTopLevel
	)

	def Link(self):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise VivadoException("Failed to launch xelab.") from ex

		self._hasOutput = False
		self._hasWarnings = False
		self._hasErrors = False
		try:
			iterator = iter(ElaborationFilter(self.GetReader()))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  xelab messages for '{0}'".format(self.Parameters[self.SwitchProjectFile]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |= (line.Severity is Severity.Warning)
				self._hasErrors |= (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			pass
		except StopIteration:
			pass
		except VivadoException:
			raise
		# except Exception as ex:
		#	raise GHDLException("Error while executing GHDL.") from ex
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))
Example #16
0
class VHDLCompiler(OutputFilteredExecutable, ToolMixIn):
    """Abstraction layer of Active-HDL's VHDL compiler 'vcom'."""
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vcom.exe"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        _value = None

    class FlagNoRangeCheck(metaclass=LongFlagArgument):
        _name = "norangecheck"
        _value = None

    class SwitchVHDLVersion(metaclass=ShortValuedFlagArgument):
        _pattern = "-{1}"
        _name = ""
        _value = None

    class SwitchVHDLLibrary(metaclass=ShortTupleArgument):
        _name = "work"
        _value = None

    class ArgSourceFile(metaclass=PathArgument):
        _value = None

    Parameters = CommandLineArgumentList(Executable, FlagNoRangeCheck,
                                         SwitchVHDLVersion, SwitchVHDLLibrary,
                                         ArgSourceFile)

    # -reorder                      enables automatic file ordering
    # -O[0 | 1 | 2 | 3]             set optimization level
    # -93                                conform to VHDL 1076-1993
    # -2002                              conform to VHDL 1076-2002 (default)
    # -2008                              conform to VHDL 1076-2008
    # -relax                             allow 32-bit integer literals
    # -incr                              switching compiler to fast incremental mode

    def Compile(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise ActiveHDLException("Failed to launch acom run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        try:
            iterator = iter(VComFilter(self.GetReader()))
            line = next(iterator)

            self._hasOutput = True
            self.LogNormal("  acom messages for '{0}'".format(
                self.Parameters[self.ArgSourceFile]))
            self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent * 2)))

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)
                line = next(iterator)

        except DryRunException:
            pass
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("  " + ("-" *
                                       (78 - self.Logger.BaseIndent * 2)))
Example #17
0
class VHDLStandaloneSimulator(OutputFilteredExecutable, ToolMixIn):
    """Abstraction layer of Active-HDL's VHDL standalone simulator 'vsimsa'."""
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vsimsa.exe"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        _value = None

    class SwitchBatchCommand(metaclass=ShortTupleArgument):
        _name = "do"
        _value = None

    Parameters = CommandLineArgumentList(Executable, SwitchBatchCommand)

    def Simulate(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))
        self.LogDebug("tcl commands: {0}".format(
            self.Parameters[self.SwitchBatchCommand]))

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise ActiveHDLException("Failed to launch vsimsa run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        simulationResult = CallByRefParam(SimulationResult.Error)
        try:
            iterator = iter(
                PoCSimulationResultFilter(VSimFilter(self.GetReader()),
                                          simulationResult))
            line = next(iterator)

            self._hasOutput = True
            self.LogNormal("  vsimsa messages for '{0}.{1}'".format(
                "?????", "?????"))
            self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent * 2)))

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)
                line = next(iterator)

        except DryRunException:
            simulationResult <<= SimulationResult.DryRun
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("  " + ("-" *
                                       (78 - self.Logger.BaseIndent * 2)))

        return simulationResult.value
Example #18
0
class Make(OutputFilteredExecutable):
    def __init__(self, platform, dryrun, logger=None):
        if (platform == "Linux"): executablePath = Path("/usr/bin/make")
        else: raise PlatformNotSupportedException(platform)
        super().__init__(platform, dryrun, executablePath, logger=logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        pass

    class SwitchGui(metaclass=ValuedFlagArgument):
        _name = "GUI"

    Parameters = CommandLineArgumentList(Executable, SwitchGui)

    def RunCocotb(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GNUException("Failed to launch Make.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        simulationResult = CallByRefParam(SimulationResult.Error)
        try:
            iterator = iter(
                CocotbSimulationResultFilter(
                    GNUMakeQuestaSimFilter(self.GetReader()),
                    simulationResult))

            line = next(iterator)
            line.IndentBy(self.Logger.BaseIndent + 1)
            self._hasOutput = True
            self.LogNormal("  Make messages")
            self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent * 2)))
            self.Log(line)

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line = next(iterator)
                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)

        except DryRunException:
            simulationResult <<= SimulationResult.DryRun
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("  " + ("-" *
                                       (78 - self.Logger.BaseIndent * 2)))

        return simulationResult.value
Example #19
0
class VHDLCompiler(OutputFilteredExecutable, ToolMixIn):
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vcom.exe"
        elif (self._platform == "Linux"):
            executablePath = self._binaryDirectoryPath / "vcom"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        _value = None

    class FlagTime(metaclass=ShortFlagArgument):
        _name = "time"  # Print the compilation wall clock time
        _value = None

    class FlagExplicit(metaclass=ShortFlagArgument):
        _name = "explicit"
        _value = None

    class FlagQuietMode(metaclass=ShortFlagArgument):
        _name = "quiet"  # Do not report 'Loading...' messages"
        _value = None

    class SwitchModelSimIniFile(metaclass=ShortTupleArgument):
        _name = "modelsimini"
        _value = None

    class FlagRangeCheck(metaclass=ShortFlagArgument):
        _name = "rangecheck"
        _value = None

    class SwitchCoverage(metaclass=OptionalModelSimPlusArgument):
        _name = "cover"

        # @property
        # def Value(self):
        # 	return self._value
        #
        # @Value.setter
        # def Value(self, value):
        # 	if (value is None):                                         self._value = None
        # 	elif isinstance(value, VHDLCompilerCoverageOptions):        self._value = value
        # 	else:	                                                      raise ValueError("Parameter 'value' is not of type VHDLCompilerCoverageOptions.")
        #
        # def __str__(self):
        # 	if (self._value is None):                                   return ""
        # 	elif (self._value is VHDLCompilerCoverageOptions.Default):  return self._pattern.format(self._name)
        # 	else:                                                       return self._patternWithValue.format(self._name, str(self._value))
        #
        # def AsArgument(self):
        # 	if (self._value is None):                                   return None
        # 	elif (self._value is VHDLCompilerCoverageOptions.Default):  return self._pattern.format(self._name)
        # 	else:                                                       return self._patternWithValue.format(self._name, str(self._value))

    class FlagEnableFocusedExpressionCoverage(metaclass=ShortFlagArgument):
        _name = "coverfec"

    class FlagDisableFocusedExpressionCoverage(metaclass=ShortFlagArgument):
        _name = "nocoverfec"

    class FlagEnableRapidExpressionCoverage(metaclass=ShortFlagArgument):
        _name = "coverrec"

    class FlagDisableRapidExpressionCoverage(metaclass=ShortFlagArgument):
        _name = "nocoverrec"

    class FlagEnableRecognitionOfImplicitFSMResetTransitions(
            metaclass=ShortFlagArgument):
        _name = "fsmresettrans"

    class FlagDisableRecognitionOfImplicitFSMResetTransitions(
            metaclass=ShortFlagArgument):
        _name = "nofsmresettrans"

    class FlagEnableRecognitionOfSingleBitFSMState(metaclass=ShortFlagArgument
                                                   ):
        _name = "fsmsingle"

    class FlagDisableRecognitionOfSingleBitFSMState(metaclass=ShortFlagArgument
                                                    ):
        _name = "nofsmsingle"

    class FlagEnableRecognitionOfImplicitFSMTransitions(
            metaclass=ShortFlagArgument):
        _name = "fsmimplicittrans"

    class FlagDisableRecognitionOfImplicitFSMTransitions(
            metaclass=ShortFlagArgument):
        _name = "nofsmimplicittrans"

    class SwitchFSMVerbosityLevel(metaclass=OptionalModelSimMinusArgument):
        _name = "fsmverbose"

        # @property
        # def Value(self):
        # 	return self._value
        #
        # @Value.setter
        # def Value(self, value):
        # 	if (value is None):                                           self._value = None
        # 	elif isinstance(value, VHDLCompilerFSMVerbosityLevel):        self._value = value
        # 	else:	                                                        raise ValueError("Parameter 'value' is not of type VHDLCompilerFSMVerbosityLevel.")
        #
        # def __str__(self):
        # 	if (self._value is None):                                     return ""
        # 	elif (self._value is VHDLCompilerFSMVerbosityLevel.Default):  return self._pattern.format(self._name)
        # 	else:                                                         return self._patternWithValue.format(self._name, str(self._value))
        #
        # def AsArgument(self):
        # 	if (self._value is None):                                     return None
        # 	elif (self._value is VHDLCompilerFSMVerbosityLevel.Default):  return self._pattern.format(self._name)
        # 	else:                                                         return self._patternWithValue.format(self._name, str(self._value))

    class FlagReportAsNote(metaclass=ShortTupleArgument):
        _name = "note"
        _value = None

    class FlagReportAsError(metaclass=ShortTupleArgument):
        _name = "error"
        _value = None

    class FlagReportAsWarning(metaclass=ShortTupleArgument):
        _name = "warning"
        _value = None

    class FlagReportAsFatal(metaclass=ShortTupleArgument):
        _name = "fatal"
        _value = None

    class FlagRelaxLanguageChecks(metaclass=ShortFlagArgument):
        _name = "permissive"

    class FlagForceLanguageChecks(metaclass=ShortFlagArgument):
        _name = "pedanticerrors"

    class SwitchVHDLVersion(metaclass=StringArgument):
        _pattern = "-{0}"
        _value = None

    class ArgLogFile(metaclass=ShortTupleArgument):
        _name = "l"  # what's the difference to -logfile ?
        _value = None

    class SwitchVHDLLibrary(metaclass=ShortTupleArgument):
        _name = "work"
        _value = None

    class ArgSourceFile(metaclass=PathArgument):
        _value = None

    Parameters = CommandLineArgumentList(
        Executable, FlagTime, FlagExplicit, FlagQuietMode,
        SwitchModelSimIniFile, FlagRangeCheck, SwitchCoverage,
        FlagEnableFocusedExpressionCoverage,
        FlagDisableFocusedExpressionCoverage,
        FlagEnableRapidExpressionCoverage, FlagDisableRapidExpressionCoverage,
        FlagEnableRecognitionOfImplicitFSMResetTransitions,
        FlagDisableRecognitionOfImplicitFSMResetTransitions,
        FlagEnableRecognitionOfSingleBitFSMState,
        FlagDisableRecognitionOfSingleBitFSMState,
        FlagEnableRecognitionOfImplicitFSMTransitions,
        FlagDisableRecognitionOfImplicitFSMTransitions,
        SwitchFSMVerbosityLevel, FlagReportAsNote, FlagReportAsError,
        FlagReportAsWarning, FlagReportAsFatal, FlagRelaxLanguageChecks,
        FlagForceLanguageChecks, SwitchVHDLVersion, ArgLogFile,
        SwitchVHDLLibrary, ArgSourceFile)

    def Compile(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise ModelSimException("Failed to launch vcom run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        try:
            iterator = iter(VComFilter(self.GetReader()))

            line = next(iterator)
            line.IndentBy(self.Logger.BaseIndent + 1)
            self._hasOutput = True
            self.LogNormal("vcom messages for '{0}'".format(
                self.Parameters[self.ArgSourceFile]),
                           indent=1)
            self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2), indent=1)
            self.Log(line)

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line = next(iterator)
                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)

        except DryRunException:
            pass
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2),
                               indent=1)

    def GetTclCommand(self):
        parameterList = self.Parameters.ToArgumentList()
        return "vcom " + " ".join(parameterList[1:])
Example #20
0
class XSim(OutputFilteredExecutable, ToolMixIn):
	def __init__(self, toolchain : ToolMixIn):
		ToolMixIn.__init__(
			self, toolchain._platform, toolchain._dryrun, toolchain._binaryDirectoryPath, toolchain._version,
			toolchain._logger)

		if (self._platform == "Windows"):    executablePath = self._binaryDirectoryPath / "xsim.bat"
		elif (self._platform == "Linux"):    executablePath = self._binaryDirectoryPath / "xsim"
		else:                                raise PlatformNotSupportedException(self._platform)
		super().__init__(self._platform, self._dryrun, executablePath, environment=toolchain._environment, logger=self._logger)

		self.Parameters[self.Executable] = executablePath

	class Executable(metaclass=ExecutableArgument):
		_value =  None

	class SwitchLogFile(metaclass=ShortTupleArgument):
		_name =    "-log"
		_value =  None

	class FlagGuiMode(metaclass=ShortFlagArgument):
		_name =    "-gui"
		_value =  None

	class SwitchTclBatchFile(metaclass=ShortTupleArgument):
		_name =    "-tclbatch"
		_value =  None

	class SwitchWaveformFile(metaclass=ShortTupleArgument):
		_name =    "-view"
		_value =  None

	class SwitchSnapshot(metaclass=StringArgument):
		_value =  None

	Parameters = CommandLineArgumentList(
		Executable,
		SwitchLogFile,
		FlagGuiMode,
		SwitchTclBatchFile,
		SwitchWaveformFile,
		SwitchSnapshot
	)

	def Simulate(self):
		parameterList = self.Parameters.ToArgumentList()
		self.LogVerbose("command: {0}".format(" ".join(parameterList)))

		try:
			self.StartProcess(parameterList)
		except Exception as ex:
			raise VivadoException("Failed to launch xsim.") from ex

		self._hasOutput = False
		self._hasWarnings = False
		self._hasErrors = False
		simulationResult =  CallByRefParam(SimulationResult.Error)
		try:
			iterator = iter(PoCSimulationResultFilter(SimulatorFilter(self.GetReader()), simulationResult))

			line = next(iterator)
			self._hasOutput = True
			self.LogNormal("  xsim messages for '{0}'".format(self.Parameters[self.SwitchSnapshot]))
			self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

			while True:
				self._hasWarnings |= (line.Severity is Severity.Warning)
				self._hasErrors |= (line.Severity is Severity.Error)

				line.IndentBy(self.Logger.BaseIndent + 1)
				self.Log(line)
				line = next(iterator)

		except DryRunException:
			simulationResult <<= SimulationResult.DryRun
		except StopIteration:
			pass
		finally:
			if self._hasOutput:
				self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent*2)))

		return simulationResult.value
Example #21
0
class VHDLSimulator(OutputFilteredExecutable, ToolMixIn):
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vsim.exe"
        elif (self._platform == "Linux"):
            executablePath = self._binaryDirectoryPath / "vsim"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        """The executable to launch."""
        _value = None

    class FlagQuietMode(metaclass=ShortFlagArgument):
        """Run simulation in quiet mode. (Don't show 'Loading...' messages."""
        _name = "quiet"
        _value = None

    class FlagBatchMode(metaclass=ShortFlagArgument):
        """Run simulation in batch mode."""
        _name = "batch"
        _value = None

    class FlagGuiMode(metaclass=ShortFlagArgument):
        """Run simulation in GUI mode."""
        _name = "gui"
        _value = None

    class SwitchBatchCommand(metaclass=ShortTupleArgument):
        """Specify a Tcl batch script for the batch mode."""
        _name = "do"
        _value = None

    class FlagCommandLineMode(metaclass=ShortFlagArgument):
        """Run simulation in command line mode."""
        _name = "c"
        _value = None

    class SwitchModelSimIniFile(metaclass=ShortTupleArgument):
        """Specify the used 'modelsim.ini' file."""
        _name = "modelsimini"
        _value = None

    class FlagEnableOptimization(metaclass=ShortFlagArgument):
        """Enabled optimization while elaborating the design."""
        _name = "vopt"

    class FlagDisableOptimization(metaclass=ShortFlagArgument):
        """Disabled optimization while elaborating the design."""
        _name = "novopt"

    class FlagEnableOptimizationVerbosity(metaclass=ShortFlagArgument):
        """Enabled optimization while elaborating the design."""
        _name = "vopt_verbose"

    class FlagEnableKeepAssertionCountsForCoverage(metaclass=ShortFlagArgument
                                                   ):
        _name = "assertcover"

    class FlagDisableKeepAssertionCountsForCoverage(metaclass=ShortFlagArgument
                                                    ):
        _name = "noassertcover"

    class FlagEnableCoverage(metaclass=ShortFlagArgument):
        _name = "coverage"

    class FlagDisableCoverage(metaclass=ShortFlagArgument):
        _name = "nocoverage"

    class FlagEnablePSL(metaclass=ShortFlagArgument):
        _name = "psl"

    class FlagDisablePSL(metaclass=ShortFlagArgument):
        _name = "nopsl"

    class FlagEnableFSMDebugging(metaclass=ShortFlagArgument):
        _name = "fsmdebug"

    class FlagReportAsNote(metaclass=ShortTupleArgument):
        _name = "note"
        _value = None

    class FlagReportAsError(metaclass=ShortTupleArgument):
        _name = "error"
        _value = None

    class FlagReportAsWarning(metaclass=ShortTupleArgument):
        _name = "warning"
        _value = None

    class FlagReportAsFatal(metaclass=ShortTupleArgument):
        _name = "fatal"
        _value = None

    class FlagRelaxLanguageChecks(metaclass=ShortFlagArgument):
        _name = "permissive"

    class FlagForceLanguageChecks(metaclass=ShortFlagArgument):
        _name = "pedanticerrors"

    class SwitchTimeResolution(metaclass=ShortTupleArgument):
        """Set simulation time resolution."""
        _name = "t"  # -t [1|10|100]fs|ps|ns|us|ms|sec  Time resolution limit
        _value = None

    class ArgLogFile(metaclass=ShortTupleArgument):
        _name = "l"  # what's the difference to -logfile ?
        _value = None

    class ArgKeepStdOut(metaclass=ShortFlagArgument):
        _name = "keepstdout"

    class ArgVHDLLibraryName(metaclass=ShortTupleArgument):
        _name = "lib"
        _value = None

    class ArgOnFinishMode(metaclass=ShortTupleArgument):
        _name = "onfinish"
        _value = None  # Customize the kernel shutdown behavior at the end of simulation; Valid modes: ask, stop, exit, final (Default: ask)

    class SwitchTopLevel(metaclass=StringArgument):
        """The top-level for simulation."""
        _value = None

    #: Specify all accepted command line arguments
    Parameters = CommandLineArgumentList(
        Executable, FlagQuietMode, FlagBatchMode, FlagGuiMode,
        SwitchBatchCommand, FlagCommandLineMode, SwitchModelSimIniFile,
        FlagEnableOptimization, FlagDisableOptimization,
        FlagEnableOptimizationVerbosity,
        FlagEnableKeepAssertionCountsForCoverage,
        FlagDisableKeepAssertionCountsForCoverage, FlagEnableCoverage,
        FlagDisableCoverage, FlagEnablePSL, FlagDisablePSL,
        FlagEnableFSMDebugging, FlagReportAsNote, FlagReportAsError,
        FlagReportAsWarning, FlagReportAsFatal, FlagRelaxLanguageChecks,
        FlagForceLanguageChecks, ArgLogFile, ArgKeepStdOut, ArgVHDLLibraryName,
        SwitchTimeResolution, ArgOnFinishMode, SwitchTopLevel)

    def Simulate(self):
        """Start a simulation."""
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise ModelSimException("Failed to launch vsim run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        simulationResult = CallByRefParam(SimulationResult.Error)
        try:
            iterator = iter(
                PoCSimulationResultFilter(VSimFilter(self.GetReader()),
                                          simulationResult))

            line = next(iterator)
            line.IndentBy(self.Logger.BaseIndent + 1)
            self._hasOutput = True
            self.LogNormal("vsim messages for '{0}'".format(
                self.Parameters[self.SwitchTopLevel]),
                           indent=1)
            self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2), indent=1)
            self.Log(line)

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line = next(iterator)
                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)

        except DryRunException:
            simulationResult <<= SimulationResult.DryRun
        except pyIPCMISimulationResultNotFoundException:
            if self.Parameters[self.FlagGuiMode]:
                simulationResult <<= SimulationResult.GUIRun
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("-" * (78 - self.Logger.BaseIndent * 2),
                               indent=1)

        return simulationResult.value
Example #22
0
class GTKWave(OutputFilteredExecutable):
    def __init__(self,
                 platform,
                 dryrun,
                 binaryDirectoryPath,
                 version,
                 logger=None):
        if (platform == "Windows"):
            executablePath = binaryDirectoryPath / "gtkwave.exe"
        elif (platform == "Linux"):
            executablePath = binaryDirectoryPath / "gtkwave"
        elif (platform == "Darwin"):
            executablePath = binaryDirectoryPath / "gtkwave"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(platform, dryrun, executablePath, logger=logger)

        self.Parameters[self.Executable] = executablePath

        self._binaryDirectoryPath = binaryDirectoryPath
        self._version = version

    @property
    def BinaryDirectoryPath(self):
        return self._binaryDirectoryPath

    @property
    def Version(self):
        return self._version

    class Executable(metaclass=ExecutableArgument):
        pass

    class SwitchDumpFile(metaclass=LongValuedFlagArgument):
        _name = "dump"

    class SwitchSaveFile(metaclass=LongValuedFlagArgument):
        _name = "save"

    Parameters = CommandLineArgumentList(Executable, SwitchDumpFile,
                                         SwitchSaveFile)

    def View(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise GTKWaveException("Failed to launch GTKWave run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        try:
            iterator = iter(GTKWaveFilter(self.GetReader()))

            line = next(iterator)
            line.IndentBy(self.Logger.BaseIndent + 1)
            self._hasOutput = True
            self.LogNormal("  GTKWave messages for '{0}'".format(
                self.Parameters[self.SwitchDumpFile]))
            self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent * 2)))
            self.Log(line)

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line = next(iterator)
                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)

        except DryRunException:
            pass
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("  " + ("-" *
                                       (78 - self.Logger.BaseIndent * 2)))
Example #23
0
class VHDLCompiler(OutputFilteredExecutable, ToolMixIn):
    """Abstraction layer of Riviera-PRO's VHDL compiler 'vcom'."""
    def __init__(self, toolchain: ToolMixIn):
        ToolMixIn.__init__(self, toolchain._platform, toolchain._dryrun,
                           toolchain._binaryDirectoryPath, toolchain._version,
                           toolchain._logger)

        if (self._platform == "Windows"):
            executablePath = self._binaryDirectoryPath / "vcom.exe"
        elif (self._platform == "Linux"):
            executablePath = self._binaryDirectoryPath / "vcom"
        else:
            raise PlatformNotSupportedException(self._platform)
        super().__init__(self._platform,
                         self._dryrun,
                         executablePath,
                         logger=self._logger)

        self.Parameters[self.Executable] = executablePath

    class Executable(metaclass=ExecutableArgument):
        _value = None

    # class FlagNoRangeCheck(metaclass=LongFlagArgument):
    # 	_name =   "norangecheck"
    # 	_value =  None

    class SwitchVHDLVersion(metaclass=ShortValuedFlagArgument):
        _pattern = "-{1}"
        _name = ""
        _value = None

    class SwitchVHDLLibrary(metaclass=ShortTupleArgument):
        _name = "work"
        _value = None

    class ArgSourceFile(metaclass=PathArgument):
        _value = None

    Parameters = CommandLineArgumentList(
        Executable,
        # FlagNoRangeCheck,
        SwitchVHDLVersion,
        SwitchVHDLLibrary,
        ArgSourceFile)

    def Compile(self):
        parameterList = self.Parameters.ToArgumentList()
        self.LogVerbose("command: {0}".format(" ".join(parameterList)))

        if (self._dryrun):
            self.LogDryRun("Start process: {0}".format(
                " ".join(parameterList)))
            return

        try:
            self.StartProcess(parameterList)
        except Exception as ex:
            raise RivieraPROException("Failed to launch acom run.") from ex

        self._hasOutput = False
        self._hasWarnings = False
        self._hasErrors = False
        try:
            iterator = iter(VComFilter(self.GetReader()))
            line = next(iterator)

            self._hasOutput = True
            self.LogNormal("  acom messages for '{0}'".format(
                self.Parameters[self.ArgSourceFile]))
            self.LogNormal("  " + ("-" * (78 - self.Logger.BaseIndent * 2)))

            while True:
                self._hasWarnings |= (line.Severity is Severity.Warning)
                self._hasErrors |= (line.Severity is Severity.Error)

                line.IndentBy(self.Logger.BaseIndent + 1)
                self.Log(line)
                line = next(iterator)

        except DryRunException:
            pass
        except StopIteration:
            pass
        finally:
            if self._hasOutput:
                self.LogNormal("  " + ("-" *
                                       (78 - self.Logger.BaseIndent * 2)))