Class ModuleGenerator
java.lang.Object
de.inetsoftware.jwebassembly.module.ModuleGenerator
Generate the WebAssembly output.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassFileLoader
private String
private final FunctionManager
private final JavaMethodWasmCodeBuilder
private final JavaScriptWriter
private String
private final CodeOptimizer
private String
private final StaticCodeBuilder
private final StringManager
private final TypeManager
private final WatParser
private final ModuleWriter
-
Constructor Summary
ConstructorsConstructorDescriptionModuleGenerator
(ModuleWriter writer, WasmTarget target, List<URL> libraries) Create a new generator. -
Method Summary
Modifier and TypeMethodDescriptionprivate WasmCodeBuilder
createInstructions
(MethodInfo method) Create the instructions in a code buildervoid
finish()
Finish the code generation.private void
iterateMethods
(ClassFile classFile, Consumer<MethodInfo> handler) Iterate over all methods of the classFile and run the handler.void
Prepare the content of the class.void
Finish the prepare after all classes/methods are prepare.private void
prepareMethod
(MethodInfo method) Prepare the method.private void
Add a start method for the static class constructorsprivate void
Scan for needed static constructors.private boolean
scanFunctionInterfaces
(ClassFile classFile, FunctionName next) Search if there is a default implementation in an interface for the given method.private void
Scan all needed methods/functions in a loop.private void
scanLibraries
(List<URL> libraries) Scan the libraries for annotated methodsprivate void
writeExport
(FunctionName name, MethodInfo method) Look for a Export annotation and if there write an export directive.private void
writeMethod
(FunctionName name, MethodInfo method) Write the content of a method.private void
writeMethodImpl
(FunctionName name, WasmCodeBuilder codeBuilder) Write the method instruction to the Wasm writer.private void
writeMethodSignature
(FunctionName name, FunctionType funcType, WasmCodeBuilder codeBuilder) Write the parameter and return signatures
-
Field Details
-
writer
-
javaScript
-
classFileLoader
-
javaCodeBuilder
-
watParser
-
sourceFile
-
className
-
methodName
-
functions
-
types
-
strings
-
optimizer
-
staticCodeBuilder
-
-
Constructor Details
-
ModuleGenerator
public ModuleGenerator(@Nonnull ModuleWriter writer, WasmTarget target, @Nonnull List<URL> libraries) Create a new generator.- Parameters:
writer
- the target writertarget
- the target for the module datalibraries
- libraries
-
-
Method Details
-
scanLibraries
Scan the libraries for annotated methods- Parameters:
libraries
- libraries
-
prepare
Prepare the content of the class.- Parameters:
classFile
- the class file- Throws:
WasmException
- if some Java code can't convertedIOException
- if any I/O error occur
-
scanFunctions
Scan all needed methods/functions in a loop. If the scan find more needed content then the loop continue.- Throws:
IOException
- if any I/O error occur
-
scanFunctionInterfaces
Search if there is a default implementation in an interface for the given method.- Parameters:
classFile
- the class to scannext
- the method to scan- Returns:
- true, if method was found
- Throws:
IOException
- if any I/O error occur
-
prepareFinish
Finish the prepare after all classes/methods are prepare. This must be call before we can start with write the first method.- Throws:
IOException
- if any I/O error occur
-
scanForClinit
Scan for needed static constructors. The static code of all classes that used in any form must be executed.- Throws:
IOException
- if any I/O error occur
-
prepareStartFunction
Add a start method for the static class constructors- Throws:
IOException
- if any I/O error occur
-
finish
Finish the code generation.- Throws:
IOException
- if any I/O error occur
-
iterateMethods
Iterate over all methods of the classFile and run the handler.- Parameters:
classFile
- the classFilehandler
- the handler- Throws:
WasmException
- if some Java code can't converted
-
prepareMethod
Prepare the method.- Parameters:
method
- the method- Throws:
WasmException
- if some Java code can't converted
-
writeMethod
Write the content of a method.- Parameters:
name
- the function name that should be written. This can be differ from the value in the MethodInfomethod
- the method- Throws:
WasmException
- if some Java code can't convertedIOException
- if any I/O error occur
-
createInstructions
Create the instructions in a code builder- Parameters:
method
- the method to parse- Returns:
- the CodeBuilder or null if it is an import function
- Throws:
IOException
- if any I/O error occur
-
writeMethodImpl
private void writeMethodImpl(FunctionName name, WasmCodeBuilder codeBuilder) throws WasmException, IOException Write the method instruction to the Wasm writer.- Parameters:
name
- the name of the functioncodeBuilder
- the code builder with instructions- Throws:
WasmException
- if some Java code can't convertedIOException
- if an i/O error occur
-
writeExport
Look for a Export annotation and if there write an export directive.- Parameters:
name
- the function namemethod
- the method- Throws:
IOException
- if any IOException occur
-
writeMethodSignature
private void writeMethodSignature(@Nonnull FunctionName name, @Nonnull FunctionType funcType, @Nullable WasmCodeBuilder codeBuilder) throws IOException, WasmException Write the parameter and return signatures- Parameters:
name
- the Java signature, typical method.getType();funcType
- the type of functioncodeBuilder
- the calculated variables- Throws:
IOException
- if any I/O error occurWasmException
- if some Java code can't converted
-