[LLVMdev] Mapping of class derivated and interfaces

Nicola Lugato nicola.lugato at gmail.com
Thu Aug 25 05:45:04 PDT 2005


Hi! i'm tring to figure out how classes and dependencies can be mapped to llvm.
I've read on docs that nesting can be used:

class base { int Y; };
class derived : base { short Z; };

becomes:

%base = type { int }
%derived = type { %base, short }


That's ok, but now the question is: how do i encode a function that
takes "base" type so that it also takes "derived" ?
For example:

// simple function that takes a base class
function myFunc(base* a)
{
...
}

now, i don't think i can just pass a %derived type class to that
function, becouse pointers are of different types. Am i right?
And if i could cast it, the "base" member of "derived" class is at
right position in memory so that myFunc could work?
And doesn't the cast hide important information for the optimizer?
In general, how should this thing be mapped on llvm?

Another question:
What's the best way in general to implement interfaces (like java ones
for example)? Any hint ? I'm just in the dark with this.

I hope those questions wasn't too stupid.
And btw LLVM is really an impressive tool. Great job :)




More information about the llvm-dev mailing list