#1379 AS3 - better handling local registers postincrement/decrement

This commit is contained in:
Jindra Petřík
2021-01-06 17:13:00 +01:00
parent 6bcb2272f1
commit ea51fdea9a
5 changed files with 73 additions and 10 deletions

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
@@ -23,6 +24,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.DecLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.SubtractAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.NotCompileTime;
@@ -54,7 +57,20 @@ public class DecLocalIIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int regId = ins.operands[0];
int regId = ins.operands[0];
boolean isPostDec = false;
if (!stack.isEmpty()) {
GraphTargetItem stackTop = stack.peek();
if (stackTop instanceof LocalRegAVM2Item) {
if (regId == ((LocalRegAVM2Item) stackTop).regIndex) {
stack.pop();
stack.push(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, stackTop));
isPostDec = true;
}
}
}
if (!isPostDec) {
output.add(new DecLocalAVM2Item(ins, localData.lineStartInstruction, regId));
}
if (localData.localRegs.containsKey(regId)) {
localData.localRegs.put(regId, new SubtractAVM2Item(ins, localData.lineStartInstruction, localData.localRegs.get(regId), new IntegerValueAVM2Item(ins, localData.lineStartInstruction, 1L)));
} else {

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
@@ -23,6 +24,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.DecLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.SubtractAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.NotCompileTime;
@@ -54,7 +57,20 @@ public class DecLocalIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int regId = ins.operands[0];
int regId = ins.operands[0];
boolean isPostDec = false;
if (!stack.isEmpty()) {
GraphTargetItem stackTop = stack.peek();
if (stackTop instanceof LocalRegAVM2Item) {
if (regId == ((LocalRegAVM2Item) stackTop).regIndex) {
stack.pop();
stack.push(new PostDecrementAVM2Item(ins, localData.lineStartInstruction, stackTop));
isPostDec = true;
}
}
}
if (!isPostDec) {
output.add(new DecLocalAVM2Item(ins, localData.lineStartInstruction, regId));
}
if (localData.localRegs.containsKey(regId)) {
localData.localRegs.put(regId, new SubtractAVM2Item(ins, localData.lineStartInstruction, localData.localRegs.get(regId), new IntegerValueAVM2Item(ins, localData.lineStartInstruction, 1L)));
} else {

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
@@ -23,6 +24,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.IncLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.AddAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.NotCompileTime;
@@ -54,11 +57,22 @@ public class IncLocalIIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int regId = ins.operands[0];
int regId = ins.operands[0];
boolean isPostInc = false;
if (!stack.isEmpty()) {
GraphTargetItem stackTop = stack.peek();
if (stackTop instanceof LocalRegAVM2Item) {
if (regId == ((LocalRegAVM2Item) stackTop).regIndex) {
stack.pop();
stack.push(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, stackTop));
isPostInc = true;
}
}
}
if (!isPostInc) {
output.add(new IncLocalAVM2Item(ins, localData.lineStartInstruction, regId));
}
if (localData.localRegs.containsKey(regId)) {
localData.localRegs.put(regId, new AddAVM2Item(ins, localData.lineStartInstruction, localData.localRegs.get(regId), new IntegerValueAVM2Item(ins, localData.lineStartInstruction, 1L)));
localData.localRegs.put(regId, new AddAVM2Item(ins, localData.lineStartInstruction, localData.localRegs.get(regId), new IntegerValueAVM2Item(ins, localData.lineStartInstruction, 1L)));
} else {
}
if (!localData.localRegAssignmentIps.containsKey(regId)) {
localData.localRegAssignmentIps.put(regId, 0);

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
import com.jpexs.decompiler.flash.abc.AVM2LocalData;
@@ -23,6 +24,8 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.IncLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.AddAVM2Item;
import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.ecma.NotCompileTime;
@@ -54,7 +57,20 @@ public class IncLocalIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int regId = ins.operands[0];
int regId = ins.operands[0];
boolean isPostInc = false;
if (!stack.isEmpty()) {
GraphTargetItem stackTop = stack.peek();
if (stackTop instanceof LocalRegAVM2Item) {
if (regId == ((LocalRegAVM2Item) stackTop).regIndex) {
stack.pop();
stack.push(new PostIncrementAVM2Item(ins, localData.lineStartInstruction, stackTop));
isPostInc = true;
}
}
}
if (!isPostInc) {
output.add(new IncLocalAVM2Item(ins, localData.lineStartInstruction, regId));
}
if (localData.localRegs.containsKey(regId)) {
localData.localRegs.put(regId, new AddAVM2Item(ins, localData.lineStartInstruction, localData.localRegs.get(regId), new IntegerValueAVM2Item(ins, localData.lineStartInstruction, 1L)));
} else {