I’m working on implementing a simple functional language in LLVM. It’s statically typed, but I’d like to a have some simple multimethods involved. Does LLVM have some intrinsics for handling something like C++ vtables? Or do I need to implement my own way of handling single-dispatch functions?
Thanks,
Timothy
I’m working on implementing a simple functional language in LLVM. It’s statically typed, but I’d like to a have some simple multimethods involved. Does LLVM have some intrinsics for handling something like C++ vtables? Or do I need to implement my own way of handling single-dispatch functions?
You’ll need to do that yourself. A vtable is just an array of function pointers.
You can map the concept in C++ and run Clang on it to output IR, so
you know more or less it should be done in your language.
cheers,
--renato
Hello Timothy,
If you are basing your language on the Clang source base then it will be able to do VTables. If you're basing it on LLVM by itself, there are no intrinsics for doing VTables. You just have to do a Load on the VPtr in your class, GetElementPtr on the array pointed to by the VPtr, and then execute the method pointer you just retrieved.
I hope this helps you,
--Sam Crow