Commit d9f0e985 authored by Lukáš Marek's avatar Lukáš Marek
Browse files

added DiSL basic structure classes

parent 680c956d
package ch.usi.dag.disl;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import ch.usi.dag.disl.analysis.Analyzer;
import ch.usi.dag.disl.marker.MarkedRegion;
import ch.usi.dag.disl.snippet.Snippet;
import ch.usi.dag.disl.viewer.Viewer;
import ch.usi.dag.jborat.agent.Instrumentation;
public class DiSLDriver implements Instrumentation {
List<Snippet> snippets = new LinkedList<Snippet>();
List<Analyzer> analyzers = new LinkedList<Analyzer>();
Viewer viewer;
public DiSLDriver() {
super();
// TODO compile DiSL classes
// TODO create snippets
// TODO create analyzers
// TODO initialize viewer
}
/**
* Instruments a method in a class.
*
* NOTE: This method changes the classNode argument
*
* @param classNode class that will be instrumented
* @param method method in the classNode argument, that will be instrumented
*/
private void instrumentMethod(ClassNode classNode, MethodNode method) {
// TODO create finite-state machine if possible
// *** match snippet scope ***
List<Snippet> matchedSnippets = new LinkedList<Snippet>();
for(Snippet snippet : snippets) {
// snippet matching
if(snippet.getScope().matches(method)) {
matchedSnippets.add(snippet);
}
}
// *** create markings ***
// all markings in one list for analysis
List<MarkedRegion> allMarkings = new LinkedList<MarkedRegion>();
// markings according to snippets for viewing
Map<Snippet, List<MarkedRegion>> snippetMarkings =
new HashMap<Snippet, List<MarkedRegion>>();
for(Snippet snippet : matchedSnippets) {
// marking
List<MarkedRegion> marking = snippet.getMarker().mark(method);
// add to lists
allMarkings.addAll(marking);
snippetMarkings.put(snippet, marking);
}
// *** analyze ***
// TODO think about structure for analysis
// - what all we need to analyze and what (structure) is the output
// *** viewing ***
viewer.instrument(classNode, snippetMarkings);
}
@Override
public void instrument(ClassNode clazz) {
// instrument all methods in a class
for(Object methodObj : clazz.methods) {
// cast - ASM still uses Java 1.4 interface
MethodNode method = (MethodNode) methodObj;
instrumentMethod(clazz, method);
}
}
}
package ch.usi.dag.disl.analysis;
public interface Analyzer {
// TODO
void analyze();
}
......@@ -9,10 +9,10 @@ import org.objectweb.asm.tree.MethodNode;
public class BodyMarker implements Marker {
@Override
public List<MarkRegion> mark(MethodNode method) {
List<MarkRegion> regions = new LinkedList<MarkRegion>();
public List<MarkedRegion> mark(MethodNode method) {
List<MarkedRegion> regions = new LinkedList<MarkedRegion>();
InsnList ilst = method.instructions;
MarkRegion region = new MarkRegion();
MarkedRegion region = new MarkedRegion();
region.start = ilst.getFirst();
// FIXME Does the region contain the return-instruction?
// What about a try-finally block?
......
......@@ -11,13 +11,13 @@ import org.objectweb.asm.tree.MethodNode;
public class InvocationMarker implements Marker {
@Override
public List<MarkRegion> mark(MethodNode method) {
List<MarkRegion> regions = new LinkedList<MarkRegion>();
public List<MarkedRegion> mark(MethodNode method) {
List<MarkedRegion> regions = new LinkedList<MarkedRegion>();
InsnList ilst = method.instructions;
for (AbstractInsnNode instruction : ilst.toArray())
if (instruction instanceof MethodInsnNode)
regions.add(new MarkRegion(instruction, instruction));
regions.add(new MarkedRegion(instruction, instruction));
return regions;
}
......
......@@ -2,16 +2,16 @@ package ch.usi.dag.disl.marker;
import org.objectweb.asm.tree.AbstractInsnNode;
public class MarkRegion {
public class MarkedRegion {
public AbstractInsnNode start;
public AbstractInsnNode end;
public MarkRegion() {
public MarkedRegion() {
this.start = null;
this.end = null;
}
public MarkRegion(AbstractInsnNode start, AbstractInsnNode end) {
public MarkedRegion(AbstractInsnNode start, AbstractInsnNode end) {
this.start = start;
this.end = end;
}
......
......@@ -5,5 +5,5 @@ import java.util.List;
import org.objectweb.asm.tree.MethodNode;
public interface Marker {
public List<MarkRegion> mark(MethodNode method);
public List<MarkedRegion> mark(MethodNode method);
}
package ch.usi.dag.disl.scope;
import org.objectweb.asm.tree.MethodNode;
public interface Scope {
boolean matches(MethodNode method);
}
package ch.usi.dag.disl.snippet;
import ch.usi.dag.disl.marker.Marker;
import ch.usi.dag.disl.scope.Scope;
public interface Snippet {
public Marker getMarker();
public Scope getScope();
}
package ch.usi.dag.disl.snippet;
import ch.usi.dag.disl.marker.Marker;
import ch.usi.dag.disl.scope.Scope;
public class SnippetImpl {
protected Marker marker;
protected Scope scope;
// TODO protected ?Code? asmCode;
public Marker getMarker() {
return marker;
}
public Scope getScope() {
return scope;
}
}
package ch.usi.dag.disl.util;
public class Parameter {
protected String name;
protected String value;
Parameter(String param) {
// TODO parse parameter
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
// TODO add methods getValueAs ... Int, Float, Boolean,...
}
package ch.usi.dag.disl.viewer;
import java.util.List;
import java.util.Map;
import org.objectweb.asm.tree.ClassNode;
import ch.usi.dag.disl.marker.MarkedRegion;
import ch.usi.dag.disl.snippet.Snippet;
public interface Viewer {
// TODO include analysis
void instrument(ClassNode classNode,
Map<Snippet, List<MarkedRegion>> snippetMarkings);
}
package ch.usi.dag.jborat.agent;
import org.objectweb.asm.tree.ClassNode;
// TODO this interface should be replaced by jborat jar
public interface Instrumentation {
public void instrument(ClassNode clazz );
}
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