def check(self, input, file):
     if self._allowed_id is None:
         self._allowed_id = [
             thin.Get_Identifier(n) for n in self._allowed_name
         ]
     for unit in thinutils.chain_iter(iirs.Get_First_Design_Unit(file)):
         for n in thinutils.chain_iter(iirs.Get_Context_Items(unit)):
             if iirs.Get_Kind(n) != iirs.Iir_Kind.Use_Clause:
                 continue
             cl = n
             while cl != thin.Null_Iir:
                 self.check_clause(cl)
                 cl = iirs.Get_Use_Clause_Chain(cl)
 def check(self, input, file):
     for unit in thinutils.chain_iter(iirs.Get_First_Design_Unit(file)):
         # Extract the list of clauses
         clauses = []
         for cl in thinutils.chain_iter(iirs.Get_Context_Items(unit)):
             k = iirs.Get_Kind(cl)
             if k == iirs.Iir_Kind.Library_Clause:
                 clauses.extend(self.extract_library(cl))
             elif k == iirs.Iir_Kind.Use_Clause:
                 clauses.extend(self.extract_use(cl))
             else:
                 assert False, "unknown context clause"
         if clauses:
             self.check_group(clauses)
Exemple #3
0
 def chk_sequential(self, head, level):
     nlevel = level + self._l
     for n in thinutils.chain_iter(head):
         k = iirs.Get_Kind(n)
         self.chk_level(n, iirs.Get_Location(n), level)
         if k == iirs.Iir_Kind.If_Statement:
             self.chk_if_stmt(n, level)
         elif (k == iirs.Iir_Kind.For_Loop_Statement
               or k == iirs.Iir_Kind.While_Loop_Statement):
             self.chk_line_or_col(
                 n, iirs.Get_Location(n), elocs.Get_Loop_Location(n))
             self.chk_sequential(
                 iirs.Get_Sequential_Statement_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_End_Location(n), level)
         elif k == iirs.Iir_Kind.Case_Statement:
             alts = iirs.Get_Case_Statement_Alternative_Chain(n)
             self.chk_case_alternatives(alts, nlevel)
         elif (k == iirs.Iir_Kind.Wait_Statement
               or k == iirs.Iir_Kind.Return_Statement
               or k == iirs.Iir_Kind.Assertion_Statement
               or k == iirs.Iir_Kind.Report_Statement
               or k == iirs.Iir_Kind.Procedure_Call_Statement
               or k == iirs.Iir_Kind.Null_Statement
               or k == iirs.Iir_Kind.Exit_Statement
               or k == iirs.Iir_Kind.Next_Statement):
             pass
         elif (k == iirs.Iir_Kind.Simple_Signal_Assignment_Statement
               or k == iirs.Iir_Kind.Variable_Assignment_Statement):
             pass
         else:
             assert False, "Indent: unhandled node {}".format(
                 thinutils.kind_image(k))
Exemple #4
0
 def check_assocs(self, n, inters, assocs):
     if assocs == thin.Null_Iir:
         # Also cover the case of no interfaces
         return
     inter = inters
     for assoc in thinutils.chain_iter(assocs):
         if iirs.Get_Kind(assoc) \
            == iirs.Iir_Kind.Association_Element_By_Individual:
             continue
         formal = iirs.Get_Formal(assoc)
         if formal == thin.Null_Iir:
             self.error(
                 Location.from_node(assoc),
                 "association by position for {}".format(
                     nodeutils.get_identifier_str(inter)))
             # Should the tool report all errors ?
             return
         assoc_inter = thin.Iirs_Utils.Get_Interface_Of_Formal(formal)
         while assoc_inter != inter:
             if inter == thin.Null_Iir:
                 self.error(
                     Location.from_node(assoc),
                     "incorrect association order for {}".format(
                         nodeutils.get_identifier_str(assoc_inter)))
                 return
             inter = iirs.Get_Chain(inter)
         if iirs.Get_Whole_Association_Flag(assoc):
             inter = iirs.Get_Chain(inter)
