mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Add method getPushValueType()
This commit is contained in:
parent
d3e80bf709
commit
cd8dd10182
@ -145,6 +145,17 @@ class LocaleVariableManager {
|
||||
return variables[slot].idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ValueType of the variable.
|
||||
*
|
||||
* @param slot
|
||||
* the memory/slot index of the local variable in Java
|
||||
* @return the ValueType
|
||||
*/
|
||||
ValueType getValueType( int slot ) {
|
||||
return variables[slot].valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that there is enough capacity.
|
||||
*
|
||||
|
@ -55,4 +55,11 @@ class WasmBlockInstruction extends WasmInstruction {
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
writer.writeBlockCode( op, data );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
return op == WasmBlockOperator.IF && data != ValueType.empty ? (ValueType)data : null;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,9 @@ import de.inetsoftware.classparser.ConstantRef;
|
||||
*/
|
||||
class WasmCallInstruction extends WasmInstruction {
|
||||
|
||||
private final String name;
|
||||
private final String name;
|
||||
|
||||
private final ValueType valueType;
|
||||
|
||||
/**
|
||||
* Create an instance of a function call instruction
|
||||
@ -43,6 +45,8 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
WasmCallInstruction( ConstantRef method, int javaCodePos ) {
|
||||
super( javaCodePos );
|
||||
this.name = new FunctionName( method ).signatureName;
|
||||
String signature = method.getType();
|
||||
this.valueType = ModuleGenerator.getValueType( signature, signature.indexOf( ')' ) + 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,4 +55,12 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
writer.writeFunctionCall( name );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
return valueType;
|
||||
}
|
||||
}
|
||||
|
@ -92,4 +92,11 @@ class WasmConstInstruction extends WasmInstruction {
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
writer.writeConst( value, valueType );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
return valueType;
|
||||
}
|
||||
}
|
||||
|
@ -47,4 +47,33 @@ class WasmConvertInstruction extends WasmInstruction {
|
||||
public void writeTo( ModuleWriter writer ) throws IOException {
|
||||
writer.writeCast( conversion );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
switch( conversion ) {
|
||||
case l2i:
|
||||
case f2i:
|
||||
case d2i:
|
||||
case i2b:
|
||||
case i2c:
|
||||
case i2s:
|
||||
return ValueType.i32;
|
||||
case i2l:
|
||||
case f2l:
|
||||
case d2l:
|
||||
return ValueType.i64;
|
||||
case i2f:
|
||||
case l2f:
|
||||
case d2f:
|
||||
return ValueType.f32;
|
||||
case i2d:
|
||||
case l2d:
|
||||
case f2d:
|
||||
return ValueType.f64;
|
||||
default:
|
||||
throw new Error( conversion.toString() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ package de.inetsoftware.jwebassembly.module;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Base class of all WasmInstruction.
|
||||
@ -65,4 +66,12 @@ abstract class WasmInstruction {
|
||||
void setCodePosition( int newPos ) {
|
||||
this.javaCodePos = newPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ValueType if this instruction push a value on the stack.
|
||||
*
|
||||
* @return the ValueType or null if no value is push
|
||||
*/
|
||||
@Nullable
|
||||
abstract ValueType getPushValueType();
|
||||
}
|
||||
|
@ -58,11 +58,18 @@ class WasmLoadStoreInstruction extends WasmInstruction {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
idx = localVariables.get( idx ); // translate slot index to position index
|
||||
int index = localVariables.get( idx ); // translate slot index to position index
|
||||
if( load ) {
|
||||
writer.writeLoad( idx );
|
||||
writer.writeLoad( index );
|
||||
} else {
|
||||
writer.writeStore( idx );
|
||||
writer.writeStore( index );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
return load ? localVariables.getValueType( idx ) : null;
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,11 @@ class WasmNopInstruction extends WasmInstruction {
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
// nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -55,4 +55,11 @@ class WasmNumericInstruction extends WasmInstruction {
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
writer.writeNumericOperator( numOp, valueType );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
ValueType getPushValueType() {
|
||||
return valueType;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user