From d81da1f342af79792a9603516dc5cabdc4f3f4ec Mon Sep 17 00:00:00 2001 From: Volker Date: Fri, 27 Jul 2018 18:30:04 +0200 Subject: [PATCH] Use byte values for ValeTypes instead of Varint values. Prepare for ref values. --- .../jwebassembly/binary/BinaryModuleWriter.java | 14 +++++++------- .../jwebassembly/binary/InstructionOpcodes.java | 6 ++++++ .../jwebassembly/module/ValueType.java | 17 ++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index 4a1e5eb..b3a3326 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -105,16 +105,16 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod WasmOutputStream stream = new WasmOutputStream(); stream.writeVaruint32( count ); for( FunctionType type : functionTypes ) { - stream.writeVarint( ValueType.func.getCode() ); + stream.write( ValueType.func.getCode() ); stream.writeVaruint32( type.params.size() ); for( ValueType valueType : type.params ) { - stream.writeVarint( valueType.getCode() ); + stream.write( valueType.getCode() ); } if( type.result == null ) { stream.writeVaruint32( 0 ); } else { stream.writeVaruint32( 1 ); - stream.writeVarint( type.result.getCode() ); + stream.write( type.result.getCode() ); } } wasm.writeSection( SectionType.Type, stream, null ); @@ -295,7 +295,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod localsStream.writeVaruint32( locals.size() ); for( ValueType valueType : locals ) { 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 ); localsStream.writeTo( functionsStream ); @@ -692,7 +692,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; case 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; case ELSE: codeStream.write( ELSE ); @@ -705,7 +705,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; case 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; case BR: codeStream.write( BR ); @@ -725,7 +725,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; case 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; case UNREACHABLE: codeStream.write( UNREACHABLE ); diff --git a/src/de/inetsoftware/jwebassembly/binary/InstructionOpcodes.java b/src/de/inetsoftware/jwebassembly/binary/InstructionOpcodes.java index a97d0d7..8a42021 100644 --- a/src/de/inetsoftware/jwebassembly/binary/InstructionOpcodes.java +++ b/src/de/inetsoftware/jwebassembly/binary/InstructionOpcodes.java @@ -334,4 +334,10 @@ interface InstructionOpcodes { static final int F64_CONVERT_U_I64 = 0xBA; static final int F64_PROMOTE_F32 = 0xBB; + + // === numerical operations ====== + + static final int REF_NULL = 0xD0; + + static final int REF_ISNULL = 0xD1; } diff --git a/src/de/inetsoftware/jwebassembly/module/ValueType.java b/src/de/inetsoftware/jwebassembly/module/ValueType.java index 2058c18..0f390d5 100644 --- a/src/de/inetsoftware/jwebassembly/module/ValueType.java +++ b/src/de/inetsoftware/jwebassembly/module/ValueType.java @@ -19,14 +19,17 @@ package de.inetsoftware.jwebassembly.module; * @author Volker Berlin */ public enum ValueType { - i32(-1), - i64(-2), - f32(-3), - f64(-4), - func(-0x20); - // void(-0x40); + i32(0x7f), + i64(0x7e), + f32(0x7d), + f64(0x7c), + anyfunc(0x70), + anyref(0x6f), + func(0x60), + empty(0x40), // empty block_type + ; - private int code; + private final int code; /** * Create instance of the enum