mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
write string constant in the text format for easer reading
This commit is contained in:
parent
63384e359a
commit
548d701444
@ -992,7 +992,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
if( options.useGC() ) {
|
||||
op = REF_EQ;
|
||||
} else {
|
||||
writeFunctionCall( options.ref_eq );
|
||||
writeFunctionCall( options.ref_eq, null );
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -1000,7 +1000,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
if( options.useGC() ) {
|
||||
codeStream.writeOpCode( REF_EQ );
|
||||
} else {
|
||||
writeFunctionCall( options.ref_eq );
|
||||
writeFunctionCall( options.ref_eq, null );
|
||||
}
|
||||
op = I32_EQZ;
|
||||
break;
|
||||
@ -1161,7 +1161,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeFunctionCall( FunctionName name ) throws IOException {
|
||||
protected void writeFunctionCall( FunctionName name, String comments ) throws IOException {
|
||||
Function func = getFunction( name );
|
||||
codeStream.writeOpCode( CALL );
|
||||
codeStream.writeVaruint32( func.id );
|
||||
|
@ -267,10 +267,12 @@ public abstract class ModuleWriter implements Closeable {
|
||||
*
|
||||
* @param name
|
||||
* the function name
|
||||
* @param comment
|
||||
* optional comment for the text format
|
||||
* @throws IOException
|
||||
* if any I/O error occur
|
||||
*/
|
||||
protected abstract void writeFunctionCall( FunctionName name ) throws IOException;
|
||||
protected abstract void writeFunctionCall( FunctionName name, String comment ) throws IOException;
|
||||
|
||||
/**
|
||||
* Write a function call to an instance function. On the stack there must be the object.
|
||||
|
@ -42,6 +42,8 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
|
||||
private final boolean needThisParameter;
|
||||
|
||||
private final String comment;
|
||||
|
||||
/**
|
||||
* Create an instance of a function call instruction
|
||||
*
|
||||
@ -57,10 +59,31 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
* true, if this function need additional to the parameter of the signature an extra "this" parameter
|
||||
*/
|
||||
WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, @Nonnull TypeManager types, boolean needThisParameter ) {
|
||||
this( name, javaCodePos, lineNumber, types, needThisParameter, null );
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of a function call instruction
|
||||
*
|
||||
* @param name
|
||||
* the function name that should be called
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
* @param lineNumber
|
||||
* the line number in the Java source code
|
||||
* @param types
|
||||
* the type manager
|
||||
* @param needThisParameter
|
||||
* true, if this function need additional to the parameter of the signature an extra "this" parameter
|
||||
* @param comment
|
||||
* optional comment for the text format
|
||||
*/
|
||||
WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, @Nonnull TypeManager types, boolean needThisParameter, String comment ) {
|
||||
super( javaCodePos, lineNumber );
|
||||
this.name = name;
|
||||
this.types = types;
|
||||
this.needThisParameter = needThisParameter;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,7 +116,7 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
writer.writeFunctionCall( name );
|
||||
writer.writeFunctionCall( name, comment );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,7 @@ class WasmCallVirtualInstruction extends WasmCallIndirectInstruction {
|
||||
writer.writeLocal( VariableOperator.get, getVariableIndexOfThis() );
|
||||
|
||||
writer.writeConst( virtualFunctionIdx * 4, ValueType.i32 );
|
||||
writer.writeFunctionCall( options.getCallVirtual() );
|
||||
writer.writeFunctionCall( options.getCallVirtual(), null );
|
||||
StructType type = getThisType();
|
||||
writer.writeVirtualFunctionCall( getFunctionName(), type );
|
||||
}
|
||||
|
@ -398,7 +398,7 @@ public abstract class WasmCodeBuilder {
|
||||
Integer id = strings.get( value );
|
||||
FunctionName name = strings.getStringConstantFunction();
|
||||
instructions.add( new WasmConstInstruction( id, ValueType.i32, javaCodePos, lineNumber ) );
|
||||
addCallInstruction( name, javaCodePos, lineNumber );
|
||||
instructions.add( new WasmCallInstruction( name, javaCodePos, lineNumber, types, false, "\"" + value + "\"" ) );
|
||||
} else if( value instanceof Number ) {
|
||||
instructions.add( new WasmConstInstruction( (Number)value, javaCodePos, lineNumber ) );
|
||||
} else if( value instanceof ConstantClass ) {
|
||||
|
@ -188,7 +188,7 @@ class WasmStructInstruction extends WasmInstruction {
|
||||
if( fieldName != null ) {
|
||||
writer.writeConst( idx, ValueType.i32 );
|
||||
}
|
||||
writer.writeFunctionCall( functionName );
|
||||
writer.writeFunctionCall( functionName, null );
|
||||
} else {
|
||||
writer.writeStructOperator( op, type, fieldName, idx );
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
newline( methodOutput );
|
||||
methodOutput.append( op );
|
||||
} else {
|
||||
writeFunctionCall( options.ref_eq );
|
||||
writeFunctionCall( options.ref_eq, null );
|
||||
}
|
||||
if( negate ) {
|
||||
writeNumericOperator( NumericOperator.eqz, ValueType.i32 );
|
||||
@ -685,9 +685,12 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeFunctionCall( FunctionName name ) throws IOException {
|
||||
protected void writeFunctionCall( FunctionName name, String comments ) throws IOException {
|
||||
newline( methodOutput );
|
||||
methodOutput.append( "call $" ).append( normalizeName( name ) );
|
||||
if( comments != null ) {
|
||||
methodOutput.append( ") ;; " ).append( comments );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -701,7 +704,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
if(spiderMonkey)
|
||||
methodOutput.append( "call_indirect $t" ).append( getFunction( name ).typeId ); // https://bugzilla.mozilla.org/show_bug.cgi?id=1556779
|
||||
else
|
||||
methodOutput.append( "call_indirect (type $t" ).append( getFunction( name ).typeId ).append( ") ;; " + name.signatureName );
|
||||
methodOutput.append( "call_indirect (type $t" ).append( getFunction( name ).typeId ).append( ") ;; " ).append( name.signatureName );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user