예제 #1
0
 def Print(self, indent=0):
     indentation = "  " * indent
     print(
         "{indent}{DARK_CYAN}CONSTANT {GREEN}{name}{NOCOLOR} : {GREEN}{type}{NOCOLOR} := xxx;"
         .format(indent=indentation,
                 name=self._name,
                 type="",
                 **LineTerminal().Foreground))
예제 #2
0
 def Pop(self, n=1, tokenMarker=None):
     top = None
     for i in range(n):
         top = self._stack.pop()
         LineTerminal().WriteDebug("popped: " + str(top[0]))
     self.NextState = top[0]
     self.Counter = top[1]
     self._tokenMarker = tokenMarker
예제 #3
0
 def TokenMarker(self) -> Token:
     if ((self.NewToken is not None) and (self._tokenMarker is self.Token)):
         LineTerminal().WriteDebug(
             "  {DARK_GREEN}@TokenMarker: {0!s} => {GREEN}{1!s}{NOCOLOR}".
             format(self._tokenMarker, self.NewToken,
                    **LineTerminal.Foreground))
         self._tokenMarker = self.NewToken
     return self._tokenMarker
예제 #4
0
    def GetGenerator(self) -> Generator['Block', Token, None]:
        from pyVHDLParser.Token import EndOfDocumentToken
        from pyVHDLParser.Blocks import BlockParserException, EndOfDocumentBlock
        from pyVHDLParser.Blocks.Common import LinebreakBlock, EmptyLineBlock

        for token in self._iterator:
            # set parserState.Token to current token
            self.Token = token

            # overwrite an existing token and connect the next token with the new one
            if (self.NewToken is not None):
                # print("{MAGENTA}NewToken: {token}{NOCOLOR}".format(token=self.NewToken, **Console.Foreground))
                # update topmost TokenMarker
                if (self._tokenMarker is token.PreviousToken):
                    # XXX: LineTerminal().WriteDebug("  update token marker: {0!s} -> {1!s}".format(self._tokenMarker, self.NewToken))
                    self._tokenMarker = self.NewToken

                token.PreviousToken = self.NewToken
                self.NewToken = None

            # an empty marker means: fill on next yield run
            if (self._tokenMarker is None):
                LineTerminal().WriteDebug(
                    "  new token marker: None -> {0!s}".format(token))
                self._tokenMarker = token

            # a new block is assembled
            while (self.NewBlock is not None):
                if (isinstance(self.NewBlock, LinebreakBlock)
                        and isinstance(self.LastBlock,
                                       (LinebreakBlock, EmptyLineBlock))):
                    self.LastBlock = EmptyLineBlock(self.LastBlock,
                                                    self.NewBlock.StartToken)
                    self.LastBlock.NextBlock = self.NewBlock.NextBlock
                else:
                    self.LastBlock = self.NewBlock

                self.NewBlock = self.NewBlock.NextBlock
                yield self.LastBlock

            # if self.debug: print("{MAGENTA}------ iteration end ------{NOCOLOR}".format(**Console.Foreground))
            # XXX: LineTerminal().WriteDebug("    {DARK_GRAY}state={state!s: <50}  token={token!s: <40}{NOCOLOR}   ".format(state=self, token=token, **LineTerminal.Foreground))
            # execute a state
            self.NextState(self)

        else:
            if (isinstance(self.Token, EndOfDocumentToken)
                    and isinstance(self.NewBlock, EndOfDocumentBlock)):
                yield self.NewBlock
            else:
                raise BlockParserException("Unexpected end of document.",
                                           self.Token)
예제 #5
0
	def Print(self, indent=0):
		indentation = "  "*indent
		for lib in self._libraries:
			print("{indent}{DARK_CYAN}LIBRARY{NOCOLOR} {GREEN}{lib}{NOCOLOR};".format(indent=indentation, lib=lib, **LineTerminal().Foreground))
		for use in self._uses:
			print("{indent}{DARK_CYAN}USE {GREEN}{lib}{NOCOLOR}.{GREEN}{pack}{NOCOLOR}.{GREEN}{item}{NOCOLOR};".format(indent=indentation, lib=use._configuration, pack=use._function, item=use._item, **LineTerminal().Foreground))
		print()
		print("{indent}{DARK_CYAN}FUNCTION{NOCOLOR} {YELLOW}{name}{NOCOLOR} {DARK_CYAN}IS{NOCOLOR}".format(indent=indentation, name=self._name, **LineTerminal().Foreground))
		if (len(self._genericItems) > 0):
			print("{indent}  {DARK_CYAN}GENERIC{NOCOLOR} (".format(indent=indentation, **LineTerminal().Foreground))
			for generic in self._genericItems:
				print("{indent}    {YELLOW}{name}{NOCOLOR} : {GREEN}{type}{NOCOLOR}".format(indent=indentation, name=generic, type="", **LineTerminal().Foreground))
			print("{indent}  );".format(indent=indentation))
		if (len(self._declaredItems) > 0):
			for item in self._declaredItems:
				item.Print(indent+1)
		print("{indent}{DARK_CYAN}END FUNCTION{NOCOLOR};".format(indent=indentation, name=self._name, **LineTerminal().Foreground))
