Class JWebAssembly

java.lang.Object
de.inetsoftware.jwebassembly.JWebAssembly

public class JWebAssembly extends Object
The main class of the compiler.
  • Field Details

    • classFiles

      private final List<URL> classFiles
    • properties

      private final HashMap<String,String> properties
    • libraries

      private final List<URL> libraries
    • DEBUG_NAMES

      public static final String DEBUG_NAMES
      Property for adding debug names to the output if true.
      See Also:
    • SOURCE_MAP_BASE

      public static final 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:
    • IMPORT_ANNOTATION

      public static final String IMPORT_ANNOTATION
      The name of the annotation for import functions.
      See Also:
    • EXPORT_ANNOTATION

      public static final String EXPORT_ANNOTATION
      The name of the annotation for export functions.
      See Also:
    • TEXTCODE_ANNOTATION

      public static final String TEXTCODE_ANNOTATION
      The name of the annotation for native WASM code in text format.
      See Also:
    • REPLACE_ANNOTATION

      public static final String REPLACE_ANNOTATION
      The name of the annotation for replacing a single method of the Java runtime.
      See Also:
    • PARTIAL_ANNOTATION

      public static final String PARTIAL_ANNOTATION
      The name of the annotation for partial class another class of the Java runtime.
      See Also:
    • WASM_USE_GC

      public static final 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:
    • WASM_USE_EH

      public static final 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:
    • LOGGER

      public static final Logger LOGGER
      The logger instance
  • Constructor Details

    • JWebAssembly

      public JWebAssembly()
      Create a instance.
  • Method Details

    • addFile

      public void addFile(@Nonnull File classFile)
      Add a classFile to compile
      Parameters:
      classFile - the file
    • addFile

      public void addFile(@Nonnull URL classFile)
      Add a classFile to compile
      Parameters:
      classFile - the file
    • setProperty

      public void setProperty(String key, String value)
      Set property to control the behavior of the compiler
      Parameters:
      key - the key
      value - the new value
    • getProperty

      public String getProperty(String key)
      Get the value of a property.
      Parameters:
      key - the key
      Returns:
      the current value
    • addLibrary

      public void addLibrary(@Nonnull 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 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 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(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(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(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(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 IOException, WasmException
      Convert the added files to a WebAssembly module.
      Parameters:
      writer - the formatter
      target - the target for the module data
      Throws:
      IOException - if any I/O error occur
      WasmException - if any conversion error occurs