Inserting function definitions into the tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello everyone,

I am writing a plugin in which I want to dynamically insert a function:

static void __atribute__(( constructor ))
func_name (void)
{
    stmt1;
    stmt2;
}

Browsing through the code, this is what I have written so far:

<CODE>

    tree fn_type = build_function_type_list(void_type_node, NULL_TREE);
    tree fn_decl = build_fn_decl ("func_name", fn_type);

    push_cfun (fn_decl);

    tree resdecl = build_decl (UNKNOWN_LOCATION,
            RESULT_DECL, NULL_TREE, void_type_node);
    DECL_ARTIFICIAL (resdecl) = 1;
    DECL_CONTEXT (resdecl) = fn_decl;
    DECL_RESULT (fn_decl) = resdecl;

    DECL_STATIC_CONSTRUCTOR (fn_decl) = 1;
    DECL_ARTIFICIAL (fn_decl) = 1;
    DECL_CONTEXT (fn_decl) = NULL_TREE;
    TREE_USED (fn_decl) = 1;
    TREE_STATIC (fn_decl) = 1;
    DECL_EXTERNAL (fn_decl) = 0;

    announce_function(fn_decl);
    make_decl_rtl(fn_decl);
    init_function_start (fn_decl);
    rest_of_decl_compilation(fn_decl, 1, 0);

    gimple_set_body(fn_decl, stmts);
    pop_cfun();

</CODE>

However, the function decl node never gets inserted into the target
binary. The plugin pass runs before the "omplower" pass.

Thanks for your help.
Zahed


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux