示例#1
0
void ByteCodeBackend::visit(IR_ProgNode* node)
{
    Symtab* top = node->symtab()->top();
    for (auto it = top->begin(); it != top->end(); ++it)
    {
        if (it->which() == Symbol::Const)
        {
            if (!m_blob.addConstant(it->data().classid(), it->data().serialize()))
                M_error(node, "internal error: unable to add constant entry to blob");
        }
    }

    // Generate bytecode for the whole program
    node->siblings()[0]->accept(this);
}
示例#2
0
void ResolveConsts::visit(ConstNode* node)
{
    Symtab* top = node->symtab()->top();

    bool found = false;
    int index = 0;
    for (auto it = top->begin(); it != top->end(); ++it)
    {
        if (it->which() == Symbol::Const)
        {
            if (it->data().classid() == node->value.classid() &&
                it->data().serialize() == node->value.serialize())
            {
                found = true;
                break;
            }

            ++index;
        }
    }

    if (!found)
    {
        index = m_alloc_index++;
        Symbol sym(Symbol::Const, Symbol::Global, "", node->value);
        top->add(sym);
    }

    ConstRefNode* new_node = new ConstRefNode(node->startToken());
    new_node->index = index;

    node->exchangeWith(new_node);
    delete node;

    M_follow(new_node);
}