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