<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">Oh, I see. <br>Also, I also tried a module pass(the short source code is
 as follow). I intended to run the module pass on the .bc file declaring
 the check function to the module's symbol table. Then I go for the 
function pass to insert the CallInst instruction. Does that make sense?<br>Thank you!!  <img src="http://mimg.163.com/jy3style/lib/htmlEditor/portrait/face/preview/face0.gif"><br>#include "llvm/Pass.h"<br>#include "llvm/Support/raw_ostream.h"<br>#include "llvm/Module.h"<br>#include "llvm/Function.h"<br>#include "llvm/LLVMContext.h"<br>#include "llvm/DerivedTypes.h"<br>#include "llvm/Constants.h"<br>#include "llvm/Instructions.h"<br>#include "llvm/Analysis/Verifier.h"<br>#include "llvm/ExecutionEngine/JIT.h"<br>#include "llvm/ExecutionEngine/Interpreter.h"<br>#include "llvm/ExecutionEngine/GenericValue.h"<br>#include "llvm/Support/TargetSelect.h"<br>using namespace llvm;<br> <br>namespace {<br>  struct Hello2 : public ModulePass {<br>    <br>    static char ID;<br>    Hello2() : ModulePass(ID) {}<br><br>    virtual bool runOnModule(Module &M) {<br>      errs() << "Hello: " << '\n' << '\n';<br>      //errs().write_escaped(F.getName()) << '\n';<br>Function *check =<br>    cast<Function>(M.getOrInsertFunction("check", <br>                                          Type::getInt32Ty(M.getContext()),<br>                                          (Type *)0));<br>     if(NULL!=M.getFunction("check"))<br>      errs()<<"declare succeeded!"<<'\n';<br>      return true;<br>    }<br><br>  };<br>}<br><br><div>--<br><div>
<div>
<div><font color="#c0c0c0" size="2">
<div><font color="#c0c0c0"><font size="3">  <span style="COLOR: #000000">          ×£ºÃ£¡</span></font></font></div><span style="COLOR: #000000">
<div> </div>
<div><font size="3">  Õç¿­</font></div>
<div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div></div>
<div><font color="#c0c0c0"><font size="3">2012-04-10</font></font></div></span></font></div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div>
<div><font color="#c0c0c0"><font size="3">Name: Õç¿­(ZhenKai)<br>Homepage:http://www.renren.com/262729393</font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank" _listener="1901"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com">846227103@qq.com</a></font></font></div>
<div><font color="#c0c0c0" size="3">TEL: 15810729006(Beijing)<br>Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.</font></div></div></div></div><div id="divNeteaseMailCard"></div><br><pre><br>At 2012-04-10 15:29:15,"Alexander Potapenko" <glider@google.com> wrote:
>Objects that form the IR (functions, basic blocks, instructions) have
>the getParent() method that returns their paren (module for a
>function, basic block for a single instruction etc.)
>BTW, LLVM Doxygen is really helpful. It's usually the first result
>when you search for "LLVM <classname> class reference"
>
>On Tue, Apr 10, 2012 at 11:17 AM, 15102925731 <zhenkaixd@126.com> wrote:
>>
>> Hi all,
>> I want to run a function pass on a certain .bc file. In the process, the
>> pass will insert a check function into the .bc file.
>>
>> I know the .bc file is regarded as a module in LLVM. So, there are two basic
>> steps needed to be done,
>> 1, Use the "getOrInsertFunction"API to add a declaration of the extern
>> "check function".
>> 2, Use the "insertBefore"API to insert the CallInst into the right position.
>>
>> My problem is about the step 1. How can I get the handle of the .bc file
>> (Probably is a Module*)? so I can
>> declare the extern function like
>> // insert the " i32 @fib(i32 )" to the module M
>> Function *FibF =
>>     cast<Function>(M->getOrInsertFunction("fib", Type::getInt32Ty(Context),
>>                                           Type::getInt32Ty(Context),
>>                                           (Type *)0));
>> How can I get the "M" of the .bc file??????
>>
>> Any help~
>>
>> --
>>             ×£ºÃ£¡
>>
>>   Õç¿­
>> ------------------------------------------------------------------------------------------------------
>> 2012-04-10
>> ------------------------------------------------------------------------------------------------------
>> Name: Õç¿­(ZhenKai)
>> Homepage:http://www.renren.com/262729393
>> Email: zhenkaixd@126.com or 846227103@qq.com
>> TEL: 15810729006(Beijing)
>> Address: Room I-406, Central Building, Tsinghua University, Beijing, China.
>> 100084.
>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev@cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>
>
>-- 
>Alexander Potapenko
>Software Engineer
>Google Moscow
</pre></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>