Exceptions for my own programming language (original) (raw)
I am working on an back end for my own programming language. I think the most challenging feature will be exceptions. I’ve read the documentation, but I’m still missing some crucial pieces.
What I (think I) know:
- Exceptions are thrown using the
_Unwind_RaiseException
function from libunwind. - Functions that can throw an exception need a personality function (but I don’t know what exactly personality functions do)
- All functions in a
try { ... }
block need to be called withinvoke
which includes references to a label for normal return and another label for exceptions. - The exceptional label should point to a basic block that starts with a
landingpad
instruction.
My main question now is about the landingpad
arguments. In particular, I need to provide at least one catch
clause with a “type” of exception. But which type should I use there? I don’t have to provide a type when using _Unwind_RaiseException
, so how does the mechanism know that my exception should land on this landingpad?
I would also appreciate any information about what the personality function is supposed to do, because the LLVM documentation is really light on the details:
The
personality
attribute permits functions to specify what function to use for exception handling.
In particular, about the personality function, I’m wondering how it should jump to the LLVM landing pad.