* Inserting function definitions into the tree
@ 2012-10-09 0:29 zahed khurasani
0 siblings, 0 replies; only message in thread
From: zahed khurasani @ 2012-10-09 0:29 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-10-09 0:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-09 0:29 Inserting function definitions into the tree zahed khurasani
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).