mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 18:44:47 +01:00
define the types in the prepare phase.
This commit is contained in:
parent
557c348ed7
commit
c410adc636
@ -478,7 +478,7 @@ public class BinaryModuleWriter extends ModuleWriter implements InstructionOpcod
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void prepareFinish() {
|
||||
protected void prepareFinish() {
|
||||
// initialize the function index IDs
|
||||
// https://github.com/WebAssembly/design/blob/master/Modules.md#function-index-space
|
||||
int id = 0;
|
||||
|
@ -150,8 +150,6 @@ public class ModuleGenerator {
|
||||
* if any I/O error occur
|
||||
*/
|
||||
public void prepareFinish() throws IOException {
|
||||
writer.prepareFinish();
|
||||
|
||||
// scan all methods that should be write to build optimize structures
|
||||
FunctionName next;
|
||||
NEXT:
|
||||
@ -159,6 +157,7 @@ public class ModuleGenerator {
|
||||
ClassFile classFile = ClassFile.get( next.className, libraries );
|
||||
if( classFile == null ) {
|
||||
if( next instanceof SyntheticFunctionName ) {
|
||||
writeMethodSignature( next, true, null );
|
||||
scanMethod( ((SyntheticFunctionName)next).getCodeBuilder( watParser ) );
|
||||
functions.markAsScanned( next );
|
||||
}
|
||||
@ -167,6 +166,7 @@ public class ModuleGenerator {
|
||||
try {
|
||||
FunctionName name = new FunctionName( method );
|
||||
if( functions.needToScan( name ) ) {
|
||||
writeMethodSignature( name, method.isStatic(), null );
|
||||
scanMethod( createInstructions( method ) );
|
||||
functions.markAsScanned( name );
|
||||
}
|
||||
@ -196,6 +196,7 @@ public class ModuleGenerator {
|
||||
functions.prepareFinish();
|
||||
|
||||
types.prepareFinish( writer, functions, libraries );
|
||||
writer.prepareFinish();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
* first method.
|
||||
*/
|
||||
public void prepareFinish() {
|
||||
|
||||
}
|
||||
protected abstract void prepareFinish();
|
||||
|
||||
/**
|
||||
* Write a type/struct.
|
||||
|
@ -71,6 +71,8 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
|
||||
private boolean isImport;
|
||||
|
||||
private boolean isPrepared;
|
||||
|
||||
private HashSet<String> globals = new HashSet<>();
|
||||
|
||||
private boolean useExceptions;
|
||||
@ -187,6 +189,14 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected void prepareFinish() {
|
||||
isPrepared = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@ -273,6 +283,9 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
writeTypeName( typeOutput, valueType );
|
||||
typeOutput.append( ')' );
|
||||
}
|
||||
if( !isPrepared ) {
|
||||
return;
|
||||
}
|
||||
methodOutput.append( '(' ).append( kind );
|
||||
if( debugNames ) {
|
||||
if( name != null ) {
|
||||
@ -563,10 +576,13 @@ public class TextModuleWriter extends ModuleWriter {
|
||||
protected void writeVirtualFunctionCall( FunctionName name, AnyType type, int virtualFunctionIdx ) throws IOException {
|
||||
callIndirect = true;
|
||||
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 );
|
||||
methodOutput.append( "i32.load offset=" ).append( virtualFunctionIdx * 4 ); // use default alignment
|
||||
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( ')' );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user