mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +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.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -784,7 +785,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, ValueType valueType ) throws IOException {
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||
int opCode;
|
||||
switch(op) {
|
||||
case NEW:
|
||||
@ -803,6 +804,6 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
throw new Error( "Unknown operator: " + op );
|
||||
}
|
||||
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.Nonnull;
|
||||
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -71,7 +72,7 @@ class WasmOutputStream extends FilterOutputStream {
|
||||
* @throws IOException
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
public void writeValueType( ValueType type ) throws IOException {
|
||||
public void writeValueType( StorageType type ) throws IOException {
|
||||
writeVarint( type.getCode() );
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ import javax.annotation.Nullable;
|
||||
import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -213,10 +214,10 @@ public abstract class ModuleWriter implements Closeable {
|
||||
*
|
||||
* @param op
|
||||
* the operation
|
||||
* @param valueType
|
||||
* @param type
|
||||
* the resulting type
|
||||
* @throws IOException
|
||||
* 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.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
|
||||
/**
|
||||
@ -35,29 +36,29 @@ class WasmArrayInstruction extends WasmInstruction {
|
||||
|
||||
private final ArrayOperator op;
|
||||
|
||||
private final ValueType valueType;
|
||||
private final StorageType type;
|
||||
|
||||
/**
|
||||
* Create an instance of numeric operation.
|
||||
*
|
||||
* @param numOp
|
||||
* the numeric operation
|
||||
* @param valueType
|
||||
* @param op
|
||||
* the array operation
|
||||
* @param type
|
||||
* the type of the parameters
|
||||
* @param javaCodePos
|
||||
* 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 );
|
||||
this.op = op;
|
||||
this.valueType = valueType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
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:
|
||||
return ValueType.anyref;
|
||||
case GET:
|
||||
return valueType;
|
||||
return type instanceof ValueType ? (ValueType)type : ValueType.anyref;
|
||||
case SET:
|
||||
return null;
|
||||
case LENGTH:
|
||||
|
@ -29,6 +29,7 @@ import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
||||
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||
import de.inetsoftware.jwebassembly.wasm.ArrayOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.NumericOperator;
|
||||
import de.inetsoftware.jwebassembly.wasm.StorageType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
import de.inetsoftware.jwebassembly.wasm.WasmBlockOperator;
|
||||
|
||||
@ -365,7 +366,7 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, ValueType valueType ) throws IOException {
|
||||
protected void writeArrayOperator( @Nonnull ArrayOperator op, StorageType type ) throws IOException {
|
||||
String operation;
|
||||
switch( op ) {
|
||||
case NEW:
|
||||
@ -384,6 +385,6 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
throw new Error( "Unknown operator: " + op );
|
||||
}
|
||||
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;
|
||||
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
|
||||
/**
|
||||
* @author Volker Berlin
|
||||
*/
|
||||
public enum ValueType {
|
||||
public enum ValueType implements StorageType {
|
||||
i32(-0x01),
|
||||
i64(-0x02),
|
||||
f32(-0x03),
|
||||
@ -50,6 +48,7 @@ public enum ValueType {
|
||||
*
|
||||
* @return the code
|
||||
*/
|
||||
@Override
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user