[LLVMdev] How to insert a self-written function to a piece of programme

Duncan Sands baldrick at free.fr
Sat Apr 7 00:28:49 PDT 2012


Hi 15102925731,

> *Referencing function in another module!
> %CallCheck = call i32 @check()
> Broken module found, compilation aborted!*

> *//Create a function prototype exactly like "int check()", then create a call
> instruction to that function.*
> Module * M;
> LLVMContext Context;
> FunctionType *STy=FunctionType::get(Type::getInt32Ty(Context), false);
> Function *check = Function::Create(STy, Function::InternalLinkage, "check" ,M);

So here M is passed in uninitialized; same with Context?

Ciao, Duncan.

> CallInst *callcheck = CallInst::Create(check,"CallCheck");
>
> namespace {
> struct Hello : public FunctionPass
> {
> static char ID;
> Hello() : FunctionPass(ID) {}
> virtual bool runOnFunction(Function &F)
> {
> *// run through all the instruction and find the one that call
> "puts*
> for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
> {
> for(BasicBlock::iterator II = BI->begin(),IE = BI->end();II != IE; ++II)
> {
> if(CallInst * III = dyn_cast<CallInst>(II))
> {
>
> if(III->getCalledFunction()!=NULL&&III->getCalledFunction()->getName()=="puts")
> {
> errs() <<III->getCalledFunction()->getName()<<" function found!\n";
> callcheck->insertBefore(II);
> errs() <<"INSERT SUCCEEDED!!!!!!!!\n";
> }
> else
> {
> errs() <<"it's not main function!\n"<<"it
> is:"<<III->getCalledFunction()->getName()<<'\n';
> }
> }/**/
>
> }
> ************************************************************************************************************************************************************************************************************************************************************************************************
> QUESTION: IS IT BECAUSE THE PASS CAN'T RECOGNIZE MY CHECK FUNCTION OR WHAT?? HOW
> TO MAKE THE PASS WORK AS EXPECTED???
> THANK YOU!!
>
> --
> 祝好!
> 甄凯
> ------------------------------------------------------------------------------------------------------
>
> 2012-04-07
> ------------------------------------------------------------------------------------------------------
>
> Name: 甄凯(ZhenKai)
> Homepage:http://www.renren.com/262729393
> Email: zhenkaixd at 126.com <mailto:zhenkaixd at 126.com> or 846227103 at qq.com
> <mailto:846227103 at qq.com>
> TEL: 15810729006(Beijing)
> Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.
>
>
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list