Example #1
0
 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
 def x_get_all_entities(self):
     res = []
     lib = libraries.Get_Libraries_Chain()
     while lib != nodes.Null_Iir:
         files = nodes.Get_Design_File_Chain(lib)
         ents = []
         while files != nodes.Null_Iir:
             units = nodes.Get_First_Design_Unit(files)
             while units != nodes.Null_Iir:
                 unitlib = nodes.Get_Library_Unit(units)
                 if nodes.Get_Kind(unitlib) == nodes.Iir_Kind.Entity_Declaration:
                     ents.append(unitlib)
                 units = nodes.Get_Chain(units)
             files = nodes.Get_Chain(files)
         ents = [pyutils.name_image(nodes.Get_Identifier(e)) for e in ents]
         lib_name = pyutils.name_image(nodes.Get_Identifier(lib))
         res.extend([{'name': n, 'library': lib_name} for n in ents])
         lib = nodes.Get_Chain(lib)
     return res
Example #3
0
def sequential_iter(n):
    """Iterator on sequential statements.  The first node must be either
    a process or a subprogram body."""
    if n == thin.Null_Iir:
        return
    k = nodes.Get_Kind(n)
    if k in [
            nodes.Iir_Kind.Process_Statement,
            nodes.Iir_Kind.Sensitized_Process_Statement,
            nodes.Iir_Kind.Function_Body,
            nodes.Iir_Kind.Procedure_Body,
    ]:
        for n1 in chain_iter(nodes.Get_Sequential_Statement_Chain(n)):
            yield n1
            for n2 in sequential_iter(n1):
                yield n2
    elif k == nodes.Iir_Kind.If_Statement:
        while True:
            n = nodes.Get_Chain(n)
            if n == thin.Null_Iir:
                break
            yield n
            for n1 in sequential_iter(n):
                yield n1
    elif k == nodes.Iir_Kind.Case_Statement:
        for ch in chain_iter(nodes.Get_Case_Statement_Alternative_Chain(n)):
            stmt = nodes.Get_Associated_Chain(ch)
            if stmt != thin.Null_Iir:
                for n1 in chain_iter(stmt):
                    yield n1
                    for n2 in sequential_iter(n1):
                        yield n2
    elif k in [
            nodes.Iir_Kind.For_Loop_Statement,
            nodes.Iir_Kind.While_Loop_Statement
    ]:
        for n1 in chain_iter(nodes.Get_Sequential_Statement_Chain(n)):
            yield n1
            for n2 in sequential_iter(n1):
                yield n2
    elif k in [
            nodes.Iir_Kind.Assertion_Statement,
            nodes.Iir_Kind.Wait_Statement,
            nodes.Iir_Kind.Null_Statement,
            nodes.Iir_Kind.Exit_Statement,
            nodes.Iir_Kind.Next_Statement,
            nodes.Iir_Kind.Return_Statement,
            nodes.Iir_Kind.Variable_Assignment_Statement,
            nodes.Iir_Kind.Simple_Signal_Assignment_Statement,
            nodes.Iir_Kind.Procedure_Call_Statement,
    ]:
        return
    else:
        assert False, "unknown node of kind {}".format(kind_image(k))
Example #4
0
 def compute_diags(self):
     log.debug("parse doc %d %s", self._fe, self.uri)
     self.parse_document()
     if self._tree == nodes.Null_Iir:
         # No units, nothing to add.
         return
     # Semantic analysis.
     unit = nodes.Get_First_Design_Unit(self._tree)
     while unit != nodes.Null_Iir:
         sem.Semantic(unit)
         nodes.Set_Date_State(unit, nodes.Date_State.Analyze)
         unit = nodes.Get_Chain(unit)
Example #5
0
 def compute_diags(self):
     log.debug("parse doc %d %s", self._fe, self.uri)
     tree = Document.parse_document(self._fe)
     assert self._tree == nodes.Null_Iir
     self._tree = Document.add_to_library(tree)
     if self._tree == nodes.Null_Iir:
         # No units, nothing to add.
         return
     nodes.Set_Design_File_Source(self._tree, self._fe)
     log.debug("add_to_library(%u) -> %u", tree, self._tree)
     # Semantic analysis.
     unit = nodes.Get_First_Design_Unit(self._tree)
     while unit != nodes.Null_Iir:
         sem.Semantic(unit)
         nodes.Set_Date_State(unit, nodes.Date_State.Analyze)
         unit = nodes.Get_Chain(unit)
Example #6
0
 def obsolete_doc(self, doc):
     if doc._tree == nodes.Null_Iir:
         return
     # Free old tree
     assert nodes.Get_Kind(doc._tree) == nodes.Iir_Kind.Design_File
     if self._last_linted_doc == doc:
         antideps = None
     else:
         antideps = self.compute_anti_dependences()
     unit = nodes.Get_First_Design_Unit(doc._tree)
     while unit != nodes.Null_Iir:
         if antideps is not None:
             self.obsolete_dependent_units(unit, antideps)
         # FIXME: free unit; it is not referenced.
         unit = nodes.Get_Chain(unit)
     libraries.Purge_Design_File(doc._tree)
     doc._tree = nodes.Null_Iir
