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 main(): """Entrypoint of GHDL's Language Protocol Server.""" logger = getLogger(__loggerName) parser = _generateCLIParser() args = parser.parse_args() if args.disp_config: errorout_console.Install_Handler() libghdl.disp_config() print("python:") print("sys.platform: {}, os.name: {}".format(sys.platform, os.name)) print(sys.version) return # Setup logging if args.verbose >= 2: loglevel = DEBUG elif args.verbose >= 1: loglevel = INFO else: loglevel = ERROR if args.log_file: __rotate_log_files(args.log_file, 5) logstream = open(args.log_file, "w") else: logstream = sys_stderr basicConfig( format="%(asctime)-15s [%(levelname)s] %(message)s", stream=logstream, level=loglevel, ) if args.verbose != 0: sys_stderr.write("Args: {}\n".format(sys_argv)) sys_stderr.write("Current directory: {}\n".format(os_getcwd())) logger.info("Args: %s", sys_argv) logger.info("Current directory is %s", os_getcwd()) # Connection instream = sys_stdin.buffer if args.input is not None: instream = open(args.input, "rb") conn = LSPConn(instream, sys_stdout.buffer) trace_file = args.trace_file if trace_file is None: trace_file = os_environ.get("GHDL_LS_TRACE") if trace_file is not None: if args.input is None: __rotate_log_files(trace_file + ".in", 5) __rotate_log_files(trace_file + ".out", 5) conn = LSPConnTrace(trace_file, conn) else: logger.info("Traces disabled when -i/--input") handler = VhdlLanguageServer() try: server = LanguageProtocolServer(handler, conn) server.run() except Exception: logger.exception("Uncaught error") sys_exit(1)