private void BuildNextFunction() { foreach (CFGNode node in ListOfCfgNodes) { if (node is CFGNodeStatement) { CFGNodeStatement stmt = (CFGNodeStatement)node; CFGNode NextNode = null; CommonAST ASTwalker = stmt.GetAST(); ASTParentByASTNode.TryGetValue(ASTwalker, out ASTwalker); bool done = false; while (!done && ASTwalker != null) { #region STMT or LSTMT if (ASTwalker.Type == BoolParserTokenTypes.LITERAL_while) { done = true; ASTParentByASTNode.TryGetValue(ASTwalker, out ASTwalker); if (AstToCfgMapping.TryGetValue(ASTwalker, out NextNode)) { stmt.Next = NextNode; } else { stmt.Next = null; } } else if ((ASTwalker.Type == BoolParserTokenTypes.STMT || ASTwalker.Type == BoolParserTokenTypes.LSTMT) && (ASTwalker.getNextSibling() != null)) { CommonAST ASTwalkerSibling = (CommonAST)ASTwalker.getNextSibling(); if (ASTwalkerSibling.Type == BoolParserTokenTypes.STMT || ASTwalkerSibling.Type == BoolParserTokenTypes.LSTMT) { done = true; if (AstToCfgMapping.TryGetValue(ASTwalkerSibling, out NextNode)) { stmt.Next = NextNode; } else { stmt.Next = null; } } } #endregion #region PROC if (ASTwalker.Type == BoolParserTokenTypes.PROC) { done = true; if (AstToCfgMapping.TryGetValue(ASTwalker, out NextNode)) { stmt.Next = NextNode; } else { stmt.Next = null; } } #endregion if (!done) { ASTParentByASTNode.TryGetValue(ASTwalker, out ASTwalker); } } if (stmt is CFGNodeStmtProcCall) { if (NextNode is CFGNodeStmtSkip) { (NextNode as CFGNodeStmtSkip).setPreviousProcCall(stmt as CFGNodeStmtProcCall); } } } else //We use this pass trough the CFG nodes to build "First Statement Of Procedure" function if (node is CFGNodeProcedure) { CFGNodeProcedure proc = (CFGNodeProcedure)node; CommonAST ASTwalker = proc.GetAST(); ASTwalker = (CommonAST)ASTwalker.getFirstChild(); while (ASTwalker.Type != BoolParserTokenTypes.SSEQ) { ASTwalker = (CommonAST)ASTwalker.getNextSibling(); } ASTwalker = (CommonAST)ASTwalker.getFirstChild(); CFGNode FirstOf; if (AstToCfgMapping.TryGetValue(ASTwalker, out FirstOf)) { proc.FirstStmtOf = FirstOf; } } } }
public static Bdd buildProcCallTransfer(CommonAST procCall, CFGNodeProcedure procedureCalled, BddManager Manager, Dictionary <string, int> LocalVarToId, Dictionary <string, int> GlobalVarToId) { Bdd transfer = Manager.CreateBddOne(); CommonAST walkerExpr = procCall.getFirstChild().getFirstChild() as CommonAST; CommonAST walkerFormal = procedureCalled.GetAST().getFirstChild() as CommonAST; #region Build Bdd for FormalParameters = Call Expressions while (walkerExpr != null) { Bdd expr = HelperFunctions.ExprToBdd(walkerExpr, Manager, LocalVarToId, GlobalVarToId); int varID; if (!procedureCalled.FormalParameters.VariablesToId.TryGetValue(walkerFormal.getText(), out varID)) { System.Diagnostics.Debug.Assert(false); } Bdd formal = Manager.GetBddVariableWithID(varID + 2); Bdd tempBdd = Manager.LogicalXnor(formal, expr); Bdd tempBdd2 = transfer; transfer = Manager.LogicalAnd(transfer, tempBdd); expr.FreeBdd(); formal.FreeBdd(); tempBdd.FreeBdd(); tempBdd2.FreeBdd(); walkerExpr = walkerExpr.getNextSibling() as CommonAST; walkerFormal = walkerFormal.getNextSibling() as CommonAST; } #endregion #region And with an identity over Global variables and true Local variables(non Formals) /* int variableCount = procedureCalled.LocalVariables.VariablesToId.Values.Count - * procedureCalled.FormalParameters.VariablesToId.Values.Count; * int[] variableIDs = new int[variableCount]; * int index = 0; * Bdd identity; * foreach (int varID in procedureCalled.LocalVariables.VariablesToId.Values) * { * if (!(procedureCalled.FormalParameters.VariablesToId.ContainsValue(varID))) * { * variableIDs[index++] = varID; * } * } * * Bdd identNewLocals = HelperFunctions.BuildIdentityOverVariableIDs(Manager, variableIDs, variableCount);*/ Bdd identGlobals = HelperFunctions.BuildIdentityTransfer(Manager, null, GlobalVarToId); /* if (identNewLocals != null && identGlobals != null) * { * identity = Manager.LogicalAnd(identGlobals, identNewLocals); * identNewLocals.FreeBdd(); * identGlobals.FreeBdd(); * } * else if (identNewLocals != null) * { * identity = identNewLocals; * } * else * { * identity = identGlobals; * }*/ Bdd identity = identGlobals; Bdd temp = transfer; transfer = Manager.LogicalAnd(transfer, identity); //temp.FreeBdd(); #endregion return(transfer); }