コード例 #1
0
void execute()
{
    string command = currentInstruction[0];
    if (command == "add" || command == "sub" || command == "neg" || command == "eq" || command == "gt" ||
        command == "lt" || command == "and" || command == "or" || command == "not")
        executeArithmetic(currentInstruction[0]);
    else if (command == "push")
        executePush(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "pop")
        executePop(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "label")
        executeLabel(currentInstruction[1]);
    else if (command == "goto")
        executeGoto(currentInstruction[1]);
    else if (command == "if-goto")
        executeIf(currentInstruction[1]);
    else if (command == "call")
        executeCall(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "return")
        executeReturn();
    else if (command == "function")
        executeFunction(currentInstruction[1], atoi(currentInstruction[2].c_str()));
    else if (command == "end")
        arriveEnd = true;
}
コード例 #2
0
ファイル: Executor.cpp プロジェクト: belolourenco/sniper
// Call, Assert, Branch
void Executor::ExecuteInst1(Instruction *i, Value *val) {

    assert(i && "Expecting an instruction!");
    assert(val && "Expecting a value!");
    assert(status==START && "Wrong status for Executor (!=START)!");
    ExprPtr expr = NULL;
    switch (i->getOpcode()) {
        case Instruction::GetElementPtr:
            //executeGep(i);
            if (!DisabledSymbolicExe) {
                expr = PathEncoder->encode(cast<GetElementPtrInst>(i));
            }
            break;
        case Instruction::Store:
            executeStore(i, val);
            if (!DisabledSymbolicExe) {
                expr = PathEncoder->encode(cast<StoreInst>(i));
            }
            break;
        case Instruction::Load:
            executeLoad(i, val);
            if (!DisabledSymbolicExe) {
                expr = PathEncoder->encode(cast<LoadInst>(i), PathFormula);
            }
            break;
        case Instruction::PHI:
            executePhi(i);
            if (!DisabledSymbolicExe) {
                expr = PathEncoder->encode(cast<PHINode>(i), LastExecutedBB);
            }
            break;
        case Instruction::Br: {
            ConstantInt *CI = dyn_cast<ConstantInt>(val);
            assert(CI && "Unsupported value!");
            const bool cond = CI->getSExtValue();
            executeBranch(i, cond);
        } break;
        // TODO
        case Instruction::Call:
            executeCall(i, 0, 0);
            break;
        default:    
            assert("test-executor");
    }
    if (expr && !DisabledSymbolicExeCurRun) {
        expr->setHard();
        PathFormula->add(expr);
    }
}
コード例 #3
0
ファイル: Executor.cpp プロジェクト: belolourenco/sniper
// BinaryOp (Add, ICmp,...), Call
void Executor::ExecuteInst2(Instruction *i, Value *val1, Value *val2) {

    assert(i && "Expecting an instruction!");
    assert((val1 && val2) && "Expecting values!");
    assert(status==START && "wrong status for Executor (!=START)!");
    ExprPtr expr = NULL;
    switch (i->getOpcode()) {
        case Instruction::Add:
        case Instruction::FAdd:
        case Instruction::Sub:
        case Instruction::FSub:
        case Instruction::Mul:
        case Instruction::FMul:
        case Instruction::UDiv:
        case Instruction::SDiv:
        case Instruction::FDiv:
        case Instruction::URem:
        case Instruction::SRem:
        case Instruction::FRem:
        case Instruction::And:
        case Instruction::Or:
        case Instruction::Xor: {
            executeBinaryOp(i, val1, val2);
            if (!DisabledSymbolicExe) {
                expr = PathEncoder->encode(cast<BinaryOperator>(i));
            }
        } break;
        case Instruction::ICmp: {
            executeBinaryOp(i, val1, val2);
            if (!DisabledSymbolicExe) {
                expr = PathEncoder->encode(cast<ICmpInst>(i));
            }
        } break;
        case Instruction::Call: // Call type foo(arg) / void foo(arg1,arg2)
            executeCall(i, val1, val2);
            break;
        default:    
            assert("test-executor");
    }
    if (expr && !DisabledSymbolicExeCurRun) {
        expr->setHard();
        PathFormula->add(expr);
    }
}