Hello World

Instruction::insertBefore? Or if you prefer, you can mess with the

result of BasicBlock::getInstList() directly.

There it is! I was looking for an equivalent to Instruction::insertBefore inside BasicBlock. (Something along the lines of BasicBlock::appendInstruction.)

You can cast your pointer to an integer, create an LLVM integer

constant, and create a constant cast from that to the relevant pointer

type. Or, you can add an arbitrarily-named Function to the module,

and map it to the appropriate address with

ExecutionEngine::addGlobalMapping. Whichever is more convenient…

AddGlobalMapping seems like a better way to go.

The IRBuilder class is more than just a factory; it’s actually designed to write instructions sequentially into the current block. However, if you don’t give it an insertion point, it will just create the instructions as orphans, and you can land them in basic blocks with the APIs that Eli mentioned.

That said, I strongly encourage you to use IRBuilder to create instructions sequentially rather than trying to place them all yourself.

At first it scared me a little, but the more I think about it, the more it becomes obvious that the order in which instructions are generated should be about the same as the order in which they’re executed.

Thanks for your help!

Félix Cloutier