Пример #1
0
void BinaryOperator::codeGen(CodeGenContext& context)
{
    if (debug)
        std::cout << "Creating binary operation " << endl;

    lhs->codeGen(context);
    rhs->codeGen(context);

    switch (op) {
    case TPLUS:
        context.vadd(type());
        break;
    case TMINUS:
        context.encode(ToyVm::SUB, type());
        break;
    case TAND:
        context.encode(ToyVm::AND, type());
        break;
    case TMUL:
        context.vmul(type());
        break;
    case TDIV:
        context.encode(ToyVm::DIV, type());
        break;
    case TCEQ:
        context.encode(ToyVm::CMP, lhs->type());
        break;
    case TCLT:
        context.encode(ToyVm::CLT, lhs->type());
        break;
        /* TODO comparison */
    }

}
Пример #2
0
void WhileStatement::codeGen(CodeGenContext &context)
{
    int start = context.getCurrent();
    m_block->codeGen(context, false);
    m_expr->codeGen(context);

    context.encode(CodeGenContext::JE, start);

}