From 714257f5deec6049a4170bdd77ca1c3df989d67e Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Thu, 30 Apr 2009 22:33:41 +0000 Subject: [PATCH] Add a mention of TypeBuilder to the programmer's manual, and clean up the class comment a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@70515 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/ProgrammersManual.html | 41 ++++++++++++++++++++++++++++++ include/llvm/Support/TypeBuilder.h | 12 ++++----- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index e2525ae84e0..253e8363610 100644 --- a/docs/ProgrammersManual.html +++ b/docs/ProgrammersManual.html @@ -117,6 +117,7 @@ with another Value
  • Deleting GlobalVariables
  • +
  • How to Create Types
  • +
    + How to Create Types +
    + +
    + +

    In generating IR, you may need some complex types. If you know these types +statically, you can use TypeBuilder<...>::get(), defined +in llvm/Support/TypeBuilder.h, to retrieve them. TypeBuilder +has two forms depending on whether you're building types for cross-compilation +or native library use. TypeBuilder<T, true> requires +that T be independent of the host environment, meaning that it's built +out of types from +the llvm::types +namespace and pointers, functions, arrays, etc. built of +those. TypeBuilder<T, false> additionally allows native C types +whose size may depend on the host compiler. For example,

    + +
    +
    +FunctionType *ft = TypeBuilder<types::i<8>(types::i<32>*), true>::get();
    +
    +
    + +

    is easier to read and write than the equivalent

    + +
    +
    +std::vector params;
    +params.push_back(PointerType::getUnqual(Type::Int32Ty));
    +FunctionType *ft = FunctionType::get(Type::Int8Ty, params, false);
    +
    +
    + +

    See the class +comment for more details.

    + +
    +
    Advanced Topics diff --git a/include/llvm/Support/TypeBuilder.h b/include/llvm/Support/TypeBuilder.h index df8bc5ea4ba..c8ffb938c60 100644 --- a/include/llvm/Support/TypeBuilder.h +++ b/include/llvm/Support/TypeBuilder.h @@ -40,21 +40,21 @@ namespace llvm { /// int8 AFunction(struct MyType *value); /// /// You'll want to use -/// Function::Create(TypeBuilder(MyType*)>::get(), ...) +/// Function::Create(TypeBuilder(MyType*), true>::get(), ...) /// to declare the function, but when you first try this, your compiler will -/// complain that TypeBuilder::get() doesn't exist. To fix this, write: +/// complain that TypeBuilder::get() doesn't exist. To fix this, +/// write: /// /// namespace llvm { -/// using types::i; /// template class TypeBuilder { /// public: /// static const StructType *get() { /// // Using the static result variable ensures that the type is /// // only looked up once. /// static const StructType *const result = StructType::get( -/// TypeBuilder, xcompile>::get(), -/// TypeBuilder*, xcompile>::get(), -/// TypeBuilder*[], xcompile>::get(), +/// TypeBuilder, xcompile>::get(), +/// TypeBuilder*, xcompile>::get(), +/// TypeBuilder*[], xcompile>::get(), /// NULL); /// return result; /// } -- 2.34.1