mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Next step of refactoring with an intermediate model in the memory of
WASM instructions.
This commit is contained in:
parent
c6ca470003
commit
95afeb17a7
@ -15,13 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package de.inetsoftware.jwebassembly.module;
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cast operations for converting one data type to another
|
* Cast operations for converting one data type to another
|
||||||
*
|
*
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum ValueTypeConvertion {
|
public enum ValueTypeConvertion implements WasmInstruction {
|
||||||
i2l,
|
i2l,
|
||||||
i2f,
|
i2f,
|
||||||
i2d,
|
i2d,
|
||||||
@ -34,4 +36,13 @@ public enum ValueTypeConvertion {
|
|||||||
d2i,
|
d2i,
|
||||||
d2l,
|
d2l,
|
||||||
d2f,
|
d2f,
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void writeTo( ModuleWriter writer ) throws IOException {
|
||||||
|
writer.writeCast( this );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2018 Volker Berlin (i-net software)
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WasmInstruction for block operation.
|
||||||
|
*
|
||||||
|
* @author Volker Berlin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class WasmBlockInstruction implements WasmInstruction {
|
||||||
|
|
||||||
|
private final WasmBlockOperator op;
|
||||||
|
|
||||||
|
private final Object data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of block operation.
|
||||||
|
*
|
||||||
|
* @param op
|
||||||
|
* the operation
|
||||||
|
* @param data
|
||||||
|
* extra data depending of the operator
|
||||||
|
*/
|
||||||
|
WasmBlockInstruction( @Nonnull WasmBlockOperator op, @Nullable Object data ) {
|
||||||
|
this.op = op;
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||||
|
writer.writeBlockCode( op, data );
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2018 Volker Berlin (i-net software)
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WasmInstruction for a function call.
|
||||||
|
*
|
||||||
|
* @author Volker Berlin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class WasmCallInstruction implements WasmInstruction {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of a function call instruction
|
||||||
|
* @param name the Java function name
|
||||||
|
*/
|
||||||
|
WasmCallInstruction( String name ) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||||
|
writer.writeFunctionCall( name );
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ import de.inetsoftware.jwebassembly.WasmException;
|
|||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class WasmConstInstruction extends WasmInstruction {
|
class WasmConstInstruction implements WasmInstruction {
|
||||||
|
|
||||||
private final Number value;
|
private final Number value;
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class WasmConstInstruction extends WasmInstruction {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||||
Class<?> clazz = value.getClass();
|
Class<?> clazz = value.getClass();
|
||||||
if( clazz == Integer.class ) {
|
if( clazz == Integer.class ) {
|
||||||
writer.writeConstInt( ((Integer)value).intValue() );
|
writer.writeConstInt( ((Integer)value).intValue() );
|
||||||
|
@ -26,7 +26,7 @@ import javax.annotation.Nonnull;
|
|||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract class WasmInstruction {
|
abstract interface WasmInstruction {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write this instruction to the WASM module.
|
* Write this instruction to the WASM module.
|
||||||
|
@ -27,7 +27,7 @@ import javax.annotation.Nonnull;
|
|||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class WasmLoadStoreInstruction extends WasmInstruction {
|
class WasmLoadStoreInstruction implements WasmInstruction {
|
||||||
|
|
||||||
private boolean load;
|
private boolean load;
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ class WasmLoadStoreInstruction extends WasmInstruction {
|
|||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||||
idx = localVariables.get( idx ); // translate slot index to position index
|
idx = localVariables.get( idx ); // translate slot index to position index
|
||||||
if( load ) {
|
if( load ) {
|
||||||
writer.writeLoad( idx );
|
writer.writeLoad( idx );
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2018 Volker Berlin (i-net software)
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WasmInstruction for numeric operation.
|
||||||
|
*
|
||||||
|
* @author Volker Berlin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class WasmNumericInstruction implements WasmInstruction {
|
||||||
|
|
||||||
|
private final NumericOperator numOp;
|
||||||
|
|
||||||
|
private final ValueType valueType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of numeric operation.
|
||||||
|
*
|
||||||
|
* @param numOp
|
||||||
|
* the numeric operation
|
||||||
|
* @param valueType
|
||||||
|
* the type of the parameters
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
WasmNumericInstruction( @Nullable NumericOperator numOp, @Nullable ValueType valueType ) {
|
||||||
|
this.numOp = numOp;
|
||||||
|
this.valueType = valueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||||
|
writer.writeNumericOperator( numOp, valueType );
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user