mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
add table for classes
This commit is contained in:
parent
9a157b74a2
commit
cc4a5e7858
@ -169,16 +169,23 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
*/
|
||||
private void writeTableSection() throws IOException {
|
||||
int stringCount = getStringCount();
|
||||
int typeCount = options.types.size();
|
||||
if( !callIndirect && stringCount == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
int elemCount = callIndirect ? imports.size() + functions.size() : 0;
|
||||
WasmOutputStream stream = new WasmOutputStream();
|
||||
int count = stringCount == 0 ? 1 : 2;
|
||||
int count = 1;
|
||||
if( stringCount > 0 ) {
|
||||
count++;
|
||||
}
|
||||
if( typeCount > 0 ) {
|
||||
count++;
|
||||
}
|
||||
stream.writeVaruint32( count ); // count of tables
|
||||
|
||||
// indirect function table
|
||||
int elemCount = callIndirect ? imports.size() + functions.size() : 0;
|
||||
stream.writeValueType( ValueType.funcref ); // the type of elements
|
||||
stream.writeVaruint32( 0 ); // flags; 1-maximum is available, 0-no maximum value available
|
||||
stream.writeVaruint32( elemCount ); // initial length
|
||||
@ -191,6 +198,13 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
stream.writeVaruint32( stringCount ); // initial length
|
||||
}
|
||||
|
||||
// table with classes
|
||||
if( count >= 3 ) {
|
||||
stream.writeValueType( ValueType.anyref ); // the type of elements
|
||||
stream.writeVaruint32( 0 ); // flags; 1-maximum is available, 0-no maximum value available
|
||||
stream.writeVaruint32( typeCount ); // initial length
|
||||
}
|
||||
|
||||
wasm.writeSection( SectionType.Table, stream );
|
||||
}
|
||||
|
||||
|
@ -82,6 +82,15 @@ public class TypeManager {
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count of used types
|
||||
*
|
||||
* @return the count
|
||||
*/
|
||||
public int size() {
|
||||
return structTypes.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish the prepare and write the types. Now no new types and functions should be added.
|
||||
*
|
||||
|
@ -37,7 +37,7 @@ public class WasmOptions {
|
||||
|
||||
final FunctionManager functions = new FunctionManager();
|
||||
|
||||
final TypeManager types = new TypeManager( this );
|
||||
public final TypeManager types = new TypeManager( this );
|
||||
|
||||
final StringManager strings = new StringManager( this );
|
||||
|
||||
|
@ -157,6 +157,13 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
textOutput.append( "(table " ).append( Integer.toString( stringCount ) ).append( " anyref)" );
|
||||
}
|
||||
|
||||
// table with classes
|
||||
int typeCount = options.types.size();
|
||||
if( typeCount > 0 ) {
|
||||
newline( textOutput );
|
||||
textOutput.append( "(table " ).append( Integer.toString( typeCount ) ).append( " anyref)" );
|
||||
}
|
||||
|
||||
int dataSize = dataStream.size();
|
||||
if( dataSize > 0 ) {
|
||||
int pages = (dataSize + 0xFFFF) / 0x10000;
|
||||
|
Loading…
x
Reference in New Issue
Block a user