mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-15 02:44:47 +01:00
Use variable slot instead variable index for duplicate of THIS of on virtual calls
This commit is contained in:
parent
1f045f312d
commit
a28d966b94
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 - 2021 Volker Berlin (i-net software)
|
||||
Copyright 2019 - 2022 Volker Berlin (i-net software)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -30,22 +30,27 @@ class DupThis extends WasmInstruction {
|
||||
|
||||
private WasmCallIndirectInstruction virtualCall;
|
||||
|
||||
private int tempVarIdx;
|
||||
private int tempVarSlot;
|
||||
|
||||
private LocaleVariableManager localVariables;
|
||||
|
||||
/**
|
||||
* Create a instance.
|
||||
*
|
||||
* @param virtualCall
|
||||
* the related virtual function call.
|
||||
* @param tempVarIdx
|
||||
* the index of the temporary variable
|
||||
* @param tempVarSlot
|
||||
* the slot of the temporary variable
|
||||
* @param localVariables
|
||||
* the manager for local variables
|
||||
* @param javaCodePos
|
||||
* the code position
|
||||
*/
|
||||
DupThis( WasmCallIndirectInstruction virtualCall, int tempVarIdx, int javaCodePos ) {
|
||||
DupThis( WasmCallIndirectInstruction virtualCall, int tempVarSlot, LocaleVariableManager localVariables, int javaCodePos ) {
|
||||
super( javaCodePos, virtualCall.getLineNumber() );
|
||||
this.virtualCall = virtualCall;
|
||||
this.tempVarIdx = tempVarIdx;
|
||||
this.tempVarSlot = tempVarSlot;
|
||||
this.localVariables = localVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +67,7 @@ class DupThis extends WasmInstruction {
|
||||
@Override
|
||||
void writeTo( ModuleWriter writer ) throws IOException {
|
||||
if( virtualCall.isVirtual() ) {
|
||||
writer.writeLocal( VariableOperator.tee, tempVarIdx );
|
||||
writer.writeLocal( VariableOperator.tee, localVariables.get( tempVarSlot, getCodePosition() ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2019 - 2020 Volker Berlin (i-net software)
|
||||
Copyright 2019 - 2022 Volker Berlin (i-net software)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -28,7 +28,9 @@ abstract class WasmCallIndirectInstruction extends WasmCallInstruction {
|
||||
|
||||
private final StructType type;
|
||||
|
||||
private int tempVarIdx;
|
||||
private int tempVarSlot;
|
||||
|
||||
private LocaleVariableManager localVariables;
|
||||
|
||||
/**
|
||||
* Create an instance of a function call instruction
|
||||
@ -57,11 +59,14 @@ abstract class WasmCallIndirectInstruction extends WasmCallInstruction {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the variable index on which this can be found.
|
||||
* @param tempVarIdx the index
|
||||
* Set the Java variable slot on which THIS can be found.
|
||||
* @param tempVarSlot the slot
|
||||
* @param localVariables
|
||||
* the manager for local variables to resolve the index
|
||||
*/
|
||||
void setVariableIndexOfThis( int tempVarIdx ) {
|
||||
this.tempVarIdx = tempVarIdx;
|
||||
void setVariableSlotOfThis( int tempVarSlot, LocaleVariableManager localVariables ) {
|
||||
this.tempVarSlot = tempVarSlot;
|
||||
this.localVariables = localVariables;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,7 +75,7 @@ abstract class WasmCallIndirectInstruction extends WasmCallInstruction {
|
||||
* @return the index of the variable
|
||||
*/
|
||||
int getVariableIndexOfThis() {
|
||||
return tempVarIdx;
|
||||
return localVariables.get( tempVarSlot, getCodePosition() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -676,21 +676,21 @@ public abstract class WasmCodeBuilder {
|
||||
int javaCodePos = indirectCall.getCodePosition();
|
||||
StackValue stackValue = StackInspector.findInstructionThatPushValue( instructions, count, javaCodePos );
|
||||
WasmInstruction instr = stackValue.instr;
|
||||
int varIndex = -1;
|
||||
int varSlot = -1;
|
||||
// if it is a GET to a local variable then we can use it
|
||||
if( instr.getType() == Type.Local ) {
|
||||
WasmLocalInstruction local1 = (WasmLocalInstruction)instr;
|
||||
if( local1.getOperator() == VariableOperator.get ) {
|
||||
varIndex = local1.getIndex();
|
||||
varSlot = local1.getSlot();
|
||||
}
|
||||
}
|
||||
//alternate we need to create a new locale variable
|
||||
if( varIndex < 0 ) {
|
||||
varIndex = getTempVariable( indirectCall.getThisType(), instr.getCodePosition(), javaCodePos + 1 );
|
||||
if( varSlot < 0 ) {
|
||||
varSlot = getTempVariable( indirectCall.getThisType(), instr.getCodePosition(), javaCodePos + 1 );
|
||||
int idx = count == 1 ? instructions.size() : stackValue.idx + 1;
|
||||
instructions.add( idx, new DupThis( indirectCall, varIndex, instr.getCodePosition() + 1 ) );
|
||||
instructions.add( idx, new DupThis( indirectCall, varSlot, localVariables, instr.getCodePosition() + 1 ) );
|
||||
}
|
||||
indirectCall.setVariableIndexOfThis( varIndex );
|
||||
indirectCall.setVariableSlotOfThis( varSlot, localVariables );
|
||||
instructions.add( indirectCall );
|
||||
options.registerGet_i32(); // for later access of the vtable
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user