define the types in the prepare phase.

This commit is contained in:
Volker Berlin 2019-06-04 18:09:34 +02:00
parent 557c348ed7
commit c410adc636
4 changed files with 22 additions and 7 deletions

View File

@ -478,7 +478,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public void prepareFinish() { protected void prepareFinish() {
// initialize the function index IDs // initialize the function index IDs
// https://github.com/WebAssembly/design/blob/master/Modules.md#function-index-space // https://github.com/WebAssembly/design/blob/master/Modules.md#function-index-space
int id = 0; int id = 0;

View File

@ -150,8 +150,6 @@ public class ModuleGenerator {
* if any I/O error occur * if any I/O error occur
*/ */
public void prepareFinish() throws IOException { public void prepareFinish() throws IOException {
writer.prepareFinish();
// scan all methods that should be write to build optimize structures // scan all methods that should be write to build optimize structures
FunctionName next; FunctionName next;
NEXT: NEXT:
@ -159,6 +157,7 @@ public class ModuleGenerator {
ClassFile classFile = ClassFile.get( next.className, libraries ); ClassFile classFile = ClassFile.get( next.className, libraries );
if( classFile == null ) { if( classFile == null ) {
if( next instanceof SyntheticFunctionName ) { if( next instanceof SyntheticFunctionName ) {
writeMethodSignature( next, true, null );
scanMethod( ((SyntheticFunctionName)next).getCodeBuilder( watParser ) ); scanMethod( ((SyntheticFunctionName)next).getCodeBuilder( watParser ) );
functions.markAsScanned( next ); functions.markAsScanned( next );
} }
@ -167,6 +166,7 @@ public class ModuleGenerator {
try { try {
FunctionName name = new FunctionName( method ); FunctionName name = new FunctionName( method );
if( functions.needToScan( name ) ) { if( functions.needToScan( name ) ) {
writeMethodSignature( name, method.isStatic(), null );
scanMethod( createInstructions( method ) ); scanMethod( createInstructions( method ) );
functions.markAsScanned( name ); functions.markAsScanned( name );
} }
@ -196,6 +196,7 @@ public class ModuleGenerator {
functions.prepareFinish(); functions.prepareFinish();
types.prepareFinish( writer, functions, libraries ); types.prepareFinish( writer, functions, libraries );
writer.prepareFinish();
} }
/** /**

View File

@ -42,9 +42,7 @@ public abstract class ModuleWriter implements Closeable {
* Finish the prepare after all classes/methods are prepare. This must be call before we can start with write the * Finish the prepare after all classes/methods are prepare. This must be call before we can start with write the
* first method. * first method.
*/ */
public void prepareFinish() { protected abstract void prepareFinish();
}
/** /**
* Write a type/struct. * Write a type/struct.

View File

@ -71,6 +71,8 @@ public class TextModuleWriter extends ModuleWriter {
private boolean isImport; private boolean isImport;
private boolean isPrepared;
private HashSet<String> globals = new HashSet<>(); private HashSet<String> globals = new HashSet<>();
private boolean useExceptions; private boolean useExceptions;
@ -187,6 +189,14 @@ public class TextModuleWriter extends ModuleWriter {
} }
} }
/**
* {@inheritDoc}
*/
@Override
protected void prepareFinish() {
isPrepared = true;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -273,6 +283,9 @@ public class TextModuleWriter extends ModuleWriter {
writeTypeName( typeOutput, valueType ); writeTypeName( typeOutput, valueType );
typeOutput.append( ')' ); typeOutput.append( ')' );
} }
if( !isPrepared ) {
return;
}
methodOutput.append( '(' ).append( kind ); methodOutput.append( '(' ).append( kind );
if( debugNames ) { if( debugNames ) {
if( name != null ) { if( name != null ) {
@ -563,10 +576,13 @@ public class TextModuleWriter extends ModuleWriter {
protected void writeVirtualFunctionCall( FunctionName name, AnyType type, int virtualFunctionIdx ) throws IOException { protected void writeVirtualFunctionCall( FunctionName name, AnyType type, int virtualFunctionIdx ) throws IOException {
callIndirect = true; callIndirect = true;
newline( methodOutput ); newline( methodOutput );
methodOutput.append( "struct.get $" ).append( normalizeName( type.toString() ) ).append( " 0 ;;vtable" ); // vtable is ever on position 0 methodOutput.append( "struct.get " ).append( normalizeName( type.toString() ) ).append( " 0 ;;vtable" ); // vtable is ever on position 0
newline( methodOutput ); newline( methodOutput );
methodOutput.append( "i32.load offset=" ).append( virtualFunctionIdx * 4 ); // use default alignment methodOutput.append( "i32.load offset=" ).append( virtualFunctionIdx * 4 ); // use default alignment
newline( methodOutput ); newline( methodOutput );
if(spiderMonkey)
methodOutput.append( "call_indirect $t" ).append( functions.get( name.signatureName ) ); // https://bugzilla.mozilla.org/show_bug.cgi?id=1556779
else
methodOutput.append( "call_indirect (type $t" ).append( functions.get( name.signatureName ) ).append( ')' ); methodOutput.append( "call_indirect (type $t" ).append( functions.get( name.signatureName ) ).append( ')' );
} }