Class LocaleVariableManager
- java.lang.Object
-
- de.inetsoftware.jwebassembly.module.LocaleVariableManager
-
class LocaleVariableManager extends java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
LocaleVariableManager.Variable
The state of a single local variable slot.
-
Field Summary
Fields Modifier and Type Field Description private java.util.ArrayList<AnyType>
localTypes
private java.util.HashSet<java.lang.String>
names
private int
size
private TypeManager
types
private LocaleVariableManager.Variable[]
variables
-
Constructor Summary
Constructors Constructor Description LocaleVariableManager()
Create a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
calculate()
Calculate the WebAssembly index position on the consumed data.private void
ensureCapacity(int slot)
Ensure that there is enough capacity.(package private) void
expandUse(int slot, int javaCodePos)
Expand code range for which the variable is validprivate java.lang.String
findUniqueVarName(java.lang.String name)
Find a unique variable name.(package private) int
get(int slot, int javaCodePos)
Get the WebAssembly variable index of the given Java Slot.(package private) LocaleVariableManager.Variable[]
getCopy()
Create a copy of the internal state(package private) java.lang.String
getLocalName(int idx)
Get the name of the variable or null if no name available(package private) java.util.List<AnyType>
getLocalTypes(int paramCount)
Get the data types of the local variables.(package private) int
getTempVariable(AnyType valueType, int startCodePosition, int endCodePosition)
Get the slot of the temporary variable.(package private) AnyType
getValueType(int idx)
Get the ValueType of the variable.(package private) void
init(TypeManager types)
Initialize the variable manager;(package private) void
reset(LocalVariableTable variableTable, MethodInfo method, java.util.Iterator<AnyType> signature)
Reset the manager to an initial state.private void
resetAddVar(AnyType type, int slot)
Add a variable in the reset with range.(package private) void
setCopy(LocaleVariableManager.Variable[] copy)
Set a previous copy(package private) void
use(AnyType valueType, int slot, int javaCodePos)
Mark a variable slot as used with its type.private void
useImpl(AnyType valueType, int idx, int javaCodePos)
(package private) void
useIndex(AnyType valueType, int wasmIdx)
-
-
-
Field Detail
-
types
private TypeManager types
-
variables
private LocaleVariableManager.Variable[] variables
-
size
private int size
-
localTypes
private final java.util.ArrayList<AnyType> localTypes
-
names
private final java.util.HashSet<java.lang.String> names
-
-
Method Detail
-
init
void init(TypeManager types)
Initialize the variable manager;- Parameters:
types
- the type manager
-
reset
void reset(LocalVariableTable variableTable, MethodInfo method, java.util.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 variableslot
- the slot of the variable
-
findUniqueVarName
private java.lang.String findUniqueVarName(java.lang.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 variableslot
- the memory/slot index of the local variablejavaCodePos
- 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
java.util.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 java.lang.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 variablestartCodePosition
- the start of the Java code positionendCodePosition
- 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 variablejavaCodePos
- 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 JavajavaCodePos
- 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
@Nonnull LocaleVariableManager.Variable[] getCopy()
Create a copy of the internal state- Returns:
- the state
-
setCopy
void setCopy(@Nonnull LocaleVariableManager.Variable[] copy)
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
-
-