How to convert a genericValue to Value in LLVM?

非 Y 不嫁゛ 提交于 2020-01-02 18:16:44

问题


I'm working in interpreter. I have the address of a variable in memory and I managed to get the real value form it and put it in a genericValue using LoadValueFromMemory function. Now I need to create a StoreInst and want to put this value got in a Value object to use it in the StoreInst. Any idea?


回答1:


To answer the question in the title, GenericValue is just a type-agnostic container for some value. To create an LLVM Value from it, you need to create a Constant of the appropriate type, and use that value to initialize the constant.

I'm assuming you are referring to getting a value from one module and using it in another unrelated module, otherwise it's not clear to me why you pass through a GenericValue for this:

  • If the value came from the interpreter side, you don't need to store it in a GenericValue, you can just create a Constant from that value.
  • If the value came from the LLVM IR side in the same module, you also don't need to load that Value into a GenericValue, you can just use that Value directly as the argument when creating the store instruction.


来源:https://stackoverflow.com/questions/19807875/how-to-convert-a-genericvalue-to-value-in-llvm

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!