LLVM  6.0.0svn
llvm::TypeBuilder< T, cross_compilable > Class Template Reference

TypeBuilder - This provides a uniform API for looking up types known at compile time. More...

#include "llvm/IR/TypeBuilder.h"

Inheritance diagram for llvm::TypeBuilder< T, cross_compilable >:
Inheritance graph

Detailed Description

template<typename T, bool cross_compilable>
class llvm::TypeBuilder< T, cross_compilable >

TypeBuilder - This provides a uniform API for looking up types known at compile time.

To support cross-compilation, we define a series of tag types in the llvm::types namespace, like i<N>, ieee_float, ppc_fp128, etc. TypeBuilder<T, false> allows T to be any of these, a native C type (whose size may depend on the host compiler), or a pointer, function, or struct type built out of these. TypeBuilder<T, true> removes native C types from this set to guarantee that its result is suitable for cross-compilation. We define the primitive types, pointer types, and functions up to 5 arguments here, but to use this class with your own types, you'll need to specialize it. For example, say you want to call a function defined externally as:

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> {
static StructType *get(LLVMContext &Context) {
// If you cache this result, be sure to cache it separately
// for each LLVMContext.
TypeBuilder<types::i<32>, xcompile>::get(Context),
TypeBuilder<types::i<32>*, xcompile>::get(Context),
TypeBuilder<types::i<8>*[], xcompile>::get(Context),
// 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 {
} // 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 do something similarly undesirable.

Definition at line 85 of file TypeBuilder.h.

The documentation for this class was generated from the following file: