Search in sources :

Example 1 with Instruction

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);
    }
}
Also used : Instruction(suite.instructionexecutor.InstructionUtil.Instruction)

Example 2 with Instruction

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;
}
Also used : Instruction(suite.instructionexecutor.InstructionUtil.Instruction)

Example 3 with Instruction

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();
    }
}
Also used : Instruction(suite.instructionexecutor.InstructionUtil.Instruction) ArrayDeque(java.util.ArrayDeque)

Example 4 with Instruction

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));
}
Also used : Instruction(suite.instructionexecutor.InstructionUtil.Instruction)

Example 5 with Instruction

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:
        }
    }
}
Also used : Node(suite.node.Node) ArrayList(java.util.ArrayList) Instruction(suite.instructionexecutor.InstructionUtil.Instruction)

Aggregations

Instruction (suite.instructionexecutor.InstructionUtil.Instruction)10 Node (suite.node.Node)4 Reference (suite.node.Reference)3 Tree (suite.node.Tree)3 TermOp (suite.node.io.TermOp)3 Activation (suite.instructionexecutor.InstructionUtil.Activation)2 Frame (suite.instructionexecutor.InstructionUtil.Frame)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 AnalyzedFrame (suite.instructionexecutor.InstructionAnalyzer.AnalyzedFrame)1 Insn (suite.instructionexecutor.InstructionUtil.Insn)1 Thunk (suite.instructionexecutor.InstructionUtil.Thunk)1 Trail (suite.lp.Trail)1 Atom (suite.node.Atom)1 Int (suite.node.Int)1 Comparer (suite.node.util.Comparer)1