LLVM API Documentation
#include <TypeBuilder.h>
struct MyType { int32 a; int32 *b; void *array[1]; // Intended as a flexible array. }; int8 AFunction(struct MyType *value);
You'll want to use Function::Create(TypeBuilder<types::i<8>(MyType*), true>get(), ...) to declare the function, but when you first try this, your compiler will complain that TypeBuilder<MyType, true>::get() doesn't exist. To fix this, write:
namespace llvm { template<bool xcompile> class TypeBuilder<MyType, xcompile> { public: static const StructType *get(LLVMContext &Context) { If you cache this result, be sure to cache it separately for each LLVMContext. return StructType::get( TypeBuilder<types::i<32>, xcompile>get(Context), TypeBuilder<types::i<32>*, xcompile>get(Context), TypeBuilder<types::i<8>*[], xcompile>get(Context), NULL); }
You may find this a convenient place to put some constants to help with getelementptr. They don't have any effect on the operation of TypeBuilder. enum Fields { FIELD_A, FIELD_B, FIELD_ARRAY }; } } // namespace llvm
TypeBuilder cannot handle recursive types or types you only know at runtime. If you try to give it a recursive type, it will deadlock, infinitely recurse, or throw a recursive_init exception.
Definition at line 77 of file TypeBuilder.h.