예제 #1
0
파일: codegen.cpp 프로젝트: abelsson/prism
void FunctionDeclaration::codeGen(CodeGenContext& context)
{
    BasicBlock *bblock = new BasicBlock();

    Function *f = new Function();

    context.push_block(bblock);
    VariableList::const_iterator it;
    for (it = m_arguments->begin(); it != m_arguments->end(); it++) {
        if (debug)
            cout << "Argument : " << (**it).m_type->m_name ;
        Value *v = (*it)->value();
        (**it).codeGen(context);
        if (debug)
            cout << " at: " << v->addr << endl;
        f->arguments.push_back(v->addr);
    }
    m_block->codeGen(context, true);
    f->pm_addr = context.getCurrent();
    m_block->codeGen(context, false);
    context.vret();
    context.pop_block();

    context.functions().insert(std::make_pair(m_id->m_name, f));

    if (debug)
        std::cout << "Creating function: " << m_id->m_name << endl;
}
예제 #2
0
파일: codegen.cpp 프로젝트: abelsson/prism
void WhileStatement::codeGen(CodeGenContext &context)
{
    int start = context.getCurrent();
    m_block->codeGen(context, false);
    m_expr->codeGen(context);

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

}
예제 #3
0
파일: codegen.cpp 프로젝트: abelsson/prism
void ForeachStatement::codeGen(CodeGenContext &context)
{
    m_var_decl->codeGen(context);
    m_expr->codeGen(context);
    context.vmake_iter();
    int pos = context.getCurrent();
    context.viter_value();
    context.vpop(context.locals()[m_var_decl->m_name->m_name]->addr);
    m_block->codeGen(context, false);
    context.vloop_iter(pos);
    context.vpop(444);
    context.vpop(444);
}
예제 #4
0
파일: codegen.cpp 프로젝트: abelsson/prism
void IfStatement::codeGen(CodeGenContext& context)
{
    int then_end;
    m_eval_expr->codeGen(context);
    int then_start = context.reserve();
    m_then_block->codeGen(context, false);

    if (m_else_block) {
        then_end = context.reserve();
        m_else_block->codeGen(context ,false);
    }

    int block_end = context.getCurrent();

    if (m_else_block) {
        context.encode_at(then_end, CodeGenContext::JMP, block_end);
        context.encode_at(then_start, CodeGenContext::JNE, then_end);
    } else {
        context.encode_at(then_start, CodeGenContext::JNE, block_end);
    }
}