public class CodeAssemblerPrinter extends AbstractCodeAssembler implements CodeAssembler
CodeDisassembler, this class makes it easier to understand
how to use a CodeAssembler.CONVERT_FP_BITS, CONVERT_FP_NORMAL, CONVERT_FP_RAW_BITS| Constructor and Description |
|---|
CodeAssemblerPrinter(TypeDesc[] paramTypes,
boolean isStatic,
PrintWriter writer) |
CodeAssemblerPrinter(TypeDesc[] paramTypes,
boolean isStatic,
PrintWriter writer,
String linePrefix,
String lineSuffix,
String builder) |
| Modifier and Type | Method and Description |
|---|---|
void |
arrayLength()
Generates code for an arraylength instruction.
|
void |
branch(Location location)
Generates code that performs an unconditional branch to the specified
location.
|
void |
breakpoint()
Generates a breakpoint instruction for use in a debugging environment.
|
void |
checkCast(TypeDesc type)
Generates code that performs an object cast operation.
|
void |
convert(TypeDesc fromType,
TypeDesc toType)
Generates code that converts the value of a primitive type already
on the stack.
|
void |
convert(TypeDesc fromType,
TypeDesc toType,
int fpConvertMode)
Generates code that converts the value of a primitive type already
on the stack.
|
Label |
createLabel()
Creates a label, whose location must be set.
|
LocalVariable |
createLocalVariable(String name,
TypeDesc type)
Creates a LocalVariable reference from a name and type.
|
void |
dup()
Generates code for the dup instruction, which duplicates the top word on
the stack.
|
void |
dup2()
Generates code for the dup2 instruction, which duplicates the top pair
of words on the stack.
|
void |
dup2X1()
Generates code for the dup2_x1 instruction, which duplicates the top
pair of words on the stack and puts it three levels down.
|
void |
dup2X2()
Generates code for the dup2_x2 instruction, which duplicates the top
pair of words on the stack and puts it four levels down.
|
void |
dupX1()
Generates code for the dup_x1 instruction, which duplicates the top word
on the stack and puts it two levels down.
|
void |
dupX2()
Generates code for the dup_x2 instruction, which duplicates the top word
on the stack and puts it three levels down.
|
void |
exceptionHandler(Location startLocation,
Location endLocation,
String catchClassName)
Sets up an exception handler located here, the location of the next
code to be generated.
|
LocalVariable |
getParameter(int index)
Returns a method input parameter by a zero-based index.
|
int |
getParameterCount()
Returns the amount of parameters that are accepted by the method being
built, not including any "this" reference.
|
void |
ifComparisonBranch(Location location,
String choice)
Generates code the performs a conditional branch based on a comparison
between two int values on the stack.
|
void |
ifEqualBranch(Location location,
boolean choice)
Generates code that performs a conditional branch based on the value of
two object references on the stack.
|
void |
ifNullBranch(Location location,
boolean choice)
Generates code that performs a conditional branch based on the
value of an object on the stack.
|
void |
ifZeroComparisonBranch(Location location,
String choice)
Generates code the performs a conditional branch based on a comparison
between an int value on the stack and zero.
|
void |
instanceOf(TypeDesc type)
Generates code that performs an instanceof operation.
|
void |
integerIncrement(LocalVariable local,
int amount)
Generates code that increments a local integer variable by a signed
constant amount.
|
void |
invokeConstructor(String className,
TypeDesc[] params)
Generates code to invoke a class constructor in any class.
|
void |
invokeConstructor(TypeDesc[] params)
Generates code to invoke a class constructor in this class.
|
void |
invokeConstructor(TypeDesc classDesc,
TypeDesc[] params)
Generates code to invoke a class constructor in any class.
|
void |
invokeInterface(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke an interface method in any class.
|
void |
invokeInterface(TypeDesc classDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke an interface method in any class.
|
void |
invokePrivate(String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a private method in this class.
|
void |
invokeStatic(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a static method in any class.
|
void |
invokeStatic(String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a static method in this class.
|
void |
invokeStatic(TypeDesc classDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a static method in any class.
|
void |
invokeSuper(String superClassName,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a method in the super class.
|
void |
invokeSuper(TypeDesc superClassDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a method in the super class.
|
void |
invokeSuperConstructor(TypeDesc[] params)
Generates code to invoke a super class constructor.
|
void |
invokeVirtual(String className,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a virtual method in any class.
|
void |
invokeVirtual(String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a virtual method in this class.
|
void |
invokeVirtual(TypeDesc classDesc,
String methodName,
TypeDesc ret,
TypeDesc[] params)
Generates code to invoke a virtual method in any class.
|
void |
jsr(Location location)
Generates code that performs a subroutine branch to the specified
location.
|
void |
loadConstant(boolean value)
Generates code that loads a constant boolean value onto the stack.
|
void |
loadConstant(double value)
Generates code that loads a constant double value onto the stack.
|
void |
loadConstant(float value)
Generates code that loads a constant float value onto the stack.
|
void |
loadConstant(int value)
Generates code that loads a constant int, char, short or byte value
onto the stack.
|
void |
loadConstant(long value)
Generates code that loads a constant long value onto the stack.
|
void |
loadConstant(String value)
Generates code that loads a constant string value onto the stack.
|
void |
loadConstant(TypeDesc type)
Generates code that loads a constant class value onto the stack.
|
void |
loadField(String className,
String fieldName,
TypeDesc type)
Generates code that loads a value from a field from any class.
|
void |
loadField(String fieldName,
TypeDesc type)
Generates code that loads a value from a field from this class.
|
void |
loadField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that loads a value from a field from any class.
|
void |
loadFromArray(TypeDesc type)
Generates code that loads a value from an array.
|
void |
loadLocal(LocalVariable local)
Generates code that loads a local variable onto the stack.
|
void |
loadNull()
Generates code that loads a null reference onto the stack.
|
void |
loadStaticField(String className,
String fieldName,
TypeDesc type)
Generates code that loads a value from a static field from any class.
|
void |
loadStaticField(String fieldName,
TypeDesc type)
Generates code that loads a value from a static field from this class.
|
void |
loadStaticField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that loads a value from a static field from any class.
|
void |
loadThis()
Loads a reference to "this" onto the stack.
|
void |
mapLineNumber(int lineNumber)
Map the location of the next code to be generated to a line number
in source code.
|
void |
math(byte opcode)
Generates code for either a unary or binary math operation on one or two
values pushed on the stack.
|
void |
monitorEnter()
Generates code to enter the monitor on an object loaded on the stack.
|
void |
monitorExit()
Generates code to exit the monitor on an object loaded on the stack.
|
void |
newObject(TypeDesc type)
Generates code to create a new object.
|
void |
newObject(TypeDesc type,
int dimensions)
Generates code to create a new array.
|
void |
nop()
Generates an instruction that does nothing.
|
void |
pop()
Generates code for the pop instruction, which simply discards the top
word on the stack.
|
void |
pop2()
Generates code for the pop2 instruction, which simply discards the top
two words on the stack.
|
void |
ret(LocalVariable local)
Generates code that returns from a subroutine invoked by jsr.
|
void |
returnValue(TypeDesc type)
Generates code that returns an object or primitive type.
|
void |
returnVoid()
Generates code that returns void.
|
void |
storeField(String className,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class.
|
void |
storeField(String fieldName,
TypeDesc type)
Generates code that stores a value into a field from this class.
|
void |
storeField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class.
|
void |
storeLocal(LocalVariable local)
Generates code that pops a value off of the stack into a local variable.
|
void |
storeStaticField(String className,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class.
|
void |
storeStaticField(String fieldName,
TypeDesc type)
Generates code that stores a value into a field from this class.
|
void |
storeStaticField(TypeDesc classDesc,
String fieldName,
TypeDesc type)
Generates code that stores a value into a field from any class.
|
void |
storeToArray(TypeDesc type)
Generates code that stores a value to an array.
|
void |
swap()
Generates code for the swap instruction, which swaps to the top two
words on the stack.
|
void |
swap2()
Generates code for a swap2 instruction, which swaps to the top two pair
of words on the stack.
|
void |
switchBranch(int[] cases,
Location[] locations,
Location defaultLocation)
Generates code for a switch statement.
|
void |
throwObject()
Generates code that throws an exception.
|
createLocalVariable, ifComparisonBranch, inline, invoke, invoke, invokeSuperclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcreateLocalVariable, ifComparisonBranch, inline, invoke, invoke, invokeSuperpublic CodeAssemblerPrinter(TypeDesc[] paramTypes, boolean isStatic, PrintWriter writer)
public CodeAssemblerPrinter(TypeDesc[] paramTypes, boolean isStatic, PrintWriter writer, String linePrefix, String lineSuffix, String builder)
linePrefix - optional prefix for each linelineSuffix - optional suffix for each linebuilder - when specified, generated method calls are invoked on
local variable by this namepublic int getParameterCount()
CodeAssemblergetParameterCount in interface CodeAssemblerpublic LocalVariable getParameter(int index)
CodeAssemblerCodeAssembler.loadThis().getParameter in interface CodeAssemblerpublic LocalVariable createLocalVariable(String name, TypeDesc type)
CodeAssemblercreateLocalVariable in interface CodeAssemblername - Optional name for the LocalVariable.type - The type of data that the requested LocalVariable can
store.public Label createLabel()
CodeAssemblerCodeBuilder builder; ... Label label = builder.createLabel().setLocation();
createLabel in interface CodeAssemblerLabel.setLocation()public void exceptionHandler(Location startLocation, Location endLocation, String catchClassName)
CodeAssemblerexceptionHandler in interface CodeAssemblerstartLocation - Location at the start of the section of
code to be wrapped by an exception handler.endLocation - Location directly after the end of the
section of code.catchClassName - The class name of exception to be caught;
if null, then catch every object.public void mapLineNumber(int lineNumber)
CodeAssemblermapLineNumber in interface CodeAssemblerpublic void loadNull()
CodeAssemblerloadNull in interface CodeAssemblerpublic void loadConstant(String value)
CodeAssemblerloadConstant in interface CodeAssemblerpublic void loadConstant(TypeDesc type)
CodeAssemblerloadConstant in interface CodeAssemblertype - any object or primitive typepublic void loadConstant(boolean value)
CodeAssemblerloadConstant in interface CodeAssemblerpublic void loadConstant(int value)
CodeAssemblerloadConstant in interface CodeAssemblerpublic void loadConstant(long value)
CodeAssemblerloadConstant in interface CodeAssemblerpublic void loadConstant(float value)
CodeAssemblerloadConstant in interface CodeAssemblerpublic void loadConstant(double value)
CodeAssemblerloadConstant in interface CodeAssemblerpublic void loadLocal(LocalVariable local)
CodeAssemblerloadLocal in interface CodeAssemblerlocal - The local variable referencepublic void loadThis()
CodeAssemblerloadThis in interface CodeAssemblerpublic void storeLocal(LocalVariable local)
CodeAssemblerstoreLocal in interface CodeAssemblerlocal - The local variable referenceCodeAssembler.getParameter(int),
CodeAssembler.createLocalVariable(java.lang.String, org.cojen.classfile.TypeDesc)public void loadFromArray(TypeDesc type)
CodeAssemblerThe type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
loadFromArray in interface CodeAssemblertype - The type of data stored in the array.public void storeToArray(TypeDesc type)
CodeAssemblerThe type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
storeToArray in interface CodeAssemblertype - The type of data stored in the array.public void loadField(String fieldName, TypeDesc type)
CodeAssemblerloadField in interface CodeAssemblerpublic void loadField(String className, String fieldName, TypeDesc type)
CodeAssemblerloadField in interface CodeAssemblerpublic void loadField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssemblerloadField in interface CodeAssemblerpublic void loadStaticField(String fieldName, TypeDesc type)
CodeAssemblerloadStaticField in interface CodeAssemblerpublic void loadStaticField(String className, String fieldName, TypeDesc type)
CodeAssemblerloadStaticField in interface CodeAssemblerpublic void loadStaticField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssemblerloadStaticField in interface CodeAssemblerpublic void storeField(String fieldName, TypeDesc type)
CodeAssemblerstoreField in interface CodeAssemblerpublic void storeField(String className, String fieldName, TypeDesc type)
CodeAssemblerstoreField in interface CodeAssemblerpublic void storeField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssemblerstoreField in interface CodeAssemblerpublic void storeStaticField(String fieldName, TypeDesc type)
CodeAssemblerstoreStaticField in interface CodeAssemblerpublic void storeStaticField(String className, String fieldName, TypeDesc type)
CodeAssemblerstoreStaticField in interface CodeAssemblerpublic void storeStaticField(TypeDesc classDesc, String fieldName, TypeDesc type)
CodeAssemblerstoreStaticField in interface CodeAssemblerpublic void returnVoid()
CodeAssemblerreturnVoid in interface CodeAssemblerpublic void returnValue(TypeDesc type)
CodeAssemblerThe type doesn't need to be an exact match for objects. TypeDesc.OBJECT works fine for all objects. For primitive types, use the appropriate TypeDesc. For an int, the type is TypeDesc.INT.
returnValue in interface CodeAssemblerpublic void convert(TypeDesc fromType, TypeDesc toType)
CodeAssemblerint to char byte to double Double to double Float to boolean long to Long Double to ShortIn all, 240 conversions are supported.
convert in interface CodeAssemblerpublic void convert(TypeDesc fromType, TypeDesc toType, int fpConvertMode)
CodeAssemblerint to char byte to double Double to double Float to boolean long to Long Double to ShortIn all, 240 conversions are supported.
convert in interface CodeAssemblerfpConvertMode - controls floating point conversion if converting
float <--> int or double <--> longpublic void invokeVirtual(String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeVirtual in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeVirtual(String className, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeVirtual in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeVirtual(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeVirtual in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeStatic(String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeStatic in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeStatic(String className, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeStatic in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeStatic(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeStatic in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeInterface(String className, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeInterface in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeInterface(TypeDesc classDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeInterface in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokePrivate(String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokePrivate in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeSuper(String superClassName, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeSuper in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeSuper(TypeDesc superClassDesc, String methodName, TypeDesc ret, TypeDesc[] params)
CodeAssemblerinvokeSuper in interface CodeAssemblerret - May be null if method returns void.params - May be null if method takes no parameters.public void invokeConstructor(TypeDesc[] params)
CodeAssemblerinvokeConstructor in interface CodeAssemblerparams - May be null if constructor takes no parameters.public void invokeConstructor(String className, TypeDesc[] params)
CodeAssemblerinvokeConstructor in interface CodeAssemblerparams - May be null if constructor takes no parameters.public void invokeConstructor(TypeDesc classDesc, TypeDesc[] params)
CodeAssemblerinvokeConstructor in interface CodeAssemblerparams - May be null if constructor takes no parameters.public void invokeSuperConstructor(TypeDesc[] params)
CodeAssemblerinvokeSuperConstructor in interface CodeAssemblerparams - May be null if constructor takes no parameters.public void newObject(TypeDesc type)
CodeAssemblerIf the specified type is an array, this call is equivalent to newObject(type, 1). The size of the dimension must be on the operand stack. To create multi-dimensional arrays, call newObject(type, dimensions).
newObject in interface CodeAssemblerCodeAssembler.invokeConstructor(org.cojen.classfile.TypeDesc[])public void newObject(TypeDesc type, int dimensions)
CodeAssemblerFor each dimension, its size must be on the operand stack. If the specified dimensions is 0 and the type is not an array, then this call is equivalent to newObject(type).
newObject in interface CodeAssemblerpublic void dup()
CodeAssemblerdup in interface CodeAssemblerpublic void dupX1()
CodeAssemblerdupX1 in interface CodeAssemblerpublic void dupX2()
CodeAssemblerdupX2 in interface CodeAssemblerpublic void dup2()
CodeAssemblerdup2 in interface CodeAssemblerpublic void dup2X1()
CodeAssemblerdup2X1 in interface CodeAssemblerpublic void dup2X2()
CodeAssemblerdup2X2 in interface CodeAssemblerpublic void pop()
CodeAssemblerpop in interface CodeAssemblerpublic void pop2()
CodeAssemblerpop2 in interface CodeAssemblerpublic void swap()
CodeAssemblerswap in interface CodeAssemblerpublic void swap2()
CodeAssemblerswap2 in interface CodeAssemblerpublic void branch(Location location)
CodeAssemblerbranch in interface CodeAssemblerlocation - The location to branch topublic void ifNullBranch(Location location, boolean choice)
CodeAssemblerThe generated instruction consumes the value on the stack.
ifNullBranch in interface CodeAssemblerlocation - The location to branch tochoice - If true, do branch when null, else branch when not nullpublic void ifEqualBranch(Location location, boolean choice)
CodeAssemblerThe generated instruction consumes the two values on the stack.
ifEqualBranch in interface CodeAssemblerlocation - The location to branch tochoice - If true, branch when equal, else branch when not equalpublic void ifZeroComparisonBranch(Location location, String choice)
CodeAssemblerThe generated instruction consumes the value on the stack.
ifZeroComparisonBranch in interface CodeAssemblerlocation - The location to branch tochoice - One of "==", "!=", "<", ">=", ">" or "<="public void ifComparisonBranch(Location location, String choice)
CodeAssemblerThe generated instruction consumes the two values on the stack.
ifComparisonBranch in interface CodeAssemblerlocation - The location to branch tochoice - One of "==", "!=", "<", ">=", ">" or "<="public void switchBranch(int[] cases,
Location[] locations,
Location defaultLocation)
CodeAssemblerThe key value to switch on must already be on the stack when this instruction executes. It is consumed by the instruction.
switchBranch in interface CodeAssemblercases - The values to match on. The array length must be the same
as for locations.locations - The locations to branch to for each case.
The array length must be the same as for cases.defaultLocation - The location to branch to if the key on
the stack was not matched.public void jsr(Location location)
CodeAssemblerjsr in interface CodeAssemblerlocation - The location to branch topublic void ret(LocalVariable local)
CodeAssemblerret in interface CodeAssemblerlocal - The local variable reference that contains the return
address. The local variable must be of an object type.public void math(byte opcode)
CodeAssemblerIADD - add top two int operands ISUB - subtract top two int operands (topmost is subtrahend) IMUL - multiply top two int operands IDIV - divide top two int operands (topmost is divisor) IREM - remainder of top two int operands (topmost is divisor) INEG - negate top int operand IAND - logical 'and' of top two int operands IOR - logical 'or' of top two int operands IXOR - logical 'exclusive or' of top two int operands ISHL - shift left of int operand by topmost int shift amount ISHR - signed shift right of int operand by topmost int shift amount IUSHR - unsigned shift right of int operand by topmost int shift amount LADD - add top two long operands LSUB - subtract top two long operands (topmost is subtrahend) LMUL - multiply top two long operands LDIV - divide top two long operands (topmost is divisor) LREM - remainder of top two long operands (topmost is divisor) LNEG - negate top long operand LAND - logical 'and' of top two long operands LOR - logical 'or' of top two long operands LXOR - logical 'exclusive or' of top two long operands LSHL - shift left of long operand by topmost int shift amount LSHR - signed shift right of long operand by topmost int shift amount LUSHR - unsigned shift right of long operand by topmost int shift amount FADD - add top two float operands FSUB - subtract top two float operands (topmost is subtrahend) FMUL - multiply top two float operands FDIV - divide top two float operands (topmost is divisor) FREM - remainder of top two float operands (topmost is divisor) FNEG - negate top float operand DADD - add top two double operands DSUB - subtract top two double operands (topmost is subtrahend) DMUL - multiply top two double operands DDIV - divide top two double operands (topmost is divisor) DREM - remainder of top two double operands (topmost is divisor) DNEG - negate top double operand LCMP - compare top two long operands, yielding an int -1, 0 or 1 FCMPG - compare top two float operands, yielding an int -1, 0 or 1 (NaN -> 1) FCMPL - compare top two float operands, yielding an int -1, 0 or 1 (NaN -> -1) DCMPG - compare top two double operands, yielding an int -1, 0 or 1 (NaN -> 1) DCMPL - compare top two double operands, yielding an int -1, 0 or 1 (NaN -> -1)A not operation (~) is performed by doing a loadConstant with either -1 or -1L followed by math(Opcode.IXOR) or math(Opcode.LXOR).
math in interface CodeAssembleropcode - An opcode from the Opcode class.Opcodepublic void arrayLength()
CodeAssemblerarrayLength in interface CodeAssemblerpublic void throwObject()
CodeAssemblerthrowObject in interface CodeAssemblerpublic void checkCast(TypeDesc type)
CodeAssemblercheckCast in interface CodeAssemblerpublic void instanceOf(TypeDesc type)
CodeAssemblerinstanceOf in interface CodeAssemblerpublic void integerIncrement(LocalVariable local, int amount)
CodeAssemblerintegerIncrement in interface CodeAssemblerpublic void monitorEnter()
CodeAssemblermonitorEnter in interface CodeAssemblerpublic void monitorExit()
CodeAssemblermonitorExit in interface CodeAssemblerpublic void nop()
CodeAssemblernop in interface CodeAssemblerpublic void breakpoint()
CodeAssemblerbreakpoint in interface CodeAssemblerCopyright © 2004-2015 Cojen. All Rights Reserved.