public class TextModuleWriter extends ModuleWriter
dataStream, options| Constructor and Description |
|---|
TextModuleWriter(WasmTarget target,
WasmOptions options)
Create a 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.
|
getStringCountpublic TextModuleWriter(WasmTarget target, WasmOptions options) throws java.io.IOException
target - target for the resultoptions - compiler propertiesjava.io.IOException - if any I/O error occurpublic void close()
throws java.io.IOException
java.io.IOExceptionprotected int writeStructType(TypeManager.StructType type) throws java.io.IOException
writeStructType in class ModuleWritertype - the type to declare/writejava.io.IOException - if any I/O error occurprotected void writeException()
throws java.io.IOException
writeException in class ModuleWriterjava.io.IOException - if any I/O error occurprotected void prepareFinish()
prepareFinish in class ModuleWriterprotected void prepareImport(FunctionName name, java.lang.String importModule, java.lang.String importName) throws java.io.IOException
prepareImport in class ModuleWritername - 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 void writeExport(FunctionName name, java.lang.String exportName) throws java.io.IOException
writeExport in class ModuleWritername - 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(@Nonnull
FunctionName name)
throws java.io.IOException
writeMethodParamStart in class ModuleWritername - 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 ModuleWriterkind - "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(@Nonnull
FunctionName name)
throws java.io.IOException
writeMethodParamFinish in class ModuleWritername - 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 ModuleWritername - the function namesourceFile - the name of the source filejava.io.IOException - if any I/O error occurprotected void markSourceLine(int javaSourceLine)
markSourceLine in class ModuleWriterjavaSourceLine - the line number in the Java codeprotected void writeMethodFinish()
throws java.io.IOException
writeMethodFinish in class ModuleWriterjava.io.IOException - if any I/O error occurprotected void writeConst(java.lang.Number value,
ValueType valueType)
throws java.io.IOException
writeConst in class ModuleWritervalue - 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 ModuleWriterop - 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 ModuleWriterload - 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 ModuleWriterload - 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 ModuleWritertype - 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 ModuleWriternumOp - 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 ModuleWritercast - the operatorjava.io.IOException - if any I/O error occurprotected void writeFunctionCall(FunctionName name) throws java.io.IOException
writeFunctionCall in class ModuleWritername - the function namejava.io.IOException - if any I/O error occurprotected void writeVirtualFunctionCall(FunctionName name, AnyType type) throws java.io.IOException
writeVirtualFunctionCall in class ModuleWritername - 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 ModuleWriterop - 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 ModuleWriterop - 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 ModuleWriterop - 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 ModuleWritermemOp - 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