diff --git a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java index 5a65663..483a3df 100644 --- a/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java +++ b/src/de/inetsoftware/jwebassembly/binary/BinaryModuleWriter.java @@ -323,7 +323,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.write( valueType.getCode() ); + localsStream.writeValueType( valueType ); } functionsStream.writeVaruint32( localsStream.size() + codeStream.size() + 1 ); localsStream.writeTo( functionsStream ); @@ -729,7 +729,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; case IF: codeStream.writeOpCode( IF ); - codeStream.write( ((ValueType)data).getCode() ); + codeStream.writeValueType( ((ValueType)data) ); break; case ELSE: codeStream.writeOpCode( ELSE ); @@ -742,7 +742,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; case BLOCK: codeStream.writeOpCode( BLOCK ); - codeStream.write( ValueType.empty.getCode() ); // void; the return type of the block. currently we does not use it + codeStream.writeValueType( ValueType.empty ); // void; the return type of the block. currently we does not use it break; case BR: codeStream.writeOpCode( BR ); @@ -762,14 +762,14 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod break; case LOOP: codeStream.writeOpCode( LOOP ); - codeStream.write( ValueType.empty.getCode() ); // void; the return type of the loop. currently we does not use it + codeStream.writeValueType( ValueType.empty ); // void; the return type of the loop. currently we does not use it break; case UNREACHABLE: codeStream.writeOpCode( UNREACHABLE ); break; case TRY: codeStream.writeOpCode( TRY ); - codeStream.write( ValueType.empty.getCode() ); // void; the return type of the try. currently we does not use it + codeStream.writeValueType( ValueType.empty ); // void; the return type of the try. currently we does not use it break; case CATCH: codeStream.writeOpCode( CATCH ); diff --git a/src/de/inetsoftware/jwebassembly/binary/FunctionType.java b/src/de/inetsoftware/jwebassembly/binary/FunctionType.java index 6cd955d..480da58 100644 --- a/src/de/inetsoftware/jwebassembly/binary/FunctionType.java +++ b/src/de/inetsoftware/jwebassembly/binary/FunctionType.java @@ -38,14 +38,14 @@ class FunctionType extends SectionEntry { */ @Override void writeSectionEntry( WasmOutputStream stream ) throws IOException { - stream.write( ValueType.func.getCode() ); + stream.writeValueType( ValueType.func ); stream.writeVaruint32( this.params.size() ); for( ValueType valueType : this.params ) { - stream.write( valueType.getCode() ); + stream.writeValueType( valueType ); } stream.writeVaruint32( this.results.size() ); for( ValueType valueType : this.results ) { - stream.write( valueType.getCode() ); + stream.writeValueType( valueType ); } } diff --git a/src/de/inetsoftware/jwebassembly/binary/Global.java b/src/de/inetsoftware/jwebassembly/binary/Global.java index 263e7ad..3933dc9 100644 --- a/src/de/inetsoftware/jwebassembly/binary/Global.java +++ b/src/de/inetsoftware/jwebassembly/binary/Global.java @@ -37,7 +37,7 @@ class Global extends SectionEntry { */ @Override void writeSectionEntry( WasmOutputStream stream ) throws IOException { - stream.write( this.type.getCode() ); + stream.writeValueType( this.type ); stream.write( this.mutability ? 1 : 0 ); stream.writeConst( 0, this.type ); stream.writeOpCode( InstructionOpcodes.END ); diff --git a/src/de/inetsoftware/jwebassembly/binary/WasmOutputStream.java b/src/de/inetsoftware/jwebassembly/binary/WasmOutputStream.java index c644d38..ae0a9c8 100644 --- a/src/de/inetsoftware/jwebassembly/binary/WasmOutputStream.java +++ b/src/de/inetsoftware/jwebassembly/binary/WasmOutputStream.java @@ -63,6 +63,18 @@ class WasmOutputStream extends FilterOutputStream { write( op ); } + /** + * Write a value type. + * + * @param type + * a type constant + * @throws IOException + * if an I/O error occurs. + */ + public void writeValueType( ValueType type ) throws IOException { + write( type.getCode() ); + } + /** * Write a integer little endian (ever 4 bytes) *