Package soot
Class AbstractASMBackend
- java.lang.Object
-
- soot.AbstractASMBackend
-
- Direct Known Subclasses:
BafASMBackend
public abstract class AbstractASMBackend extends Object
Abstract super-class for ASM-based back-ends. Generates byte-code for everything except the method bodies, as they are dependent on the IR.- Author:
- Tobias Hamann, Florian Kuebler, Dominik Helm, Lukas Sommer
-
-
Field Summary
Fields Modifier and Type Field Description protected org.objectweb.asm.ClassVisitorcvprotected intjavaVersionprotected SootClasssc
-
Constructor Summary
Constructors Constructor Description AbstractASMBackend(SootClass sc, int javaVersion)Creates a new ASM backend
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidgenerateAnnotationElems(org.objectweb.asm.AnnotationVisitor av, Collection<AnnotationElem> elements, boolean addName)Emits the bytecode for the values of an annotationprotected voidgenerateAnnotations(Object visitor, Host host)Emits the bytecode for all annotations of a class, field or methodprotected voidgenerateAttributes()Emits the bytecode for all attributes of the classprotected voidgenerateAttributes(org.objectweb.asm.FieldVisitor fv, SootField f)Emits the bytecode for all attributes of a fieldprotected voidgenerateAttributes(org.objectweb.asm.MethodVisitor mv, SootMethod m)Emits the bytecode for all attributes of a methodprotected voidgenerateByteCode()Emits the bytecode for the complete classvoidgenerateClassFile(OutputStream os)Outputs the bytecode generated as a class fileprotected voidgenerateClassHeader()Emits the bytecode for the class itself, including its signatureprotected voidgenerateFields()Emits the bytecode for all fields of the classprotected voidgenerateInnerClassReferences()Emits the bytecode for all references to inner classes if presentprotected abstract voidgenerateMethodBody(org.objectweb.asm.MethodVisitor mv, SootMethod method)Emits the bytecode for the body of a single method Has to be implemented by subclasses to suit their needsprotected voidgenerateMethods()Emits the bytecode for all methods of the classprotected voidgenerateOuterClassReference()Emits the bytecode for a reference to an outer class if necessaryvoidgenerateTextualRepresentation(PrintWriter pw)Outputs the bytecode generated as a textual representationprotected BafBodygetBafBody(SootMethod method)Gets the baf body for the given SootMethod.protected intgetMinJavaVersion(SootMethod sm)Determines the minimum Java version required for the bytecode of the given SootMethod Subclasses should override this method to suit their needs, otherwise Java 1.7 is assumed for compatibility with invokeDynamicprotected static intgetModifiers(int modVal, Host host)Utility method to get the access modifiers of a Hostprotected voidwriteInnerClassTags(List<InnerClassTag> sortedTags)Write out the given sorted list of inner class tags
-
-
-
Field Detail
-
sc
protected final SootClass sc
-
javaVersion
protected final int javaVersion
-
cv
protected org.objectweb.asm.ClassVisitor cv
-
-
Constructor Detail
-
AbstractASMBackend
public AbstractASMBackend(SootClass sc, int javaVersion)
Creates a new ASM backend- Parameters:
sc- The SootClass that is to be converted into bytecodejavaVersion- A particular Java version enforced by the user, may be 0 for automatic detection, must not be lower than necessary for all features used
-
-
Method Detail
-
getBafBody
protected BafBody getBafBody(SootMethod method)
Gets the baf body for the given SootMethod. This method will first check whether the method already has a baf body. If not, it will query the local cache. If this fails as well, it will construct a new baf body.- Parameters:
method- The method for which to obtain a baf body- Returns:
- The baf body for the given method
-
getMinJavaVersion
protected int getMinJavaVersion(SootMethod sm)
Determines the minimum Java version required for the bytecode of the given SootMethod Subclasses should override this method to suit their needs, otherwise Java 1.7 is assumed for compatibility with invokeDynamic- Parameters:
sm- The SootMethod the minimum Java version is to be determined for- Returns:
- The minimum Java version required for the given SootMethod
-
generateClassFile
public void generateClassFile(OutputStream os)
Outputs the bytecode generated as a class file- Parameters:
os- The OutputStream the class file is written to
-
generateTextualRepresentation
public void generateTextualRepresentation(PrintWriter pw)
Outputs the bytecode generated as a textual representation- Parameters:
pw- The PrintWriter the textual representation is written to
-
generateByteCode
protected void generateByteCode()
Emits the bytecode for the complete class
-
generateMethods
protected void generateMethods()
Emits the bytecode for all methods of the class
-
generateFields
protected void generateFields()
Emits the bytecode for all fields of the class
-
generateInnerClassReferences
protected void generateInnerClassReferences()
Emits the bytecode for all references to inner classes if present
-
writeInnerClassTags
protected void writeInnerClassTags(List<InnerClassTag> sortedTags)
Write out the given sorted list of inner class tags- Parameters:
sortedTags- The sorted list of inner class tags
-
generateAttributes
protected void generateAttributes()
Emits the bytecode for all attributes of the class
-
generateAttributes
protected void generateAttributes(org.objectweb.asm.FieldVisitor fv, SootField f)Emits the bytecode for all attributes of a field- Parameters:
fv- The FieldVisitor to emit the bytecode tof- The SootField the bytecode is to be emitted for
-
generateAttributes
protected void generateAttributes(org.objectweb.asm.MethodVisitor mv, SootMethod m)Emits the bytecode for all attributes of a method- Parameters:
mv- The MethodVisitor to emit the bytecode tom- The SootMethod the bytecode is to be emitted for
-
generateAnnotations
protected void generateAnnotations(Object visitor, Host host)
Emits the bytecode for all annotations of a class, field or method- Parameters:
visitor- A ClassVisitor, FieldVisitor or MethodVisitor to emit the bytecode tohost- A Host (SootClass, SootField or SootMethod) the bytecode is to be emitted for, has to match the visitor
-
generateAnnotationElems
protected void generateAnnotationElems(org.objectweb.asm.AnnotationVisitor av, Collection<AnnotationElem> elements, boolean addName)Emits the bytecode for the values of an annotation- Parameters:
av- The AnnotationVisitor to emit the bytecode toelements- A collection of AnnatiotionElem that are the values of the annotationaddName- True, if the name of the annotation has to be added, false otherwise (should be false only in recursive calls!)
-
generateOuterClassReference
protected void generateOuterClassReference()
Emits the bytecode for a reference to an outer class if necessary
-
generateClassHeader
protected void generateClassHeader()
Emits the bytecode for the class itself, including its signature
-
getModifiers
protected static int getModifiers(int modVal, Host host)Utility method to get the access modifiers of a Host- Parameters:
modVal- The bitset representation of the Host's modifiershost- The Host (SootClass, SootField or SootMethod) the modifiers are to be retrieved from- Returns:
- A bitset representation of the Host's modifiers in ASM's internal representation
-
generateMethodBody
protected abstract void generateMethodBody(org.objectweb.asm.MethodVisitor mv, SootMethod method)Emits the bytecode for the body of a single method Has to be implemented by subclasses to suit their needs- Parameters:
mv- The MethodVisitor to emit the bytecode tomethod- The SootMethod the bytecode is to be emitted for
-
-