Exemple #5
0
 def chk_context_clauses(self, parent, level):
     for n in thinutils.chain_iter(iirs.Get_Context_Items(parent)):
         k = iirs.Get_Kind(n)
         if k == iirs.Iir_Kind.Library_Clause:
             self.chk_level(n, elocs.Get_Start_Location(n), level)
             # Check: same line for next clauses
         elif k == iirs.Iir_Kind.Use_Clause:
             self.chk_level(n, iirs.Get_Location(n), level)
             # Check: same line for next clauses
         else:
             assert False, "unhandled context clause"
 def check_entity(self, ent):
     decl = iirs.Get_Declaration_Chain(ent)
     if decl != thin.Null_Iir:
         self.error(Location.from_node(decl),
                    "declaration not allowed in entity")
     first_stmt = iirs.Get_Concurrent_Statement_Chain(ent)
     for s in thinutils.chain_iter(first_stmt):
         k = iirs.Get_Kind(s)
         if k != iirs.Iir_Kind.Concurrent_Assertion_Statement:
             self.error(Location.from_node(s),
                        "concurrent statement not allowed in entity")
 def gather_identifiers(self, pkg):
     res = set()
     for d in thinutils.chain_iter(iirs.Get_Declaration_Chain(pkg)):
         k = iirs.Get_Kind(d)
         if d in iirs.Iir_Kinds.Specification:
             continue
         self.add_identifier(res, d)
         if k in [
                 iirs.Iir_Kind.Type_Declaration,
                 iirs.Iir_Kind.Anonymous_Type_Declaration
         ]:
             typ = iirs.Get_Type_Definition(d)
             k = iirs.Get_Kind(typ)
             if k == iirs.Iir_Kind.Enumeration_Type_Definition:
                 for lit in thinutils.list_iter(
                         iirs.Get_Enumeration_Literal_List(typ)):
                     self.add_identifier(res, lit)
             elif k == iirs.Iir_Kind.Physical_Type_Definition:
                 for un in thinutils.chain_iter(iirs.Get_Unit_Chain(typ)):
                     self.add_identifier(res, un)
     return res
Exemple #8
0
 def check(self, input, ast):
     if 'top' not in input.props:
         return
     unit = iirs.Get_Library_Unit(ast)
     if iirs.Get_Kind(unit) != iirs.Iir_Kind.Entity_Declaration:
         return
     for port in thinutils.chain_iter(iirs.Get_Port_Chain(unit)):
         if not self.check_type(iirs.Get_Type(port)):
             self.error(
                 Location.from_node(port),
                 "type of port '{0}' must be std_logic/_vector".format(
                     nodeutils.get_identifier_str(port)))
 def check(self, input, ast):
     for du in thinutils.chain_iter(iirs.Get_First_Design_Unit(ast)):
         ent = iirs.Get_Library_Unit(du)
         if iirs.Get_Kind(ent) != iirs.Iir_Kind.Entity_Declaration:
             continue
         gen = iirs.Get_Generic_Chain(ent)
         if gen != thin.Null_Iir:
             self.check_declarations(gen)
         ports = iirs.Get_Port_Chain(ent)
         if ports != thin.Null_Iir:
             self.check_declarations(ports)
             port = ports
             while port != thin.Null_Iir:
                 if not iirs.Get_Has_Mode(port):
                     self.error(Location.from_node(port),
                                "in/out/inout required for port")
                 port = iirs.Get_Chain(port)
