<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif">Sorry ,I forgot to give the definition. I define the print in the doInitialization(Module &M); and it seems in the InstVisitor(), this can not be identified . </div>
<div class="gmail_default" style="font-family:tahoma,sans-serif">What I really want to do is to get every load/store instructions's operand address in runtime and print it out when the program is running. I wrote a function to do the print work and make it into a dynamic library, so in the functionPass , I define the print functiono like this :</div>
<div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default"><span style="font-family:tahoma,sans-serif"> </span><font face="tahoma, sans-serif"> bool doInitialization(Module &M)</font></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">            </span>{</font></div><div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                     </span>//Get the refference of the types</font></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                    </span>IntegerType* Int8Type  = IntegerType::getInt8Ty(M.getContext());</font></div><div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                     </span>IntegerType* Int32Type = IntegerType::getInt32Ty(M.getContext());</font></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                    </span>IntegerType* Int64Type = IntegerType::getInt64Ty(M.getContext());</font></div><div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                     </span>PointerType* VoidPtrType = PointerType::getUnqual(Int8Type);</font></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                    </span>Type* VoidType = Type::getVoidTy(M.getContext());</font></div><div class="gmail_default"><span class="" style="white-space:pre"><font face="tahoma, sans-serif">                     </font></span></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                    </span>//Get the function we needed in runtime</font></div><div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">               </span>    Function *print = cast<Function>(M.getOrInsertFunction("my_print",</font></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                                                                                                            </span> VoidType,</font></div><div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                                                                                                            </span> Int32Type,</font></div>
<div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                                                                                                            </span> VoidPtrType</font></div><div class="gmail_default"><font face="tahoma, sans-serif"><span class="" style="white-space:pre">                                                                                                          </span>));</font></div>
<div class="gmail_default"><span class="" style="font-family:tahoma,sans-serif;white-space:pre">              </span><span style="font-family:tahoma,sans-serif">};</span><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">
I thought if I define the function here ,then in the InstVisitor, I can use it directly,without define it in every specific InstVisitor function()(eg:visitStoreInst() visitLoadInst(),etc).But I was wrong.<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">
I redefine the function in the visitStoreInst(), and it works.</div><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Is there any easy way to use the function I wrote myself in the instVisitor? </div>
<div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif">Thanks.</div><div class="gmail_extra"><br><br></div></div>