Dong Chen
2012-Dec-05 11:07 UTC
[LLVMdev] how to get and modify a global variable inside a module
recently, i use LLVM API to write a program to read *.ll and excute it automatically. Further more, i want to change some global variables inside a module. i tried some functions provided by Module.h and ExecutionEngine.h but none were seemed to match my need. did someone have the experience or some advices? thank you ;) -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Eduardo
2012-Dec-05 11:56 UTC
[LLVMdev] how to get and modify a global variable inside a module
Hi Dong Chen, You can write a ModulePass class and implement a runOnModule method. Inside this method you can access Module::global_iterator and get a reference to all global variables of a module. With this reference, you can change this variable. But be careful, you may need to change also the references to those variables. Have a look to the method GlobalVariable::use_begin and use_end. They give you references to the users of the global variable. I hope this helps, Regards, Eduardo On Wed, Dec 5, 2012 at 9:07 AM, Dong Chen <jameschennerd at gmail.com> wrote:> recently, i use LLVM API to write a program to read *.ll and excute it > automatically. > Further more, i want to change some global variables inside a module. > i tried some functions provided by Module.h and ExecutionEngine.h but none > were seemed to match my need. > did someone have the experience or some advices? > thank you ;) > > > > -- > View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289.html > Sent from the LLVM - Dev mailing list archive at Nabble.com. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Duncan Sands
2012-Dec-05 13:15 UTC
[LLVMdev] how to get and modify a global variable inside a module
On 05/12/12 12:07, Dong Chen wrote:> recently, i use LLVM API to write a program to read *.ll and excute it > automatically. > Further more, i want to change some global variables inside a module. > i tried some functions provided by Module.h and ExecutionEngine.h but none > were seemed to match my need. > did someone have the experience or some advices? > thank you ;)You can get hold of the global variable by passing it's name to Module::getNamedValue. For modification it depends on what kind of modification you have in mind, so please clarify. Ciao, Duncan.
Dong Chen
2012-Dec-05 13:37 UTC
[LLVMdev] how to get and modify a global variable inside a module
hi Eduardo, thanks for your attention, i checked the iterator, but i didn't see any fucntion can return or modify the main memory address of a global variable inside the module. can you provide some reference code or program can achieve this? thank you very much -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52294.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Dong Chen
2012-Dec-05 13:49 UTC
[LLVMdev] how to get and modify a global variable inside a module
hi Duncan Sands, i have tried the functions: GlobalValue * getNamedValue (StringRef Name) const GlobalVariable * getGlobalVariable (StringRef Name, bool AllowInternal=false) const GlobalVariable * getNamedGlobal (StringRef Name) const but i think these functions just return the ID or something else (not the Global Variable's main memory address, i am not sure) here is the thing. i want to know the exact main memory address of the Global Varibale's address when ExecutionEngine execut the *.ll code. further more, i want to change the address, is it possible? do you have some good idea? thank you very much -- View this message in context: http://llvm.1065342.n5.nabble.com/how-to-get-and-modify-a-global-variable-inside-a-module-tp52289p52295.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Possibly Parallel Threads
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] Finding the uses of a global variable
- [LLVMdev] GlobalVariable initializer using from beyond the grave
- [LLVMdev] how to get and modify a global variable inside a module
- [LLVMdev] How to get the Instruction where one function use the global variable.