mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Write also the import function names into the debug section (custom section name).
This commit is contained in:
parent
87f986e30b
commit
8262a45343
@ -23,6 +23,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.annotation.Nonnegative;
|
import javax.annotation.Nonnegative;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -358,7 +359,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write optional the debug names into the name section
|
* Write optional the debug names into the custom "name" section.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if any I/O error occur
|
* if any I/O error occur
|
||||||
@ -373,21 +374,55 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
// write function names
|
// write function names
|
||||||
stream.write( 1 ); // 1 - Function name
|
stream.write( 1 ); // 1 - Function name
|
||||||
WasmOutputStream section = new WasmOutputStream();
|
WasmOutputStream section = new WasmOutputStream();
|
||||||
section.writeVaruint32( functions.size() );
|
section.writeVaruint32( imports.size() + functions.size() );
|
||||||
for( Entry<String, Function> entry : functions.entrySet() ) {
|
writeDebugFunctionNames( imports.entrySet(), section );
|
||||||
section.writeVaruint32( entry.getValue().id ); // function index
|
writeDebugFunctionNames( functions.entrySet(), section );
|
||||||
String functionName = entry.getKey();
|
|
||||||
functionName = functionName.substring( 0, functionName.indexOf( '(' ) );
|
|
||||||
section.writeString( functionName );
|
|
||||||
}
|
|
||||||
stream.writeVaruint32( section.size() );
|
stream.writeVaruint32( section.size() );
|
||||||
section.writeTo( stream );
|
section.writeTo( stream );
|
||||||
|
|
||||||
// write function parameter names
|
// write function parameter names
|
||||||
stream.write( 2 ); // 2 - Local names
|
stream.write( 2 ); // 2 - Local names
|
||||||
section.reset();
|
section.reset();
|
||||||
section.writeVaruint32( functions.size() );
|
section.writeVaruint32( imports.size() + functions.size() );
|
||||||
for( Entry<String, Function> entry : functions.entrySet() ) {
|
writeDebugParameternNames( imports.entrySet(), section );
|
||||||
|
writeDebugParameternNames( functions.entrySet(), section );
|
||||||
|
stream.writeVaruint32( section.size() );
|
||||||
|
section.writeTo( stream );
|
||||||
|
|
||||||
|
wasm.writeSection( SectionType.Custom, stream );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write function names to the custom "name" section.
|
||||||
|
*
|
||||||
|
* @param entries
|
||||||
|
* the functions
|
||||||
|
* @param section
|
||||||
|
* the target
|
||||||
|
* @throws IOException
|
||||||
|
* if any I/O error occur
|
||||||
|
*/
|
||||||
|
private void writeDebugFunctionNames( Set<? extends Entry<String, ? extends Function>> entries, WasmOutputStream section ) throws IOException {
|
||||||
|
for( Entry<String, ? extends Function> entry : entries ) {
|
||||||
|
section.writeVaruint32( entry.getValue().id ); // function index
|
||||||
|
String functionName = entry.getKey();
|
||||||
|
functionName = functionName.substring( 0, functionName.indexOf( '(' ) );
|
||||||
|
section.writeString( functionName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write parameter names to the custom "name" section.
|
||||||
|
*
|
||||||
|
* @param entries
|
||||||
|
* the functions
|
||||||
|
* @param section
|
||||||
|
* the target
|
||||||
|
* @throws IOException
|
||||||
|
* if any I/O error occur
|
||||||
|
*/
|
||||||
|
private void writeDebugParameternNames( Set<? extends Entry<String, ? extends Function>> entries, WasmOutputStream section ) throws IOException {
|
||||||
|
for( Entry<String, ? extends Function> entry : entries ) {
|
||||||
Function func = entry.getValue();
|
Function func = entry.getValue();
|
||||||
section.writeVaruint32( func.id ); // function index
|
section.writeVaruint32( func.id ); // function index
|
||||||
List<String> paramNames = func.paramNames;
|
List<String> paramNames = func.paramNames;
|
||||||
@ -398,10 +433,6 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
|||||||
section.writeString( paramNames.get( i ) );
|
section.writeString( paramNames.get( i ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream.writeVaruint32( section.size() );
|
|
||||||
section.writeTo( stream );
|
|
||||||
|
|
||||||
wasm.writeSection( SectionType.Custom, stream );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user