2013-03-05 67 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该文件中缺少函数。