[LLVMdev] How to handle nested procedures?

Jeff Cohen jeffc at jolt-lang.org
Sat Aug 21 17:35:30 PDT 2004


How would following Pascal code be translated to LLVM?

  procedure outer(a: integer): integer;
    procedure inner(b: integer): integer;
    begin
      return a + b
    end;
  begin
    return inner(a)
  end;

If outer(10) is called, it returns 20.

The problem here is that inner has access to the locals and formal
arguments of outer.  I do not see any direct support for this.  It could
be handled by creating a struct for outer that contains everything used
by inner procedures and explicitly passing its address to the inner
procedures as an extra parameter.

Am I missing something?  If not, are there any plans to directly support
this?




More information about the llvm-dev mailing list