[llvm-commits] [llvm] r70515 - in /llvm/trunk: docs/ProgrammersManual.html include/llvm/Support/TypeBuilder.h
Jeffrey Yasskin
jyasskin at google.com
Thu Apr 30 15:33:41 PDT 2009
Author: jyasskin
Date: Thu Apr 30 17:33:41 2009
New Revision: 70515
URL: http://llvm.org/viewvc/llvm-project?rev=70515&view=rev
Log:
Add a mention of TypeBuilder to the programmer's manual, and clean up the class
comment a bit.
Modified:
llvm/trunk/docs/ProgrammersManual.html
llvm/trunk/include/llvm/Support/TypeBuilder.h
Modified: llvm/trunk/docs/ProgrammersManual.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ProgrammersManual.html?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- llvm/trunk/docs/ProgrammersManual.html (original)
+++ llvm/trunk/docs/ProgrammersManual.html Thu Apr 30 17:33:41 2009
@@ -117,6 +117,7 @@
<li><a href="#schanges_deletingGV">Deleting <tt>GlobalVariable</tt>s</a> </li>
</ul>
</li>
+ <li><a href="#create_types">How to Create Types</a></li>
<!--
<li>Working with the Control Flow Graph
<ul>
@@ -2088,6 +2089,46 @@
</div>
+<!-- ======================================================================= -->
+<div class="doc_subsection">
+ <a name="create_types">How to Create Types</a>
+</div>
+
+<div class="doc_text">
+
+<p>In generating IR, you may need some complex types. If you know these types
+statically, you can use <tt>TypeBuilder<...>::get()</tt>, defined
+in <tt>llvm/Support/TypeBuilder.h</tt>, to retrieve them. <tt>TypeBuilder</tt>
+has two forms depending on whether you're building types for cross-compilation
+or native library use. <tt>TypeBuilder<T, true></tt> requires
+that <tt>T</tt> be independent of the host environment, meaning that it's built
+out of types from
+the <a href="/doxygen/namespacellvm_1_1types.html"><tt>llvm::types</tt></a>
+namespace and pointers, functions, arrays, etc. built of
+those. <tt>TypeBuilder<T, false></tt> additionally allows native C types
+whose size may depend on the host compiler. For example,</p>
+
+<div class="doc_code">
+<pre>
+FunctionType *ft = TypeBuilder<types::i<8>(types::i<32>*), true>::get();
+</pre>
+</div>
+
+<p>is easier to read and write than the equivalent</p>
+
+<div class="doc_code">
+<pre>
+std::vector<const Type*> params;
+params.push_back(PointerType::getUnqual(Type::Int32Ty));
+FunctionType *ft = FunctionType::get(Type::Int8Ty, params, false);
+</pre>
+</div>
+
+<p>See the <a href="/doxygen/TypeBuilder_8h-source.html#l00001">class
+comment</a> for more details.</p>
+
+</div>
+
<!-- *********************************************************************** -->
<div class="doc_section">
<a name="advanced">Advanced Topics</a>
Modified: llvm/trunk/include/llvm/Support/TypeBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/TypeBuilder.h?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/TypeBuilder.h (original)
+++ llvm/trunk/include/llvm/Support/TypeBuilder.h Thu Apr 30 17:33:41 2009
@@ -40,21 +40,21 @@
/// int8 AFunction(struct MyType *value);
///
/// You'll want to use
-/// Function::Create(TypeBuilder<types::i<8>(MyType*)>::get(), ...)
+/// 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>::get() doesn't exist. To fix this, write:
+/// complain that TypeBuilder<MyType, true>::get() doesn't exist. To fix this,
+/// write:
///
/// namespace llvm {
-/// using types::i;
/// template<bool xcompile> class TypeBuilder<MyType, xcompile> {
/// 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<i<32>, xcompile>::get(),
-/// TypeBuilder<i<32>*, xcompile>::get(),
-/// TypeBuilder<i<8>*[], xcompile>::get(),
+/// TypeBuilder<types::i<32>, xcompile>::get(),
+/// TypeBuilder<types::i<32>*, xcompile>::get(),
+/// TypeBuilder<types::i<8>*[], xcompile>::get(),
/// NULL);
/// return result;
/// }
More information about the llvm-commits
mailing list