translate slot index to position index

This commit is contained in:
Volker Berlin 2017-04-09 22:45:52 +02:00
parent 68aaa5c589
commit cf55b7c52e

View File

@ -31,6 +31,7 @@ import de.inetsoftware.classparser.Code;
import de.inetsoftware.classparser.CodeInputStream; import de.inetsoftware.classparser.CodeInputStream;
import de.inetsoftware.classparser.ConstantPool; import de.inetsoftware.classparser.ConstantPool;
import de.inetsoftware.classparser.LineNumberTable; import de.inetsoftware.classparser.LineNumberTable;
import de.inetsoftware.classparser.LocalVariableTable;
import de.inetsoftware.classparser.MethodInfo; import de.inetsoftware.classparser.MethodInfo;
import de.inetsoftware.jwebassembly.WasmException; import de.inetsoftware.jwebassembly.WasmException;
@ -45,6 +46,8 @@ public abstract class ModuleWriter implements Closeable {
private ArrayList<ValueType> locals = new ArrayList<>(); private ArrayList<ValueType> locals = new ArrayList<>();
private LocalVariableTable localTable;
private String sourceFile; private String sourceFile;
/** /**
@ -91,6 +94,7 @@ public abstract class ModuleWriter implements Closeable {
writeMethodStart( methodName ); writeMethodStart( methodName );
writeMethodSignature( method ); writeMethodSignature( method );
locals.clear(); locals.clear();
localTable = code.getLocalVariableTable();
LineNumberTable lineNumberTable = code.getLineNumberTable(); LineNumberTable lineNumberTable = code.getLineNumberTable();
if( lineNumberTable != null ) { if( lineNumberTable != null ) {
int lineNumber; int lineNumber;
@ -395,13 +399,14 @@ public abstract class ModuleWriter implements Closeable {
* @param valueType * @param valueType
* the type of the variable * the type of the variable
* @param idx * @param idx
* the idx of the variable * the memory/slot idx of the variable
* @throws WasmException * @throws WasmException
* occur a if a variable was used for a different type * occur a if a variable was used for a different type
* @throws IOException * @throws IOException
* if any I/O error occur * if any I/O error occur
*/ */
private void writeLoadStore( boolean load, @Nonnull ValueType valueType, @Nonnegative int idx ) throws WasmException, IOException { private void writeLoadStore( boolean load, @Nonnull ValueType valueType, @Nonnegative int idx ) throws WasmException, IOException {
idx = localTable.get( idx ).getPosition(); // translate slot index to position index
while( locals.size() <= idx ) { while( locals.size() <= idx ) {
locals.add( null ); locals.add( null );
} }