use needThisParameter for popCount of method calls

This commit is contained in:
Volker Berlin 2020-01-11 21:48:04 +01:00
parent f87e1c6519
commit 4377db747d
3 changed files with 15 additions and 17 deletions

View File

@ -59,7 +59,7 @@ class WasmCallIndirectInstruction extends WasmCallInstruction {
* compiler properties
*/
WasmCallIndirectInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types, WasmOptions options ) {
super( name, javaCodePos, lineNumber, types );
super( name, javaCodePos, lineNumber, types, true );
this.type = types.valueOf( name.className );
this.options = options;
}
@ -128,12 +128,4 @@ class WasmCallIndirectInstruction extends WasmCallInstruction {
writer.writeVirtualFunctionCall( getFunctionName(), type );
}
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
return super.getPopCount() + 1; // this -> +1
}
}

View File

@ -31,13 +31,15 @@ import de.inetsoftware.jwebassembly.wasm.AnyType;
*/
class WasmCallInstruction extends WasmInstruction {
private AnyType valueType;
private AnyType valueType;
private FunctionName name;
private FunctionName name;
private int paramCount = -1;
private int paramCount = -1;
private TypeManager types;
private final TypeManager types;
private final boolean needThisParameter;
/**
* Create an instance of a function call instruction
@ -50,11 +52,14 @@ class WasmCallInstruction extends WasmInstruction {
* 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
*/
WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types ) {
WasmCallInstruction( FunctionName name, int javaCodePos, int lineNumber, TypeManager types, boolean needThisParameter ) {
super( javaCodePos, lineNumber );
this.name = name;
this.types = types;
this.needThisParameter = needThisParameter;
}
/**
@ -117,7 +122,7 @@ class WasmCallInstruction extends WasmInstruction {
return;
}
Iterator<AnyType> parser = name.getSignature( types );
paramCount = name.methodName.equals( "<init>" ) ? 1 : 0;
paramCount = needThisParameter ? 1 : 0;
while( parser.next() != null ) {
paramCount++;
}

View File

@ -421,7 +421,8 @@ public abstract class WasmCodeBuilder {
* the line number in the Java source code
*/
protected void addCallInstruction( FunctionName name, int javaCodePos, int lineNumber ) {
WasmCallInstruction instruction = new WasmCallInstruction( name, javaCodePos, lineNumber, types );
boolean needThisParameter = functions.needThisParameter( name );
WasmCallInstruction instruction = new WasmCallInstruction( name, javaCodePos, lineNumber, types, needThisParameter );
if( "<init>".equals( name.methodName ) ) {
// check if there a factory for the constructor in JavaScript then we need to do some more complex patching
@ -459,7 +460,7 @@ public abstract class WasmCodeBuilder {
}
}
// the new instruction
instruction = new WasmCallInstruction( factoryName, javaCodePos, lineNumber, types );
instruction = new WasmCallInstruction( factoryName, javaCodePos, lineNumber, types, false );
}
}