[LLVMdev] Manipulating basic blocks with the C bindings

Evan Shaw chickencha at gmail.com
Thu May 27 15:47:32 PDT 2010


I'm writing a frontend with the LLVM C bindings for a language that
has a goto statement, similar to C's. I'm having some trouble figuring
out what to do for the case where the label is declared after the
goto, like this:

goto label;
...
label:
...

When I generate the code for the goto, I'd like to create a basic
block that's not inserted anywhere in particular and then put it in
the right place when I hit the label (or error out appropriately if I
never find it). It looks like the C++ API allows one to do what I'm
describing, but I don't see a way to do it with the C bindings.

I'd like to add the following functions. Hopefully my intent is clear.
I'm very open to name suggestions, as these are a mouthful:

void LLVMAppendExistingBasicBlockInContext(LLVMContextRef C,
LLVMValueRef Fn, LLVMBasicBlock BB);
void LLVMInsertExistingBasicBlockInContext(LLVMContextRef C,
LLVMBasicBlockRef InsertBeforeBB, LLVMBasicBlock BB);
void LLVMAppendExistingBasicBlock(LLVMValueRef Fn, LLVMBasicBlock BB);
void LLVMInsertExistingBasicBlock(LLVMBasicBlockRef InsertBeforeBB,
LLVMBasicBlock BB);

Does this sound reasonable? Am I missing something?

- Evan



More information about the llvm-dev mailing list