Add getPopCount()

This commit is contained in:
Volker 2018-08-10 18:25:38 +02:00
parent cd8dd10182
commit b78e6054c6
8 changed files with 92 additions and 4 deletions

View File

@ -62,4 +62,12 @@ class WasmBlockInstruction extends WasmInstruction {
ValueType getPushValueType() {
return op == WasmBlockOperator.IF && data != ValueType.empty ? (ValueType)data : null;
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
return 0;
}
}

View File

@ -30,7 +30,7 @@ import de.inetsoftware.classparser.ConstantRef;
*/
class WasmCallInstruction extends WasmInstruction {
private final String name;
private final ConstantRef method;
private final ValueType valueType;
@ -44,7 +44,7 @@ class WasmCallInstruction extends WasmInstruction {
*/
WasmCallInstruction( ConstantRef method, int javaCodePos ) {
super( javaCodePos );
this.name = new FunctionName( method ).signatureName;
this.method = method;
String signature = method.getType();
this.valueType = ModuleGenerator.getValueType( signature, signature.indexOf( ')' ) + 1 );
}
@ -53,7 +53,7 @@ class WasmCallInstruction extends WasmInstruction {
* {@inheritDoc}
*/
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
writer.writeFunctionCall( name );
writer.writeFunctionCall( new FunctionName( method ).signatureName );
}
@ -63,4 +63,22 @@ class WasmCallInstruction extends WasmInstruction {
ValueType getPushValueType() {
return valueType;
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
String signature = method.getType();
int paramCount = 0;
ValueType type = null;
for( int i = 1; i < signature.length(); i++ ) {
if( signature.charAt( i ) == ')' ) {
return paramCount;
}
paramCount++;
ModuleGenerator.getValueType( signature, i );
}
throw new Error();
}
}

View File

@ -99,4 +99,12 @@ class WasmConstInstruction extends WasmInstruction {
ValueType getPushValueType() {
return valueType;
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
return 0;
}
}

View File

@ -76,4 +76,12 @@ class WasmConvertInstruction extends WasmInstruction {
throw new Error( conversion.toString() );
}
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
return 1;
}
}

View File

@ -74,4 +74,11 @@ abstract class WasmInstruction {
*/
@Nullable
abstract ValueType getPushValueType();
/**
* Get the count of values that are removed from the stack.
*
* @return the count
*/
abstract int getPopCount();
}

View File

@ -72,4 +72,12 @@ class WasmLoadStoreInstruction extends WasmInstruction {
ValueType getPushValueType() {
return load ? localVariables.getValueType( idx ) : null;
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
return load ? 0 : 1;
}
}

View File

@ -51,4 +51,12 @@ class WasmNopInstruction extends WasmInstruction {
ValueType getPushValueType() {
return null;
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
return 0;
}
}

View File

@ -60,6 +60,29 @@ class WasmNumericInstruction extends WasmInstruction {
* {@inheritDoc}
*/
ValueType getPushValueType() {
return valueType;
switch( numOp ) {
case eq:
case ne:
case gt:
case lt_s:
case le_s:
case ge_s:
return null;
default:
return valueType;
}
}
/**
* {@inheritDoc}
*/
@Override
int getPopCount() {
switch( numOp ) {
case neg:
return 1;
default:
return 2;
}
}
}