detect all needed types in the prepare phase

This commit is contained in:
Volker Berlin 2019-05-19 11:14:32 +02:00
parent 30efaaed95
commit 8f09d4d04a
3 changed files with 27 additions and 7 deletions

View File

@ -576,15 +576,23 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
addStructInstruction( StructOperator.SET, ref.getClassName(), new NamedStorageType( ref, getTypeManager() ), codePos, lineNumber );
break;
case 182: // invokevirtual
idx = byteCode.readUnsignedShort();
ref = (ConstantRef)constantPool.get( idx );
addCallVirtualInstruction( new FunctionName( ref ), codePos, lineNumber );
break;
case 183: // invokespecial, invoke a constructor
case 184: // invokestatic
idx = byteCode.readUnsignedShort();
ref = (ConstantRef)constantPool.get( idx );
addCallInstruction( new FunctionName( ref ), codePos, lineNumber );
FunctionName funcName = new FunctionName( ref );
switch( op ) {
case 182:
addCallVirtualInstruction( funcName, codePos, lineNumber );
break;
case 183:
getTypeManager().valueOf( funcName.className ); // TODO pass this as first parameter
addCallInstruction( funcName, codePos, lineNumber );
break;
case 184:
addCallInstruction( funcName, codePos, lineNumber );
break;
}
break;
//TODO case 185: // invokeinterface
//TODO case 186: // invokedynamic

View File

@ -180,6 +180,7 @@ public class ModuleGenerator {
}
if( functions.needToScan( next ) ) { // function was not found
// search if there is a super class with the same signature
ClassFile superClassFile = classFile;
while( superClassFile != null ) {
MethodInfo method = superClassFile.getMethod( next.methodName, next.signature );
@ -187,7 +188,7 @@ public class ModuleGenerator {
FunctionName name = new FunctionName( method );
functions.markAsNeeded( name );
functions.setAlias( next, name );
continue NEXT;
continue NEXT; // we have found a super method
}
ConstantClass superClass = superClassFile.getSuperClass();
superClassFile = superClass == null ? null : ClassFile.get( superClass.getName(), libraries );
@ -196,6 +197,8 @@ public class ModuleGenerator {
}
}
functions.prepareFinish();
types.prepareFinish();
}
/**

View File

@ -17,6 +17,7 @@
package de.inetsoftware.jwebassembly.module;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -33,7 +34,15 @@ import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
*/
public class TypeManager {
private final Map<String, StructType> map = new LinkedHashMap<>();
private Map<String, StructType> map = new LinkedHashMap<>();
/**
* Finish the prepare. Now no new function should be added.
*/
public void prepareFinish() {
map = Collections.unmodifiableMap( map );
}
/**
* Use the type in the output.