[LLVMdev] inserting exit function into IR
Frits van Bommel
fvbommel at gmail.com
Thu Mar 31 12:51:03 PDT 2011
On Thu, Mar 31, 2011 at 9:31 PM, George Baah <georgebaah at gmail.com> wrote:
> Hi Joshua,
> I have a function foo and I want to insert exit(0) at the end of foo.
> The problem is M.getFunction returns null, which is understandable. I am not
> sure what to do. Below is the code snippet.
> void foo(int argc, char* argv[]) {
> printf("hello world\n");
> exit(0); //***I want to insert this exit
> }
> My llvm code snippet is
>
> vector<const Type *> params = vector<const Type *>();
The initialization is unnecessary (but harmless).
> params.push_back(Type::getInt32Ty(M.getContext()));
>
> FunctionType *fType = FunctionType::get(Type::getVoidTy(M.getContext()),
> params, false);
>
> Constant *temp = M.getFunction("exit", fType);
M.getOrInsertFunction("exit", fType);
> if(!temp){
>
> errs() << "exit function not in symbol table\n";
>
> exit(1);
>
> }
>
> Function *f = cast<Function>(temp);
>
> CallInst *ci = CallInst::Create(...)
More information about the llvm-dev
mailing list