Example #7
0
 def add_to_library(tree):
     # Detach the chain of units.
     unit = nodes.Get_First_Design_Unit(tree)
     nodes.Set_First_Design_Unit(tree, nodes.Null_Iir)
     # FIXME: free the design file ?
     tree = nodes.Null_Iir
     # Analyze unit after unit.
     while unit != nodes.Null_Iir:
         # Pop the first unit.
         next_unit = nodes.Get_Chain(unit)
         nodes.Set_Chain(unit, nodes.Null_Iir)
         lib_unit = nodes.Get_Library_Unit(unit)
         if (lib_unit != nodes.Null_Iir and
                 nodes.Get_Identifier(unit) != name_table.Null_Identifier):
             # Put the unit (only if it has a library unit) in the library.
             libraries.Add_Design_Unit_Into_Library(unit, False)
             tree = nodes.Get_Design_File(unit)
         unit = next_unit
     return tree
Example #8
0
 def lint(self, doc_uri):
     doc = self.get_document(doc_uri)
     if doc._tree != nodes.Null_Iir:
         # Free old tree
         assert nodes.Get_Kind(doc._tree) == nodes.Iir_Kind.Design_File
         if self._last_linted_doc == doc:
             antideps = None
         else:
             antideps = self.compute_anti_dependences()
         unit = nodes.Get_First_Design_Unit(doc._tree)
         while unit != nodes.Null_Iir:
             if antideps is not None:
                 self.obsolete_dependent_units(unit, antideps)
             # FIXME: free unit; it is not referenced.
             unit = nodes.Get_Chain(unit)
         libraries.Purge_Design_File(doc._tree)
         doc._tree = nodes.Null_Iir
     doc.compute_diags()
     self.gather_diagnostics(doc)
Example #9
0
def nodes_iter(n):
    """Iterate of all nodes of n, including n.
    Nodes are returned only once."""
    if n == nodes.Null_Iir:
        return


#    print 'nodes_iter for {0}'.format(n)
    yield n
    for f in fields_iter(n):
        typ = nodes_meta.get_field_type(f)
        #        print ' {0}: field {1} (type: {2})'.format(
        #            n, fields_image(f), types_image(typ))
        if typ == nodes_meta.types.Iir:
            attr = nodes_meta.get_field_attribute(f)
            if attr == Attr.ANone:
                for n1 in nodes_iter(nodes_meta.Get_Iir(n, f)):
                    yield n1
            elif attr == Attr.Chain:
                n2 = nodes_meta.Get_Iir(n, f)
                while n2 != nodes.Null_Iir:
                    for n1 in nodes_iter(n2):
                        yield n1
                    n2 = nodes.Get_Chain(n2)
            elif attr == Attr.Maybe_Ref:
                if not nodes.Get_Is_Ref(n, f):
                    for n1 in nodes_iter(nodes_meta.Get_Iir(n, f)):
                        yield n1
        elif typ == types.Iir_List:
            attr = nodes_meta.get_field_attribute(f)
            if attr == Attr.ANone:
                for n1 in list_iter(nodes_meta.Get_Iir_List(n, f)):
                    for n2 in nodes_iter(n1):
                        yield n2
        elif typ == types.Iir_Flist:
            attr = nodes_meta.get_field_attribute(f)
            if attr == Attr.ANone:
                for n1 in flist_iter(nodes_meta.Get_Iir_Flist(n, f)):
                    for n2 in nodes_iter(n1):
                        yield n2
Example #10
0
def list_units(filename):
    # Load the file
    file_id = name_table.Get_Identifier(filename.encode('utf_8'))
    sfe = files_map.Read_Source_File(name_table.Null_Identifier, file_id)
    if sfe == files_map.No_Source_File_Entry:
        print("cannot open file '{}'".format(filename))
        return

    # Parse and analyze
    file = sem_lib.Load_File(sfe)

    # Display all design units
    unit = nodes.Get_First_Design_Unit(file)
    while unit != nodes.Null_Iir:
        lib_unit = nodes.Get_Library_Unit(unit)
        if nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Entity_Declaration:
            print('entity {}'.format(get_identifier_ptr(lib_unit)))
        elif nodes.Get_Kind(lib_unit) == nodes.Iir_Kind.Architecture_Body:
            print('architecture {}'.format(get_identifier_ptr(lib_unit)))
        else:
            print('unknown unit!')
        unit = nodes.Get_Chain(unit)
Example #11
0
def chain_iter(n):
    """Iterate of a chain headed by node n"""
    while n != nodes.Null_Iir:
        yield n
        n = nodes.Get_Chain(n)