mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Does not register primitive types as StructType in wasm
This commit is contained in:
parent
71b28f1d47
commit
58d6cbc4de
@ -33,6 +33,7 @@ import de.inetsoftware.jwebassembly.WasmException;
|
|||||||
import de.inetsoftware.jwebassembly.module.FunctionName;
|
import de.inetsoftware.jwebassembly.module.FunctionName;
|
||||||
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
||||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||||
|
import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind;
|
||||||
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||||
import de.inetsoftware.jwebassembly.module.WasmOptions;
|
import de.inetsoftware.jwebassembly.module.WasmOptions;
|
||||||
import de.inetsoftware.jwebassembly.module.WasmTarget;
|
import de.inetsoftware.jwebassembly.module.WasmTarget;
|
||||||
@ -497,6 +498,10 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
protected int writeStructType( StructType type ) throws IOException {
|
protected int writeStructType( StructType type ) throws IOException {
|
||||||
type.writeToStream( dataStream, (funcName) -> getFunction( funcName ).id, options );
|
type.writeToStream( dataStream, (funcName) -> getFunction( funcName ).id, options );
|
||||||
|
|
||||||
|
if( type.getKind() == StructTypeKind.primitive ) {
|
||||||
|
return -9; // Should never use
|
||||||
|
}
|
||||||
|
|
||||||
if( !options.useGC() ) {
|
if( !options.useGC() ) {
|
||||||
return ValueType.externref.getCode();
|
return ValueType.externref.getCode();
|
||||||
}
|
}
|
||||||
|
@ -148,6 +148,8 @@ public class TypeManager {
|
|||||||
|
|
||||||
private Map<Object, StructType> structTypes = new LinkedHashMap<>();
|
private Map<Object, StructType> structTypes = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
private int typeIndexCounter;
|
||||||
|
|
||||||
private boolean isFinish;
|
private boolean isFinish;
|
||||||
|
|
||||||
final WasmOptions options;
|
final WasmOptions options;
|
||||||
@ -260,7 +262,7 @@ public class TypeManager {
|
|||||||
|
|
||||||
if( structTypes.size() == 0 ) {
|
if( structTypes.size() == 0 ) {
|
||||||
for( String primitiveTypeName : PRIMITIVE_CLASSES ) {
|
for( String primitiveTypeName : PRIMITIVE_CLASSES ) {
|
||||||
structTypes.put( primitiveTypeName, new StructType( primitiveTypeName, structTypes.size() ) );
|
structTypes.put( primitiveTypeName, new StructType( primitiveTypeName, StructTypeKind.primitive, this ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -279,7 +281,12 @@ public class TypeManager {
|
|||||||
return (StructType)new ValueTypeParser( name, options.types ).next();
|
return (StructType)new ValueTypeParser( name, options.types ).next();
|
||||||
} else {
|
} else {
|
||||||
checkStructTypesState( name );
|
checkStructTypesState( name );
|
||||||
type = new StructType( name, structTypes.size() );
|
type = new StructType( name, StructTypeKind.normal, this );
|
||||||
|
|
||||||
|
if( "java/lang/String".equals( name ) ) {
|
||||||
|
// looks like strings are used, that register helper functions
|
||||||
|
options.strings.getStringConstantFunction();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
structTypes.put( name, type );
|
structTypes.put( name, type );
|
||||||
@ -337,7 +344,7 @@ public class TypeManager {
|
|||||||
componentClassIndex = ((StructType)arrayType).classIndex;
|
componentClassIndex = ((StructType)arrayType).classIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
type = new ArrayType( arrayType, structTypes.size(), componentClassIndex );
|
type = new ArrayType( arrayType, this, componentClassIndex );
|
||||||
structTypes.put( arrayType, type );
|
structTypes.put( arrayType, type );
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
@ -486,6 +493,15 @@ public class TypeManager {
|
|||||||
, valueOf( "java/lang/Object" ), ValueType.i32, null, valueOf( "java/lang/Object" ) );
|
, valueOf( "java/lang/Object" ), ValueType.i32, null, valueOf( "java/lang/Object" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The kind of type
|
||||||
|
*
|
||||||
|
* @author Volker Berlin
|
||||||
|
*/
|
||||||
|
public static enum StructTypeKind {
|
||||||
|
primitive, normal, array, array_native;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reference to a type.
|
* A reference to a type.
|
||||||
*
|
*
|
||||||
@ -495,6 +511,8 @@ public class TypeManager {
|
|||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
private final StructTypeKind kind;
|
||||||
|
|
||||||
private final int classIndex;
|
private final int classIndex;
|
||||||
|
|
||||||
private int code = Integer.MAX_VALUE;
|
private int code = Integer.MAX_VALUE;
|
||||||
@ -519,12 +537,21 @@ public class TypeManager {
|
|||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* the Java class name
|
* the Java class name
|
||||||
* @param classIndex
|
* @param kind
|
||||||
* the running index of the class/type
|
* the type kind
|
||||||
|
* @param manager
|
||||||
|
* the manager which hold all StructTypes
|
||||||
*/
|
*/
|
||||||
protected StructType( String name, int classIndex ) {
|
protected StructType( @Nonnull String name, @Nonnull StructTypeKind kind, @Nonnull TypeManager manager ) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.classIndex = classIndex;
|
this.kind = kind;
|
||||||
|
switch( kind ) {
|
||||||
|
case array_native:
|
||||||
|
this.classIndex = -1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.classIndex = manager.typeIndexCounter++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -850,6 +877,14 @@ public class TypeManager {
|
|||||||
return type == this || type == ValueType.externref || type == ValueType.anyref || type == ValueType.eqref;
|
return type == this || type == ValueType.externref || type == ValueType.anyref || type == ValueType.eqref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get kind of the StructType
|
||||||
|
* @return the type kind
|
||||||
|
*/
|
||||||
|
public StructTypeKind getKind() {
|
||||||
|
return kind;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the Java type
|
* Get the name of the Java type
|
||||||
* @return the name
|
* @return the name
|
||||||
|
@ -32,6 +32,7 @@ import de.inetsoftware.jwebassembly.WasmException;
|
|||||||
import de.inetsoftware.jwebassembly.module.FunctionName;
|
import de.inetsoftware.jwebassembly.module.FunctionName;
|
||||||
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
import de.inetsoftware.jwebassembly.module.ModuleWriter;
|
||||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||||
|
import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind;
|
||||||
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
import de.inetsoftware.jwebassembly.module.ValueTypeConvertion;
|
||||||
import de.inetsoftware.jwebassembly.module.WasmOptions;
|
import de.inetsoftware.jwebassembly.module.WasmOptions;
|
||||||
import de.inetsoftware.jwebassembly.module.WasmTarget;
|
import de.inetsoftware.jwebassembly.module.WasmTarget;
|
||||||
@ -194,6 +195,10 @@ public class TextModuleWriter extends ModuleWriter {
|
|||||||
protected int writeStructType( StructType type ) throws IOException {
|
protected int writeStructType( StructType type ) throws IOException {
|
||||||
type.writeToStream( dataStream, (funcName) -> getFunction( funcName ).id, options );
|
type.writeToStream( dataStream, (funcName) -> getFunction( funcName ).id, options );
|
||||||
|
|
||||||
|
if( type.getKind() == StructTypeKind.primitive ) {
|
||||||
|
return -9; // Should never use
|
||||||
|
}
|
||||||
|
|
||||||
if( !options.useGC() ) {
|
if( !options.useGC() ) {
|
||||||
return ValueType.externref.getCode();
|
return ValueType.externref.getCode();
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package de.inetsoftware.jwebassembly.wasm;
|
package de.inetsoftware.jwebassembly.wasm;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import de.inetsoftware.jwebassembly.WasmException;
|
import de.inetsoftware.jwebassembly.WasmException;
|
||||||
|
import de.inetsoftware.jwebassembly.module.TypeManager;
|
||||||
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
|
||||||
|
import de.inetsoftware.jwebassembly.module.TypeManager.StructTypeKind;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A reference to an array type
|
* A reference to an array type
|
||||||
@ -35,13 +39,13 @@ public class ArrayType extends StructType {
|
|||||||
*
|
*
|
||||||
* @param arrayType
|
* @param arrayType
|
||||||
* the type of the array
|
* the type of the array
|
||||||
* @param classIndex
|
* @param manager
|
||||||
* the running index of the main class/type
|
* the manager which hold all StructTypes
|
||||||
* @param componentClassIndex
|
* @param componentClassIndex
|
||||||
* the running index of the component/array class/type
|
* the running index of the component/array class/type
|
||||||
*/
|
*/
|
||||||
public ArrayType( AnyType arrayType, int classIndex, int componentClassIndex ) {
|
public ArrayType( AnyType arrayType, @Nonnull TypeManager manager, int componentClassIndex ) {
|
||||||
super( getJavaClassName( arrayType ), classIndex );
|
super( getJavaClassName( arrayType ), StructTypeKind.array, manager );
|
||||||
this.arrayType = arrayType;
|
this.arrayType = arrayType;
|
||||||
this.componentClassIndex = componentClassIndex;
|
this.componentClassIndex = componentClassIndex;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user