[LLVMdev] Defining/Accessing Structs Dynamically
Eli Friedman
eli.friedman at gmail.com
Wed Jun 10 13:29:59 PDT 2009
On Wed, Jun 10, 2009 at 10:02 AM, Nyx<mcheva at cs.mcgill.ca> wrote:
> Thus, I need to know how I can define a struct dynamically without having to
> write LLVM assembly (is there an API for doing this?), whether or not LLVM
> functions can actually return those on the stack, as well as how I can read
> and write values to the struct.
There's a C++ API for everything you can write in LLVM assembly. In
this case, I think you want llvm::StructType::get().
> Another issue I have is that I need to interface this with C code. Thus, I
> will need to be able to know at what address specific values in the struct
> lie.
This can get a bit tricky. If you're using the right TargetData,
simple structures (without any bit-fields, packed members, or other
unusual stuff like that) should just work. If you're having trouble,
though, you can just force both the C and LLVM structures to be
packed, which should make computing the offsets completely reliable
and straightforward.
-Eli
More information about the llvm-dev
mailing list