Class LocaleVariableManager

java.lang.Object
de.inetsoftware.jwebassembly.module.LocaleVariableManager

class LocaleVariableManager extends Object
This manager monitor the locale variables of a method to create a translation from the slot based index in Java to the variable based index in WebAssembly. An 8-byte variable of type long and double consumes in Java 2 slots, but only one index in WebAssmenbly.
  • Field Details

  • Constructor Details

    • LocaleVariableManager

      LocaleVariableManager()
      Create a new instance.
  • Method Details

    • init

      void init(TypeManager types)
      Initialize the variable manager;
      Parameters:
      types - the type manager
    • reset

      void reset(LocalVariableTable variableTable, MethodInfo method, Iterator<AnyType> signature)
      Reset the manager to an initial state.
      Parameters:
      variableTable - variable table of the Java method.
      method - the method with signature as fallback for a missing variable table. If null signature is used and the method must be static.
      signature - alternative for method signature, can be null if method is set
    • resetAddVar

      private void resetAddVar(AnyType type, int slot)
      Add a variable in the reset with range.
      Parameters:
      type - the type of the variable
      slot - the slot of the variable
    • findUniqueVarName

      private String findUniqueVarName(String name)
      Find a unique variable name.
      Parameters:
      name - the suggested name
      Returns:
      a name that not was used before
    • use

      void use(AnyType valueType, int slot, int javaCodePos)
      Mark a variable slot as used with its type.
      Parameters:
      valueType - the type of the local variable
      slot - the memory/slot index of the local variable
      javaCodePos - the code position/offset in the Java method
    • useImpl

      private void useImpl(AnyType valueType, int idx, int javaCodePos)
    • useIndex

      void useIndex(AnyType valueType, int wasmIdx)
    • calculate

      void calculate()
      Calculate the WebAssembly index position on the consumed data.
    • getLocalTypes

      List<AnyType> getLocalTypes(int paramCount)
      Get the data types of the local variables. The value is only valid until the next call.
      Parameters:
      paramCount - the count of method parameter which should be exclude
      Returns:
      the reused list with fresh values
    • getLocalName

      @Nullable String getLocalName(int idx)
      Get the name of the variable or null if no name available
      Parameters:
      idx - the wasm variable index
      Returns:
      the name
    • getTempVariable

      int getTempVariable(AnyType valueType, int startCodePosition, int endCodePosition)
      Get the slot of the temporary variable.
      Parameters:
      valueType - the valueType for the variable
      startCodePosition - the start of the Java code position
      endCodePosition - the end of the Java code position
      Returns:
      the slot
    • expandUse

      void expandUse(int slot, int javaCodePos)
      Expand code range for which the variable is valid
      Parameters:
      slot - the memory/slot index of the local variable
      javaCodePos - the new end code position in the Java method
    • get

      int get(int slot, int javaCodePos)
      Get the WebAssembly variable index of the given Java Slot.
      Parameters:
      slot - the memory/slot index of the local variable in Java
      javaCodePos - the current code position in the Java method
      Returns:
      the variable index in WebAssembly
    • getValueType

      AnyType getValueType(int idx)
      Get the ValueType of the variable.
      Parameters:
      idx - the index of the local variable in WASM
      Returns:
      the ValueType
    • getCopy

      Create a copy of the internal state
      Returns:
      the state
    • setCopy

      Set a previous copy
      Parameters:
      copy - the previous state
    • ensureCapacity

      private void ensureCapacity(int slot)
      Ensure that there is enough capacity.
      Parameters:
      slot - the needed slot