2017-04-19 205 views
3

我想寫一個LLVM傳遞,它將提取函數調用的參數。如果爭論是一個常數,我的目標是恢復常數。如何在LLVM中獲取函數調用的參數?

紅外看起來像

%2 = call noalias i8* @malloc(i64 512) #3 

LLVM的傳球看起來像

bool runOnFunction(Function &F) override { 
    for (auto& B : F) { 
     for (auto& 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 arg = fn->arg_begin(); arg != fn->arg_end(); ++arg) { 
        errs() << *arg << "\n"; 
       } 
      } 
     } 
    } 

    return false; 
} 

如果我通過opt跑通,它產生以下

malloc : 0x3df3f40 
i64 %0 

是什麼0x3df3f40代表?爲什麼會產生i64%0?而不是i64512

回答

3

這是一個指向Value的指針。嘗試cast<>將其更改爲ConstantInt,然後致電getValue()

相關問題