mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Add interface StorageType for struct support
This commit is contained in:
parent
c0efe35626
commit
f5e5d11af7
@ -36,6 +36,7 @@ import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
|||||||
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||||
|
|
||||||
@ -784,7 +785,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, ValueType valueType ) throws IOException {
|
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||||
int opCode;
|
int opCode;
|
||||||
switch(op) {
|
switch(op) {
|
||||||
case NEW:
|
case NEW:
|
||||||
@ -803,6 +804,6 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
throw new Error( "Unknown operator: " + op );
|
throw new Error( "Unknown operator: " + op );
|
||||||
}
|
}
|
||||||
codeStream.writeOpCode( opCode );
|
codeStream.writeOpCode( opCode );
|
||||||
codeStream.writeValueType( valueType );
|
codeStream.writeValueType( type );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import javax.annotation.Nonnegative;
|
import javax.annotation.Nonnegative;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +72,7 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if an I/O error occurs.
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void writeValueType( ValueType type ) throws IOException {
|
public void writeValueType( StorageType type ) throws IOException {
|
||||||
writeVarint( type.getCode() );
|
writeVarint( type.getCode() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import javax.annotation.Nullable;
|
|||||||
import de.inetsoftware.classparser.Member;
|
import de.inetsoftware.classparser.Member;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||||
|
|
||||||
@ -213,10 +214,10 @@ public abstract class ModuleWriter implements Closeable {
|
|||||||
*
|
*
|
||||||
* @param op
|
* @param op
|
||||||
* the operation
|
* the operation
|
||||||
* @param valueType
|
* @param type
|
||||||
* the resulting type
|
* the resulting type
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if any I/O error occur
|
* if any I/O error occur
|
||||||
*/
|
*/
|
||||||
protected abstract void writeArrayOperator( @Nonnull ArrayOperator op, ValueType valueType ) throws IOException;
|
protected abstract void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import javax.annotation.Nullable;
|
|||||||
|
|
||||||
import de.inetsoftware.jwebassembly.WasmException;
|
import de.inetsoftware.jwebassembly.WasmException;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,29 +36,29 @@ class WasmArrayInstruction extends WasmInstruction {
|
|||||||
|
|
||||||
private final ArrayOperator op;
|
private final ArrayOperator op;
|
||||||
|
|
||||||
private final ValueType valueType;
|
private final StorageType type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of numeric operation.
|
* Create an instance of numeric operation.
|
||||||
*
|
*
|
||||||
* @param numOp
|
* @param op
|
||||||
* the numeric operation
|
* the array operation
|
||||||
* @param valueType
|
* @param type
|
||||||
* the type of the parameters
|
* the type of the parameters
|
||||||
* @param javaCodePos
|
* @param javaCodePos
|
||||||
* the code position/offset in the Java method
|
* the code position/offset in the Java method
|
||||||
*/
|
*/
|
||||||
WasmArrayInstruction( @Nullable ArrayOperator op, @Nullable ValueType valueType, int javaCodePos ) {
|
WasmArrayInstruction( @Nullable ArrayOperator op, @Nullable StorageType type, int javaCodePos ) {
|
||||||
super( javaCodePos );
|
super( javaCodePos );
|
||||||
this.op = op;
|
this.op = op;
|
||||||
this.valueType = valueType;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
|
||||||
writer.writeArrayOperator( op, valueType );
|
writer.writeArrayOperator( op, type );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,7 +69,7 @@ class WasmArrayInstruction extends WasmInstruction {
|
|||||||
case NEW:
|
case NEW:
|
||||||
return ValueType.anyref;
|
return ValueType.anyref;
|
||||||
case GET:
|
case GET:
|
||||||
return valueType;
|
return type instanceof ValueType ? (ValueType)type : ValueType.anyref;
|
||||||
case SET:
|
case SET:
|
||||||
return null;
|
return null;
|
||||||
case LENGTH:
|
case LENGTH:
|
||||||
|
@ -29,6 +29,7 @@ import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
|||||||
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||||
|
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||||
|
|
||||||
@ -365,7 +366,7 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, ValueType valueType ) throws IOException {
|
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||||
String operation;
|
String operation;
|
||||||
switch( op ) {
|
switch( op ) {
|
||||||
case NEW:
|
case NEW:
|
||||||
@ -384,6 +385,6 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
throw new Error( "Unknown operator: " + op );
|
throw new Error( "Unknown operator: " + op );
|
||||||
}
|
}
|
||||||
newline( methodOutput );
|
newline( methodOutput );
|
||||||
methodOutput.append( "array." ).append( operation ).append( ' ' ).append( valueType );
|
methodOutput.append( "array." ).append( operation ).append( ' ' ).append( type );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
37
src/de/inetsoftware/jwebassembly/wasm/StorageType.java
Normal file
37
src/de/inetsoftware/jwebassembly/wasm/StorageType.java
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.wasm;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre><code>
|
||||||
|
* numtype ::= i32 | i64 | f32 | f64
|
||||||
|
* packedtype ::= i8 | i16
|
||||||
|
* reftype ::= anyref | anyfunc | nullref
|
||||||
|
* valtype ::= numtype | reftype
|
||||||
|
*
|
||||||
|
* storagetype ::= valtype | packedtype
|
||||||
|
* </code></pre>
|
||||||
|
* @author Volker Berlin
|
||||||
|
*/
|
||||||
|
public interface StorageType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operation code in WebAssembly.
|
||||||
|
*
|
||||||
|
* @return the code
|
||||||
|
*/
|
||||||
|
public int getCode();
|
||||||
|
}
|
@ -15,12 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package de.inetsoftware.jwebassembly.wasm;
|
package de.inetsoftware.jwebassembly.wasm;
|
||||||
|
|
||||||
import de.inetsoftware.jwebassembly.WasmException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Volker Berlin
|
* @author Volker Berlin
|
||||||
*/
|
*/
|
||||||
public enum ValueType {
|
public enum ValueType implements StorageType {
|
||||||
i32(-0x01),
|
i32(-0x01),
|
||||||
i64(-0x02),
|
i64(-0x02),
|
||||||
f32(-0x03),
|
f32(-0x03),
|
||||||
@ -50,6 +48,7 @@ public enum ValueType {
|
|||||||
*
|
*
|
||||||
* @return the code
|
* @return the code
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user