[LLVMdev] recursive nested functions

Eugene Toder eltoder at gmail.com
Fri Jun 25 14:58:02 PDT 2010


Curtis described a fairly standard approach -- you put all variables
used in nested functions into a struct and pass pointer to it to these
functions. The only difference is that these structs are usually
linked (struct in a nested function has a pointer to struct in outer
function), so deep nested functions only need one extra argument. gcc
supports nested functions in C (including mutually recursive nested
functions, forward declarations need to use "auto" linkage) using this
approach, you can look at what it does with llvm-gcc.

Eugene

On Fri, Jun 25, 2010 at 6:46 PM, Nicolas Ojeda Bar
<nojb at math.harvard.edu> wrote:
> Hello,
>
> This is a little off-topic. But I am writing a compiler to llvm ir
> for a language that admits recursive nested functions and am stuck
> as to how to translate them. Concretely, I'm trying to lift them all
> to the topmost level and pass all their free variables explicitly as
> arguments. To do this, I have to determine all their free variables
> in their bodies. In particular when I come across a function call,
> I have to add _its_ free variables to the list of free variables of
> the enclosing function. You can see how this will not work if we
> allow recursive functions.
>
> Any pointers would be greatly appreciated.
>
> Thanks!
> N
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>




More information about the llvm-dev mailing list