LLVM,将内部结构的偏移偏移

LLVM, get the offset of inside struct

本文关键字:结构 内部 LLVM      更新时间:2023-10-16

我想使用LLVM中每个结构元素的细粒偏移。例如:

struct A{
    int a;
    int b;
};
struct B{
    int c;
    struct A sa;
};
struct B s;

对于struct B,我想枚举其中的每个元素,即:偏移(s.c)= 0,偏移(s.sa.a)= 4,offset(s.sa.b)= 8。除了dump()?

使用模块:: getDatalayout获取DataLayout对象,该对象可以为您提供StructLayout作为Datalayout :: getsstructlayout的返回。StructLayout具有执行您想要的getElementOffset()方法。