Hi, On Wed, Jul 17, 2013 at 04:52:30PM -0300, Rodolfo Guilherme Wottrich wrote: > Hello there, > > Please disregard this message in case it doesn't fit here. > > During compilation of a C file, I need to be able to create a global > function definition, with whatever a body I may have forged. I mean, > the function is not going to be present in the source file and I got > to create the respective tree structure so it can be later gimplified > and further compiled like any other function present in the source. I > would only need to create that function in case some OpenMP directive > is encountered, so my latest and unsuccessful try to do so was to > create the tree structures for a FUNCTION_DECL and, say, a variable > declared inside the scope of that function, after the parsing of a > #pragma omp parallel in c_parser_omp_parallel() in file c-parser.c. I > followed and tried to re-create the steps I found in the function > create_omp_child_function(), in file omp-low.c, and > http://gcc.gnu.org/onlinedocs/gccint/Function-Basics.html#Function-Basics. > > I think maybe the problem is that my new function doesn't go under > rest_of_compilation, therefore it is not gimplified and obviously no > code for it is generated.
it's a bit difficult to say without knowing what you are doing and at what compilation stage you are doing it but perhaps you could try calling cgraph_add_new_function on the new decl? Also try reading the comment at the beginning of cgraphunit.c. Hope it helps, Martin > > Summarizing: I tried to forge a function in parsing time, but > couldn't. What am I doing wrong, and how can one do such a thing? > Maybe the problem is that I create no calls to that new function, what > do you think? Anyway, I'm compiling with -O0, so I guess no > optimization pass would remove my function just because it is not > being used. > > Thanks in advance, > > --- > Rodolfo Guilherme Wottrich > Universidade Estadual de Campinas - Unicamp