Use byte values for ValeTypes instead of Varint values. Prepare for ref

values.
This commit is contained in:
Volker 2018-07-27 18:30:04 +02:00
parent 776cf133bc
commit d81da1f342
3 changed files with 23 additions and 14 deletions

View File

@ -105,16 +105,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
WasmOutputStream stream = new WasmOutputStream(); WasmOutputStream stream = new WasmOutputStream();
stream.writeVaruint32( count ); stream.writeVaruint32( count );
for( FunctionType type : functionTypes ) { for( FunctionType type : functionTypes ) {
stream.writeVarint( ValueType.func.getCode() ); stream.write( ValueType.func.getCode() );
stream.writeVaruint32( type.params.size() ); stream.writeVaruint32( type.params.size() );
for( ValueType valueType : type.params ) { for( ValueType valueType : type.params ) {
stream.writeVarint( valueType.getCode() ); stream.write( valueType.getCode() );
} }
if( type.result == null ) { if( type.result == null ) {
stream.writeVaruint32( 0 ); stream.writeVaruint32( 0 );
} else { } else {
stream.writeVaruint32( 1 ); stream.writeVaruint32( 1 );
stream.writeVarint( type.result.getCode() ); stream.write( type.result.getCode() );
} }
} }
wasm.writeSection( SectionType.Type, stream, null ); wasm.writeSection( SectionType.Type, stream, null );
@ -295,7 +295,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
localsStream.writeVaruint32( locals.size() ); localsStream.writeVaruint32( locals.size() );
for( ValueType valueType : locals ) { for( ValueType valueType : locals ) {
localsStream.writeVaruint32( 1 ); // TODO optimize, write the count of same types. localsStream.writeVaruint32( 1 ); // TODO optimize, write the count of same types.
localsStream.writeVarint( valueType.getCode() ); localsStream.write( valueType.getCode() );
} }
functionsStream.writeVaruint32( localsStream.size() + codeStream.size() + 1 ); functionsStream.writeVaruint32( localsStream.size() + codeStream.size() + 1 );
localsStream.writeTo( functionsStream ); localsStream.writeTo( functionsStream );
@ -692,7 +692,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break; break;
case IF: case IF:
codeStream.write( IF ); codeStream.write( IF );
codeStream.write( 0x40 ); // void; the return type of the block. currently we does not use it codeStream.write( ValueType.empty.getCode() ); // void; the return type of the block. currently we does not use it
break; break;
case ELSE: case ELSE:
codeStream.write( ELSE ); codeStream.write( ELSE );
@ -705,7 +705,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break; break;
case BLOCK: case BLOCK:
codeStream.write( BLOCK ); codeStream.write( BLOCK );
codeStream.write( 0x40 ); // void; the return type of the block. currently we does not use it codeStream.write( ValueType.empty.getCode() ); // void; the return type of the block. currently we does not use it
break; break;
case BR: case BR:
codeStream.write( BR ); codeStream.write( BR );
@ -725,7 +725,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
break; break;
case LOOP: case LOOP:
codeStream.write( LOOP ); codeStream.write( LOOP );
codeStream.write( 0x40 ); // void; the return type of the loop. currently we does not use it codeStream.write( ValueType.empty.getCode() ); // void; the return type of the loop. currently we does not use it
break; break;
case UNREACHABLE: case UNREACHABLE:
codeStream.write( UNREACHABLE ); codeStream.write( UNREACHABLE );

View File

@ -334,4 +334,10 @@ interface InstructionOpcodes {
static final int F64_CONVERT_U_I64 = 0xBA; static final int F64_CONVERT_U_I64 = 0xBA;
static final int F64_PROMOTE_F32 = 0xBB; static final int F64_PROMOTE_F32 = 0xBB;
// === numerical operations ======
static final int REF_NULL = 0xD0;
static final int REF_ISNULL = 0xD1;
} }

View File

@ -19,14 +19,17 @@ package de.inetsoftware.jwebassembly.module;
* @author Volker Berlin * @author Volker Berlin
*/ */
public enum ValueType { public enum ValueType {
i32(-1), i32(0x7f),
i64(-2), i64(0x7e),
f32(-3), f32(0x7d),
f64(-4), f64(0x7c),
func(-0x20); anyfunc(0x70),
// void(-0x40); anyref(0x6f),
func(0x60),
empty(0x40), // empty block_type
;
private int code; private final int code;
/** /**
* Create instance of the enum * Create instance of the enum