mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +01:00
Add getPopCount()
This commit is contained in:
parent
cd8dd10182
commit
b78e6054c6
@ -62,4 +62,12 @@ class WasmBlockInstruction extends WasmInstruction {
|
|||||||
ValueType getPushValueType() {
|
ValueType getPushValueType() {
|
||||||
return op == WasmBlockOperator.IF && data != ValueType.empty ? (ValueType)data : null;
|
return op == WasmBlockOperator.IF && data != ValueType.empty ? (ValueType)data : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int getPopCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ import de.inetsoftware.classparser.ConstantRef;
|
|||||||
*/
|
*/
|
||||||
class WasmCallInstruction extends WasmInstruction {
|
class WasmCallInstruction extends WasmInstruction {
|
||||||
|
|
||||||
private final String name;
|
private final ConstantRef method;
|
||||||
|
|
||||||
private final ValueType valueType;
|
private final ValueType valueType;
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class WasmCallInstruction extends WasmInstruction {
|
|||||||
*/
|
*/
|
||||||
WasmCallInstruction( ConstantRef method, int javaCodePos ) {
|
WasmCallInstruction( ConstantRef method, int javaCodePos ) {
|
||||||
super( javaCodePos );
|
super( javaCodePos );
|
||||||
this.name = new FunctionName( method ).signatureName;
|
this.method = method;
|
||||||
String signature = method.getType();
|
String signature = method.getType();
|
||||||
this.valueType = ModuleGenerator.getValueType( signature, signature.indexOf( ')' ) + 1 );
|
this.valueType = ModuleGenerator.getValueType( signature, signature.indexOf( ')' ) + 1 );
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ class WasmCallInstruction extends WasmInstruction {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
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() {
|
ValueType getPushValueType() {
|
||||||
return valueType;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,4 +99,12 @@ class WasmConstInstruction extends WasmInstruction {
|
|||||||
ValueType getPushValueType() {
|
ValueType getPushValueType() {
|
||||||
return valueType;
|
return valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int getPopCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,4 +76,12 @@ class WasmConvertInstruction extends WasmInstruction {
|
|||||||
throw new Error( conversion.toString() );
|
throw new Error( conversion.toString() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int getPopCount() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,4 +74,11 @@ abstract class WasmInstruction {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
abstract ValueType getPushValueType();
|
abstract ValueType getPushValueType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the count of values that are removed from the stack.
|
||||||
|
*
|
||||||
|
* @return the count
|
||||||
|
*/
|
||||||
|
abstract int getPopCount();
|
||||||
}
|
}
|
||||||
|
@ -72,4 +72,12 @@ class WasmLoadStoreInstruction extends WasmInstruction {
|
|||||||
ValueType getPushValueType() {
|
ValueType getPushValueType() {
|
||||||
return load ? localVariables.getValueType( idx ) : null;
|
return load ? localVariables.getValueType( idx ) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int getPopCount() {
|
||||||
|
return load ? 0 : 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,4 +51,12 @@ class WasmNopInstruction extends WasmInstruction {
|
|||||||
ValueType getPushValueType() {
|
ValueType getPushValueType() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int getPopCount() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,29 @@ class WasmNumericInstruction extends WasmInstruction {
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
ValueType getPushValueType() {
|
ValueType getPushValueType() {
|
||||||
|
switch( numOp ) {
|
||||||
|
case eq:
|
||||||
|
case ne:
|
||||||
|
case gt:
|
||||||
|
case lt_s:
|
||||||
|
case le_s:
|
||||||
|
case ge_s:
|
||||||
|
return null;
|
||||||
|
default:
|
||||||
return valueType;
|
return valueType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
int getPopCount() {
|
||||||
|
switch( numOp ) {
|
||||||
|
case neg:
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user