Class ModuleGenerator
java.lang.Object
de.inetsoftware.jwebassembly.module.ModuleGenerator
Generate the WebAssembly output.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassFileLoaderprivate Stringprivate final FunctionManagerprivate final JavaMethodWasmCodeBuilderprivate final JavaScriptWriterprivate Stringprivate final CodeOptimizerprivate Stringprivate final StaticCodeBuilderprivate final StringManagerprivate final TypeManagerprivate final WatParserprivate final ModuleWriter -
Constructor Summary
ConstructorsConstructorDescriptionModuleGenerator(ModuleWriter writer, WasmTarget target, List<URL> libraries) Create a new generator. -
Method Summary
Modifier and TypeMethodDescriptionprivate WasmCodeBuildercreateInstructions(MethodInfo method) Create the instructions in a code buildervoidfinish()Finish the code generation.private voiditerateMethods(ClassFile classFile, Consumer<MethodInfo> handler) Iterate over all methods of the classFile and run the handler.voidPrepare the content of the class.voidFinish the prepare after all classes/methods are prepare.private voidprepareMethod(MethodInfo method) Prepare the method.private voidAdd a start method for the static class constructorsprivate voidScan for needed static constructors.private booleanscanFunctionInterfaces(ClassFile classFile, FunctionName next) Search if there is a default implementation in an interface for the given method.private voidScan all needed methods/functions in a loop.private voidscanLibraries(List<URL> libraries) Scan the libraries for annotated methodsprivate voidwriteExport(FunctionName name, MethodInfo method) Look for a Export annotation and if there write an export directive.private voidwriteMethod(FunctionName name, MethodInfo method) Write the content of a method.private voidwriteMethodImpl(FunctionName name, WasmCodeBuilder codeBuilder) Write the method instruction to the Wasm writer.private voidwriteMethodSignature(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
-
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
-