mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
Add support for a temporary local variable to reused values on the
stack.
This commit is contained in:
parent
5ea2eff713
commit
61c7f8edf4
@ -36,6 +36,8 @@ class LocaleVariableManager {
|
|||||||
|
|
||||||
private int size;
|
private int size;
|
||||||
|
|
||||||
|
private boolean needTempI32;
|
||||||
|
|
||||||
private ArrayList<ValueType> localTypes = new ArrayList<>();
|
private ArrayList<ValueType> localTypes = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,6 +61,7 @@ class LocaleVariableManager {
|
|||||||
var.idx = -1;
|
var.idx = -1;
|
||||||
}
|
}
|
||||||
size = 0;
|
size = 0;
|
||||||
|
needTempI32 = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,10 +83,20 @@ class LocaleVariableManager {
|
|||||||
var.valueType = valueType;
|
var.valueType = valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We need an extra temporary variable inn the WebAssembly code.
|
||||||
|
*/
|
||||||
|
void useTempI32() {
|
||||||
|
needTempI32 = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the WebAssembly index position on the consumed data.
|
* Calculate the WebAssembly index position on the consumed data.
|
||||||
*/
|
*/
|
||||||
void calculate() {
|
void calculate() {
|
||||||
|
if( needTempI32 ) {
|
||||||
|
use( ValueType.i32, size );
|
||||||
|
}
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for( int i = 0; i < size; i++ ) {
|
for( int i = 0; i < size; i++ ) {
|
||||||
LocaleVariable var = variables[i];
|
LocaleVariable var = variables[i];
|
||||||
@ -112,6 +125,15 @@ class LocaleVariableManager {
|
|||||||
return localTypes;
|
return localTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the slot of the temporary variable.
|
||||||
|
*
|
||||||
|
* @return the slot
|
||||||
|
*/
|
||||||
|
int getTempI32() {
|
||||||
|
return size - 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the WebAssembly variable index of the given Java Slot.
|
* Get the WebAssembly variable index of the given Java Slot.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user