Exemple #10
0
def extract_packages_from_context_clause(dsgn):
    """Return a list of package declarations from design unit dsgn (which must
    have been analyzed)."""
    res = []
    for n in thinutils.chain_iter(iirs.Get_Context_Items(dsgn)):
        if iirs.Get_Kind(n) != iirs.Iir_Kind.Use_Clause:
            continue
        cl = n
        while cl != thin.Null_Iir:
            name = iirs.Get_Selected_Name(cl)
            if iirs.Get_Kind(name) == iirs.Iir_Kind.Selected_By_All_Name:
                name = iirs.Get_Prefix(name)
            name = iirs.Get_Named_Entity(name)
            assert name != thin.Null_Iir, "unit not analyzed"
            if iirs.Get_Kind(name) == iirs.Iir_Kind.Package_Declaration:
                res.append(name)
            cl = iirs.Get_Use_Clause_Chain(cl)
    return res
Exemple #11
0
 def __init__(self, ruleexec, comment, rule, files):
     super(TestRun, self).__init__(quiet=ruleexec._quiet)
     print('  test: {0}'.format(comment))
     if isinstance(files, str):
         files = [files]
     basedir = os.path.join(os.path.dirname(__file__), 'testfiles')
     files = map(
         lambda f: f
         if f.startswith('--') else os.path.join(basedir, f), files)
     # Be sure the work library is empty.  This is brut force.
     work = thin.Work_Library.value
     if work != thin.Null_Iir:
         for f in thinutils.chain_iter(iirs.Get_Design_File_Chain(work)):
             thin.Purge_Design_File(f)
         iirs.Set_Design_File_Chain(work, thin.Null_Iir)
     self.add(rule)
     self.execute(files)
     if not self.is_ok():
         ruleexec._nbr_errors += 1
         sys.stderr.write("ERROR: {0}: test failed\n".format(rule.rulename))
Exemple #12
0
 def chk_concurrent(self, head, level):
     nlevel = level + self._l
     for n in thinutils.chain_iter(head):
         self.chk_level(n, iirs.Get_Location(n), level)
         k = iirs.Get_Kind(n)
         if k == iirs.Iir_Kind.Component_Instantiation_Statement:
             # TODO
             pass
         elif (k == iirs.Iir_Kind.Concurrent_Assertion_Statement
               or k == iirs.Iir_Kind.Concurrent_Simple_Signal_Assignment
               or k ==
                 iirs.Iir_Kind.Concurrent_Conditional_Signal_Assignment
               or k == iirs.Iir_Kind.Concurrent_Selected_Signal_Assignment):
             pass
         elif k == iirs.Iir_Kind.Concurrent_Procedure_Call_Statement:
             pass
         elif k == iirs.Iir_Kind.Block_Statement:
             self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_Begin_Location(n), level)
             self.chk_concurrent(
                 iirs.Get_Concurrent_Statement_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_End_Location(n), level)
         elif k == iirs.Iir_Kind.For_Generate_Statement:
             self.chk_line_or_col(
                 n, iirs.Get_Location(n), elocs.Get_Generate_Location(n))
             self.chk_generate_body(
                 iirs.Get_Generate_Statement_Body(n), level)
             self.chk_level(n, elocs.Get_End_Location(n), level)
         elif k == iirs.Iir_Kind.If_Generate_Statement:
             self.chk_line_or_col(
                 n, iirs.Get_Location(n), elocs.Get_Generate_Location(n))
             self.chk_generate_body(
                 iirs.Get_Generate_Statement_Body(n), level)
             self.chk_level(n, elocs.Get_End_Location(n), level)
         elif (k == iirs.Iir_Kind.Sensitized_Process_Statement
               or k == iirs.Iir_Kind.Process_Statement):
             self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_Begin_Location(n), level)
             self.chk_sequential(
                 iirs.Get_Sequential_Statement_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_End_Location(n), level)
