Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问llvm中数组的变量元素_Llvm_Llvm C++ Api - Fatal编程技术网

访问llvm中数组的变量元素

访问llvm中数组的变量元素,llvm,llvm-c++-api,Llvm,Llvm C++ Api,我想在变量索引处获取数组的值。索引由程序计算,在解析时未知。因此它存储在一个值中,并转换为Int,如下所示: Value *IndexV = Index->Codegen(); Value *IntV = Builder.CreateFPToUI( IndexV, Type::getInt32Ty( getGlobalContext() ) ); 如果我知道索引,我可以使用: Value *VV = Builder.CreateExtractValue( Builder.CreateLo

我想在变量索引处获取数组的值。索引由程序计算,在解析时未知。因此它存储在一个值中,并转换为Int,如下所示:

Value *IndexV = Index->Codegen();
Value *IntV = Builder.CreateFPToUI( IndexV, Type::getInt32Ty( getGlobalContext() ) );
如果我知道索引,我可以使用:

Value *VV = Builder.CreateExtractValue( Builder.CreateLoad( V ), 0 );
这给了我数组的第一个元素。并且工作正常。但是我如何使用
IntV
作为索引呢
CreateExtractValue
只接受ArrayRef,无法将
IntV
强制转换为ArrayRef,还是我错了?一个人怎么会做这样的事


谢谢

首先,每当需要一个ArrayRef时,您总是可以只传递一个项目,因为在任何
T
ArrayRef
之间都有一个项目


但是,这里特别需要常量索引,并且不能接受常规值,这就是为什么它需要
无符号
值的原因。如果要访问数组中未知索引中的元素,请改用指令:在索引为0和
IntV
的数组地址上调用它,你应该在
IntV

位置得到一个指向数组的指针,这给了我一个编译错误:
错误:从'llvm::Value*'到'ArrayRef'没有可行的转换。
@Philip my bad,我把
提取值
提取元素
(它接受
索引)混淆了。我更新了我的答案-我想你想要一个GEP在这里。