Class WasmCodeBuilder
java.lang.Object
de.inetsoftware.jwebassembly.module.WasmCodeBuilder
- Direct Known Subclasses:
WatParser
Base class for Code Building.
- Author:
- Volker Berlin
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddArrayInstruction(ArrayOperator op, AnyType type, int javaCodePos, int lineNumber) Add an array operation to the instruction list as marker on the code position.protected voidaddBlockInstruction(WasmBlockOperator op, Object data, int javaCodePos, int lineNumber) Add a block operation.protected voidaddCallInstruction(FunctionName name, boolean needThisParameter, int javaCodePos, int lineNumber) Add a static function call.protected voidaddCallInterfaceInstruction(FunctionName name, int javaCodePos, int lineNumber) Add interface function callprotected voidaddCallVirtualInstruction(FunctionName name, int javaCodePos, int lineNumber) Add a virtual/method function call.protected voidaddConstInstruction(Number value, ValueType valueType, int javaCodePos, int lineNumber) Add a constant instruction.protected voidaddConstInstruction(Object value, int javaCodePos, int lineNumber) Add a constant instruction with unknown value type.protected voidaddConvertInstruction(ValueTypeConvertion conversion, int javaCodePos, int lineNumber) Add a value convert/cast instruction.protected voidaddDupInstruction(boolean dup2, int javaCodePos, int lineNumber) Create a WasmDupInstruction.protected voidaddDupX1Instruction(int javaCodePos, int lineNumber) Simulate the dup_x1 Java byte code instruction.protected voidaddDupX2Instruction(int javaCodePos, int lineNumber) Simulate the dup_x2 Java byte code instruction.protected voidaddGlobalInstruction(boolean load, Member ref, int javaCodePos, int lineNumber) Add a global instructionprotected voidaddGlobalInstruction(boolean load, FunctionName name, AnyType type, FunctionName clinit, int javaCodePos, int lineNumber) Add a global instructionprotected voidaddInvokeDynamic(BootstrapMethod method, String factorySignature, String interfaceMethodName, int javaCodePos, int lineNumber) Add invoke dynamic operation.protected voidaddJumpPlaceholder(int jumpPos, int popCount, AnyType pushValueType, int javaCodePos, int lineNumber) Add a Jump instruction for later stack inspectionprotected voidaddLoadStoreInstruction(AnyType valueType, boolean load, int javaIdx, int javaCodePos, int lineNumber) Create a WasmLoadStoreInstruction.protected voidaddLocalInstruction(VariableOperator op, int wasmIdx, int javaCodePos, int lineNumber) Create a WasmLoadStoreInstruction local.get/local.set.protected voidaddMemoryInstruction(MemoryOperator op, ValueType type, int offset, int alignment, int javaCodePos, int lineNumber) Create an instance of a load/store to the linear memory instructionprotected voidaddMultiNewArrayInstruction(int dim, ArrayType type, int javaCodePos, int lineNumber) Add a new multi dimensional array instructionprotected voidaddMultiNewArrayInstruction(int dim, String typeName, int javaCodePos, int lineNumber) Add a new multi dimensional array instructionprotected voidaddNopInstruction(int javaCodePos, int lineNumber) Add a no operation to the instruction list as marker on the code position.protected de.inetsoftware.jwebassembly.module.WasmNumericInstructionaddNumericInstruction(NumericOperator numOp, ValueType valueType, int javaCodePos, int lineNumber) Add a numeric operation instructionprotected voidaddStructInstruction(StructOperator op, String typeName, NamedStorageType fieldName, int javaCodePos, int lineNumber) Add a struct/object operation to the instruction list.protected voidaddTableInstruction(boolean load, int idx, int javaCodePos, int lineNumber) Add a WasmTableInstruction table.get/table.set.protected voidCalculate the index of the variablesprotected TypeManagerGet the type manager.protected voidreset(LocalVariableTable variableTable, MethodInfo method, Iterator<AnyType> signature) Reset the code builder.
-
Constructor Details
-
WasmCodeBuilder
protected WasmCodeBuilder()Create a new instance of CodeBuilder
-
-
Method Details
-
getTypeManager
-
reset
protected void reset(LocalVariableTable variableTable, MethodInfo method, Iterator<AnyType> signature) Reset the code builder.- Parameters:
variableTable- variable table of the Java method.method- the method with signature as fallback for a missing variable table. If null signature is used and the method must be static.signature- alternative for method signature, can be null if method is set
-
calculateVariables
protected void calculateVariables()Calculate the index of the variables -
addLoadStoreInstruction
protected void addLoadStoreInstruction(AnyType valueType, boolean load, @Nonnegative int javaIdx, int javaCodePos, int lineNumber) Create a WasmLoadStoreInstruction.- Parameters:
valueType- the value typeload- true: if loadjavaIdx- the memory/slot index of the variable in Java byte codejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addLocalInstruction
protected void addLocalInstruction(VariableOperator op, @Nonnegative int wasmIdx, int javaCodePos, int lineNumber) Create a WasmLoadStoreInstruction local.get/local.set.- Parameters:
op- the operationwasmIdx- the index of the variablejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addDupInstruction
protected void addDupInstruction(boolean dup2, int javaCodePos, int lineNumber) Create a WasmDupInstruction.- Parameters:
dup2- call from dup2 instructionjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addDupX1Instruction
protected void addDupX1Instruction(int javaCodePos, int lineNumber) Simulate the dup_x1 Java byte code instruction...., value2, value1 → ..., value1, value2, value1
- Parameters:
javaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addDupX2Instruction
protected void addDupX2Instruction(int javaCodePos, int lineNumber) Simulate the dup_x2 Java byte code instruction...., value3, value2, value1 → ..., value1, value3, value2, value1
- Parameters:
javaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addGlobalInstruction
Add a global instruction- Parameters:
load- true: if loadref- reference to a static fieldjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addGlobalInstruction
protected void addGlobalInstruction(boolean load, FunctionName name, AnyType type, FunctionName clinit, int javaCodePos, int lineNumber) Add a global instruction- Parameters:
load- true: if loadname- reference to a static fieldtype- the type of the static fieldclinit- a reference to the class/static constructor which should executed before access a static fieldjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addTableInstruction
protected void addTableInstruction(boolean load, @Nonnegative int idx, int javaCodePos, int lineNumber) Add a WasmTableInstruction table.get/table.set.- Parameters:
load- true: if loadidx- the index of the tablejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addConstInstruction
-
addConstInstruction
Add a constant instruction with unknown value type.- Parameters:
value- the valuejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addNumericInstruction
protected de.inetsoftware.jwebassembly.module.WasmNumericInstruction addNumericInstruction(@Nullable NumericOperator numOp, @Nullable ValueType valueType, int javaCodePos, int lineNumber) Add a numeric operation instruction- Parameters:
numOp- the operationvalueType- the value typejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code- Returns:
- the added instruction
-
addConvertInstruction
protected void addConvertInstruction(ValueTypeConvertion conversion, int javaCodePos, int lineNumber) Add a value convert/cast instruction.- Parameters:
conversion- the conversionjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addCallInstruction
protected void addCallInstruction(FunctionName name, boolean needThisParameter, int javaCodePos, int lineNumber) Add a static function call.- Parameters:
name- the function name that should be calledneedThisParameter- true, if the hidden THIS parameter is needed, If it is an instance method call.javaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addCallVirtualInstruction
Add a virtual/method function call.- Parameters:
name- the function name that should be calledjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addCallInterfaceInstruction
Add interface function call- Parameters:
name- the function name that should be calledjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addBlockInstruction
protected void addBlockInstruction(WasmBlockOperator op, @Nullable Object data, int javaCodePos, int lineNumber) Add a block operation.- Parameters:
op- the operationdata- extra data for some operationsjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addNopInstruction
protected void addNopInstruction(int javaCodePos, int lineNumber) Add a no operation to the instruction list as marker on the code position. This instruction will not be write to the output.- Parameters:
javaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addJumpPlaceholder
protected void addJumpPlaceholder(int jumpPos, int popCount, AnyType pushValueType, int javaCodePos, int lineNumber) Add a Jump instruction for later stack inspection- Parameters:
jumpPos- the position of the jumppopCount- the the count of values that are removed from the stack.pushValueType- optional type of a push valuejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addArrayInstruction
protected void addArrayInstruction(@Nonnull ArrayOperator op, @Nonnull AnyType type, int javaCodePos, int lineNumber) Add an array operation to the instruction list as marker on the code position.- Parameters:
op- the operationtype- the array/component type of the arrayjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addMultiNewArrayInstruction
protected void addMultiNewArrayInstruction(int dim, String typeName, int javaCodePos, int lineNumber) Add a new multi dimensional array instruction- Parameters:
dim- the dimension of the array >= 2typeName- the full type namejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addMultiNewArrayInstruction
protected void addMultiNewArrayInstruction(int dim, ArrayType type, int javaCodePos, int lineNumber) Add a new multi dimensional array instruction- Parameters:
dim- the dimension of the array >= 2type- the full typejavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addStructInstruction
protected void addStructInstruction(StructOperator op, @Nonnull String typeName, @Nullable NamedStorageType fieldName, int javaCodePos, int lineNumber) Add a struct/object operation to the instruction list.- Parameters:
op- the operationtypeName- the type name like "java/lang/Object"fieldName- the name of field if needed for the operationjavaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addInvokeDynamic
protected void addInvokeDynamic(BootstrapMethod method, String factorySignature, String interfaceMethodName, int javaCodePos, int lineNumber) Add invoke dynamic operation. (Creating of a lambda expression)- Parameters:
method- the BootstrapMethod, described the method that should be executedfactorySignature- Get the signature of the factory method. For example "()Ljava.lang.Runnable;" for the lamba expressionRunnable run = () -> foo();interfaceMethodName- The simple name of the generated method of the single function interface.javaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-
addMemoryInstruction
protected void addMemoryInstruction(MemoryOperator op, ValueType type, int offset, int alignment, int javaCodePos, int lineNumber) Create an instance of a load/store to the linear memory instruction- Parameters:
op- the operationtype- the type of the static fieldoffset- the base offset which will be added to the offset value on the stackalignment- the alignment of the value on the linear memory (0: 8 Bit; 1: 16 Bit; 2: 32 Bit)javaCodePos- the code position/offset in the Java methodlineNumber- the line number in the Java source code
-