add producer section

This commit is contained in:
Volker Berlin 2019-02-28 21:28:23 +01:00
parent 14229c374f
commit e47ee64a7b

View File

@ -115,6 +115,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
writeExportSection();
writeCodeSection();
writeDebugNames();
writeProducersSection();
wasm.close();
}
@ -250,6 +251,40 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
wasm.writeSection( SectionType.Custom, stream );
}
/**
* Write producer information to wasm
*
* @throws IOException
* if any I/O error occur
*/
private void writeProducersSection() throws IOException {
Package pack = getClass().getPackage();
String version = pack == null ? null : pack.getImplementationVersion();
WasmOutputStream stream = new WasmOutputStream();
stream.writeString( "producers" ); // Custom Section name "producers", content is part of the section length
stream.writeVaruint32( 2 ); // field_count; number of fields that follow (language and processed-by)
// field source language list
stream.writeString( "language" );
stream.writeVaruint32( 1 ); // field_value_count; number of value strings that follow
stream.writeString( "Java bytecode" );
// field individual tool list
stream.writeString( "processed-by" );
if( version == null ) {
stream.writeVaruint32( 1 ); // field_value_count; number of value strings that follow
stream.writeString( "JWebAssembly" );
} else {
stream.writeVaruint32( 2 ); // field_value_count; number of value strings that follow
stream.writeString( "JWebAssembly" );
stream.writeString( version );
}
wasm.writeSection( SectionType.Custom, stream );
}
/**
* {@inheritDoc}
*/