I want to use fine-grained offset of each struct element in LLVM. For example:
struct A{
int a;
int b;
};
struct B{
int c;
struct A sa;
};
struct B s;
For struct B, I want to enumerate each element inside it, i.e: offset(s.c) = 0, offset(s.sa.a) = 4, offset(s.sa.b)=8. How can I get this information (which API could be used?) inside my pass other than dump()?
Use Module::getDataLayout to obtain a DataLayout object, which can give you a StructLayout
as a return of DataLayout::getStructLayout. The StructLayout
has getElementOffset() method, that does what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With