def __init__( self, path: Path, sourceCode: str = None, dontParse: bool = False, dontTranslate: bool = False, ): super().__init__(path) self._filename = path if sourceCode is None: self.__loadFromPath() else: self.__loadFromString(sourceCode) if dontParse == False: # Parse input file t1 = time.perf_counter() self.__ghdlFile = sem_lib.Load_File(self.__ghdlSourceFileEntry) CheckForErrors() self.__ghdlProcessingTime = time.perf_counter() - t1 if dontTranslate == False: t1 = time.perf_counter() self.translate() self.__domTranslateTime = time.perf_counter() - t1
def __ghdl_init(self): # Read input file self.__ghdlFileID = name_table.Get_Identifier(str(self.Path)) self.__ghdlSourceFileEntry = files_map.Read_Source_File(name_table.Null_Identifier, self.__ghdlFileID) if self.__ghdlSourceFileEntry == files_map.No_Source_File_Entry: raise LibGHDLException("Cannot load file '{!s}'".format(self.Path)) # parse self.__ghdlFile = sem_lib.Load_File(self.__ghdlSourceFileEntry)
def parse_document(self): """Parse a document and put the units in the library""" assert self._tree == nodes.Null_Iir tree = sem_lib.Load_File(self._fe) if tree == nodes.Null_Iir: return self._tree = Document.add_to_library(tree) log.debug("add_to_library(%u) -> %u", tree, self._tree) if self._tree == nodes.Null_Iir: return nodes.Set_Design_File_Source(self._tree, self._fe)
def test_InitializeGHDL(self) -> None: """Initialization: set options and then load libaries.""" libghdl.initialize() # Print error messages on the console. errorout_console.Install_Handler() # Set options. This must be done before analyze_init() libghdl.set_option("--std=08") # Finish initialization. This will load the standard package. if libghdl.analyze_init_status() != 0: self.fail("libghdl initialization error") # Load the file file_id = name_table.Get_Identifier(str(self._filename)) sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id) if sfe == files_map.No_Source_File_Entry: self.fail("Cannot read file '{!s}'".format(self._filename)) # Parse file = sem_lib.Load_File(sfe) # Display all design units designUnit = nodes.Get_First_Design_Unit(file) while designUnit != nodes.Null_Iir: libraryUnit = nodes.Get_Library_Unit(designUnit) if nodes.Get_Kind( libraryUnit) == nodes.Iir_Kind.Entity_Declaration: entityName = self.getIdentifier(libraryUnit) self.assertEqual( entityName, "entity_1", "expected entity name 'e1', got '{}'".format(entityName), ) elif nodes.Get_Kind( libraryUnit) == nodes.Iir_Kind.Architecture_Body: architectureName = self.getIdentifier(libraryUnit) self.assertEqual( architectureName, "behav", "expected architecture name 'behav', got '{}'".format( architectureName), ) else: self.fail("Unknown unit.") designUnit = nodes.Get_Chain(designUnit)