mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
add support for global.get/set for the WatParser
This commit is contained in:
parent
0dfb7c4a34
commit
128906e4ef
@ -29,6 +29,7 @@ import javax.annotation.Nullable;
|
||||
import de.inetsoftware.classparser.BootstrapMethod;
|
||||
import de.inetsoftware.classparser.ClassFile;
|
||||
import de.inetsoftware.classparser.ConstantClass;
|
||||
import de.inetsoftware.classparser.FieldInfo;
|
||||
import de.inetsoftware.classparser.LocalVariableTable;
|
||||
import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.classparser.MethodInfo;
|
||||
@ -536,6 +537,33 @@ public abstract class WasmCodeBuilder {
|
||||
functions.markClassAsUsed( name.className );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a global field access instruction
|
||||
*
|
||||
* @param load
|
||||
* true: if load (get)
|
||||
* @param fieldName
|
||||
* the fieldName like java/lang/System.err
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
* @param lineNumber
|
||||
* the line number in the Java source code
|
||||
*/
|
||||
protected void addGlobalInstruction( boolean load, String fieldName, int javaCodePos, int lineNumber ) {
|
||||
try {
|
||||
if( fieldName.startsWith( "$" ) ) {
|
||||
fieldName = fieldName.substring( 1 );
|
||||
}
|
||||
FunctionName name = new FunctionName( fieldName + "()V" );
|
||||
ClassFile classFile = classFileLoader.get( name.className );
|
||||
FieldInfo field = classFile.getField( name.methodName );
|
||||
AnyType type = new ValueTypeParser( field.getType(), types ).next();
|
||||
addGlobalInstruction( load, name, type, null, javaCodePos, lineNumber );
|
||||
} catch( Exception ex ) {
|
||||
throw WasmException.create( ex, lineNumber );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a WasmTableInstruction table.get/table.set.
|
||||
*
|
||||
|
@ -77,9 +77,12 @@ public class WatParser extends WasmCodeBuilder {
|
||||
case "local.tee":
|
||||
addLocalInstruction( VariableOperator.tee, getInt( tokens, ++i), javaCodePos, lineNumber );
|
||||
break;
|
||||
// case "get_global":
|
||||
// addGlobalInstruction( true, ref, javaCodePos );
|
||||
// break;
|
||||
case "global.get":
|
||||
addGlobalInstruction( true, get( tokens, ++i), javaCodePos, lineNumber );
|
||||
break;
|
||||
case "global.set":
|
||||
addGlobalInstruction( false, get( tokens, ++i), javaCodePos, lineNumber );
|
||||
break;
|
||||
case "i32.const":
|
||||
addConstInstruction( getInt( tokens, ++i), ValueType.i32, javaCodePos, lineNumber );
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user