[LLVMdev] LLVM languages cooperation

Chris Lattner sabre at nondot.org
Tue Feb 24 09:00:01 PST 2004


On Tue, 24 Feb 2004, Vikram S. Adve wrote:

> LLVM does define a common function call and struct/array/pointer model.  You
> could use that to define a language-interoperability scheme, but I think it
> would require some special support from the front-ends to translate
> functions exposed to a different language to conform with the scheme, or to
> generate wrappers for them.  For example, calling a Fortran function
> (call-by-reference) from C (call-by-value) would not work automatically --
> something has to generate wrappers to allow the call.  The scheme would have
> to define an object model and exceptions model.

Another way of putting this is that LLVM _allows_ the code to
interoperate, but, like a microprocessor, does not establish any
conventions that makes interoperability happen automatically.  In Vikram's
example, if you are interfacing C to a language with pass by reference
parameters, either the programmer can be required to prototype those
parameters as taking "a pointer to" the argument type (making the
'reference' explicit in C), or the compiler could generate the interface
code automatically, given a declaration like 'extern "Fortran"' that C++
provides.  Also as Vikram mentioned, the exception model and runtime model
interactions would have to be specified.

MSIL in contrast, requires languages to match a particular object model
and runtime system.  This is great for interoperability, as it almost
happens for free, but at a potential cost in expressibility (e.g., things
get messy supporting multiple inheritence).  This really stems from
differing goals, though LLVM can certainly be used to compile MSIL-like
systems, so it's just a matter of specifying the rules and making the
front-ends stick to them.  :)

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/




More information about the llvm-dev mailing list