simplify the scan and the compiler structure, remove some old hacks.

This commit is contained in:
Volker Berlin 2020-02-29 16:14:32 +01:00
parent 7ed9ee576a
commit 3d8f49c79a
4 changed files with 7 additions and 56 deletions

View File

@ -199,7 +199,7 @@ public class ModuleGenerator {
JWebAssembly.LOGGER.fine( '\t' + next.methodName + next.signature );
SyntheticFunctionName synth = (SyntheticFunctionName)next;
if( synth.hasWasmCode() ) {
scanMethod( synth.getCodeBuilder( watParser ) );
synth.getCodeBuilder( watParser );
} else {
functions.markAsImport( synth, synth.getAnnotation() );
}
@ -219,7 +219,7 @@ public class ModuleGenerator {
method = functions.replace( next, null );
}
if( method != null ) {
scanMethod( createInstructions( functions.replace( next, method ) ) );
createInstructions( functions.replace( next, method ) );
boolean needThisParameter = !method.isStatic() || "<init>".equals( method.getName() );
functions.markAsScanned( next, needThisParameter );
continue;
@ -304,30 +304,6 @@ public class ModuleGenerator {
writer.prepareFinish();
}
/**
* Scan the method and list all needed methods.
*
* @param codeBuilder
* the codeBuilder with instructions of the method
* @throws IOException
* if any I/O error occur
*/
private void scanMethod( WasmCodeBuilder codeBuilder ) throws IOException {
if( codeBuilder == null ) {
return;
}
List<WasmInstruction> instructions = codeBuilder.getInstructions();
for( WasmInstruction instruction : instructions ) {
switch( instruction.getType() ) {
case Call:
case CallVirtual:
((WasmCallInstruction)instruction).markAsNeeded( functions );
break;
default:
}
}
}
/**
* Finish the code generation.
*
@ -548,10 +524,6 @@ public class ModuleGenerator {
default:
}
break;
case Call:
case CallVirtual:
((WasmCallInstruction)instruction).markAsNeeded( functions );
break;
case Struct:
if( !writer.options.useGC() ) {
break;

View File

@ -89,16 +89,6 @@ class WasmCallInstruction extends WasmInstruction {
return types;
}
/**
* Mark the function as needed in the functions manager and replace the function name with a possible super name.
*
* @param functions
* the function manager
*/
void markAsNeeded( @Nonnull FunctionManager functions ) {
name = functions.markAsNeeded( name );
}
/**
* {@inheritDoc}
*/

View File

@ -21,9 +21,6 @@ import java.io.IOException;
import javax.annotation.Nonnull;
import de.inetsoftware.jwebassembly.module.TypeManager.StructType;
import de.inetsoftware.jwebassembly.wasm.MemoryOperator;
import de.inetsoftware.jwebassembly.wasm.NamedStorageType;
import de.inetsoftware.jwebassembly.wasm.StructOperator;
import de.inetsoftware.jwebassembly.wasm.ValueType;
import de.inetsoftware.jwebassembly.wasm.VariableOperator;
@ -35,8 +32,6 @@ import de.inetsoftware.jwebassembly.wasm.VariableOperator;
*/
class WasmCallVirtualInstruction extends WasmCallIndirectInstruction {
private int virtualFunctionIdx = -1;
private final WasmOptions options;
/**
@ -66,22 +61,13 @@ class WasmCallVirtualInstruction extends WasmCallIndirectInstruction {
return Type.CallVirtual;
}
/**
* {@inheritDoc}
*/
@Override
void markAsNeeded( FunctionManager functions ) {
super.markAsNeeded( functions );
virtualFunctionIdx = functions.getFunctionIndex( getFunctionName() );
}
/**
* if this call is executed virtual or if is was optimized.
*
* @return true, virtual call
*/
boolean isVirtual() {
return virtualFunctionIdx > 0;
return options.functions.getFunctionIndex( getFunctionName() ) > 0;
}
/**
@ -89,6 +75,7 @@ class WasmCallVirtualInstruction extends WasmCallIndirectInstruction {
*/
@Override
public void writeTo( @Nonnull ModuleWriter writer ) throws IOException {
int virtualFunctionIdx = options.functions.getFunctionIndex( getFunctionName() );
if( virtualFunctionIdx < 0 ) {
super.writeTo( writer );
} else {

View File

@ -30,7 +30,6 @@ import de.inetsoftware.classparser.Member;
import de.inetsoftware.classparser.MethodInfo;
import de.inetsoftware.jwebassembly.WasmException;
import de.inetsoftware.jwebassembly.javascript.JavaScriptNewMultiArrayFunctionName;
import de.inetsoftware.jwebassembly.javascript.JavaScriptSyntheticFunctionName;
import de.inetsoftware.jwebassembly.javascript.NonGC;
import de.inetsoftware.jwebassembly.module.WasmInstruction.Type;
import de.inetsoftware.jwebassembly.wasm.AnyType;
@ -416,6 +415,7 @@ public abstract class WasmCodeBuilder {
* the line number in the Java source code
*/
protected void addCallInstruction( FunctionName name, int javaCodePos, int lineNumber ) {
name = functions.markAsNeeded( name );
boolean needThisParameter = functions.needThisParameter( name );
WasmCallInstruction instruction = new WasmCallInstruction( name, javaCodePos, lineNumber, types, needThisParameter );
@ -506,6 +506,7 @@ public abstract class WasmCodeBuilder {
* the line number in the Java source code
*/
protected void addCallVirtualInstruction( FunctionName name, int javaCodePos, int lineNumber ) {
name = functions.markAsNeeded( name );
addCallIndirectInstruction( new WasmCallVirtualInstruction( name, javaCodePos, lineNumber, types, options ) );
options.getCallVirtual(); // mark the function as needed
}
@ -520,6 +521,7 @@ public abstract class WasmCodeBuilder {
* the line number in the Java source code
*/
protected void addCallInterfaceInstruction( FunctionName name, int javaCodePos, int lineNumber ) {
//TODO name = functions.markAsNeeded( name );
addCallIndirectInstruction( new WasmCallInterfaceInstruction( name, javaCodePos, lineNumber, types, options ) );
}