2013-03-05 46 views
-1

我想創建一個傳遞加載值的外部函數。 這是我在做什麼llvm將加載值傳遞給外部函數

cpProfFunc = M.getOrInsertFunction("_Z6cpProfiiiiii",Type::getVoidTy(*Context),Type::getInt8tInt8PtrTy(*Context),NULL); 
if(isa<LoadInst>(&(*BI)))  //next in block iterator 
    std::vector<Value*> a1(1);    
LoadInst *CI = dyn_cast<LoadInst>(BI); 
a1[0]=dyn_cast<ConstantExpr>(CI->getPointerOperand()); 
CallInst* newInst = CallInst::Create(cpProf,a1,""); 
BB->getInstList().insert((Instruction*)CI, newInst); 

這是給我error.I不知道我在哪裏wrong.Somebody,請大家指正。

+0

「這給了我一個錯誤」 - 那是什麼錯誤? – Oak 2013-03-05 08:25:22

+0

編譯錯誤或運行時錯誤? – Alex 2013-03-05 08:47:54

+0

錯誤在運行選擇-load 錯誤的時間是: 一個@的ubuntu:〜/桌面$ ./myscript LLVM [0]:編譯printFunc.cpp用於推出+斷言建立(PIC) LLVM [0] :鏈接發佈+聲明可加載模塊Ass1Pri.so 0 opt 0x0854449b 堆棧轉儲: 0. \t程序參數:opt -load /home/anshul/llvm/llvm-3.2/Release+Asserts/lib/Ass1Pri.so -anshul_insert 1. \t模塊''上存在運行通行'測試功能'。 ./myscript:line 6:10726分段錯誤(核心轉儲)opt -load /home/anshul/llvm/llvm-3.2/Release+Asserts/lib/Ass1Pri.so -anshul_insert < a.bc > b1.bc 'main'function not在模塊中找到。 – user2118561 2013-03-05 11:17:06

回答

0

你寫,你收到的錯誤:

Stack dump: 
0. Program arguments: opt -load /home/anshul/llvm/llvm-3.2/Release+Asserts/lib/Ass1Pri.so -anshul_insert 
1. Running pass 'test function exist' on module '<stdin>'. 
./myscript: line 6: 10726 Segmentation fault (core dumped) 
opt -load /home/anshul/llvm/llvm-3.2/Release+Asserts/lib/Ass1Pri.so -anshul_insert <a.bc> b1.bc 
'main' function not found in module. 

如此看來,所謂的「測試功能存在」通正試圖實際運行一些位碼文件(可能調用就可以了LLI),但main該文件中缺少函數。