def concurrent_stmts_iter(n): """Iterator on concurrent statements in n.""" k = iirs.Get_Kind(n) if k == iirs.Iir_Kind.Design_File: for n1 in chain_iter(iirs.Get_First_Design_Unit(n)): for n2 in concurrent_stmts_iter(n1): yield n2 elif k == iirs.Iir_Kind.Design_Unit: for n1 in concurrent_stmts_iter(iirs.Get_Library_Unit(n)): yield n1 elif k == iirs.Iir_Kind.Entity_Declaration \ or k == iirs.Iir_Kind.Architecture_Body \ or k == iirs.Iir_Kind.Block_Statement: for n1 in chain_iter(iirs.Get_Concurrent_Statement_Chain(n)): yield n1 for n2 in concurrent_stmts_iter(n1): yield n2 elif k == iirs.Iir_Kind.For_Generate_Statement: for n1 in concurrent_stmts_iter(iirs.Get_Generate_Statement_Body(n)): yield n1 elif k == iirs.Iir_Kind.If_Generate_Statement: while n != Null_Iir: for n1 in concurrent_stmts_iter( iirs.Get_Generate_Statement_Body(n)): yield n1 n = iirs.Get_Generate_Else_Clause(n) elif k == iirs.Iir_Kind.Case_Generate_Statement: alt = iirs.Get_Case_Statement_Alternative_Chain(n) for n1 in chain_iter(alt): blk = iirs.Get_Associated_Block(n1) if blk != Null_Iir: for n2 in concurrent_stmts_iter( iirs.Get_Generate_Statement_Body(n)): yield n2
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))
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 = iirs.Get_Kind(n) if k in [ iirs.Iir_Kind.Process_Statement, iirs.Iir_Kind.Sensitized_Process_Statement, iirs.Iir_Kind.Function_Body, iirs.Iir_Kind.Procedure_Body ]: for n1 in chain_iter(iirs.Get_Sequential_Statement_Chain(n)): yield n1 for n2 in sequential_iter(n1): yield n2 elif k == iirs.Iir_Kind.If_Statement: while True: n = iirs.Get_Chain(n) if n == thin.Null_Iir: break yield n for n1 in sequential_iter(n): yield n1 elif k == iirs.Iir_Kind.Case_Statement: for ch in chain_iter(iirs.Get_Case_Statement_Alternative_Chain(n)): stmt = iirs.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 [ iirs.Iir_Kind.For_Loop_Statement, iirs.Iir_Kind.While_Loop_Statement ]: for n1 in chain_iter(iirs.Get_Sequential_Statement_Chain(n)): yield n1 for n2 in sequential_iter(n1): yield n2 elif k in [ iirs.Iir_Kind.Assertion_Statement, iirs.Iir_Kind.Wait_Statement, iirs.Iir_Kind.Null_Statement, iirs.Iir_Kind.Exit_Statement, iirs.Iir_Kind.Next_Statement, iirs.Iir_Kind.Return_Statement, iirs.Iir_Kind.Variable_Assignment_Statement, iirs.Iir_Kind.Simple_Signal_Assignment_Statement, iirs.Iir_Kind.Procedure_Call_Statement ]: return else: assert False, "unknown node of kind {}".format(kind_image(k))
def constructs_iter(n): """Iterator on library unit, concurrent statements and declarations that appear directly within a declarative part.""" if n == thin.Null_Iir: return k = iirs.Get_Kind(n) if k == iirs.Iir_Kind.Design_File: for n1 in chain_iter(iirs.Get_First_Design_Unit(n)): for n2 in constructs_iter(n1): yield n2 elif k == iirs.Iir_Kind.Design_Unit: n1 = iirs.Get_Library_Unit(n) yield n1 for n2 in constructs_iter(n1): yield n2 elif k in [ iirs.Iir_Kind.Entity_Declaration, iirs.Iir_Kind.Architecture_Body, iirs.Iir_Kind.Block_Statement, iirs.Iir_Kind.Generate_Statement_Body ]: for n1 in chain_iter(iirs.Get_Declaration_Chain(n)): yield n1 for n2 in constructs_iter(n1): yield n2 for n1 in chain_iter(iirs.Get_Concurrent_Statement_Chain(n)): yield n1 for n2 in constructs_iter(n1): yield n2 elif k in [ iirs.Iir_Kind.Configuration_Declaration, iirs.Iir_Kind.Package_Declaration, iirs.Iir_Kind.Package_Body, iirs.Iir_Kind.Function_Body, iirs.Iir_Kind.Procedure_Body, iirs.Iir_Kind.Protected_Type_Declaration, iirs.Iir_Kind.Protected_Type_Body, iirs.Iir_Kind.Process_Statement, iirs.Iir_Kind.Sensitized_Process_Statement ]: for n1 in chain_iter(iirs.Get_Declaration_Chain(n)): yield n1 for n2 in constructs_iter(n1): yield n2 elif k == iirs.Iir_Kind.For_Generate_Statement: n1 = iirs.Get_Generate_Statement_Body(n) yield n1 for n2 in constructs_iter(n1): yield n2 elif k == iirs.Iir_Kind.If_Generate_Statement: while n != Null_Iir: n1 = iirs.Get_Generate_Statement_Body(n) yield n1 for n2 in constructs_iter(n1): yield n2 n = iirs.Get_Generate_Else_Clause(n) elif k == iirs.Iir_Kind.Case_Generate_Statement: alt = iirs.Get_Case_Statement_Alternative_Chain(n) for n1 in chain_iter(alt): blk = iirs.Get_Associated_Block(n1) if blk != Null_Iir: n2 = iirs.Get_Generate_Statement_Body(blk) yield n2 for n3 in constructs_iter(n2): yield n3