问题
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 aConstantfrom that value. - If the value came from the LLVM IR side in the same module, you also don't need to load that
Valueinto aGenericValue, you can just use thatValuedirectly as the argument when creating thestoreinstruction.
来源:https://stackoverflow.com/questions/19807875/how-to-convert-a-genericvalue-to-value-in-llvm