确定模块的所有全局变量

Determine all global variables of a module

如何确定一个LLVM模块的所有全局变量?

我想使用模块传递修改它们。

llvm::Module class 有 getGlobalList() 方法:

/// Get the Module's list of global variables.
GlobalListType         &getGlobalList()             { return GlobalList; }

所以你可以这样做:

for (auto &Global : M->getModule()->getGlobalList()) ...