use of suite.instructionexecutor.InstructionUtil.Instruction in project suite by stupidsing.
the class InstructionAnalyzer method analyzeFpTailCalls.
private void analyzeFpTailCalls(List<Instruction> instructions) {
for (int ip = 0; ip < instructions.size() - 1; ip++) {
Source<Instruction> source = flow(instructions, ip);
Instruction instruction0 = source.source();
Instruction instruction1 = source.source();
if (//
instruction0 != null && instruction0.insn == Insn.CALLTHUNK_____ && instruction1 != null && //
instruction1.insn == Insn.ASSIGNRESULT__ && isReturningValue(source, instruction1.op0))
tailCalls.add(ip);
}
}
use of suite.instructionexecutor.InstructionUtil.Instruction in project suite by stupidsing.
the class InstructionAnalyzer method isReturningValue.
private boolean isReturningValue(Source<Instruction> source, int returnReg) {
Instruction instruction;
boolean isLeft = false, isReturningValue = false;
while ((instruction = source.source()) != null) switch(instruction.insn) {
case ASSIGNFRAMEREG:
if (instruction.op1 == 0 && instruction.op2 == returnReg) {
returnReg = instruction.op0;
break;
} else
return false;
case LEAVE_________:
isLeft = true;
break;
case RETURN________:
return isLeft && isReturningValue;
case SETRESULT_____:
isReturningValue = instruction.op0 == returnReg;
break;
default:
return false;
}
return false;
}
use of suite.instructionexecutor.InstructionUtil.Instruction in project suite by stupidsing.
the class InstructionAnalyzer method analyzeFrames.
private void analyzeFrames(List<Instruction> instructions) {
Deque<AnalyzedFrame> analyzedFrames = new ArrayDeque<>();
// assumes every FRAME-BEGIN has a ASSIGN-THUNK referencing it.
for (int ip = 0; ip < instructions.size(); ip++) {
Instruction insn = instructions.get(ip);
if (insn.insn == Insn.FRAMEBEGIN____)
analyzedFrames.push(new AnalyzedFrame(ip));
AnalyzedFrame frame = !analyzedFrames.isEmpty() ? analyzedFrames.peek() : null;
frameByIp.add(frame);
if (insn.insn == Insn.FRAMEEND______)
analyzedFrames.pop();
}
}
use of suite.instructionexecutor.InstructionUtil.Instruction in project suite by stupidsing.
the class InstructionExecutor method postprocessInstructions.
protected void postprocessInstructions(List<Instruction> list) {
yawnEntryPoint = list.size();
list.add(new Instruction(Insn.FRAMEBEGIN____, 2, 0, 0));
list.add(new Instruction(Insn.CALLTHUNK_____, 0, 0, 0));
list.add(new Instruction(Insn.ASSIGNRESULT__, 1, 0, 0));
list.add(new Instruction(Insn.EXIT__________, 0, 0, 0));
list.add(new Instruction(Insn.FRAMEEND______, 0, 0, 0));
}
use of suite.instructionexecutor.InstructionUtil.Instruction in project suite by stupidsing.
the class InstructionAnalyzer method analyzeFrameRegisters.
private void analyzeFrameRegisters(List<Instruction> instructions) {
int ip = 0;
while (ip < instructions.size()) {
int currentIp = ip;
Instruction insn = instructions.get(ip++);
int op0 = insn.op0, op1 = insn.op1, op2 = insn.op2;
AnalyzedFrame frame = frameByIp.get(currentIp);
List<AnalyzedRegister> registers = frame != null ? frame.registers : null;
switch(insn.insn) {
case EVALEQ________:
case EVALLE________:
case EVALLT________:
case EVALNE________:
case ISCONS________:
registers.get(op0).clazz = boolean.class;
break;
case ASSIGNTHUNK___:
registers.get(op0).clazz = Thunk.class;
break;
case ASSIGNINT_____:
case BACKUPCSP_____:
case BACKUPDSP_____:
case BINDMARK______:
case COMPARE_______:
case ERROR_________:
case EVALADD_______:
case EVALDIV_______:
case EVALMOD_______:
case EVALMUL_______:
case EVALSUB_______:
registers.get(op0).clazz = int.class;
break;
case ASSIGNCONST___:
case ASSIGNRESULT__:
case ASSIGNTHUNKRES:
case CALLINTRINSIC_:
case CONSPAIR______:
case CONSLIST______:
case DATACHARS_____:
case GETINTRINSIC__:
case HEAD__________:
case IFNOTCONS_____:
case IFNOTPAIR_____:
case LOGREG________:
case NEWNODE_______:
case POP___________:
case TAIL__________:
case TOP___________:
registers.get(op0).clazz = Node.class;
break;
case FORMTREE1_____:
registers.get(insn.op1).clazz = Tree.class;
break;
case ASSIGNFRAMEREG:
AnalyzedFrame frame1 = frame;
for (int i = op1; i < 0; i++) {
frame1.isRequireParent = true;
frame1 = frame1.parent;
}
AnalyzedRegister op0register = registers.get(op0);
AnalyzedRegister op2Register = frame1.registers.get(op2);
if (frame != frame1)
op2Register.isAccessedByChildFrames = true;
// merge into Node if clashed
if (op0register.clazz != op2Register.clazz)
op0register.clazz = op0register.clazz != null ? Node.class : op2Register.clazz;
break;
case DECOMPOSETREE1:
registers.get(op1).clazz = registers.get(op2).clazz = Node.class;
break;
case FRAMEBEGIN____:
registers = frame.registers = new ArrayList<>();
for (int i = 0; i < op0; i++) registers.add(new AnalyzedRegister());
break;
default:
}
}
}
Aggregations