mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 10:44:47 +01:00
pass the LocalVariableTable and the code position of variable using to the VariableManager
This commit is contained in:
parent
03a5c36ace
commit
cd7e20f5ed
@ -55,7 +55,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
||||
void buildCode( @Nonnull Code code, boolean hasReturn ) {
|
||||
CodeInputStream byteCode = null;
|
||||
try {
|
||||
reset();
|
||||
reset( code.getLocalVariableTable() );
|
||||
branchManager.reset( code );
|
||||
|
||||
byteCode = code.getByteCode();
|
||||
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.inetsoftware.classparser.LocalVariableTable;
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
import de.inetsoftware.jwebassembly.wasm.ValueType;
|
||||
@ -55,8 +56,11 @@ class LocaleVariableManager {
|
||||
|
||||
/**
|
||||
* Reset the manager to an initial state
|
||||
*
|
||||
* @param variableTable
|
||||
* variable table of the Java method.
|
||||
*/
|
||||
void reset() {
|
||||
void reset( LocalVariableTable variableTable ) {
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
LocaleVariable var = variables[i];
|
||||
var.valueType = null;
|
||||
@ -73,8 +77,10 @@ class LocaleVariableManager {
|
||||
* the type of the local variable
|
||||
* @param slot
|
||||
* the memory/slot index of the local variable
|
||||
* @param javaCodePos
|
||||
* the code position/offset in the Java method
|
||||
*/
|
||||
void use( AnyType valueType, int slot ) {
|
||||
void use( AnyType valueType, int slot, int javaCodePos ) {
|
||||
if( slot < 0 ) {
|
||||
needTempI32 = true;
|
||||
return;
|
||||
@ -100,7 +106,7 @@ class LocaleVariableManager {
|
||||
*/
|
||||
void calculate() {
|
||||
if( needTempI32 ) {
|
||||
use( ValueType.i32, size );
|
||||
use( ValueType.i32, size, -1 );
|
||||
}
|
||||
int idx = 0;
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
|
@ -22,6 +22,7 @@ import javax.annotation.Nonnegative;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.classparser.LocalVariableTable;
|
||||
import de.inetsoftware.classparser.Member;
|
||||
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
|
||||
import de.inetsoftware.jwebassembly.wasm.AnyType;
|
||||
@ -89,10 +90,13 @@ public abstract class WasmCodeBuilder {
|
||||
|
||||
/**
|
||||
* Reset the code builder.
|
||||
*
|
||||
* @param variableTable
|
||||
* variable table of the Java method.
|
||||
*/
|
||||
protected void reset() {
|
||||
protected void reset( LocalVariableTable variableTable ) {
|
||||
instructions.clear();
|
||||
localVariables.reset();
|
||||
localVariables.reset( variableTable );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +122,7 @@ public abstract class WasmCodeBuilder {
|
||||
*/
|
||||
@Nonnull
|
||||
protected void addLoadStoreInstruction( AnyType valueType, boolean load, @Nonnegative int javaIdx, int javaCodePos, int lineNumber ) {
|
||||
localVariables.use( valueType, javaIdx );
|
||||
localVariables.use( valueType, javaIdx, javaCodePos );
|
||||
instructions.add( new WasmLoadStoreInstruction( load, javaIdx, localVariables, javaCodePos, lineNumber ) );
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class WatParser extends WasmCodeBuilder {
|
||||
*/
|
||||
public void parse( String wat, int lineNumber ) {
|
||||
try {
|
||||
reset();
|
||||
reset( null );
|
||||
|
||||
List<String> tokens = splitTokens( wat );
|
||||
for( int i = 0; i < tokens.size(); i++ ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user