Exemple #13
0
 def chk_declarations(self, head, level):
     nlevel = level + self._l
     for n in thinutils.chain_iter(head):
         k = iirs.Get_Kind(n)
         if k == iirs.Iir_Kind.Constant_Declaration \
            or k == iirs.Iir_Kind.Signal_Declaration \
            or k == iirs.Iir_Kind.Variable_Declaration \
            or k == iirs.Iir_Kind.File_Declaration \
            or k == iirs.Iir_Kind.Object_Alias_Declaration \
            or k == iirs.Iir_Kind.Attribute_Declaration \
            or k == iirs.Iir_Kind.Attribute_Specification:
             self.chk_level(n, elocs.Get_Start_Location(n), level)
         elif (k == iirs.Iir_Kind.Configuration_Specification
               or k == iirs.Iir_Kind.Disconnection_Specification):
             self.chk_level(n, iirs.Get_Location(n), level)
         elif (k == iirs.Iir_Kind.Subtype_Declaration
               or k == iirs.Iir_Kind.Type_Declaration
               or k == iirs.Iir_Kind.Anonymous_Type_Declaration):
             self.chk_level(n, elocs.Get_Start_Location(n), level)
         elif k == iirs.Iir_Kind.Component_Declaration:
             self.chk_level(n, elocs.Get_Start_Location(n), level)
             self.chk_level(n, elocs.Get_Generic_Location(n), nlevel)
             self.chk_level(n, elocs.Get_Port_Location(n), nlevel)
             self.chk_level(n, elocs.Get_End_Location(n), level)
         elif (k == iirs.Iir_Kind.Function_Declaration
               or k == iirs.Iir_Kind.Procedure_Declaration):
             self.chk_level(n, elocs.Get_Start_Location(n), level)
         elif (k == iirs.Iir_Kind.Function_Body
               or k == iirs.Iir_Kind.Procedure_Body):
             self.chk_declarations(iirs.Get_Declaration_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_Begin_Location(n), level)
             self.chk_sequential(
                 iirs.Get_Sequential_Statement_Chain(n), nlevel)
             self.chk_level(n, elocs.Get_End_Location(n), level)
             # check start
         elif k == iirs.Iir_Kind.Use_Clause:
             self.chk_level(n, iirs.Get_Location(n), level)
         else:
             assert False, "unhandled declaration {}".format(
                 thinutils.kind_image(k))
 def check(self, input, ast):
     # Build the list of use'd packages.
     pkgs = []
     for n in thinutils.chain_iter(iirs.Get_Context_Items(ast)):
         if iirs.Get_Kind(n) != iirs.Iir_Kind.Use_Clause:
             continue
         cl = n
         while cl != thin.Null_Iir:
             name = iirs.Get_Selected_Name(cl)
             if iirs.Get_Kind(name) == iirs.Iir_Kind.Selected_By_All_Name:
                 name = iirs.Get_Prefix(name)
             p = iirs.Get_Named_Entity(name)
             if iirs.Get_Kind(p) == iirs.Iir_Kind.Package_Declaration:
                 pkgs.append(p)
             cl = iirs.Get_Use_Clause_Chain(cl)
     # Check dependences
     for du in thinutils.list_iter(iirs.Get_Dependence_List(ast)):
         lu = iirs.Get_Library_Unit(du)
         if iirs.Get_Kind(lu) == iirs.Iir_Kind.Package_Declaration:
             if lu != thin.Standard_Package.value and lu not in pkgs:
                 self.error(
                     Location.from_node(ast),
                     "unit depends on '{}' but not by a use clause".format(
                         nodeutils.get_identifier_str(lu)))
Exemple #15
0
 def check(self, input, ast):
     assert iirs.Get_Kind(ast) == iirs.Iir_Kind.Design_File
     for u in thinutils.chain_iter(iirs.Get_First_Design_Unit(ast)):
         self.chk_context_clauses(u, 1)
         lib_unit = iirs.Get_Library_Unit(u)
         self.chk_library_unit(lib_unit, 1)
 def check(self, input, ast):
     assert iirs.Get_Kind(ast) == iirs.Iir_Kind.Design_File
     for u in thinutils.chain_iter(iirs.Get_First_Design_Unit(ast)):
         lu = iirs.Get_Library_Unit(u)
         if iirs.Get_Kind(lu) == iirs.Iir_Kind.Entity_Declaration:
             self.check_entity(lu)