我想学习如何以编程方式与LLVM / Clang集成以查找我的Xcode项目中的所有fclose()调用。 我意识到我可以通过正常的文本搜索来实现这一点,但这只是更详细问题的第一步。
I would like to learn how I might programmatically integrate with LLVM/Clang to find all of the fclose() calls in my Xcode project. I realize I can accomplish this via normal text searching but this is just the first step in a more detailed problem.
最满意答案
您可以编写函数pass并查找函数名称,如下所示:
#include "llvm/Pass.h" #include "llvm/IR/Function.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { struct Hello : public FunctionPass { static char ID; Hello() : FunctionPass(ID) {} virtual bool runOnFunction(Function &F) { errs() << "Hello: "; errs().write_escaped(F.getName()) << '\n'; return false; } }; } char Hello::ID = 0; static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);使用opt -hello input.ll从opt调用此传递,您将获得所有打印函数的名称。 更改上述代码中的逻辑以查找所需的功能。 有关写通行证的更多详细信息,请参阅以下链接:
http://llvm.org/docs/WritingAnLLVMPass.html
You can write function pass and find the name of the function as below:
#include "llvm/Pass.h" #include "llvm/IR/Function.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; namespace { struct Hello : public FunctionPass { static char ID; Hello() : FunctionPass(ID) {} virtual bool runOnFunction(Function &F) { errs() << "Hello: "; errs().write_escaped(F.getName()) << '\n'; return false; } }; } char Hello::ID = 0; static RegisterPass<Hello> X("hello", "Hello World Pass", false, false);Call this pass from opt using opt -hello input.ll and you will get the names of all functions printed. Change the logic in the above code to find your required function. See the following link for more details on writing passes:
http://llvm.org/docs/WritingAnLLVMPass.html
更多推荐
发布评论