示例#1
0
    def x_get_entity_interface(self, library, name):
        def create_interfaces(inters):
            res = []
            while inters != nodes.Null_Iir:
                res.append({
                    "name":
                    name_table.Get_Name_Ptr(
                        nodes.Get_Identifier(inters)).decode("latin-1")
                })
                inters = nodes.Get_Chain(inters)
            return res

        # Find library
        lib_id = name_table.Get_Identifier(library.encode("utf-8"))
        lib = libraries.Get_Library_No_Create(lib_id)
        if lib == name_table.Null_Identifier:
            return None
        # Find entity
        ent_id = name_table.Get_Identifier(name.encode("utf-8"))
        unit = libraries.Find_Primary_Unit(lib, ent_id)
        if unit == nodes.Null_Iir:
            return None
        ent = nodes.Get_Library_Unit(unit)
        return {
            "library": library,
            "entity": name,
            "generics": create_interfaces(nodes.Get_Generic_Chain(ent)),
            "ports": create_interfaces(nodes.Get_Port_Chain(ent)),
        }
示例#2
0
 def load(source, dirname, filename):
     # Write text to file buffer.
     src_bytes = source.encode(Document.encoding, "replace")
     src_len = len(src_bytes)
     buf_len = src_len + Document.initial_gap_size
     fileid = name_table.Get_Identifier(filename.encode("utf-8"))
     if os.path.isabs(filename):
         dirid = name_table.Null_Identifier
     else:
         dirid = name_table.Get_Identifier(dirname.encode("utf-8"))
     sfe = files_map.Reserve_Source_File(dirid, fileid, buf_len)
     files_map_editor.Fill_Text(sfe, ctypes.c_char_p(src_bytes), src_len)
     return sfe
示例#3
0
	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)
示例#4
0
    def __loadFromString(self, sourceCode: str):
        sourcesBytes = sourceCode.encode("utf-8")
        sourceLength = len(sourcesBytes)
        bufferLength = sourceLength + 128
        self.__ghdlFileID = name_table.Get_Identifier(str(self._filename))
        dirId = name_table.Null_Identifier
        self.__ghdlSourceFileEntry = files_map.Reserve_Source_File(
            dirId, self.__ghdlFileID, bufferLength)
        files_map_editor.Fill_Text(self.__ghdlSourceFileEntry,
                                   ctypes.c_char_p(sourcesBytes), sourceLength)

        CheckForErrors()
示例#5
0
    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)