add method writeValueType to the WasmStream

This commit is contained in:
Volker Berlin 2018-12-02 18:17:27 +01:00
parent fce0ab5586
commit fe1e15ee30
4 changed files with 21 additions and 9 deletions

View File

@ -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 );

View File

@ -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 );
}
}

View File

@ -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 );

View File

@ -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)
*