gpt4 book ai didi

c++ - LLVM,获取内部结构的偏移量

转载 作者:太空狗 更新时间:2023-10-29 20:09:17 25 4
gpt4 key购买 nike

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

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

对于结构 B,我想枚举其中的每个元素,即:offset(s.c) = 0, offset(s.sa.a) = 4, offset(s.sa.b)=8。除了 dump() 之外,我如何在我的通行证中获取此信息(可以使用哪个 API?)?

最佳答案

使用Module::getDataLayout获得DataLayout对象,它可以为您提供 StructLayout 作为 DataLayout::getStructLayout 的返回值. StructLayoutgetElementOffset()方法,它可以满足您的需求。

关于c++ - LLVM,获取内部结构的偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47949969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com