From 4ff45b1341c5b0a4d735347d23d6beae070ea5b1 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 25 Mar 2010 03:49:18 +0000 Subject: [PATCH] code for Jim to use once he gets everything working... the idea is that this takes in a flatmethod and generates next/prev nodes for each node that the pointer analysis actually cares about --- .../src/Analysis/Disjoint/PointerMethod.java | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Robust/src/Analysis/Disjoint/PointerMethod.java diff --git a/Robust/src/Analysis/Disjoint/PointerMethod.java b/Robust/src/Analysis/Disjoint/PointerMethod.java new file mode 100644 index 00000000..bace6eb4 --- /dev/null +++ b/Robust/src/Analysis/Disjoint/PointerMethod.java @@ -0,0 +1,97 @@ +package Analysis.Disjoint; + +import IR.*; +import IR.Flat.*; +import java.util.*; + + +public class PointerMethod { + public PointerMethod() { + nextmap=new Hashtable>(); + prevmap=new Hashtable>(); + } + + Hashtable> nextmap; + Hashtable> prevmap; + + public void analyzeMethod(FlatMethod fm) { + Hashtable> map=new Hashtable>(); + HashSet toprocess=new HashSet(); + toprocess.add(fm); + while(!toprocess.isEmpty()) { + FlatNode fn=toprocess.iterator().next(); + toprocess.remove(fn); + HashSet myset=new HashSet(); + if (!analysisCares(fn)) { + for(int i=0;i it=map.keySet().iterator();it.hasNext();) { + FlatNode fn=it.next(); + if (analysisCares(fn)) { + HashSet myset=new HashSet(); + for(int i=0;i it2=myset.iterator();it2.hasNext();) { + FlatNode fnprev=it2.next(); + if (!nextmap.containsKey(fnprev)) + nextmap.put(fnprev, new Vector()); + nextmap.get(fnprev).add(fn); + prevmap.get(fn).add(fnprev); + } + } + } + } + + public int numNext(FlatNode fn) { + return nextmap.get(fn).size(); + } + + public FlatNode getNext(FlatNode fn, int i) { + return nextmap.get(fn).get(i); + } + + public int numPrev(FlatNode fn) { + return prevmap.get(fn).size(); + } + + public FlatNode getPrev(FlatNode fn, int i) { + return prevmap.get(fn).get(i); + } + + public boolean analysisCares(FlatNode fn) { + switch(fn.kind()) { + case FKind.FlatMethod: + case FKind.FlatFieldNode: + case FKind.FlatSetFieldNode: + case FKind.FlatElementNode: + case FKind.FlatSetElementNode: + case FKind.FlatNew: + case FKind.FlatCall: + case FKind.FlatReturnNode: + return true; + case FKind.FlatCastNode: + FlatCastNode fcn=(FlatCastNode)fn; + TypeDescriptor td=fcn.getType(); + return td.isPtr(); + case FKind.FlatOpNode: + FlatOpNode fon = (FlatOpNode) fn; + return fon.getOp().getOp()==Operation.ASSIGN&&fon.getLeft().getType().isPtr(); + default: + return false; + } + } +} \ No newline at end of file -- 2.34.1