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)
def __ghdl_init(self): """Initialization: set options and then load libraries""" # Initialize libghdl libghdl.finalize() libghdl.initialize() # Collect error messages in memory errorout_memory.Install_Handler() libghdl.set_option(b"--std=08") # Finish initialization. This will load the standard package. if libghdl.analyze_init_status() != 0: raise LibGHDLException("Error initializing 'libghdl'.")
def set_options_from_project(self): try: if self._prj is None: return if not isinstance(self._prj, dict): raise ProjectError("project file is not a dictionnary") opts = self._prj.get("options", None) if opts is None: return if not isinstance(opts, dict): raise ProjectError("'options' is not a dictionnary") ghdl_opts = opts.get("ghdl_analysis", None) if ghdl_opts is None: return log.info("Using options: %s", ghdl_opts) for opt in ghdl_opts: if not libghdl.set_option(opt.encode("utf-8")): self._server.show_message( lsp.MessageType.Error, "error with option: {}".format(opt)) except ProjectError as e: self._server.show_message( lsp.MessageType.Error, "error in project file: {}".format(e.msg))