public abstract class ModuleWriter
extends java.lang.Object
implements java.io.Closeable
Modifier and Type | Field and Description |
---|---|
protected java.io.ByteArrayOutputStream |
dataStream
The stream of the data section for constant data like strings and vtables
|
protected WasmOptions |
options
The compiler options.
|
Modifier | Constructor and Description |
---|---|
protected |
ModuleWriter(WasmOptions options)
Create a instance with its options.
|
Modifier and Type | Method and Description |
---|---|
protected int |
getStringCount()
Get the string count
|
protected abstract void |
markSourceLine(int javaSourceLine)
Mark the current output position with Java code position for crating of a source map.
|
protected abstract void |
prepareFinish()
Finish the prepare after all classes/methods are prepare.
|
protected abstract void |
prepareImport(FunctionName name,
java.lang.String importModule,
java.lang.String importName)
Prepare a imported single function in the prepare phase.
|
protected abstract void |
writeArrayOperator(ArrayOperator op,
AnyType type)
Write an array operation.
|
protected abstract void |
writeBlockCode(WasmBlockOperator op,
java.lang.Object data)
Write a block/branch code
|
protected abstract void |
writeCast(ValueTypeConvertion cast)
Cast a value from one type to another
|
protected abstract void |
writeConst(java.lang.Number value,
ValueType valueType)
Write a constant number value
|
protected abstract void |
writeDefaultValue(AnyType type)
Write the default/initial value for a type.
|
protected abstract void |
writeException()
Mark to write exceptions
|
protected abstract void |
writeExport(FunctionName name,
java.lang.String exportName)
Write an export directive
|
protected abstract void |
writeFunctionCall(FunctionName name)
Write a call to a function.
|
protected abstract void |
writeGlobalAccess(boolean load,
FunctionName name,
AnyType type)
Write a global variable operation
|
protected abstract void |
writeLocal(VariableOperator op,
int idx)
Write a local variable operation.
|
protected abstract void |
writeMemoryOperator(MemoryOperator memOp,
ValueType valueType,
int offset,
int alignment)
Write a memory operation for the linear memory.
|
protected abstract void |
writeMethodFinish()
Complete the method
|
protected abstract void |
writeMethodParam(java.lang.String kind,
AnyType valueType,
java.lang.String name)
Write a method parameter.
|
protected abstract void |
writeMethodParamFinish(FunctionName name)
Finish the function parameter.
|
protected abstract void |
writeMethodParamStart(FunctionName name)
Write the method header.
|
protected abstract void |
writeMethodStart(FunctionName name,
java.lang.String sourceFile)
Write the method header.
|
protected abstract void |
writeNumericOperator(NumericOperator numOp,
ValueType valueType)
Write a add operator
|
protected abstract void |
writeStructOperator(StructOperator op,
AnyType type,
NamedStorageType fieldName,
int idx)
Write a struct operation
|
protected abstract int |
writeStructType(TypeManager.StructType type)
Write a type/struct.
|
protected abstract void |
writeTable(boolean load,
int idx)
Write a table operation.
|
protected abstract void |
writeVirtualFunctionCall(FunctionName name,
AnyType type)
Write a function call to an instance function.
|
protected final WasmOptions options
protected final java.io.ByteArrayOutputStream dataStream
protected ModuleWriter(WasmOptions options)
options
- the compiler optionsprotected int getStringCount()
protected abstract void prepareFinish()
protected abstract int writeStructType(TypeManager.StructType type) throws java.io.IOException
type
- the type to declare/writejava.io.IOException
- if any I/O error occurprotected abstract void writeException() throws java.io.IOException
java.io.IOException
- if any I/O error occurprotected abstract void prepareImport(FunctionName name, java.lang.String importModule, java.lang.String importName) throws java.io.IOException
name
- the function nameimportModule
- the import module name if it is a import functionimportName
- the import name if it is a import functionjava.io.IOException
- if any I/O error occurprotected abstract void writeExport(FunctionName name, java.lang.String exportName) throws java.io.IOException
name
- the function nameexportName
- the export name, if null then the same like the method namejava.io.IOException
- if any I/O error occurprotected abstract void writeMethodParamStart(@Nonnull FunctionName name) throws java.io.IOException
name
- the function namejava.io.IOException
- if any I/O error occurprotected abstract void writeMethodParam(java.lang.String kind, AnyType valueType, @Nullable java.lang.String name) throws java.io.IOException
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 abstract void writeMethodParamFinish(@Nonnull FunctionName name) throws java.io.IOException
name
- the function namejava.io.IOException
- if any I/O error occurprotected abstract void writeMethodStart(FunctionName name, java.lang.String sourceFile) throws java.io.IOException
name
- the function namesourceFile
- the name of the source filejava.io.IOException
- if any I/O error occurprotected abstract void markSourceLine(int javaSourceLine)
javaSourceLine
- the line number in the Java codeprotected abstract void writeMethodFinish() throws java.io.IOException
java.io.IOException
- if any I/O error occurprotected abstract void writeConst(java.lang.Number value, ValueType valueType) throws java.io.IOException
value
- the valuevalueType
- the data type of the numberjava.io.IOException
- if any I/O error occurprotected abstract void writeLocal(VariableOperator op, int idx) throws java.io.IOException
op
- the operationidx
- the index of the parameter variablejava.io.IOException
- if any I/O error occurprotected abstract void writeGlobalAccess(boolean load, FunctionName name, AnyType type) throws java.io.IOException
load
- true: if load or GETname
- the variable nametype
- the type of the variablejava.io.IOException
- if any I/O error occurprotected abstract void writeTable(boolean load, @Nonnegative int idx) throws java.io.IOException
load
- true: if "get" else "set"idx
- the index of the tablejava.io.IOException
- if any I/O error occurprotected abstract void writeDefaultValue(AnyType type) throws java.io.IOException
type
- the typejava.io.IOException
- if an I/O error occurs.protected abstract void writeNumericOperator(NumericOperator numOp, @Nullable ValueType valueType) throws java.io.IOException
numOp
- the numeric operationvalueType
- the type of the parametersjava.io.IOException
- if any I/O error occurprotected abstract void writeCast(ValueTypeConvertion cast) throws java.io.IOException
cast
- the operatorjava.io.IOException
- if any I/O error occurprotected abstract void writeFunctionCall(FunctionName name) throws java.io.IOException
name
- the function namejava.io.IOException
- if any I/O error occurprotected abstract void writeVirtualFunctionCall(FunctionName name, AnyType type) throws java.io.IOException
name
- the function nametype
- the base type that should be calledjava.io.IOException
- if any I/O error occurprotected abstract void writeBlockCode(@Nonnull WasmBlockOperator op, @Nullable java.lang.Object data) throws java.io.IOException
op
- the operationdata
- extra data depending of the operatorjava.io.IOException
- if any I/O error occurprotected abstract void writeArrayOperator(@Nonnull ArrayOperator op, AnyType type) throws java.io.IOException
op
- the operationtype
- the resulting typejava.io.IOException
- if any I/O error occurprotected abstract void writeStructOperator(StructOperator op, AnyType type, NamedStorageType fieldName, int idx) throws java.io.IOException
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 abstract void writeMemoryOperator(MemoryOperator memOp, ValueType valueType, int offset, int alignment) throws java.io.IOException
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