pass the LocalVariableTable and the code position of variable using to the VariableManager

This commit is contained in:
Volker Berlin 2019-04-06 17:51:29 +02:00
parent 03a5c36ace
commit cd7e20f5ed
4 changed files with 18 additions and 8 deletions

View File

@ -55,7 +55,7 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
void buildCode( @Nonnull Code code, boolean hasReturn ) { void buildCode( @Nonnull Code code, boolean hasReturn ) {
CodeInputStream byteCode = null; CodeInputStream byteCode = null;
try { try {
reset(); reset( code.getLocalVariableTable() );
branchManager.reset( code ); branchManager.reset( code );
byteCode = code.getByteCode(); byteCode = code.getByteCode();

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import de.inetsoftware.classparser.LocalVariableTable;
import de.inetsoftware.jwebassembly.WasmException; import de.inetsoftware.jwebassembly.WasmException;
import de.inetsoftware.jwebassembly.wasm.AnyType; import de.inetsoftware.jwebassembly.wasm.AnyType;
import de.inetsoftware.jwebassembly.wasm.ValueType; import de.inetsoftware.jwebassembly.wasm.ValueType;
@ -55,8 +56,11 @@ class LocaleVariableManager {
/** /**
* Reset the manager to an initial state * 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++ ) { for( int i = 0; i < size; i++ ) {
LocaleVariable var = variables[i]; LocaleVariable var = variables[i];
var.valueType = null; var.valueType = null;
@ -73,8 +77,10 @@ class LocaleVariableManager {
* the type of the local variable * the type of the local variable
* @param slot * @param slot
* the memory/slot index of the local variable * 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 ) { if( slot < 0 ) {
needTempI32 = true; needTempI32 = true;
return; return;
@ -100,7 +106,7 @@ class LocaleVariableManager {
*/ */
void calculate() { void calculate() {
if( needTempI32 ) { if( needTempI32 ) {
use( ValueType.i32, size ); use( ValueType.i32, size, -1 );
} }
int idx = 0; int idx = 0;
for( int i = 0; i < size; i++ ) { for( int i = 0; i < size; i++ ) {

View File

@ -22,6 +22,7 @@ import javax.annotation.Nonnegative;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import de.inetsoftware.classparser.LocalVariableTable;
import de.inetsoftware.classparser.Member; import de.inetsoftware.classparser.Member;
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type; import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
import de.inetsoftware.jwebassembly.wasm.AnyType; import de.inetsoftware.jwebassembly.wasm.AnyType;
@ -89,10 +90,13 @@ public abstract class WasmCodeBuilder {
/** /**
* Reset the code builder. * Reset the code builder.
*
* @param variableTable
* variable table of the Java method.
*/ */
protected void reset() { protected void reset( LocalVariableTable variableTable ) {
instructions.clear(); instructions.clear();
localVariables.reset(); localVariables.reset( variableTable );
} }
/** /**
@ -118,7 +122,7 @@ public abstract class WasmCodeBuilder {
*/ */
@Nonnull @Nonnull
protected void addLoadStoreInstruction( AnyType valueType, boolean load, @Nonnegative int javaIdx, int javaCodePos, int lineNumber ) { 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 ) ); instructions.add( new WasmLoadStoreInstruction( load, javaIdx, localVariables, javaCodePos, lineNumber ) );
} }

View File

@ -47,7 +47,7 @@ public class WatParser extends WasmCodeBuilder {
*/ */
public void parse( String wat, int lineNumber ) { public void parse( String wat, int lineNumber ) {
try { try {
reset(); reset( null );
List<String> tokens = splitTokens( wat ); List<String> tokens = splitTokens( wat );
for( int i = 0; i < tokens.size(); i++ ) { for( int i = 0; i < tokens.size(); i++ ) {