我是 llvm 框架的新手,我开始非常基础。有什么比 hello world 更基本的呢? 我想在 main.c 中迭代我的主函数。看起来像节 “在函数中迭代 BasicBlock”将是一个很好的起点”
Function &Func = ...
for (BasicBlock &BB : Func)
// Print out the name of the basic block if it has one, and then the
// number of instructions that it contains
errs() << "Basic block (name=" << BB.getName() << ") has "
<< BB.size() << " instructions.\n";
我要设置什么Function &Func =
到?
我想看看我的 main.c 文件中的 main 函数。
当我们讨论这个话题时。我会将 BasicBlock& BB = ...
设置为什么?
我的代码。
bool Prereqs::runOnModule(Module &M) {
/* Add your code here */
errs() << "Hi: ";
errs().write_escaped(M.getName()) << '\n';
NumOfFunctions +=10;
outs()<<"get opcode yields: getOpcode()" <<"\n";
Function &Func = main.c;
for (BasicBlock &BB : Func)
// Print out the name of the basic block if it has one, and then the
// // number of instructions that it contains
// errs() << "Basic block (name=" << BB.getName() << ") has "
// << BB.size() << " instructions.\n";
print(M);
return false;
}
文档 https://releases.llvm.org/8.0.0/docs/ProgrammersManual.html#basic-inspection-and-traversal-routines
答案 0 :(得分:1)
您可能希望将 Func
设置为 Module::getFunction() 的返回值,如果您不知道模块是什么或如何制作模块,请there is a tutorial。>