예제 #1
0
파일: gen.c 프로젝트: catseye/Kosheri
/*
 * Generate a reference to a label into the tuple, for instance as the
 * immediate argument of a branch instruction.  If the label parameter
 * is NULL, this will generate and return a forward reference which
 * should be resolved by subsequently passing it to gen_define_label().
 */
void
gen_gen_label_ref(struct value *gen, struct value *gen_label)
{
    struct value *bp;
    struct value next;
    int global_pos;

    assert(gen_label != NULL);

    if (value_is_null(gen_label)) {
        /* Not yet allocated, so allocate a new undefined one. */
        gen_label_new(gen_label);
    }

    global_pos = value_tuple_fetch_integer(gen_label, GEN_LABEL_GLOBAL_POS);
    if (global_pos != 0) {
        /* Already defined, so just use it. */
        gen_integer(gen, global_pos);
        return;
    }

    /*
     * The label is newly allocated, or at least has not been defined
     * yet.  So, we remember that we will need to backpatch here in the
     * future (by adding an entry to the label's backpatch list) and,
     * for now, generate a NULL in its slot.
     */

    value_copy(&next, value_tuple_fetch(gen_label, GEN_LABEL_NEXT));
    bp = value_tuple_fetch(gen_label, GEN_LABEL_NEXT);
    gen_label_new(bp);
    value_tuple_store(bp, GEN_LABEL_TUPLE, value_tuple_fetch(gen, GEN_CURRENT_TUPLE));
    value_tuple_store(bp, GEN_LABEL_LOCAL_POS, value_tuple_fetch(gen, GEN_LOCAL_POS));
    value_tuple_store(bp, GEN_LABEL_GLOBAL_POS, value_tuple_fetch(gen, GEN_GLOBAL_POS));
    value_tuple_store(bp, GEN_LABEL_NEXT, &next);

    gen_value(gen, &VNULL);
}
예제 #2
0
void jvmcodegen::gen_node(const ast::node_ptr &node) {

    switch (node->type) {
//    case ast::no_node: gen_node(node); break;
    case ast::integer_node: gen_integer(node); break;
    case ast::string_node: gen_string(node); break;
    case ast::if_stmt_node: gen_if_stmt(node); break;
    case ast::while_stmt_node: gen_while_stmt(node); break;
    case ast::return_stmt_node: gen_return_stmt(node); break;
    case ast::variable_node: gen_variable(node); break;
    case ast::assign_stmt_node: gen_assign_stmt(node); break;
    case ast::call_node: gen_call(node); break;
    case ast::op_arithm_node: gen_op_arithm(node); break;
    case ast::op_logical_node: gen_op_logical(node); break;
    case ast::program_node: gen_program(node); break;
    case ast::type_node: gen_type(node); break;
    case ast::argument_node: gen_argument(node); break;
    case ast::variable_decl_node: gen_variable_decl(node); break;
    case ast::function_decl_node: gen_function_decl(node); break;
    case ast::read_stmt_node: gen_read_stmt(node); break;
    case ast::write_stmt_node: gen_write_stmt(node); break;
    }
}
예제 #3
0
void cpp_gen::visit(const mfast::uint64_field_instruction* inst, void*)
{
  gen_integer(inst, "uint64", get_initial_value<uint64_t>(inst->initial_value(), "ULL") );
}
예제 #4
0
void cpp_gen::visit(const mfast::int32_field_instruction* inst, void*)
{
  gen_integer(inst, "int32", get_initial_value<int32_t>(inst->initial_value(), "") );
}