如何在LLVM中将genericValue转换为Value? [英] How to convert a genericValue to Value in LLVM?
问题描述
我正在翻译中.我在内存中有一个变量的地址,并且设法通过LoadValueFromMemory函数从中获取了真实值并将其放入genericValue中.现在,我需要创建一个StoreInst,并希望将此值放入Value对象中,以便在StoreInst中使用它.有什么主意吗?
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?
推荐答案
要回答标题中的问题,GenericValue
只是一个与类型无关的容器,具有某些值.要从中创建LLVM Value
,您需要创建 Constant
并使用该值初始化常量.
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.
我假设您是指从一个模块中获取值,然后在另一个不相关的模块中使用它,否则我不清楚为什么您要为此通过GenericValue
:
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:
- 如果该值来自解释器端,则无需将其存储在
GenericValue
中,只需从该值创建一个Constant
. - 如果该值来自同一模块中的LLVM IR端,那么您也无需将该
Value
加载到GenericValue
中,则可以在创建该文件时直接将Value
用作参数.store
指令.
- If the value came from the interpreter side, you don't need to store it in a
GenericValue
, you can just create aConstant
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 aGenericValue
, you can just use thatValue
directly as the argument when creating thestore
instruction.
这篇关于如何在LLVM中将genericValue转换为Value?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!