Commit accb6f81 authored by Yudi Zheng's avatar Yudi Zheng

Extensible analysis context.

parent c5edf974
package ch.usi.dag.disl.staticcontext;
import java.util.HashMap;
import java.util.Map;
import ch.usi.dag.disl.snippet.Shadow;
import ch.usi.dag.disl.staticcontext.AbstractStaticContext;
public abstract class AnalysisContext<K, V> extends AbstractStaticContext {
private Map<K, V> analysisCache = new HashMap<K, V>();
protected V thisAnalysis;
public void staticContextData(Shadow sa) {
staticContextData = sa;
thisAnalysis = analysisCache.get(key());
if (thisAnalysis == null) {
thisAnalysis = analysis();
analysisCache.put(key(), thisAnalysis);
}
}
protected abstract K key();
protected abstract V analysis();
}
......@@ -3,7 +3,6 @@ package ch.usi.dag.disl.staticcontext;
import java.util.List;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.util.cfg.CtrlFlowGraph;
......@@ -40,7 +39,7 @@ public class BasicBlockStaticContext extends
}
@Override
protected CtrlFlowGraph analysis(MethodNode method) {
return new CtrlFlowGraph(method);
protected CtrlFlowGraph analysis() {
return new CtrlFlowGraph(staticContextData.getMethodNode());
}
}
package ch.usi.dag.disl.staticcontext;
public abstract class ClassAnalysisContext<V> extends
AnalysisContext<String, V> {
@Override
protected final String key() {
return staticContextData.getClassNode().name;
}
}
......@@ -16,8 +16,9 @@ public class LoopStaticContext extends BasicBlockStaticContext {
private Map<BasicBlock, Set<BasicBlock>> dominatormapping;
@Override
protected CtrlFlowGraph analysis(MethodNode method) {
protected CtrlFlowGraph analysis() {
MethodNode method = staticContextData.getMethodNode();
CtrlFlowGraph cfg = CtrlFlowGraph.build(method);
dominatormapping = new HashMap<BasicBlock, Set<BasicBlock>>();
......
package ch.usi.dag.disl.staticcontext;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.snippet.Shadow;
import ch.usi.dag.disl.staticcontext.AbstractStaticContext;
public abstract class MethodAnalysisContext<V> extends AbstractStaticContext {
private Map<MethodNode, V> analysisCache = new HashMap<MethodNode, V>();
protected V thisAnalysis;
public void staticContextData(Shadow sa) {
staticContextData = sa;
MethodNode method = sa.getMethodNode();
thisAnalysis = analysisCache.get(method);
if (thisAnalysis == null) {
thisAnalysis = analysis(method);
analysisCache.put(method, thisAnalysis);
}
public abstract class MethodAnalysisContext<V> extends
AnalysisContext<String, V> {
@Override
protected final String key() {
return staticContextData.getClassNode().name
+ staticContextData.getMethodNode().name
+ staticContextData.getMethodNode().desc;
}
protected abstract V analysis(MethodNode method);
}
......@@ -50,6 +50,11 @@ public class MethodStaticContext extends AbstractStaticContext {
return staticContextData.getClassNode().name;
}
public String thisClassCanonicalName() {
return staticContextData.getClassNode().name.replace('/', '.');
}
public String thisClassOuterClass() {
return staticContextData.getClassNode().outerClass;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment