llvm中是否有用于迭代结构数组变量?;
为了做一些代码分析工作,我正在尝试开始使用LLVM,但要从LLVM文档中理解所有这些类型和函数对我来说很困难。llvm中是否有用于迭代结构数组变量?;,llvm,Llvm,为了做一些代码分析工作,我正在尝试开始使用LLVM,但要从LLVM文档中理解所有这些类型和函数对我来说很困难。 现在我的问题是如何从结构数组类型的变量中获取每个元素。假设我有一个名为apple的结构,和一个名为apple的apple数组,如何通过分析LLVM-IR获得apple数组中的元素 C代码如下所示: struct apple { int a; int b; int (*eat)(int x,int y); }; int eat_apple(int x,int y) { r
现在我的问题是如何从结构数组类型的变量中获取每个元素。假设我有一个名为apple的结构,和一个名为apple的apple数组,如何通过分析LLVM-IR获得apple数组中的元素
C代码如下所示:
struct apple
{
int a;
int b;
int (*eat)(int x,int y);
};
int eat_apple(int x,int y)
{
return x+y;
}
int sub_apple(int x,int y)
{
return x-y;
}
struct apple apples[]=
{
{
.b=7,
.eat=eat_apple,
},
{
.a=8,
.eat=sub_apple,
},
};
IR表示中的结构apple
和全局变量数组apples[]
如下所示:
%struct.apple = type { i32, i32, i32 (i32, i32)* }
@apples = dso_local global [2 x %struct.apple] [%struct.apple { i32 0, i32 7, i32 (i32, i32)* @eat_apple }, %struct.apple { i32 8, i32 0, i32 (i32, i32)* @sub_apple }], align 16
我想知道如何在数组apples[]
中迭代并获取元素值,因此我可以知道函数eat_apple()
被array apples[]
的第一个元素使用,函数sub_apple()
被apples[]
的第二个元素在初始化时使用。我在网上浏览了一些课程。包括:GlobalVariable、Cosntant、ConstantAggregate、ConstantArray、StructType、ArrayType,但我只找到了
gettypatindex()
来获取元素类型,是否有类似的函数可以获取元素值提前谢谢 IIRC ConstantStruct::GetOperator()和GetNumPerands()将执行您想要的操作。