我有一个对象callInst.How,我可以取函数的实名,而不是IR代码中的名称?如果我在我的pass中运行这段代码( 无用在另一个问题中发布)
StringRef get_function_name(CallInst *call)
{
Function *fun = call->getCalledFunction();
if (fun)
return call->getName();
else
return StringRef("indirect call");
}
这给了我IR代码的名称(例如,call,call1,call2),.I想要有callInst的实名(printf,foo,main)。
有什么想法吗?
非常感谢
发布于 2015-01-23 01:48:51
它比要求的逻辑简单得多,我只是打印callinst的名称,而不是真正调用函数的值。
StringRef get_function_name(CallInst *call)
{
Function *fun = call->getCalledFunction();
if (fun)
return fun->getName(); //here i would take fun and not call!
else
return StringRef("indirect call");
}
现在一切都好了!
errs()<<fun->getName().str()<<"\n";
我要取真名!我希望我能帮助那些有同样问题的人.
发布于 2015-01-20 06:51:03
你得到了什么--这个函数的坏名字。你必须解开它才能拿回“真实”的名字。我假设您正在linux上工作,并使用clang生成您的IR (因为您的问题上有clang标记)。在linux上,您可以使用
#include <iostream>
#include <memory>
#include <string>
#include <cxxabi.h>
using namespace std;
inline std::string demangle(const char* name)
{
int status = -1;
std::unique_ptr<char, void(*)(void*)> res { abi::__cxa_demangle(name, NULL, NULL, &status), std::free };
return (status == 0) ? res.get() : std::string(name);
}
int main() {
cout << demangle("mangled name here");
return 0;
}
若要拆分函数的名称,请执行以下操作。
https://stackoverflow.com/questions/28045339
复制相似问题