mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
add getType() to WasmInstruction
This commit is contained in:
parent
5d237c2ae1
commit
bc2975683a
@ -233,8 +233,11 @@ public class ModuleGenerator {
|
||||
writeMethodSignature( name, method.isStatic(), localVariableTable, codeBuilder );
|
||||
|
||||
for( WasmInstruction instruction : codeBuilder.getInstructions() ) {
|
||||
if( instruction instanceof WasmCallInstruction ) {
|
||||
functions.functionCall( ((WasmCallInstruction)instruction).getFunctionName() );
|
||||
switch( instruction.getType() ) {
|
||||
case Call:
|
||||
functions.functionCall( ((WasmCallInstruction)instruction).getFunctionName() );
|
||||
break;
|
||||
default:
|
||||
}
|
||||
instruction.writeTo( writer );
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
@ -54,6 +55,14 @@ class WasmArrayInstruction extends WasmInstruction {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Array;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -52,6 +53,14 @@ class WasmBlockInstruction extends WasmInstruction {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Block;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -54,6 +54,14 @@ class WasmCallInstruction extends WasmInstruction {
|
||||
this.name = new FunctionName( method );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Call;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function name that should be called
|
||||
*
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -63,6 +64,14 @@ class WasmConstInstruction extends WasmInstruction {
|
||||
this( value, getValueType( value ), javaCodePos );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Const;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the matching ValueType for the given value.
|
||||
*
|
||||
|
@ -17,6 +17,7 @@ package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -42,6 +43,14 @@ class WasmConvertInstruction extends WasmInstruction {
|
||||
this.conversion = conversion;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Convert;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -51,6 +52,14 @@ class WasmGlobalInstruction extends WasmInstruction {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Global;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -31,6 +31,13 @@ import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
private int javaCodePos;
|
||||
|
||||
/**
|
||||
@ -43,6 +50,13 @@ abstract class WasmInstruction {
|
||||
this.javaCodePos = javaCodePos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the type of instruction
|
||||
* @return the type
|
||||
*/
|
||||
@Nonnull
|
||||
abstract Type getType();
|
||||
|
||||
/**
|
||||
* Write this instruction to the WASM module.
|
||||
*
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -56,6 +57,14 @@ class WasmLoadStoreInstruction extends WasmInstruction {
|
||||
this.localVariables = localVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.LoadStore;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -51,6 +52,14 @@ class WasmLocalInstruction extends WasmInstruction {
|
||||
this.idx = idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Local;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -40,6 +41,14 @@ class WasmNopInstruction extends WasmInstruction {
|
||||
super( javaCodePos );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Nop;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
@ -52,6 +53,14 @@ class WasmNumericInstruction extends WasmInstruction {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Numeric;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
@ -22,6 +22,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.StructOperator;
|
||||
@ -55,6 +56,14 @@ class WasmStructInstruction extends WasmInstruction {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
Type getType() {
|
||||
return Type.Struct;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user