예제 #6
0
    def GetGenerator(self):  # XXX: return type
        from pyVHDLParser.Groups import GroupParserException

        # yield StartOfDocumentGroup
        self.LastGroup = self.NextGroup
        yield self.LastGroup

        for block in self._iterator:
            # an empty marker means: set on next yield run
            if (self._blockMarker is None):
                # if self.debug: print("  new block marker: None -> {0!s}".format(block))
                self._blockMarker = block

            # if self.debug: print("{MAGENTA}------ iteration end ------{NOCOLOR}".format(**Console.Foreground))
            # execute a state and reissue execution if needed
            self.ReIssue = True
            while self.ReIssue:
                self.ReIssue = False
                LineTerminal().WriteDryRun(
                    "{DARK_GRAY}reissue state={state!s: <50}  block={block!s: <40}     {NOCOLOR}"
                    .format(state=self,
                            block=self.Block,
                            **LineTerminal.Foreground))
                self.NextState(self)

                # yield a new group
                if (self.NewGroup is not None):
                    yield self.NewGroup
                    self.LastGroup = self.NewGroup
                    self.NewGroup = None

                    if (isinstance(self.Block, EndOfDocumentBlock) and
                            isinstance(self.LastGroup, EndOfDocumentGroup)):
                        return

        else:
            raise GroupParserException("Unexpected end of document.",
                                       self.Block)
예제 #7
0
def main():  # mccabe:disable=MC0001
    """This is the entry point for pyVHDLParser written as a function.

	1. It extracts common flags from the script's arguments list, before :py:class:`~argparse.ArgumentParser` is fully loaded.
	2. It creates an instance of VHDLParser and hands over to a class based execution.
	   All is wrapped in a big ``try..except`` block to catch every unhandled exception.
	3. Shutdown the script and return its exit code.
	"""
    from sys import argv as sys_argv

    debug = "-d" in sys_argv
    verbose = "-v" in sys_argv
    quiet = "-q" in sys_argv

    try:
        # handover to a class instance
        app = Application(debug, verbose, quiet)
        app.Run()
        app.exit()

    # except (CommonException, ConfigurationException) as ex:
    # 	print("{RED}ERROR:{NOCOLOR} {message}".format(message=ex.message, **Init.Foreground))
    # 	cause = ex.__cause__
    # 	if isinstance(cause, FileNotFoundError):
    # 		print("{YELLOW}  FileNotFound:{NOCOLOR} '{cause}'".format(cause=str(cause), **Init.Foreground))
    # 	elif isinstance(cause, NotADirectoryError):
    # 		print("{YELLOW}  NotADirectory:{NOCOLOR} '{cause}'".format(cause=str(cause), **Init.Foreground))
    # 	elif isinstance(cause, ParserException):
    # 		print("{YELLOW}  ParserException:{NOCOLOR} {cause}".format(cause=str(cause), **Init.Foreground))
    # 		cause = cause.__cause__
    # 		if (cause is not None):
    # 			print("{YELLOW}    {name}:{NOCOLOR} {cause}".format(name=cause.__class__.__name__, cause= str(cause), **Init.Foreground))
    #
    # 	if (not (verbose or debug)):
    # 		print()
    # 		print("{CYAN}  Use '-v' for verbose or '-d' for debug to print out extended messages.{NOCOLOR}".format(**Init.Foreground))
    # 	LineTerminal.exit(1)

    except ExceptionBase as ex:
        LineTerminal.printExceptionBase(ex)
    except NotImplementedError as ex:
        LineTerminal.printNotImplementedError(ex)
        #except ImportError as ex:                   printImportError(ex)
    except Exception as ex:
        LineTerminal.printException(ex)
