mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 23:47:51 +01:00
next step for scanning on prepare
This commit is contained in:
parent
cd4f1cf307
commit
0b7fa50520
@ -48,13 +48,23 @@ public class FunctionManager {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mark the a function as scanned in the prepare phase. This should only occur with needed functions.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the function name
|
||||||
|
*/
|
||||||
|
void markAsScanned( FunctionName name ) {
|
||||||
|
getOrCreate( name ).state = State.Scanned;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the a function as written to the wasm file.
|
* Mark the a function as written to the wasm file.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* the function name
|
* the function name
|
||||||
*/
|
*/
|
||||||
void writeFunction( FunctionName name ) {
|
void markAsWritten( FunctionName name ) {
|
||||||
getOrCreate( name ).state = State.Written;
|
getOrCreate( name ).state = State.Written;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,13 +74,28 @@ public class FunctionManager {
|
|||||||
* @param name
|
* @param name
|
||||||
* the function name
|
* the function name
|
||||||
*/
|
*/
|
||||||
void functionCall( FunctionName name ) {
|
void markAsNeeded( FunctionName name ) {
|
||||||
FunctionState state = getOrCreate( name );
|
FunctionState state = getOrCreate( name );
|
||||||
if( state.state == State.None ) {
|
if( state.state == State.None ) {
|
||||||
state.state = State.Need;
|
state.state = State.Needed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the first FunctionName that is required but was not scanned.
|
||||||
|
*
|
||||||
|
* @return the FunctionName or null
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
FunctionName nextScannLater() {
|
||||||
|
for( Entry<FunctionName, FunctionState> entry : states.entrySet() ) {
|
||||||
|
if( entry.getValue().state == State.Needed ) {
|
||||||
|
return entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the first FunctionName that is required but was not written.
|
* Get the first FunctionName that is required but was not written.
|
||||||
*
|
*
|
||||||
@ -79,13 +104,31 @@ public class FunctionManager {
|
|||||||
@Nullable
|
@Nullable
|
||||||
FunctionName nextWriteLater() {
|
FunctionName nextWriteLater() {
|
||||||
for( Entry<FunctionName, FunctionState> entry : states.entrySet() ) {
|
for( Entry<FunctionName, FunctionState> entry : states.entrySet() ) {
|
||||||
if( entry.getValue().state == State.Need ) {
|
switch( entry.getValue().state ) {
|
||||||
return entry.getKey();
|
case Needed:
|
||||||
|
case Scanned:
|
||||||
|
return entry.getKey();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if the given function is required but was not scanned.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* the function name
|
||||||
|
* @return true, if the function on the to do list
|
||||||
|
*/
|
||||||
|
boolean needToScan( FunctionName name ) {
|
||||||
|
switch( getOrCreate( name ).state ) {
|
||||||
|
case Needed:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if the given function is required but was not written.
|
* if the given function is required but was not written.
|
||||||
*
|
*
|
||||||
@ -93,8 +136,14 @@ public class FunctionManager {
|
|||||||
* the function name
|
* the function name
|
||||||
* @return true, if the function on the to do list
|
* @return true, if the function on the to do list
|
||||||
*/
|
*/
|
||||||
boolean isToWrite( FunctionName name ) {
|
boolean needToWrite( FunctionName name ) {
|
||||||
return getOrCreate( name ).state == State.Need;
|
switch( getOrCreate( name ).state ) {
|
||||||
|
case Needed:
|
||||||
|
case Scanned:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,6 +183,6 @@ public class FunctionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static enum State {
|
private static enum State {
|
||||||
None, Need, Written;
|
None, Needed, Scanned, Written;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ package de.inetsoftware.jwebassembly.module;
|
|||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -148,9 +147,26 @@ public class ModuleGenerator {
|
|||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
* @throws IOException
|
||||||
|
* if any I/O error occur
|
||||||
*/
|
*/
|
||||||
public void prepareFinish() {
|
public void prepareFinish() throws IOException {
|
||||||
writer.prepareFinish();
|
writer.prepareFinish();
|
||||||
|
|
||||||
|
FunctionName next;
|
||||||
|
while( (next = functions.nextScannLater()) != null ) {
|
||||||
|
ClassFile classFile = ClassFile.get( next.className, libraries );
|
||||||
|
if( classFile == null ) {
|
||||||
|
} else {
|
||||||
|
iterateMethods( classFile, method -> {
|
||||||
|
FunctionName name = new FunctionName( method );
|
||||||
|
if( functions.needToScan( name ) ) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
functions.markAsScanned( next );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +200,7 @@ public class ModuleGenerator {
|
|||||||
name = new FunctionName( method );
|
name = new FunctionName( method );
|
||||||
method = functions.replace( name, method );
|
method = functions.replace( name, method );
|
||||||
}
|
}
|
||||||
if( functions.isToWrite( name ) ) {
|
if( functions.needToWrite( name ) ) {
|
||||||
writeMethod( name, method );
|
writeMethod( name, method );
|
||||||
}
|
}
|
||||||
} catch (IOException ioex){
|
} catch (IOException ioex){
|
||||||
@ -193,7 +209,7 @@ public class ModuleGenerator {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( functions.isToWrite( next ) ) {
|
if( functions.needToWrite( next ) ) {
|
||||||
throw new WasmException( "Missing function: " + next.signatureName, -1 );
|
throw new WasmException( "Missing function: " + next.signatureName, -1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -310,7 +326,7 @@ public class ModuleGenerator {
|
|||||||
if( !method.isStatic() ) {
|
if( !method.isStatic() ) {
|
||||||
throw new WasmException( "Import method must be static: " + name.fullName, -1 );
|
throw new WasmException( "Import method must be static: " + name.fullName, -1 );
|
||||||
}
|
}
|
||||||
functions.writeFunction( name );
|
functions.markAsWritten( name );
|
||||||
String impoarModule = (String)annotationValues.get( "module" );
|
String impoarModule = (String)annotationValues.get( "module" );
|
||||||
String importName = (String)annotationValues.get( "name" );
|
String importName = (String)annotationValues.get( "name" );
|
||||||
writer.prepareImport( name, impoarModule, importName );
|
writer.prepareImport( name, impoarModule, importName );
|
||||||
@ -321,7 +337,7 @@ public class ModuleGenerator {
|
|||||||
if( !method.isStatic() ) {
|
if( !method.isStatic() ) {
|
||||||
throw new WasmException( "Export method must be static: " + name.fullName, -1 );
|
throw new WasmException( "Export method must be static: " + name.fullName, -1 );
|
||||||
}
|
}
|
||||||
functions.functionCall( name );
|
functions.markAsNeeded( name );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if( (annotationValues = method.getAnnotation( JWebAssembly.REPLACE_ANNOTATION )) != null ) {
|
if( (annotationValues = method.getAnnotation( JWebAssembly.REPLACE_ANNOTATION )) != null ) {
|
||||||
@ -378,7 +394,7 @@ public class ModuleGenerator {
|
|||||||
|
|
||||||
private void writeMethodImpl( FunctionName name, boolean isStatic, WasmCodeBuilder codeBuilder ) throws WasmException, IOException {
|
private void writeMethodImpl( FunctionName name, boolean isStatic, WasmCodeBuilder codeBuilder ) throws WasmException, IOException {
|
||||||
writer.writeMethodStart( name, sourceFile );
|
writer.writeMethodStart( name, sourceFile );
|
||||||
functions.writeFunction( name );
|
functions.markAsWritten( name );
|
||||||
writeMethodSignature( name, isStatic, codeBuilder );
|
writeMethodSignature( name, isStatic, codeBuilder );
|
||||||
|
|
||||||
List<WasmInstruction> instructions = codeBuilder.getInstructions();
|
List<WasmInstruction> instructions = codeBuilder.getInstructions();
|
||||||
@ -405,7 +421,7 @@ public class ModuleGenerator {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Call:
|
case Call:
|
||||||
functions.functionCall( ((WasmCallInstruction)instruction).getFunctionName() );
|
functions.markAsNeeded( ((WasmCallInstruction)instruction).getFunctionName() );
|
||||||
break;
|
break;
|
||||||
case Struct:
|
case Struct:
|
||||||
WasmStructInstruction instr = (WasmStructInstruction)instruction;
|
WasmStructInstruction instr = (WasmStructInstruction)instruction;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user