From 5c23611794e22e727ea0d74b0ce5e2d619d95671 Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 22 Sep 2011 23:47:25 +0000 Subject: [PATCH] Be able to get def reach state out at a given program point --- .../Disjoint/DefiniteReachAnalysis.java | 13 +++++++ .../Analysis/Disjoint/DefiniteReachState.java | 2 +- .../Analysis/Disjoint/DisjointAnalysis.java | 8 +++++ .../src/Analysis/Disjoint/PointerMethod.java | 1 + Robust/src/Analysis/Loops/DeadCode.java | 1 + Robust/src/IR/Flat/BuildCode.java | 3 +- Robust/src/IR/Flat/BuildFlat.java | 8 +++++ Robust/src/IR/Flat/FKind.java | 1 + Robust/src/IR/Flat/FlatGenDefReachNode.java | 35 +++++++++++++++++++ Robust/src/IR/Tree/BuildIR.java | 5 +++ Robust/src/IR/Tree/GenDefReachNode.java | 22 ++++++++++++ Robust/src/IR/Tree/Kind.java | 1 + Robust/src/IR/Tree/SemanticCheck.java | 1 + Robust/src/Lex/Keyword.java | 1 + Robust/src/Lex/Lexer.java | 2 +- Robust/src/Parse/java14.cup | 10 ++++++ Robust/src/Tests/disjoint/definite/test.java | 2 ++ 17 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 Robust/src/IR/Flat/FlatGenDefReachNode.java create mode 100644 Robust/src/IR/Tree/GenDefReachNode.java diff --git a/Robust/src/Analysis/Disjoint/DefiniteReachAnalysis.java b/Robust/src/Analysis/Disjoint/DefiniteReachAnalysis.java index 098fc9ca..cb69890c 100644 --- a/Robust/src/Analysis/Disjoint/DefiniteReachAnalysis.java +++ b/Robust/src/Analysis/Disjoint/DefiniteReachAnalysis.java @@ -1,5 +1,6 @@ package Analysis.Disjoint; +import java.io.*; import java.util.*; import IR.*; @@ -67,6 +68,18 @@ public class DefiniteReachAnalysis { } + public void writeState( FlatNode fn, String outputName ) { + DefiniteReachState state = makeIn( fn ); + try { + BufferedWriter bw = new BufferedWriter( new FileWriter( outputName+".txt" ) ); + bw.write( state.toString() ); + bw.close(); + } catch( IOException e ) { + System.out.println( "ERROR writing definite reachability state:\n "+e ); + } + } + + // get the current state for just after the given // program point private DefiniteReachState get( FlatNode fn ) { diff --git a/Robust/src/Analysis/Disjoint/DefiniteReachState.java b/Robust/src/Analysis/Disjoint/DefiniteReachState.java index 06525ffb..a08b4a2b 100644 --- a/Robust/src/Analysis/Disjoint/DefiniteReachState.java +++ b/Robust/src/Analysis/Disjoint/DefiniteReachState.java @@ -37,7 +37,7 @@ public class DefiniteReachState { rs = new HashMap(); } - // what are the transfer functions that are relevant for this analyis? + public void methodEntry(Set parameters) { // R' := {} diff --git a/Robust/src/Analysis/Disjoint/DisjointAnalysis.java b/Robust/src/Analysis/Disjoint/DisjointAnalysis.java index d170b65e..5c230a4a 100644 --- a/Robust/src/Analysis/Disjoint/DisjointAnalysis.java +++ b/Robust/src/Analysis/Disjoint/DisjointAnalysis.java @@ -1330,6 +1330,14 @@ public class DisjointAnalysis implements HeapAnalysis { } break; + case FKind.FlatGenDefReachNode: { + FlatGenDefReachNode fgdrn = (FlatGenDefReachNode) fn; + if( doDefiniteReachAnalysis ) { + definiteReachAnalysis.writeState( fn, fgdrn.getOutputName() ); + } + } break; + + case FKind.FlatMethod: { // construct this method's initial heap model (IHM) // since we're working on the FlatMethod, we know diff --git a/Robust/src/Analysis/Disjoint/PointerMethod.java b/Robust/src/Analysis/Disjoint/PointerMethod.java index 5246c9b8..aaab9a87 100644 --- a/Robust/src/Analysis/Disjoint/PointerMethod.java +++ b/Robust/src/Analysis/Disjoint/PointerMethod.java @@ -99,6 +99,7 @@ public class PointerMethod { case FKind.FlatSESEEnterNode: case FKind.FlatSESEExitNode: case FKind.FlatGenReachNode: + case FKind.FlatGenDefReachNode: case FKind.FlatExit: return true; diff --git a/Robust/src/Analysis/Loops/DeadCode.java b/Robust/src/Analysis/Loops/DeadCode.java index c3ba42a0..f944819c 100644 --- a/Robust/src/Analysis/Loops/DeadCode.java +++ b/Robust/src/Analysis/Loops/DeadCode.java @@ -38,6 +38,7 @@ nextfn: case FKind.FlatSESEEnterNode: case FKind.FlatSESEExitNode: case FKind.FlatGenReachNode: + case FKind.FlatGenDefReachNode: if (!useful.contains(fn)) { useful.add(fn); changed=true; diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 5b32498f..6773d14f 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -2378,7 +2378,8 @@ fldloop: break; case FKind.FlatGenReachNode: - // this node is just for generating a reach graph + case FKind.FlatGenDefReachNode: + // these nodes are just for generating analysis data // in disjointness analysis at a particular program point break; diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index c506e7ad..8eb9ce6a 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -1608,6 +1608,11 @@ public class BuildFlat { return new NodePair(fgrn, fgrn); } + private NodePair flattenGenDefReachNode(GenDefReachNode gdrn) { + FlatGenDefReachNode fgdrn = new FlatGenDefReachNode(gdrn.getOutputName() ); + return new NodePair(fgdrn, fgdrn); + } + private NodePair flattenSESENode(SESENode sn) { if( sn.isStart() ) { FlatSESEEnterNode fsen=new FlatSESEEnterNode(sn); @@ -1761,6 +1766,9 @@ public class BuildFlat { case Kind.GenReachNode: return flattenGenReachNode((GenReachNode)bsn); + case Kind.GenDefReachNode: + return flattenGenDefReachNode((GenDefReachNode)bsn); + case Kind.ContinueBreakNode: return flattenContinueBreakNode((ContinueBreakNode)bsn); } diff --git a/Robust/src/IR/Flat/FKind.java b/Robust/src/IR/Flat/FKind.java index 89cbf474..3acc8fc5 100644 --- a/Robust/src/IR/Flat/FKind.java +++ b/Robust/src/IR/Flat/FKind.java @@ -29,4 +29,5 @@ public class FKind { public static final int FlatInstanceOfNode=26; public static final int FlatExit=27; public static final int FlatGenReachNode=28; + public static final int FlatGenDefReachNode=29; } diff --git a/Robust/src/IR/Flat/FlatGenDefReachNode.java b/Robust/src/IR/Flat/FlatGenDefReachNode.java new file mode 100644 index 00000000..47e8dce5 --- /dev/null +++ b/Robust/src/IR/Flat/FlatGenDefReachNode.java @@ -0,0 +1,35 @@ +package IR.Flat; +import IR.TypeDescriptor; + +public class FlatGenDefReachNode extends FlatNode { + String outputName; + + public FlatGenDefReachNode(String outputName) { + this.outputName = outputName; + } + + public String getOutputName() { + return outputName; + } + + public FlatNode clone(TempMap t) { + return new FlatGenDefReachNode(outputName); + } + public void rewriteUse(TempMap t) { + } + public void rewriteDst(TempMap t) { + } + + + public String toString() { + return "FlatGenDefReachNode_"+outputName; + } + + public int kind() { + return FKind.FlatGenDefReachNode; + } + + public TempDescriptor [] writesTemps() { + return new TempDescriptor[0]; + } +} diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index cc3845eb..b95f781c 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -1578,10 +1578,15 @@ public class BuildIR { ParseNode idopt_pn=pn.getChild("identifier_opt"); ParseNode name_pn=idopt_pn.getChild("name"); // name_pn.getTerminal() gives you the label + } else if (isNode(pn,"genreach")) { String graphName = pn.getChild("graphName").getTerminal(); blockstatements.add(new GenReachNode(graphName) ); + } else if (isNode(pn,"gen_def_reach")) { + String outputName = pn.getChild("outputName").getTerminal(); + blockstatements.add(new GenDefReachNode(outputName) ); + } else if(isNode(pn,"labeledstatement")) { String labeledstatement = pn.getChild("name").getTerminal(); BlockNode bn=parseSingleBlock(pn.getChild("statement").getFirstChild(),labeledstatement); diff --git a/Robust/src/IR/Tree/GenDefReachNode.java b/Robust/src/IR/Tree/GenDefReachNode.java new file mode 100644 index 00000000..aa180eff --- /dev/null +++ b/Robust/src/IR/Tree/GenDefReachNode.java @@ -0,0 +1,22 @@ +package IR.Tree; + +public class GenDefReachNode extends BlockStatementNode { + String outputName; + + public GenDefReachNode(String outputName) { + assert outputName != null; + this.outputName = outputName; + } + + public String printNode(int indent) { + return "genDefReach "+outputName; + } + + public String getOutputName() { + return outputName; + } + + public int kind() { + return Kind.GenDefReachNode; + } +} diff --git a/Robust/src/IR/Tree/Kind.java b/Robust/src/IR/Tree/Kind.java index 6887303e..496d59a0 100644 --- a/Robust/src/IR/Tree/Kind.java +++ b/Robust/src/IR/Tree/Kind.java @@ -34,4 +34,5 @@ public class Kind { public final static int SwitchLabelNode=31; public final static int SwitchBlockNode=32; public final static int ClassTypeNode=33; + public final static int GenDefReachNode=34; } diff --git a/Robust/src/IR/Tree/SemanticCheck.java b/Robust/src/IR/Tree/SemanticCheck.java index f6f5df32..f82fe80c 100644 --- a/Robust/src/IR/Tree/SemanticCheck.java +++ b/Robust/src/IR/Tree/SemanticCheck.java @@ -389,6 +389,7 @@ public class SemanticCheck { case Kind.SESENode: case Kind.GenReachNode: + case Kind.GenDefReachNode: // do nothing, no semantic check for SESEs return; } diff --git a/Robust/src/Lex/Keyword.java b/Robust/src/Lex/Keyword.java index eea77f5e..8edd81c8 100644 --- a/Robust/src/Lex/Keyword.java +++ b/Robust/src/Lex/Keyword.java @@ -42,6 +42,7 @@ class Keyword extends Token { key_table.put("float", new Integer(Sym.FLOAT)); key_table.put("for", new Integer(Sym.FOR)); key_table.put("genreach", new Integer(Sym.GENREACH)); + key_table.put("gendefreach", new Integer(Sym.GEN_DEF_REACH)); key_table.put("goto", new Integer(Sym.GOTO)); key_table.put("if", new Integer(Sym.IF)); key_table.put("import", new Integer(Sym.IMPORT)); diff --git a/Robust/src/Lex/Lexer.java b/Robust/src/Lex/Lexer.java index d6f18175..c6113f9a 100644 --- a/Robust/src/Lex/Lexer.java +++ b/Robust/src/Lex/Lexer.java @@ -270,7 +270,7 @@ public class Lexer { "else", "enum", "extends", "external", "final", "finally", "flag", //keyword for failure aware computation - "float", "for", "genreach", "getoffset", "global", "goto", "if", + "float", "for", "gendefreach", "genreach", "getoffset", "global", "goto", "if", "implements", "import", "instanceof", "int", "interface", diff --git a/Robust/src/Parse/java14.cup b/Robust/src/Parse/java14.cup index 7e8f0d88..061fe2c9 100644 --- a/Robust/src/Parse/java14.cup +++ b/Robust/src/Parse/java14.cup @@ -108,6 +108,7 @@ terminal ENUM; // added for disjoint reachability analysis terminal GENREACH; +terminal GEN_DEF_REACH; // 19.2) The Syntactic Grammar @@ -204,6 +205,7 @@ non terminal ParseNode catches, catch_clause; non terminal ParseNode finally; //non terminal ParseNode assert_statement; non terminal ParseNode genreach_statement; +non terminal ParseNode gen_def_reach_statement; // 19.12) Expressions non terminal ParseNode primary, primary_no_new_array; non terminal ParseNode class_instance_creation_expression; @@ -1575,6 +1577,7 @@ statement_without_trailing_substatement ::= | sese_statement:st {: RESULT=st; :} | synchronized_statement:st {: RESULT=st; :} | genreach_statement:st {: RESULT=st; :} + | gen_def_reach_statement:st {: RESULT=st; :} | throw_statement:st {: RESULT=st; :} | try_statement:st {: RESULT=st; :} // | assert_statement @@ -2541,3 +2544,10 @@ genreach_statement ::= pn.addChild("graphName").addChild(graphName); RESULT=pn; :} ; + +gen_def_reach_statement ::= + GEN_DEF_REACH IDENTIFIER:outputName SEMICOLON {: + ParseNode pn=new ParseNode("gen_def_reach",parser.lexer.line_num); + pn.addChild("outputName").addChild(outputName); + RESULT=pn; :} + ; diff --git a/Robust/src/Tests/disjoint/definite/test.java b/Robust/src/Tests/disjoint/definite/test.java index 898d1d87..04defe83 100644 --- a/Robust/src/Tests/disjoint/definite/test.java +++ b/Robust/src/Tests/disjoint/definite/test.java @@ -18,6 +18,8 @@ public class Test { f = yodel( f, g ); + gendefreach yo; + System.out.println( f ); } -- 2.34.1