我有以下LLVM IR,我想从store指令中提取变量名string
。请指导我如何做到这一点。
%call = call noalias i8* @malloc(i64 100) #3
store i8* %call, i8** %string, align 8
我的LLVM传递看起来像
virtual bool runOnModule(Module &M) {
for (Function &F: M) {
for (BasicBlock &B: F) {
for (Instruction &I: B) {
if(CallInst* call_inst = dyn_cast<CallInst>(&I)) {
Function* fn = call_inst->getCalledFunction();
StringRef fn_name = fn->getName();
errs() << fn_name << " : " << call_inst->getArgOperand(0) << "\n";
//for(auto args = fn->arg_begin(); args != fn->arg_end(); ++args) {
// ConstantInt* arg = dyn_cast<ConstantInt>(&(*args));
// errs() << arg->getValue() << "\n";
//}
} else {
errs() << I.getName() << "\n" << I.getOpcodeName();
}
}
}
}
return false;
}
答案 0 :(得分:3)
检查I
是StoreInst
后,您可以在I.op_begin()
和I.op_end()
之间进行迭代:
for (auto op = I.op_begin(); op != I.op_end(); op++) {
Value* v = op.get();
StringRef name = v->getName();
}