#include <bytecode.hpp>
Inheritance diagram for ClassEncoder::ByteCode:
Public Member Functions | |
ByteCode (ConstantPool *pool) | |
Constructor. | |
virtual | ~ByteCode () |
Destructor. | |
unsigned int | maxStackSize () const |
Get the maximum stack size during execution. | |
unsigned int | nextInstrAddr () const |
Get the address of the next instruction. | |
void | write (std::ofstream &stream) const |
Write bytecode to stream. | |
pushtostack | |
Push constants onto the stack | |
unsigned int | emit_iconst (int number) |
Push integer between 0 and 5 to the stack. | |
unsigned int | emit_bipush (u1 num) |
Push an unsigned byte onto the stack. | |
unsigned int | emit_sipush (u2 num) |
Push an unsigned two-byte value onto the stack. | |
unsigned int | emit_ldc (u1 index) |
push single-word constant onto stack | |
unsigned int | emit_ldc2 (u2 index) |
push single-word constant onto stack (wide index) | |
localtostack | |
Loading locals onto the stack | |
unsigned int | emit_iload (u1 vindex) |
Load integer from local variable. | |
unsigned int | emit_lload (u1 vindex) |
Load long integer from local variable. | |
unsigned int | emit_fload (u1 vindex) |
Load single float from local variable. | |
unsigned int | emit_dload (u1 vindex) |
Load double float from local variable. | |
unsigned int | emit_aload (u1 vindex) |
Load object reference from local variable. | |
storetostack | |
Store stack values into locals. | |
unsigned int | emit_istore (u1 vindex) |
Store integer into local variable. | |
unsigned int | emit_lstore (u1 vindex) |
Store long integer into local variable. | |
unsigned int | emit_fstore (u1 vindex) |
Store float into local variable. | |
unsigned int | emit_dstore (u1 vindex) |
Store double float into local variable. | |
unsigned int | emit_astore (u1 vindex) |
Store double float into local variable. | |
unsigned int | emit_iinc (u1 vindex, u1 value) |
Increment local variable by constant. | |
arrayfunctions | |
Stack instructions | |
unsigned int | emit_newarray (_basic_data_types type) |
unsigned int | emit_multianewarray (u2 index, u1 dimensions) |
Allocate new multi-dimensional array. | |
unsigned int | emit_multianewarray (const std::string classType, u1 dimensions) |
Allocate new multi-dimensional array. | |
unsigned int | emit_iastore () |
Store into integer array. | |
unsigned int | emit_lastore () |
Store into long integer array. | |
unsigned int | emit_fastore () |
Store into single float array. | |
unsigned int | emit_dastore () |
Store into double float array. | |
unsigned int | emit_aastore () |
Store into object reference array. | |
unsigned int | emit_bastore () |
Store into signed byte array. | |
unsigned int | emit_castore () |
Store into character array. | |
unsigned int | emit_sastore () |
Store into short array. | |
unsigned int | emit_iaload () |
Load integer from array. | |
unsigned int | emit_laload () |
Load long integer from array. | |
unsigned int | emit_faload () |
Load single float from array. | |
unsigned int | emit_daload () |
Load double float from array. | |
unsigned int | emit_aaload () |
Load object reference from array. | |
unsigned int | emit_baload () |
Load signed byte from array. | |
unsigned int | emit_caload () |
Load character from array. | |
unsigned int | emit_saload () |
Load short from array. | |
stackinstructions | |
Stack instructions | |
unsigned int | emit_pop () |
Pop top stack word. | |
unsigned int | emit_pop2 () |
Pop top two stack word. | |
unsigned int | emit_dup () |
Duplicate top stack word. | |
unsigned int | emit_dup2 () |
Duplicate top two stack word. | |
unsigned int | emit_dup_x1 () |
Duplicate top stack word and put it two down. | |
unsigned int | emit_dup_x2 () |
Duplicate top stack word and put it three down. | |
unsigned int | emit_swap () |
Swap top two stack words. | |
arithmetic | |
Arithmetic instructions | |
unsigned int | emit_iadd () |
Integer add. | |
unsigned int | emit_ladd () |
Long integer add. | |
unsigned int | emit_fadd () |
Float add. | |
unsigned int | emit_dadd () |
Double float add. | |
unsigned int | emit_isub () |
Integer subtract. | |
unsigned int | emit_lsub () |
Long Integer subtract. | |
unsigned int | emit_fsub () |
Float subtract. | |
unsigned int | emit_dsub () |
Double Float subtract. | |
unsigned int | emit_imul () |
Integer multiplication. | |
unsigned int | emit_lmul () |
Long Integer multiplication. | |
unsigned int | emit_fmul () |
Float multiplication. | |
unsigned int | emit_dmul () |
Double Float multiplication. | |
unsigned int | emit_idiv () |
Integer division. | |
unsigned int | emit_ldiv () |
Long Integer division. | |
unsigned int | emit_fdiv () |
Float division. | |
unsigned int | emit_ddiv () |
Double Float division. | |
unsigned int | emit_irem () |
Integer remainder. | |
unsigned int | emit_lrem () |
Long Integer remainder. | |
unsigned int | emit_frem () |
Float remainder. | |
unsigned int | emit_drem () |
Double Float remainder. | |
unsigned int | emit_ineg () |
Integer negate. | |
unsigned int | emit_lneg () |
Long Integer negate. | |
unsigned int | emit_fneg () |
Float negate. | |
unsigned int | emit_dneg () |
Double Float negate. | |
logical | |
Transfer control in the program. | |
unsigned int | emit_iand () |
Integer logical and. | |
unsigned int | emit_ior () |
Integer logical or. | |
unsigned int | emit_ixor () |
Integer logical xor. | |
controltransfer | |
Transfer control in the program. | |
void | patch (unsigned int instrAddr, u2 jump) |
Patch jump to jump to a new position. | |
unsigned int | emit_ifeq (u2 jump) |
Branch if equal. | |
unsigned int | emit_ifnull (u2 jump) |
Branch if null. | |
unsigned int | emit_iflt (u2 jump) |
Branch if less than. | |
unsigned int | emit_ifle (u2 jump) |
Branch if less or equal. | |
unsigned int | emit_ifne (u2 jump) |
Branch if not equal. | |
unsigned int | emit_ifnonnull (u2 jump) |
Branch if not null. | |
unsigned int | emit_ifgt (u2 jump) |
Branch if greater than. | |
unsigned int | emit_ifge (u2 jump) |
Branch if greater or equal. | |
unsigned int | emit_if_icmpeq (u2 jump) |
Branch if integers equal. | |
unsigned int | emit_if_icmpne (u2 jump) |
Branch if integers not equal. | |
unsigned int | emit_if_icmplt (u2 jump) |
Branch if integer less than. | |
unsigned int | emit_if_icmpgt (u2 jump) |
Branch if integer greater than. | |
unsigned int | emit_if_icmple (u2 jump) |
Branch if integer less or equal. | |
unsigned int | emit_if_icmpge (u2 jump) |
Branch if integer greater or equal. | |
unsigned int | emit_goto (u2 jump) |
Branch. | |
unsigned int | emit_jsr (u2 jump) |
Jump subroutine. | |
unsigned int | emit_ret (u1 vindex) |
Return from subroutine. | |
manipulateobjectfields | |
Manipulate object fields | |
unsigned int | emit_getstatic (u2 index) |
Get static field from class. | |
unsigned int | emit_getstatic (const std::string &className, const std::string &fieldName, const std::string &fieldType) |
Get static field from class. | |
manipulateobjectfields | |
Manipulate object fields | |
unsigned int | emit_invokevirtual (u2 index) |
Invoke instance method. | |
unsigned int | emit_invokespecial (u2 index) |
Invoke instance method, dispatching based on compile-time type. | |
unsigned int | emit_invokestatic (u2 index) |
Invoke a class (static) method. | |
unsigned int | emit_invokeinterface (u2 index, u1 nargs) |
Invoke an interface method. | |
unsigned int | emit_invokestatic (const std::string &classType, const std::string &function, const std::string &footprint) |
Invoke a class (static) method. | |
unsigned int | emit_invokevirtual (const std::string &classType, const std::string &function, const std::string &footprint) |
Invoke instance method. | |
unsigned int | emit_invokespecial (const std::string &object, const std::string &function, const std::string &footprint) |
Invoke instance method, dispatching based on compile-time type. | |
unsigned int | emit_invokeinterface (const std::string &objectType, const std::string &function, const std::string &footprint, u1 nargs) |
Invoke interface method. | |
miscobjectfunc | |
Manipulate object fields | |
unsigned int | emit_new (u2 index) |
Allocate an object on the heap. | |
unsigned int | emit_new (const std::string &className) |
Allocate an object on the heap. | |
manipulateobjectfields | |
Manipulate object fields | |
unsigned int | emit_ireturn () |
Return integer from function. | |
unsigned int | emit_lreturn () |
Return long integer from function. | |
unsigned int | emit_freturn () |
Return float from function. | |
unsigned int | emit_dreturn () |
Return double float from function. | |
unsigned int | emit_return () |
Return from function. | |
Private Member Functions | |
unsigned int | emit_arithmetic (_opcode code, unsigned int popVal=1) |
Internal arithmetic helper function. | |
unsigned int | emit_transfer (_opcode code, u2 jump, unsigned int popVal=1) |
Internal control transfer helper function. | |
void | push (int num=1) |
Internal push function to monitor run time stack size. | |
void | pop (int num=1) |
Internal pop function to monitor run time stack size. | |
Private Attributes | |
unsigned int | MaxStackSize |
unsigned int | StackSize |
std::vector< u1 > | Code |
ConstantPool * | ConstantPoolEntries |
This is done through the emit_xxx... functions representing java assembly commands. The java assembly codes are not documented in detail, however detailed information about what they do can be found here: http://mrl.nyu.edu/~meyer/jvmref/ This class consists of quite a lot of duplicated or very similar code. This was a design decision to keep things simple. Smart and short functions would be error prone and hard to maintain.
Definition at line 30 of file bytecode.hpp.
|
Constructor. Init of object. Definition at line 34 of file bytecode.cpp. |
|
Destructor. Emptry Definition at line 45 of file bytecode.cpp. |
|
Load object reference from local variable.
Definition at line 317 of file bytecode.cpp. References push(). |
|
Internal arithmetic helper function. Since all arithmetic instructions take no parameters this helper function avoids duplicating code.
Definition at line 793 of file bytecode.cpp. References pop(). Referenced by emit_dadd(), emit_ddiv(), emit_dmul(), emit_dneg(), emit_drem(), emit_dsub(), emit_fadd(), emit_fdiv(), emit_fmul(), emit_fneg(), emit_frem(), emit_fsub(), emit_iadd(), emit_idiv(), emit_imul(), emit_ineg(), emit_irem(), emit_isub(), emit_ladd(), emit_ldiv(), emit_lmul(), emit_lneg(), emit_lrem(), and emit_lsub(). |
|
Store double float into local variable.
Definition at line 476 of file bytecode.cpp. References pop(). |
|
Push an unsigned byte onto the stack.
Definition at line 132 of file bytecode.cpp. References push(). |
|
Double float add.
Definition at line 839 of file bytecode.cpp. References emit_arithmetic(). |
|
Double Float division.
Definition at line 947 of file bytecode.cpp. References emit_arithmetic(). |
|
Load double float from local variable.
Definition at line 287 of file bytecode.cpp. References push(). |
|
Double Float multiplication.
Definition at line 911 of file bytecode.cpp. References emit_arithmetic(). |
|
Double Float negate.
Definition at line 1019 of file bytecode.cpp. References emit_arithmetic(). |
|
Double Float remainder.
Definition at line 983 of file bytecode.cpp. References emit_arithmetic(). |
|
Return double float from function. Returns the top double float value on the stack. Definition at line 1624 of file bytecode.cpp. |
|
Store double float into local variable.
Definition at line 446 of file bytecode.cpp. References pop(). |
|
Double Float subtract.
Definition at line 875 of file bytecode.cpp. References emit_arithmetic(). |
|
Duplicate top stack word.
Definition at line 727 of file bytecode.cpp. References push(). |
|
Duplicate top two stack word.
Definition at line 739 of file bytecode.cpp. References push(). |
|
Duplicate top stack word and put it two down.
Definition at line 751 of file bytecode.cpp. References push(). |
|
Duplicate top stack word and put it three down.
Definition at line 763 of file bytecode.cpp. References push(). |
|
Float add.
Definition at line 830 of file bytecode.cpp. References emit_arithmetic(). |
|
Float division.
Definition at line 938 of file bytecode.cpp. References emit_arithmetic(). |
|
Load single float from local variable.
Definition at line 257 of file bytecode.cpp. References push(). |
|
Float multiplication.
Definition at line 902 of file bytecode.cpp. References emit_arithmetic(). |
|
Float negate.
Definition at line 1010 of file bytecode.cpp. References emit_arithmetic(). |
|
Float remainder.
Definition at line 974 of file bytecode.cpp. References emit_arithmetic(). |
|
Return float from function. Returns the top float value on the stack. Definition at line 1613 of file bytecode.cpp. |
|
Store float into local variable.
Definition at line 415 of file bytecode.cpp. References pop(). |
|
Float subtract.
Definition at line 866 of file bytecode.cpp. References emit_arithmetic(). |
|
Get static field from class. Convenience function for getting static fields. This function creates the needed entries in the static pool for you.
Definition at line 1342 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_getstatic(). |
|
Get static field from class.
Definition at line 1323 of file bytecode.cpp. References push(). Referenced by emit_getstatic(). |
|
Branch. Unconditional jump.
Definition at line 1274 of file bytecode.cpp. References emit_transfer(). |
|
Integer add.
Definition at line 812 of file bytecode.cpp. References emit_arithmetic(). |
|
Integer logical and. Performs logical and on the two top integer stack values. Result on stack top.
Definition at line 1037 of file bytecode.cpp. References pop(). |
|
Push integer between 0 and 5 to the stack.
Definition at line 95 of file bytecode.cpp. References emit_sipush(), and push(). |
|
Integer division.
Definition at line 920 of file bytecode.cpp. References emit_arithmetic(). |
|
Branch if integers equal. Jumps if top two integers on stack are equal.
Definition at line 1208 of file bytecode.cpp. References emit_transfer(). |
|
Branch if integer greater or equal. Jumps if first value on stack is greater than or equal to the top value.
Definition at line 1263 of file bytecode.cpp. References emit_transfer(). |
|
Branch if integer greater than. Jumps if first value on stack is greater than the top value.
Definition at line 1241 of file bytecode.cpp. References emit_transfer(). |
|
Branch if integer less or equal. Jumps if first value on stack is less than or equal to the top value.
Definition at line 1252 of file bytecode.cpp. References emit_transfer(). |
|
Branch if integer less than. Jumps if first value on stack is less than the top value.
Definition at line 1230 of file bytecode.cpp. References emit_transfer(). |
|
Branch if integers not equal. Jumps if top two integers on stack are not equal.
Definition at line 1219 of file bytecode.cpp. References emit_transfer(). |
|
Branch if equal. Jumps if top integer on stack is zero.
Definition at line 1120 of file bytecode.cpp. References emit_transfer(). |
|
Branch if greater or equal. Jumps if top integer on stack is greater than or equal to zero.
Definition at line 1197 of file bytecode.cpp. References emit_transfer(). |
|
Branch if greater than. Jumps if top integer on stack is greater than zero.
Definition at line 1186 of file bytecode.cpp. References emit_transfer(). |
|
Branch if less or equal. Jumps if top integer on stack is less or equal to zero.
Definition at line 1153 of file bytecode.cpp. References emit_transfer(). |
|
Branch if less than. Jumps if top integer on stack is less than zero.
Definition at line 1142 of file bytecode.cpp. References emit_transfer(). |
|
Branch if not equal. Jumps if top integer on stack is not equal to zero.
Definition at line 1164 of file bytecode.cpp. References emit_transfer(). |
|
Branch if not null. Jumps if top reference on stack is not null.
Definition at line 1175 of file bytecode.cpp. References emit_transfer(). |
|
Branch if null. Jumps if top reference on stack is null.
Definition at line 1131 of file bytecode.cpp. References emit_transfer(). |
|
Increment local variable by constant.
Definition at line 507 of file bytecode.cpp. |
|
Load integer from local variable.
Definition at line 197 of file bytecode.cpp. References push(). |
|
Integer multiplication.
Definition at line 884 of file bytecode.cpp. References emit_arithmetic(). |
|
Integer negate.
Definition at line 992 of file bytecode.cpp. References emit_arithmetic(). |
|
Invoke interface method. Convenience function for invoking interface methods This function creates the needed entries in the static pool for you.
Definition at line 1529 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_invokeinterface(). |
|
Invoke an interface method. The operand stack must contain the required number of arguments for the function.
Definition at line 1422 of file bytecode.cpp. Referenced by emit_invokeinterface(). |
|
Invoke instance method, dispatching based on compile-time type. Convenience function for invoking a special function. This function creates the needed entries in the static pool for you.
Definition at line 1443 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_invokespecial(). |
|
Invoke instance method, dispatching based on compile-time type. The operand stack must contain a reference to an object and some number of arguments
Definition at line 1389 of file bytecode.cpp. Referenced by emit_invokespecial(). |
|
Invoke a class (static) method. Convenience function for invoking a static function. This function creates the needed entries in the static pool for you.
Definition at line 1474 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_invokestatic(). |
|
Invoke a class (static) method. The operand stack must contain the required number of arguments for the function.
Definition at line 1405 of file bytecode.cpp. References push(). Referenced by emit_invokestatic(). |
|
Invoke instance method. Convenience function for invoking normal class function. This function creates the needed entries in the static pool for you.
Definition at line 1501 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_invokevirtual(). |
|
Invoke instance method. This is the normal method dispatch in Java. The operand stack must contain a reference to an object and some number of arguments
Definition at line 1373 of file bytecode.cpp. Referenced by emit_invokevirtual(). |
|
Integer logical or. Performs logical or on the two top integer stack values. Result on stack top.
Definition at line 1050 of file bytecode.cpp. References pop(). |
|
Integer remainder.
Definition at line 956 of file bytecode.cpp. References emit_arithmetic(). |
|
Return integer from function. Returns the top integer value on the stack. Definition at line 1591 of file bytecode.cpp. |
|
Store integer into local variable.
Definition at line 355 of file bytecode.cpp. References pop(). |
|
Integer subtract.
Definition at line 848 of file bytecode.cpp. References emit_arithmetic(). |
|
Integer logical xor. Performs logical xor on the two top integer stack values. Result on stack top.
Definition at line 1063 of file bytecode.cpp. References pop(). |
|
Jump subroutine. Pushes ret value to stack and jumps.
Definition at line 1286 of file bytecode.cpp. References push(). |
|
Long integer add.
Definition at line 821 of file bytecode.cpp. References emit_arithmetic(). |
|
push single-word constant onto stack
Definition at line 161 of file bytecode.cpp. |
|
push single-word constant onto stack (wide index)
Definition at line 174 of file bytecode.cpp. |
|
Long Integer division.
Definition at line 929 of file bytecode.cpp. References emit_arithmetic(). |
|
Load long integer from local variable.
Definition at line 227 of file bytecode.cpp. References push(). |
|
Long Integer multiplication.
Definition at line 893 of file bytecode.cpp. References emit_arithmetic(). |
|
Long Integer negate.
Definition at line 1001 of file bytecode.cpp. References emit_arithmetic(). |
|
Long Integer remainder.
Definition at line 965 of file bytecode.cpp. References emit_arithmetic(). |
|
Return long integer from function. Returns the top long integer value on the stack. Definition at line 1602 of file bytecode.cpp. |
|
Store long integer into local variable.
Definition at line 385 of file bytecode.cpp. References pop(). |
|
Long Integer subtract.
Definition at line 857 of file bytecode.cpp. References emit_arithmetic(). |
|
Allocate new multi-dimensional array. Convenience function for getting static fields. This function creates the needed entries in the static pool for you.
Definition at line 556 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_multianewarray(). |
|
Allocate new multi-dimensional array. the index is used to construct an index into the constant pool of the current class. The item at that index is resolved. The resulting entry must be an array class of one or more dimensions.
Definition at line 541 of file bytecode.cpp. Referenced by emit_multianewarray(). |
|
Allocate an object on the heap.
Definition at line 1572 of file bytecode.cpp. References ClassEncoder::ConstantPool::add(), and emit_new(). |
|
Allocate an object on the heap.
Definition at line 1558 of file bytecode.cpp. References push(). Referenced by emit_new(). |
|
Pop top stack word.
Definition at line 702 of file bytecode.cpp. References pop(). |
|
Pop top two stack word.
Definition at line 714 of file bytecode.cpp. References pop(). |
|
Return from subroutine.
Definition at line 1302 of file bytecode.cpp. |
|
Push an unsigned two-byte value onto the stack.
Definition at line 146 of file bytecode.cpp. References push(). Referenced by emit_iconst(). |
|
Swap top two stack words.
Definition at line 775 of file bytecode.cpp. |
|
Internal control transfer helper function. Since all control instructions take the same parameters this helper function avoids duplicating code.
Definition at line 1084 of file bytecode.cpp. References pop(). Referenced by emit_goto(), emit_if_icmpeq(), emit_if_icmpge(), emit_if_icmpgt(), emit_if_icmple(), emit_if_icmplt(), emit_if_icmpne(), emit_ifeq(), emit_ifge(), emit_ifgt(), emit_ifle(), emit_iflt(), emit_ifne(), emit_ifnonnull(), and emit_ifnull(). |
|
Get the maximum stack size during execution.
Definition at line 40 of file bytecode.hpp. Referenced by ClassEncoder::code_attribute::write(). |
|
Get the address of the next instruction.
Definition at line 45 of file bytecode.hpp. Referenced by ClassEncoder::code_attribute::size(), and ClassEncoder::code_attribute::write(). |
|
Patch jump to jump to a new position. Patches the given jump to jump to the new position given. This can be useful when the position to jump to is not known at the time the jump is created.
Definition at line 1108 of file bytecode.cpp. |
|
Internal pop function to monitor run time stack size. This function must be called each time an emit function is called that pops something to the stack.
Definition at line 78 of file bytecode.cpp. Referenced by emit_arithmetic(), emit_astore(), emit_dstore(), emit_fstore(), emit_iand(), emit_ior(), emit_istore(), emit_ixor(), emit_lstore(), emit_pop(), emit_pop2(), and emit_transfer(). |
|
Internal push function to monitor run time stack size. This function must be called each time an emit function is called that pushes something to the stack.
Definition at line 66 of file bytecode.cpp. Referenced by emit_aload(), emit_bipush(), emit_dload(), emit_dup(), emit_dup2(), emit_dup_x1(), emit_dup_x2(), emit_fload(), emit_getstatic(), emit_iconst(), emit_iload(), emit_invokestatic(), emit_jsr(), emit_lload(), emit_new(), and emit_sipush(). |
|
Write bytecode to stream.
Definition at line 53 of file bytecode.cpp. References ClassEncoder::ClassWriterBase::writeu1(). Referenced by ClassEncoder::code_attribute::write(). |