Package de.inetsoftware.jwebassembly
Class JWebAssembly
- java.lang.Object
-
- de.inetsoftware.jwebassembly.JWebAssembly
-
public class JWebAssembly extends java.lang.ObjectThe main class of the compiler.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.net.URL>classFilesstatic java.lang.StringDEBUG_NAMESProperty for adding debug names to the output if true.static java.lang.StringEXPORT_ANNOTATIONThe name of the annotation for export functions.static java.lang.StringIMPORT_ANNOTATIONThe name of the annotation for import functions.private java.util.List<java.net.URL>librariesstatic java.util.logging.LoggerLOGGERThe logger instancestatic java.lang.StringPARTIAL_ANNOTATIONThe name of the annotation for partial class another class of the Java runtime.private java.util.HashMap<java.lang.String,java.lang.String>propertiesstatic java.lang.StringREPLACE_ANNOTATIONThe name of the annotation for replacing a single method of the Java runtime.static java.lang.StringSOURCE_MAP_BASEProperty for relative path between the final wasm file location and the source files location for the source map.static java.lang.StringTEXTCODE_ANNOTATIONThe name of the annotation for native WASM code in text format.static java.lang.StringWASM_USE_EHIf the exception handling feature of WASM should be use or an unreachable instruction.static java.lang.StringWASM_USE_GCIf the GC feature of WASM should be use or the GC of the JavaScript host.
-
Constructor Summary
Constructors Constructor Description JWebAssembly()Create a instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFile(java.io.File classFile)Add a classFile to compilevoidaddFile(java.net.URL classFile)Add a classFile to compilevoidaddLibrary(java.io.File library)Add a jar or zip file as library to the compiler.voidaddLibrary(java.net.URL library)Add a jar or zip file as library to the compiler.private voidcompile(ModuleWriter writer, WasmTarget target)Convert the added files to a WebAssembly module.byte[]compileToBinary()Convert the added files to a WebAssembly module in binary representation.private voidcompileToBinary(WasmTarget target)Convert the added files to a WebAssembly module in binary representation.voidcompileToBinary(java.io.File file)Convert the added files to a WebAssembly module in binary representation.voidcompileToBinary(java.io.OutputStream output)Convert the added files to a WebAssembly module in binary representation.java.lang.StringcompileToText()Convert the added files to a WebAssembly module in text representation.private voidcompileToText(WasmTarget target)Convert the added files to a WebAssembly module in text representation.voidcompileToText(java.io.File file)Convert the added files to a WebAssembly module in text representation.voidcompileToText(java.lang.Appendable output)Convert the added files to a WebAssembly module in text representation.java.lang.StringgetProperty(java.lang.String key)Get the value of a property.voidsetProperty(java.lang.String key, java.lang.String value)Set property to control the behavior of the compiler
-
-
-
Field Detail
-
classFiles
private final java.util.List<java.net.URL> classFiles
-
properties
private final java.util.HashMap<java.lang.String,java.lang.String> properties
-
libraries
private final java.util.List<java.net.URL> libraries
-
DEBUG_NAMES
public static final java.lang.String DEBUG_NAMES
Property for adding debug names to the output if true.- See Also:
- Constant Field Values
-
SOURCE_MAP_BASE
public static final java.lang.String SOURCE_MAP_BASE
Property for relative path between the final wasm file location and the source files location for the source map. If not empty it should end with a slash like "../../src/main/java/".- See Also:
- Constant Field Values
-
IMPORT_ANNOTATION
public static final java.lang.String IMPORT_ANNOTATION
The name of the annotation for import functions.- See Also:
- Constant Field Values
-
EXPORT_ANNOTATION
public static final java.lang.String EXPORT_ANNOTATION
The name of the annotation for export functions.- See Also:
- Constant Field Values
-
TEXTCODE_ANNOTATION
public static final java.lang.String TEXTCODE_ANNOTATION
The name of the annotation for native WASM code in text format.- See Also:
- Constant Field Values
-
REPLACE_ANNOTATION
public static final java.lang.String REPLACE_ANNOTATION
The name of the annotation for replacing a single method of the Java runtime.- See Also:
- Constant Field Values
-
PARTIAL_ANNOTATION
public static final java.lang.String PARTIAL_ANNOTATION
The name of the annotation for partial class another class of the Java runtime.- See Also:
- Constant Field Values
-
WASM_USE_GC
public static final java.lang.String WASM_USE_GC
If the GC feature of WASM should be use or the GC of the JavaScript host. If true use the GC instructions of WASM.- See Also:
- Constant Field Values
-
WASM_USE_EH
public static final java.lang.String WASM_USE_EH
If the exception handling feature of WASM should be use or an unreachable instruction. If true use the exception instructions of WASM.- See Also:
- Constant Field Values
-
LOGGER
public static final java.util.logging.Logger LOGGER
The logger instance
-
-
Method Detail
-
addFile
public void addFile(@Nonnull java.io.File classFile)Add a classFile to compile- Parameters:
classFile- the file
-
addFile
public void addFile(@Nonnull java.net.URL classFile)Add a classFile to compile- Parameters:
classFile- the file
-
setProperty
public void setProperty(java.lang.String key, java.lang.String value)Set property to control the behavior of the compiler- Parameters:
key- the keyvalue- the new value
-
getProperty
public java.lang.String getProperty(java.lang.String key)
Get the value of a property.- Parameters:
key- the key- Returns:
- the current value
-
addLibrary
public void addLibrary(@Nonnull java.io.File library)Add a jar or zip file as library to the compiler. Methods from the library will be add to the wasm only when used.- Parameters:
library- a archive file
-
addLibrary
public void addLibrary(@Nonnull java.net.URL library)Add a jar or zip file as library to the compiler. Methods from the library will be add to the wasm only when used.- Parameters:
library- a archive file
-
compileToText
public java.lang.String compileToText() throws WasmExceptionConvert the added files to a WebAssembly module in text representation.- Returns:
- the module as string
- Throws:
WasmException- if any conversion error occurs
-
compileToText
public void compileToText(java.io.File file) throws WasmExceptionConvert the added files to a WebAssembly module in text representation.- Parameters:
file- the target for the module data- Throws:
WasmException- if any conversion error occurs
-
compileToText
public void compileToText(java.lang.Appendable output) throws WasmExceptionConvert the added files to a WebAssembly module in text representation.- Parameters:
output- the target for the module data- Throws:
WasmException- if any conversion error occurs
-
compileToText
private void compileToText(WasmTarget target) throws WasmException
Convert the added files to a WebAssembly module in text representation.- Parameters:
target- the target for the module data- Throws:
WasmException- if any conversion error occurs
-
compileToBinary
public byte[] compileToBinary() throws WasmExceptionConvert the added files to a WebAssembly module in binary representation.- Returns:
- the module as string
- Throws:
WasmException- if any conversion error occurs
-
compileToBinary
public void compileToBinary(java.io.File file) throws WasmExceptionConvert the added files to a WebAssembly module in binary representation.- Parameters:
file- the target for the module data- Throws:
WasmException- if any conversion error occurs
-
compileToBinary
public void compileToBinary(java.io.OutputStream output) throws WasmExceptionConvert the added files to a WebAssembly module in binary representation.- Parameters:
output- the target for the module data- Throws:
WasmException- if any conversion error occurs
-
compileToBinary
private void compileToBinary(WasmTarget target) throws WasmException
Convert the added files to a WebAssembly module in binary representation.- Parameters:
target- the target for the module data- Throws:
WasmException- if any conversion error occurs
-
compile
private void compile(ModuleWriter writer, WasmTarget target) throws java.io.IOException, WasmException
Convert the added files to a WebAssembly module.- Parameters:
writer- the formattertarget- the target for the module data- Throws:
java.io.IOException- if any I/O error occurWasmException- if any conversion error occurs
-
-