Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine all global variables of a module

Tags:

llvm

llvm-ir

How to determine all global variables of a LLVM module?

I want to modify them using a module pass.

like image 515
Peter W. Avatar asked Mar 06 '17 08:03

Peter W.


People also ask

How can I see all global variables?

Use the env command. The env command returns a list of all global variables that have been defined. If a global variable exists in a script that hasn't been run yet, it will not show up in the output from env .

Can modules access global variables?

A global variable is a variable which is accessible in multiple scopes. In Python, it is better to use a single module to hold all the global variables you want to use and whenever you want to use them, just import this module, and then you can modify that and it will be visible in other modules that do the same.

How can we create a variable foo to be used globally across all modules?

The best way to share global variables across modules across a single program is to create a config module. Just import the config module in all modules of your application; the module then becomes available as a global name.


1 Answers

llvm::Module class has getGlobalList() method:

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

So you can do something like:

for (auto &Global : M->getModule()->getGlobalList()) ...
like image 133
Stanislav Pankevich Avatar answered Sep 28 '22 15:09

Stanislav Pankevich