Class WatParser

java.lang.Object
de.inetsoftware.jwebassembly.module.WasmCodeBuilder
de.inetsoftware.jwebassembly.watparser.WatParser

public class WatParser extends WasmCodeBuilder
Parser for text format of a function.
  • Constructor Details

    • WatParser

      public WatParser()
  • Method Details

    • parse

      public void parse(String wat, MethodInfo method, Iterator<AnyType> signature, int lineNumber)
      Parse the given wasm text format and generate a list of WasmInstuctions
      Parameters:
      wat - the text format content of a function
      method - the method with signature as fallback for a missing variable table
      signature - alternative for method signature, can be null if method is set
      lineNumber - the line number for an error message
    • getInt

      private int getInt(List<String> tokens, @Nonnegative int idx)
      Get the token at given position as int.
      Parameters:
      tokens - the token list
      idx - the position in the tokens
      Returns:
      the int value
    • get

      @Nonnull private String get(List<String> tokens, @Nonnegative int idx)
      Get the token at given position
      Parameters:
      tokens - the token list
      idx - the position in the tokens
      Returns:
      the token
    • splitTokens

      private List<String> splitTokens(@Nullable String wat)
      Split the string in tokens.
      Parameters:
      wat - string with wasm text format
      Returns:
      the token list.
    • addMemoryInstruction

      private int addMemoryInstruction(MemoryOperator op, ValueType type, List<String> tokens, int i, int lineNumber)
      Parse the optional tokens of a load memory instruction and add it.
      Parameters:
      op - the operation
      type - the type of the static field
      tokens - the token list
      i - the position in the tokens
      lineNumber - the line number in the Java source code
      Returns:
      the current index to the tokens