public class BinaryModuleWriter extends ModuleWriter
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY_GET |
static int |
ARRAY_LEN |
static int |
ARRAY_NEW |
static int |
ARRAY_SET |
static int |
BLOCK |
static int |
BR
Break a block/loop
sequence: BR {call deep} call deep: How many blocks are break. |
static int |
BR_IF |
static int |
BR_ON_EXN |
static int |
BR_TABLE
- br_table
- target_count - count of entries in the table
- target_table - levels of block breaks
- default_target - levels of block breaks for default value
|
static int |
CALL |
static int |
CALL_INDIRECT |
static int |
CATCH |
static int |
DROP |
static int |
ELSE |
static int |
END |
static int |
F32_ABS |
static int |
F32_ADD |
static int |
F32_CEIL |
static int |
F32_CONST |
static int |
F32_CONVERT_I32_S |
static int |
F32_CONVERT_I32_U |
static int |
F32_CONVERT_I64_S |
static int |
F32_CONVERT_I64_U |
static int |
F32_COPYSIGN |
static int |
F32_DEMOTE_F64 |
static int |
F32_DIV |
static int |
F32_EQ |
static int |
F32_FLOOR |
static int |
F32_GE |
static int |
F32_GT |
static int |
F32_LE |
static int |
F32_LOAD |
static int |
F32_LT |
static int |
F32_MAX |
static int |
F32_MIN |
static int |
F32_MUL |
static int |
F32_NE |
static int |
F32_NEAREST |
static int |
F32_NEG |
static int |
F32_REINTERPRET_I32 |
static int |
F32_SQRT |
static int |
F32_STORE |
static int |
F32_SUB |
static int |
F32_TRUNC |
static int |
F64_ABS |
static int |
F64_ADD |
static int |
F64_CEIL |
static int |
F64_CONST |
static int |
F64_CONVERT_I32_S |
static int |
F64_CONVERT_I32_U |
static int |
F64_CONVERT_I64_S |
static int |
F64_CONVERT_I64_U |
static int |
F64_COPYSIGN |
static int |
F64_DIV |
static int |
F64_EQ |
static int |
F64_FLOOR |
static int |
F64_GE |
static int |
F64_GT |
static int |
F64_LE |
static int |
F64_LOAD |
static int |
F64_LT |
static int |
F64_MAX |
static int |
F64_MIN |
static int |
F64_MUL |
static int |
F64_NE |
static int |
F64_NEAREST |
static int |
F64_NEG |
static int |
F64_PROMOTE_F32 |
static int |
F64_REINTERPRET_I64 |
static int |
F64_SQRT |
static int |
F64_STORE |
static int |
F64_SUB |
static int |
F64_TRUNC |
static int |
GLOBAL_GET |
static int |
GLOBAL_SET |
static int |
I32_ADD |
static int |
I32_AND |
static int |
I32_CLZ |
static int |
I32_CONST |
static int |
I32_CTZ |
static int |
I32_DIV_S |
static int |
I32_DIV_U |
static int |
I32_EQ |
static int |
I32_EQZ |
static int |
I32_EXTEND16_S |
static int |
I32_EXTEND8_S |
static int |
I32_GE_S |
static int |
I32_GE_U |
static int |
I32_GT_S |
static int |
I32_GT_U |
static int |
I32_LE_S |
static int |
I32_LE_U |
static int |
I32_LOAD |
static int |
I32_LOAD16_S |
static int |
I32_LOAD16_U |
static int |
I32_LOAD8_S |
static int |
I32_LOAD8_U |
static int |
I32_LT_S |
static int |
I32_LT_U |
static int |
I32_MUL |
static int |
I32_NE |
static int |
I32_OR |
static int |
I32_POPCNT |
static int |
I32_REINTERPRET_F32 |
static int |
I32_REM_S |
static int |
I32_REM_U |
static int |
I32_ROTL |
static int |
I32_ROTR |
static int |
I32_SHL |
static int |
I32_SHR_S |
static int |
I32_SHR_U |
static int |
I32_STORE |
static int |
I32_STORE16 |
static int |
I32_STORE8 |
static int |
I32_SUB |
static int |
I32_TRUNC_F32_S |
static int |
I32_TRUNC_F32_U |
static int |
I32_TRUNC_F64_S |
static int |
I32_TRUNC_F64_U |
static int |
I32_TRUNC_SAT_F32_S |
static int |
I32_TRUNC_SAT_F32_U |
static int |
I32_TRUNC_SAT_F64_S |
static int |
I32_TRUNC_SAT_F64_U |
static int |
I32_WRAP_I64 |
static int |
I32_XOR |
static int |
I54_STORE16 |
static int |
I54_STORE32 |
static int |
I54_STORE8 |
static int |
I64_ADD |
static int |
I64_AND |
static int |
I64_CLZ |
static int |
I64_CONST |
static int |
I64_CTZ |
static int |
I64_DIV_S |
static int |
I64_DIV_U |
static int |
I64_EQ |
static int |
I64_EQZ |
static int |
I64_EXTEND_I32_S |
static int |
I64_EXTEND_I32_U |
static int |
I64_EXTEND16_S |
static int |
I64_EXTEND32_S |
static int |
I64_EXTEND8_S |
static int |
I64_GE_S |
static int |
I64_GE_U |
static int |
I64_GT_S |
static int |
I64_GT_U |
static int |
I64_LE_S |
static int |
I64_LE_U |
static int |
I64_LOAD |
static int |
I64_LOAD16_S |
static int |
I64_LOAD16_U |
static int |
I64_LOAD32_S |
static int |
I64_LOAD32_U |
static int |
I64_LOAD8_S |
static int |
I64_LOAD8_U |
static int |
I64_LT_S |
static int |
I64_LT_U |
static int |
I64_MUL |
static int |
I64_NE |
static int |
I64_OR |
static int |
I64_POPCNT |
static int |
I64_REINTERPRET_F64 |
static int |
I64_REM_S |
static int |
I64_REM_U |
static int |
I64_ROTL |
static int |
I64_ROTR |
static int |
I64_SHL |
static int |
I64_SHR_S |
static int |
I64_SHR_U |
static int |
I64_STORE |
static int |
I64_SUB |
static int |
I64_TRUNC_F32_S |
static int |
I64_TRUNC_F32_U |
static int |
I64_TRUNC_F64_S |
static int |
I64_TRUNC_F64_U |
static int |
I64_TRUNC_SAT_F32_S |
static int |
I64_TRUNC_SAT_F32_U |
static int |
I64_TRUNC_SAT_F64_S |
static int |
I64_TRUNC_SAT_F64_U |
static int |
I64_XOR |
static int |
IF
If the value on the stack is true then the if block is executed.
|
static int |
LOCAL_GET |
static int |
LOCAL_SET |
static int |
LOCAL_TEE |
static int |
LOOP |
static int |
MEMORY_GROW |
static int |
MEMORY_SIZE |
static int |
NOP |
static int |
REF_EQ |
static int |
REF_ISNULL |
static int |
REF_NULL |
static int |
RETHROW |
static int |
RETURN |
static int |
RETURN_CALL |
static int |
RETURN_CALL_INDIRECT |
static int |
SELECT
select one of two values based on condition
|
static int |
STRUCT_GET |
static int |
STRUCT_NARROW |
static int |
STRUCT_NEW |
static int |
STRUCT_SET |
static int |
TABLE_FILL |
static int |
TABLE_GET |
static int |
TABLE_GROW |
static int |
TABLE_SET |
static int |
TABLE_SIZE |
static int |
THROW |
static int |
TRY |
static int |
UNREACHABLE |
dataStream, options
Constructor and Description |
---|
BinaryModuleWriter(WasmTarget target,
WasmOptions options)
Create new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
markSourceLine(int javaSourceLine)
Mark the current output position with Java code position for crating of a source map.
|
protected void |
prepareFinish()
Finish the prepare after all classes/methods are prepare.
|
protected void |
prepareImport(FunctionName name,
java.lang.String importModule,
java.lang.String importName)
Prepare a imported single function in the prepare phase.
|
protected void |
writeArrayOperator(ArrayOperator op,
AnyType type)
Write an array operation.
|
protected void |
writeBlockCode(WasmBlockOperator op,
java.lang.Object data)
Write a block/branch code
|
protected void |
writeCast(ValueTypeConvertion cast)
Cast a value from one type to another
|
protected void |
writeConst(java.lang.Number value,
ValueType valueType)
Write a constant number value
|
protected void |
writeDefaultValue(AnyType type)
Write the default/initial value for a type.
|
protected void |
writeException()
Mark to write exceptions
|
protected void |
writeExport(FunctionName name,
java.lang.String exportName)
Write an export directive
|
protected void |
writeFunctionCall(FunctionName name)
Write a call to a function.
|
protected void |
writeGlobalAccess(boolean load,
FunctionName name,
AnyType type)
Write a global variable operation
|
protected void |
writeLocal(VariableOperator op,
int idx)
Write a local variable operation.
|
protected void |
writeMemoryOperator(MemoryOperator memOp,
ValueType valueType,
int offset,
int alignment)
Write a memory operation for the linear memory.
|
protected void |
writeMethodFinish()
Complete the method
|
protected void |
writeMethodParam(java.lang.String kind,
AnyType valueType,
java.lang.String name)
Write a method parameter.
|
protected void |
writeMethodParamFinish(FunctionName name)
Finish the function parameter.
|
protected void |
writeMethodParamStart(FunctionName name)
Write the method header.
|
protected void |
writeMethodStart(FunctionName name,
java.lang.String sourceFile)
Write the method header.
|
protected void |
writeNumericOperator(NumericOperator numOp,
ValueType valueType)
Write a add operator
|
protected void |
writeStructOperator(StructOperator op,
AnyType type,
NamedStorageType fieldName,
int idx)
Write a struct operation
|
protected int |
writeStructType(TypeManager.StructType type)
Write a type/struct.
|
protected void |
writeTable(boolean load,
int idx)
Write a table operation.
|
protected void |
writeVirtualFunctionCall(FunctionName name,
AnyType type)
Write a function call to an instance function.
|
getStringCount
public static final int UNREACHABLE
public static final int NOP
public static final int BLOCK
public static final int LOOP
public static final int IF
public static final int ELSE
public static final int TRY
public static final int CATCH
public static final int THROW
public static final int RETHROW
public static final int BR_ON_EXN
public static final int END
public static final int BR
public static final int BR_IF
public static final int BR_TABLE
public static final int RETURN
public static final int CALL
public static final int CALL_INDIRECT
public static final int RETURN_CALL
public static final int RETURN_CALL_INDIRECT
public static final int DROP
public static final int SELECT
public static final int LOCAL_GET
public static final int LOCAL_SET
public static final int LOCAL_TEE
public static final int GLOBAL_GET
public static final int GLOBAL_SET
public static final int TABLE_GET
public static final int TABLE_SET
public static final int I32_LOAD
public static final int I64_LOAD
public static final int F32_LOAD
public static final int F64_LOAD
public static final int I32_LOAD8_S
public static final int I32_LOAD8_U
public static final int I32_LOAD16_S
public static final int I32_LOAD16_U
public static final int I64_LOAD8_S
public static final int I64_LOAD8_U
public static final int I64_LOAD16_S
public static final int I64_LOAD16_U
public static final int I64_LOAD32_S
public static final int I64_LOAD32_U
public static final int I32_STORE
public static final int I64_STORE
public static final int F32_STORE
public static final int F64_STORE
public static final int I32_STORE8
public static final int I32_STORE16
public static final int I54_STORE8
public static final int I54_STORE16
public static final int I54_STORE32
public static final int MEMORY_SIZE
public static final int MEMORY_GROW
public static final int I32_CONST
public static final int I64_CONST
public static final int F32_CONST
public static final int F64_CONST
public static final int I32_EQZ
public static final int I32_EQ
public static final int I32_NE
public static final int I32_LT_S
public static final int I32_LT_U
public static final int I32_GT_S
public static final int I32_GT_U
public static final int I32_LE_S
public static final int I32_LE_U
public static final int I32_GE_S
public static final int I32_GE_U
public static final int I64_EQZ
public static final int I64_EQ
public static final int I64_NE
public static final int I64_LT_S
public static final int I64_LT_U
public static final int I64_GT_S
public static final int I64_GT_U
public static final int I64_LE_S
public static final int I64_LE_U
public static final int I64_GE_S
public static final int I64_GE_U
public static final int F32_EQ
public static final int F32_NE
public static final int F32_LT
public static final int F32_GT
public static final int F32_LE
public static final int F32_GE
public static final int F64_EQ
public static final int F64_NE
public static final int F64_LT
public static final int F64_GT
public static final int F64_LE
public static final int F64_GE
public static final int I32_CLZ
public static final int I32_CTZ
public static final int I32_POPCNT
public static final int I32_ADD
public static final int I32_SUB
public static final int I32_MUL
public static final int I32_DIV_S
public static final int I32_DIV_U
public static final int I32_REM_S
public static final int I32_REM_U
public static final int I32_AND
public static final int I32_OR
public static final int I32_XOR
public static final int I32_SHL
public static final int I32_SHR_S
public static final int I32_SHR_U
public static final int I32_ROTL
public static final int I32_ROTR
public static final int I64_CLZ
public static final int I64_CTZ
public static final int I64_POPCNT
public static final int I64_ADD
public static final int I64_SUB
public static final int I64_MUL
public static final int I64_DIV_S
public static final int I64_DIV_U
public static final int I64_REM_S
public static final int I64_REM_U
public static final int I64_AND
public static final int I64_OR
public static final int I64_XOR
public static final int I64_SHL
public static final int I64_SHR_S
public static final int I64_SHR_U
public static final int I64_ROTL
public static final int I64_ROTR
public static final int F32_ABS
public static final int F32_NEG
public static final int F32_CEIL
public static final int F32_FLOOR
public static final int F32_TRUNC
public static final int F32_NEAREST
public static final int F32_SQRT
public static final int F32_ADD
public static final int F32_SUB
public static final int F32_MUL
public static final int F32_DIV
public static final int F32_MIN
public static final int F32_MAX
public static final int F32_COPYSIGN
public static final int F64_ABS
public static final int F64_NEG
public static final int F64_CEIL
public static final int F64_FLOOR
public static final int F64_TRUNC
public static final int F64_NEAREST
public static final int F64_SQRT
public static final int F64_ADD
public static final int F64_SUB
public static final int F64_MUL
public static final int F64_DIV
public static final int F64_MIN
public static final int F64_MAX
public static final int F64_COPYSIGN
public static final int I32_WRAP_I64
public static final int I32_TRUNC_F32_S
public static final int I32_TRUNC_F32_U
public static final int I32_TRUNC_F64_S
public static final int I32_TRUNC_F64_U
public static final int I64_EXTEND_I32_S
public static final int I64_EXTEND_I32_U
public static final int I64_TRUNC_F32_S
public static final int I64_TRUNC_F32_U
public static final int I64_TRUNC_F64_S
public static final int I64_TRUNC_F64_U
public static final int F32_CONVERT_I32_S
public static final int F32_CONVERT_I32_U
public static final int F32_CONVERT_I64_S
public static final int F32_CONVERT_I64_U
public static final int F32_DEMOTE_F64
public static final int F64_CONVERT_I32_S
public static final int F64_CONVERT_I32_U
public static final int F64_CONVERT_I64_S
public static final int F64_CONVERT_I64_U
public static final int F64_PROMOTE_F32
public static final int I32_REINTERPRET_F32
public static final int I64_REINTERPRET_F64
public static final int F32_REINTERPRET_I32
public static final int F64_REINTERPRET_I64
public static final int I32_EXTEND8_S
public static final int I32_EXTEND16_S
public static final int I64_EXTEND8_S
public static final int I64_EXTEND16_S
public static final int I64_EXTEND32_S
public static final int REF_NULL
public static final int REF_ISNULL
public static final int REF_EQ
public static final int I32_TRUNC_SAT_F32_S
public static final int I32_TRUNC_SAT_F32_U
public static final int I32_TRUNC_SAT_F64_S
public static final int I32_TRUNC_SAT_F64_U
public static final int I64_TRUNC_SAT_F32_S
public static final int I64_TRUNC_SAT_F32_U
public static final int I64_TRUNC_SAT_F64_S
public static final int I64_TRUNC_SAT_F64_U
public static final int TABLE_GROW
public static final int TABLE_SIZE
public static final int TABLE_FILL
public static final int STRUCT_NEW
public static final int STRUCT_GET
public static final int STRUCT_SET
public static final int STRUCT_NARROW
public static final int ARRAY_NEW
public static final int ARRAY_GET
public static final int ARRAY_SET
public static final int ARRAY_LEN
public BinaryModuleWriter(WasmTarget target, WasmOptions options) throws java.io.IOException
target
- the target for the module data.options
- compiler propertiesjava.io.IOException
- if any I/O error occurpublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
protected int writeStructType(TypeManager.StructType type) throws java.io.IOException
writeStructType
in class ModuleWriter
type
- the type to declare/writejava.io.IOException
- if any I/O error occurprotected void writeException() throws java.io.IOException
writeException
in class ModuleWriter
java.io.IOException
- if any I/O error occurprotected void prepareImport(FunctionName name, java.lang.String importModule, java.lang.String importName)
prepareImport
in class ModuleWriter
name
- the function nameimportModule
- the import module name if it is a import functionimportName
- the import name if it is a import functionprotected void prepareFinish()
prepareFinish
in class ModuleWriter
protected void writeExport(FunctionName name, java.lang.String exportName) throws java.io.IOException
writeExport
in class ModuleWriter
name
- the function nameexportName
- the export name, if null then the same like the method namejava.io.IOException
- if any I/O error occurprotected void writeMethodParamStart(FunctionName name) throws java.io.IOException
writeMethodParamStart
in class ModuleWriter
name
- the function namejava.io.IOException
- if any I/O error occurprotected void writeMethodParam(java.lang.String kind, AnyType valueType, @Nullable java.lang.String name) throws java.io.IOException
writeMethodParam
in class ModuleWriter
kind
- "param", "result" or "local"valueType
- the data type of the parametername
- optional name of the parameterjava.io.IOException
- if any I/O error occurprotected void writeMethodParamFinish(FunctionName name) throws java.io.IOException
writeMethodParamFinish
in class ModuleWriter
name
- the function namejava.io.IOException
- if any I/O error occurprotected void writeMethodStart(FunctionName name, java.lang.String sourceFile) throws java.io.IOException
writeMethodStart
in class ModuleWriter
name
- the function namesourceFile
- the name of the source filejava.io.IOException
- if any I/O error occurprotected void markSourceLine(int javaSourceLine)
markSourceLine
in class ModuleWriter
javaSourceLine
- the line number in the Java codeprotected void writeMethodFinish() throws java.io.IOException
writeMethodFinish
in class ModuleWriter
java.io.IOException
- if any I/O error occurprotected void writeConst(java.lang.Number value, ValueType valueType) throws java.io.IOException
writeConst
in class ModuleWriter
value
- the valuevalueType
- the data type of the numberjava.io.IOException
- if any I/O error occurprotected void writeLocal(VariableOperator op, int idx) throws java.io.IOException
writeLocal
in class ModuleWriter
op
- the operationidx
- the index of the parameter variablejava.io.IOException
- if any I/O error occurprotected void writeGlobalAccess(boolean load, FunctionName name, AnyType type) throws java.io.IOException
writeGlobalAccess
in class ModuleWriter
load
- true: if load or GETname
- the variable nametype
- the type of the variablejava.io.IOException
- if any I/O error occurprotected void writeTable(boolean load, @Nonnegative int idx) throws java.io.IOException
writeTable
in class ModuleWriter
load
- true: if "get" else "set"idx
- the index of the tablejava.io.IOException
- if any I/O error occurprotected void writeDefaultValue(AnyType type) throws java.io.IOException
writeDefaultValue
in class ModuleWriter
type
- the typejava.io.IOException
- if an I/O error occurs.protected void writeNumericOperator(NumericOperator numOp, @Nullable ValueType valueType) throws java.io.IOException
writeNumericOperator
in class ModuleWriter
numOp
- the numeric operationvalueType
- the type of the parametersjava.io.IOException
- if any I/O error occurprotected void writeCast(ValueTypeConvertion cast) throws java.io.IOException
writeCast
in class ModuleWriter
cast
- the operatorjava.io.IOException
- if any I/O error occurprotected void writeFunctionCall(FunctionName name) throws java.io.IOException
writeFunctionCall
in class ModuleWriter
name
- the function namejava.io.IOException
- if any I/O error occurprotected void writeVirtualFunctionCall(FunctionName name, AnyType type) throws java.io.IOException
writeVirtualFunctionCall
in class ModuleWriter
name
- the function nametype
- the base type that should be calledjava.io.IOException
- if any I/O error occurprotected void writeBlockCode(@Nonnull WasmBlockOperator op, @Nullable java.lang.Object data) throws java.io.IOException
writeBlockCode
in class ModuleWriter
op
- the operationdata
- extra data depending of the operatorjava.io.IOException
- if any I/O error occurprotected void writeArrayOperator(@Nonnull ArrayOperator op, AnyType type) throws java.io.IOException
writeArrayOperator
in class ModuleWriter
op
- the operationtype
- the resulting typejava.io.IOException
- if any I/O error occurprotected void writeStructOperator(StructOperator op, AnyType type, NamedStorageType fieldName, int idx) throws java.io.IOException
writeStructOperator
in class ModuleWriter
op
- the operationtype
- the type of the structfieldName
- the fieldName if the operation is per fieldidx
- the index of the field if the operation is per fieldjava.io.IOException
- if any I/O error occurprotected void writeMemoryOperator(MemoryOperator memOp, ValueType valueType, int offset, int alignment) throws java.io.IOException
writeMemoryOperator
in class ModuleWriter
memOp
- the memory operationvalueType
- the value type of the stack valueoffset
- the offset into the memory. Should be ideally a factor of 4.alignment
- the alignment of the value on the linear memory (0: 8 Bit; 1: 16 Bit; 2: 32 Bit)java.io.IOException
- if any I/O error occur