Class JavaMethodWasmCodeBuilder
java.lang.Object
de.inetsoftware.jwebassembly.module.WasmCodeBuilder
de.inetsoftware.jwebassembly.module.JavaMethodWasmCodeBuilder
Convert Java Byte Code to a list of WasmInstruction.
-
Field Summary
FieldsFields inherited from class WasmCodeBuilder
CLASS_INIT, CONSTRUCTOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidbuildCode(Code code, MethodInfo method) Build the wasm instructionsprivate static intfindNext(int current, int[] values) Find the next higher value.(package private) voidinit(WasmOptions options, ClassFileLoader classFileLoader) Initialize the code builder;private voidopCompare(ValueType valueType, CodeInputStream byteCode, int codePos, int lineNumber) Handle the different compare operator.private voidopIfCompareCondition(NumericOperator compareOp, CodeInputStream byteCode, int codePos, int lineNumber) Handle the ifof the Java byte code. private voidopIfCondition(NumericOperator compareOp, CodeInputStream byteCode, int codePos, int lineNumber) Handle the ifof the Java byte code. private voidNULL const has no type in Java.private voidwriteCode(CodeInputStream byteCode, ConstantPool constantPool, ClassFile classFile, AnyType returnType) Write the byte code of a method.private voidwriteSwitchCode(CodeInputStream byteCode, boolean isLookupSwitch) Write the both switch operation codesMethods inherited from class WasmCodeBuilder
addArrayInstruction, addBlockInstruction, addCallInstruction, addCallInterfaceInstruction, addCallVirtualInstruction, addConstInstruction, addConstInstruction, addConvertInstruction, addDupInstruction, addDupX1Instruction, addDupX2Instruction, addGlobalInstruction, addGlobalInstruction, addInvokeDynamic, addJumpPlaceholder, addLoadStoreInstruction, addLocalInstruction, addMemoryInstruction, addMultiNewArrayInstruction, addMultiNewArrayInstruction, addNopInstruction, addNumericInstruction, addStructInstruction, addTableInstruction, calculateVariables, findArrayTypeFromStack, findBlockStartCodePosition, findValueTypeFromStack, getInstructions, getLocalName, getLocalTypes, getLocalVariables, getOptions, getTempVariable, getTypeManager, isEndsWithReturn, reset
-
Field Details
-
branchManager
-
-
Constructor Details
-
JavaMethodWasmCodeBuilder
JavaMethodWasmCodeBuilder(@Nonnull WasmCodeBuilder codeBuilder) Create an instance- Parameters:
codeBuilder- other code builder for shred references
-
-
Method Details
-
init
Initialize the code builder;- Overrides:
initin classWasmCodeBuilder- Parameters:
options- compiler propertiesclassFileLoader- for loading the class files
-
buildCode
Build the wasm instructions- Parameters:
code- the Java method codemethod- the method with signature as fallback for a missing variable table- Throws:
WasmException- if some Java code can't converted
-
writeCode
private void writeCode(CodeInputStream byteCode, ConstantPool constantPool, ClassFile classFile, AnyType returnType) throws WasmException Write the byte code of a method.- Parameters:
byteCode- a stream of byte codeconstantPool- the constant pool of the the current classclassFile- the declaring class filereturnType- the return type of the method- Throws:
WasmException- if some Java code can't converted
-
writeSwitchCode
Write the both switch operation codes- Parameters:
byteCode- the current stream with a position after the operation codeisLookupSwitch- true, if the operation was a loopupswitch; false, if the operation was a tableswitch- Throws:
IOException- if any I/O error occur
-
findNext
private static int findNext(int current, int[] values) Find the next higher value.- Parameters:
current- the current valuevalues- the unordered list of values- Returns:
- the next value or current value if not found.
-
opIfCondition
private void opIfCondition(NumericOperator compareOp, CodeInputStream byteCode, int codePos, int lineNumber) throws IOException Handle the ifof the Java byte code. This Java instruction compare the first stack value with value 0. Important: In the Java IF expression the condition for the jump to the else block is saved. In WebAssembler we need to use condition for the if block. The caller of the method must already negate this - Parameters:
compareOp- The condition for the continue of a loop.byteCode- current byte code stream to read the target offset.codePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code- Throws:
IOException- if any I/O errors occur.
-
opIfCompareCondition
private void opIfCompareCondition(NumericOperator compareOp, CodeInputStream byteCode, int codePos, int lineNumber) throws IOException Handle the ifof the Java byte code. This Java instruction compare 2 values from stack. Important: In the Java IF expression the condition for the jump to the else block is saved. In WebAssembler we need to use condition for the if block. The caller of the method must already negate this. - Parameters:
compareOp- The condition for the continue of a loop.byteCode- current byte code stream to read the target offset.codePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code- Throws:
IOException- if any I/O errors occur.
-
opCompare
private void opCompare(ValueType valueType, CodeInputStream byteCode, int codePos, int lineNumber) throws IOException Handle the different compare operator. The compare operator returns the integer values -1, 0 or 1. There is no equivalent in WebAssembly. That we need to read the next operation to find an equivalent.- Parameters:
valueType- the value type of the comparedbyteCode- current byte code stream to read the next operation.codePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code- Throws:
IOException- if any I/O errors occur.
-
patchTypeOfNullConst
private void patchTypeOfNullConst()NULL const has no type in Java. In WebAssembly currently.
-