mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
constant pool can also contains string constants
This commit is contained in:
parent
4f79782bfe
commit
ca9efce370
@ -16,7 +16,6 @@
|
||||
package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
@ -126,11 +125,11 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
||||
addConstInstruction( Integer.valueOf( byteCode.readShort() ), ValueType.i32, codePos, lineNumber );
|
||||
break;
|
||||
case 18: // ldc
|
||||
addConstInstruction( (Number)constantPool.get( byteCode.readUnsignedByte() ), codePos, lineNumber );
|
||||
addConstInstruction( constantPool.get( byteCode.readUnsignedByte() ), codePos, lineNumber );
|
||||
break;
|
||||
case 19: // ldc_w
|
||||
case 20: // ldc2_w
|
||||
addConstInstruction( (Number)constantPool.get( byteCode.readUnsignedShort() ), codePos, lineNumber );
|
||||
addConstInstruction( constantPool.get( byteCode.readUnsignedShort() ), codePos, lineNumber );
|
||||
break;
|
||||
case 21: // iload
|
||||
addLoadStoreInstruction( ValueType.i32, true, byteCode.readUnsignedIndex( wide ), codePos, lineNumber );
|
||||
|
@ -17,7 +17,9 @@ package de.inetsoftware.jwebassembly.module;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnegative;
|
||||
@ -59,6 +61,8 @@ public abstract class WasmCodeBuilder {
|
||||
|
||||
private WasmOptions options;
|
||||
|
||||
private Map<String, Integer> strings = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Initialize the code builder;
|
||||
*
|
||||
@ -308,8 +312,17 @@ public abstract class WasmCodeBuilder {
|
||||
* @param lineNumber
|
||||
* the line number in the Java source code
|
||||
*/
|
||||
protected void addConstInstruction( Number value, int javaCodePos, int lineNumber ) {
|
||||
instructions.add( new WasmConstInstruction( value, javaCodePos, lineNumber ) );
|
||||
protected void addConstInstruction( Object value, int javaCodePos, int lineNumber ) {
|
||||
if( value.getClass() == String.class ) {
|
||||
Integer id = strings.get( value );
|
||||
if( id == null ) {
|
||||
strings.put( (String)value, id = strings.size() );
|
||||
}
|
||||
FunctionName name = getNonGC( "stringConstant", lineNumber );
|
||||
addCallInstruction( name, javaCodePos, lineNumber );
|
||||
} else {
|
||||
instructions.add( new WasmConstInstruction( (Number)value, javaCodePos, lineNumber ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user