예제 #8
0
 def __str__(self):
     return "{GREEN}{0}{NOCOLOR} : {YELLOW}{1}{NOCOLOR}".format(
         self._name, self._subType,
         **LineTerminal().Foreground)
예제 #9
0
	def AddConstant(self, constant):
		if DEBUG: print("{DARK_CYAN}Adding constant to function {GREEN}{0}{NOCOLOR}:\n  {1!s}".format(self._name, constant, **LineTerminal().Foreground))
		self._declaredItems.append(constant)
예제 #10
0
	def AddGeneric(self, generic):
		if DEBUG: print("{DARK_CYAN}Adding generic to function {GREEN}{0}{NOCOLOR}:\n  {YELLOW}{1}{NOCOLOR} : {2}".format(self._name, generic, "", **LineTerminal().Foreground))
		self._genericItems.append(generic)
예제 #11
0
	def AddUses(self, uses: List[PackageReference]):
		if ((DEBUG is True) and (len(uses) > 0)): print("{DARK_CYAN}Adding uses to function {GREEN}{0}{NOCOLOR}:".format(self._name, **LineTerminal().Foreground))
		for use in uses:
			if DEBUG: print("  {GREEN}{0!s}{NOCOLOR}".format(use, **LineTerminal().Foreground))
			self._uses.append(use)
예제 #12
0
	def AddLibraries(self, libraries: List[LibraryClause]):
		if ((DEBUG is True) and (len(libraries) > 0)): print("{DARK_CYAN}Adding libraries to function {GREEN}{0}{NOCOLOR}:".format(self._name, **LineTerminal().Foreground))
		for library in libraries:
			if DEBUG: print("  {GREEN}{0!s}{NOCOLOR}".format(library, **LineTerminal().Foreground))
			self._libraries.append(library._library)
예제 #13
0
 def PushState(self, value):
     self._stack.append((self.NextState, self.Counter))
     LineTerminal().WriteDebug("  pushed: " + str(self.NextState))
     self.NextState = value
     self._tokenMarker = None
예제 #14
0
def main():  # mccabe:disable=MC0001
    """This is the entry point for pyghdl.cli.dom written as a function.

    1. It extracts common flags from the script's arguments list, before :py:class:`~argparse.ArgumentParser` is fully loaded.
    2. It creates an instance of DOM test application and hands over to a class based execution.
       All is wrapped in a big ``try..except`` block to catch every unhandled exception.
    3. Shutdown the script and return its exit code.
    """
    from sys import argv as sys_argv

    debug = "-d" in sys_argv
    verbose = "-v" in sys_argv
    quiet = "-q" in sys_argv

    try:
        # handover to a class instance
        app = Application(debug, verbose, quiet)
        app.Run()
        app.exit()
    except PrettyPrintException as ex:
        print("PP: {!s}".format(ex))
        LineTerminal.exit()

    except DOMException as ex:
        print("DOM: {!s}".format(ex))
        ex2: LibGHDLException = ex.__cause__
        if ex2 is not None:
            for message in ex2.InternalErrors:
                print("libghdl: {message}".format(message=message))
            LineTerminal.exit(0)

        LineTerminal.exit(6)

    except LibGHDLException as ex:
        print("LIB: {!s}".format(ex))
        for message in ex.InternalErrors:
            print("  {message}".format(message=message))
        LineTerminal.exit(5)

    except GHDLBaseException as ex:
        LineTerminal.printExceptionBase(ex)

    except NotImplementedError as ex:
        LineTerminal.printNotImplementedError(ex)

    # except ImportError as ex:
    #     printImportError(ex)
    except Exception as ex:
        LineTerminal.printException(ex)
예제 #15
0
        ex2: LibGHDLException = ex.__cause__
        if ex2 is not None:
            for message in ex2.InternalErrors:
                print("libghdl: {message}".format(message=message))
            LineTerminal.exit(0)

        LineTerminal.exit(6)

    except LibGHDLException as ex:
        print("LIB: {!s}".format(ex))
        for message in ex.InternalErrors:
            print("  {message}".format(message=message))
        LineTerminal.exit(5)

    except GHDLBaseException as ex:
        LineTerminal.printExceptionBase(ex)

    except NotImplementedError as ex:
        LineTerminal.printNotImplementedError(ex)

    # except ImportError as ex:
    #     printImportError(ex)
    except Exception as ex:
        LineTerminal.printException(ex)


# entry point
if __name__ == "__main__":
    LineTerminal.versionCheck((3, 6, 0))
    main()