mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
normalization the local instruction
This commit is contained in:
parent
80e922fa26
commit
ff345e68c2
@ -35,7 +35,7 @@ abstract class WasmInstruction {
|
||||
* Type of instruction to faster differ as with instanceof.
|
||||
*/
|
||||
static enum Type {
|
||||
LoadStore, Const, Convert, Local, Global, Block, Numeric, Nop, Call, Array, Struct;
|
||||
Const, Convert, Local, Global, Block, Numeric, Nop, Call, Array, Struct;
|
||||
}
|
||||
|
||||
private int javaCodePos;
|
||||
|
@ -16,12 +16,8 @@
|
||||
*/
|
||||
package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
|
||||
/**
|
||||
@ -30,11 +26,7 @@ import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
* @author Volker Berlin
|
||||
*
|
||||
*/
|
||||
class WasmLoadStoreInstruction extends WasmInstruction {
|
||||
|
||||
private boolean load;
|
||||
|
||||
private int idx;
|
||||
class WasmLoadStoreInstruction extends WasmLocalInstruction {
|
||||
|
||||
private LocaleVariableManager localVariables;
|
||||
|
||||
@ -51,9 +43,7 @@ class WasmLoadStoreInstruction extends WasmInstruction {
|
||||
* the code position/offset in the Java method
|
||||
*/
|
||||
WasmLoadStoreInstruction( boolean load, @Nonnegative int idx, LocaleVariableManager localVariables, int javaCodePos ) {
|
||||
super( javaCodePos );
|
||||
this.load = load;
|
||||
this.idx = idx;
|
||||
super( load, idx, javaCodePos );
|
||||
this.localVariables = localVariables;
|
||||
}
|
||||
|
||||
@ -61,34 +51,14 @@ class WasmLoadStoreInstruction extends WasmInstruction {
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.LoadStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
int index = localVariables.get( idx ); // translate slot index to position index
|
||||
if( load ) {
|
||||
writer.writeLoad( index );
|
||||
} else {
|
||||
writer.writeStore( index );
|
||||
}
|
||||
int getIndex() {
|
||||
return localVariables.get( super.getIndex() ); // translate slot index to position index
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
AnyType getPushValueType() {
|
||||
return load ? localVariables.getValueType( idx ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
int getPopCount() {
|
||||
return load ? 0 : 1;
|
||||
return getPopCount() == 0 ? localVariables.getValueType( super.getIndex() ) : null;
|
||||
}
|
||||
}
|
||||
|
@ -60,14 +60,25 @@ class WasmLocalInstruction extends WasmInstruction {
|
||||
return Type.Local;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of the locals
|
||||
*
|
||||
* @return the index
|
||||
*/
|
||||
@Nonnegative
|
||||
int getIndex() {
|
||||
return idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||
int index = getIndex();
|
||||
if( load ) {
|
||||
writer.writeLoad( idx );
|
||||
writer.writeLoad( index );
|
||||
} else {
|
||||
writer.writeStore( idx );
|
||||
writer.writeStore( index );
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user