mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
detect all needed types in the prepare phase
This commit is contained in:
parent
30efaaed95
commit
8f09d4d04a
@ -576,15 +576,23 @@ class JavaMethodWasmCodeBuilder extends WasmCodeBuilder {
|
|||||||
addStructInstruction( StructOperator.SET, ref.getClassName(), new NamedStorageType( ref, getTypeManager() ), codePos, lineNumber );
|
addStructInstruction( StructOperator.SET, ref.getClassName(), new NamedStorageType( ref, getTypeManager() ), codePos, lineNumber );
|
||||||
break;
|
break;
|
||||||
case 182: // invokevirtual
|
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 183: // invokespecial, invoke a constructor
|
||||||
case 184: // invokestatic
|
case 184: // invokestatic
|
||||||
idx = byteCode.readUnsignedShort();
|
idx = byteCode.readUnsignedShort();
|
||||||
ref = (ConstantRef)constantPool.get( idx );
|
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;
|
break;
|
||||||
//TODO case 185: // invokeinterface
|
//TODO case 185: // invokeinterface
|
||||||
//TODO case 186: // invokedynamic
|
//TODO case 186: // invokedynamic
|
||||||
|
@ -180,6 +180,7 @@ public class ModuleGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( functions.needToScan( next ) ) { // function was not found
|
if( functions.needToScan( next ) ) { // function was not found
|
||||||
|
// search if there is a super class with the same signature
|
||||||
ClassFile superClassFile = classFile;
|
ClassFile superClassFile = classFile;
|
||||||
while( superClassFile != null ) {
|
while( superClassFile != null ) {
|
||||||
MethodInfo method = superClassFile.getMethod( next.methodName, next.signature );
|
MethodInfo method = superClassFile.getMethod( next.methodName, next.signature );
|
||||||
@ -187,7 +188,7 @@ public class ModuleGenerator {
|
|||||||
FunctionName name = new FunctionName( method );
|
FunctionName name = new FunctionName( method );
|
||||||
functions.markAsNeeded( name );
|
functions.markAsNeeded( name );
|
||||||
functions.setAlias( next, name );
|
functions.setAlias( next, name );
|
||||||
continue NEXT;
|
continue NEXT; // we have found a super method
|
||||||
}
|
}
|
||||||
ConstantClass superClass = superClassFile.getSuperClass();
|
ConstantClass superClass = superClassFile.getSuperClass();
|
||||||
superClassFile = superClass == null ? null : ClassFile.get( superClass.getName(), libraries );
|
superClassFile = superClass == null ? null : ClassFile.get( superClass.getName(), libraries );
|
||||||
@ -196,6 +197,8 @@ public class ModuleGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
functions.prepareFinish();
|
functions.prepareFinish();
|
||||||
|
|
||||||
|
types.prepareFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package de.inetsoftware.jwebassembly.module;
|
package de.inetsoftware.jwebassembly.module;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -33,7 +34,15 @@ import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
|
|||||||
*/
|
*/
|
||||||
public class TypeManager {
|
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.
|
* Use the type in the output.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user