Package de.inetsoftware.jwebassembly
Class JWebAssembly
- java.lang.Object
-
- de.inetsoftware.jwebassembly.JWebAssembly
-
public class JWebAssembly extends java.lang.Object
The main class of the compiler.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.net.URL>
classFiles
static java.lang.String
DEBUG_NAMES
Property for adding debug names to the output if true.static java.lang.String
EXPORT_ANNOTATION
The name of the annotation for export functions.static java.lang.String
IMPORT_ANNOTATION
The name of the annotation for import functions.private java.util.List<java.net.URL>
libraries
static java.util.logging.Logger
LOGGER
The logger instancestatic java.lang.String
PARTIAL_ANNOTATION
The name of the annotation for partial class another class of the Java runtime.private java.util.HashMap<java.lang.String,java.lang.String>
properties
static java.lang.String
REPLACE_ANNOTATION
The name of the annotation for replacing a single method of the Java runtime.static 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.static java.lang.String
TEXTCODE_ANNOTATION
The name of the annotation for native WASM code in text format.static java.lang.String
WASM_USE_EH
If the exception handling feature of WASM should be use or an unreachable instruction.static java.lang.String
WASM_USE_GC
If 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 void
addFile(java.io.File classFile)
Add a classFile to compilevoid
addFile(java.net.URL classFile)
Add a classFile to compilevoid
addLibrary(java.io.File library)
Add a jar or zip file as library to the compiler.void
addLibrary(java.net.URL library)
Add a jar or zip file as library to the compiler.private void
compile(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 void
compileToBinary(WasmTarget target)
Convert the added files to a WebAssembly module in binary representation.void
compileToBinary(java.io.File file)
Convert the added files to a WebAssembly module in binary representation.void
compileToBinary(java.io.OutputStream output)
Convert the added files to a WebAssembly module in binary representation.java.lang.String
compileToText()
Convert the added files to a WebAssembly module in text representation.private void
compileToText(WasmTarget target)
Convert the added files to a WebAssembly module in text representation.void
compileToText(java.io.File file)
Convert the added files to a WebAssembly module in text representation.void
compileToText(java.lang.Appendable output)
Convert the added files to a WebAssembly module in text representation.java.lang.String
getProperty(java.lang.String key)
Get the value of a property.void
setProperty(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 WasmException
Convert 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 WasmException
Convert 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 WasmException
Convert 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 WasmException
Convert 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 WasmException
Convert 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 WasmException
Convert 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
-
-