fix type handling for NUL values with GC support

This commit is contained in:
Volker Berlin 2020-09-24 21:46:02 +02:00
parent 77d81e3f13
commit 856194dbce
5 changed files with 11 additions and 8 deletions

View File

@ -1395,7 +1395,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break; break;
case NULL: case NULL:
opCode = REF_NULL; opCode = REF_NULL;
type = options.useGC() ? ValueType.eqref : ValueType.externref; type = options.useGC() ? type : ValueType.externref;
break; break;
default: default:
throw new Error( "Unknown operator: " + op ); throw new Error( "Unknown operator: " + op );

View File

@ -98,8 +98,7 @@ class WasmOutputStream extends LittleEndianOutputStream {
public void writeRefValueType( AnyType type ) throws IOException { public void writeRefValueType( AnyType type ) throws IOException {
if( type.isRefType() ) { if( type.isRefType() ) {
if( options.useGC() ) { if( options.useGC() ) {
//TODO writeValueType( ValueType.ref_type ); writeValueType( ValueType.optref );
type = ValueType.eqref;
} else { } else {
type = ValueType.externref; type = ValueType.externref;
} }

View File

@ -108,7 +108,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
case 0: // nop case 0: // nop
break; break;
case 1: // aconst_null case 1: // aconst_null
addStructInstruction( StructOperator.NULL, null, null, codePos, lineNumber ); addStructInstruction( StructOperator.NULL, "java/lang/Object", null, codePos, lineNumber );
break; break;
case 2: // iconst_m1 case 2: // iconst_m1
case 3: // iconst_0 case 3: // iconst_0

View File

@ -64,10 +64,10 @@ class WasmStructInstruction extends WasmInstruction {
* @param types * @param types
* the type manager * the type manager
*/ */
WasmStructInstruction( @Nullable StructOperator op, @Nullable String typeName, @Nullable NamedStorageType fieldName, int javaCodePos, int lineNumber, TypeManager types ) { WasmStructInstruction( @Nullable StructOperator op, @Nonnull String typeName, @Nullable NamedStorageType fieldName, int javaCodePos, int lineNumber, TypeManager types ) {
super( javaCodePos, lineNumber ); super( javaCodePos, lineNumber );
this.op = op; this.op = op;
this.type = typeName == null ? null : types.valueOf( typeName ); this.type = types.valueOf( typeName );
this.fieldName = fieldName; this.fieldName = fieldName;
if( type != null && fieldName != null ) { if( type != null && fieldName != null ) {
type.useFieldName( fieldName ); type.useFieldName( fieldName );

View File

@ -861,8 +861,12 @@ public class TextModuleWriter extends ModuleWriter {
operation = "struct.set"; operation = "struct.set";
break; break;
case NULL: case NULL:
operation = options.useGC() ? "ref.null eq" : "ref.null extern"; if( options.useGC() ) {
type = null; operation = "ref.null";
} else {
operation = "ref.null extern";
type = null;
}
break; break;
default: default:
throw new Error( "Unknown operator: " + op ); throw new Error( "Unknown operator: " + op );