mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
add method writeValueType to the WasmStream
This commit is contained in:
parent
fce0ab5586
commit
fe1e15ee30
@ -323,7 +323,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.write( valueType.getCode() );
|
localsStream.writeValueType( valueType );
|
||||||
}
|
}
|
||||||
functionsStream.writeVaruint32( localsStream.size() + codeStream.size() + 1 );
|
functionsStream.writeVaruint32( localsStream.size() + codeStream.size() + 1 );
|
||||||
localsStream.writeTo( functionsStream );
|
localsStream.writeTo( functionsStream );
|
||||||
@ -729,7 +729,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
break;
|
break;
|
||||||
case IF:
|
case IF:
|
||||||
codeStream.writeOpCode( IF );
|
codeStream.writeOpCode( IF );
|
||||||
codeStream.write( ((ValueType)data).getCode() );
|
codeStream.writeValueType( ((ValueType)data) );
|
||||||
break;
|
break;
|
||||||
case ELSE:
|
case ELSE:
|
||||||
codeStream.writeOpCode( ELSE );
|
codeStream.writeOpCode( ELSE );
|
||||||
@ -742,7 +742,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
break;
|
break;
|
||||||
case BLOCK:
|
case BLOCK:
|
||||||
codeStream.writeOpCode( 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;
|
break;
|
||||||
case BR:
|
case BR:
|
||||||
codeStream.writeOpCode( BR );
|
codeStream.writeOpCode( BR );
|
||||||
@ -762,14 +762,14 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
break;
|
break;
|
||||||
case LOOP:
|
case LOOP:
|
||||||
codeStream.writeOpCode( 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;
|
break;
|
||||||
case UNREACHABLE:
|
case UNREACHABLE:
|
||||||
codeStream.writeOpCode( UNREACHABLE );
|
codeStream.writeOpCode( UNREACHABLE );
|
||||||
break;
|
break;
|
||||||
case TRY:
|
case TRY:
|
||||||
codeStream.writeOpCode( 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;
|
break;
|
||||||
case CATCH:
|
case CATCH:
|
||||||
codeStream.writeOpCode( CATCH );
|
codeStream.writeOpCode( CATCH );
|
||||||
|
@ -38,14 +38,14 @@ class FunctionType extends SectionEntry {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
void writeSectionEntry( WasmOutputStream stream ) throws IOException {
|
void writeSectionEntry( WasmOutputStream stream ) throws IOException {
|
||||||
stream.write( ValueType.func.getCode() );
|
stream.writeValueType( ValueType.func );
|
||||||
stream.writeVaruint32( this.params.size() );
|
stream.writeVaruint32( this.params.size() );
|
||||||
for( ValueType valueType : this.params ) {
|
for( ValueType valueType : this.params ) {
|
||||||
stream.write( valueType.getCode() );
|
stream.writeValueType( valueType );
|
||||||
}
|
}
|
||||||
stream.writeVaruint32( this.results.size() );
|
stream.writeVaruint32( this.results.size() );
|
||||||
for( ValueType valueType : this.results ) {
|
for( ValueType valueType : this.results ) {
|
||||||
stream.write( valueType.getCode() );
|
stream.writeValueType( valueType );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class Global extends SectionEntry {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
void writeSectionEntry( WasmOutputStream stream ) throws IOException {
|
void writeSectionEntry( WasmOutputStream stream ) throws IOException {
|
||||||
stream.write( this.type.getCode() );
|
stream.writeValueType( this.type );
|
||||||
stream.write( this.mutability ? 1 : 0 );
|
stream.write( this.mutability ? 1 : 0 );
|
||||||
stream.writeConst( 0, this.type );
|
stream.writeConst( 0, this.type );
|
||||||
stream.writeOpCode( InstructionOpcodes.END );
|
stream.writeOpCode( InstructionOpcodes.END );
|
||||||
|
@ -63,6 +63,18 @@ class WasmOutputStream extends FilterOutputStream {
|
|||||||
write( op );
|
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)
|
* Write a integer little endian (ever 4 bytes)
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user