[llvm] r271985 - [Kaleidoscope] Update Chapter 3 of the "Implementing a Language" tutorial to

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 6 22:40:09 PDT 2016


Author: lhames
Date: Tue Jun  7 00:40:08 2016
New Revision: 271985

URL: http://llvm.org/viewvc/llvm-project?rev=271985&view=rev
Log:
[Kaleidoscope] Update Chapter 3 of the "Implementing a Language" tutorial to
take into account modernizations in r246002 and r270381.

Patch based on http://reviews.llvm.org/D20954 by Miroslav Hrncir.
Thanks Miroslav!


Modified:
    llvm/trunk/docs/tutorial/LangImpl3.rst

Modified: llvm/trunk/docs/tutorial/LangImpl3.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/LangImpl3.rst?rev=271985&r1=271984&r2=271985&view=diff
==============================================================================
--- llvm/trunk/docs/tutorial/LangImpl3.rst (original)
+++ llvm/trunk/docs/tutorial/LangImpl3.rst Tue Jun  7 00:40:08 2016
@@ -73,20 +73,20 @@ parser, which will be used to report err
 
 .. code-block:: c++
 
-    static std::unique_ptr<Module> *TheModule;
-    static IRBuilder<> Builder(LLVMContext);
-    static std::map<std::string, Value*> NamedValues;
+    static LLVMContext TheContext;
+    static IRBuilder<> Builder(TheContext);
+    static std::unique_ptr<Module> TheModule;
+    static std::map<std::string, Value *> NamedValues;
 
     Value *LogErrorV(const char *Str) {
       LogError(Str);
       return nullptr;
     }
 
-The static variables will be used during code generation. ``TheModule``
-is an LLVM construct that contains functions and global variables. In many
-ways, it is the top-level structure that the LLVM IR uses to contain code.
-It will own the memory for all of the IR that we generate, which is why
-the codegen() method returns a raw Value\*, rather than a unique_ptr<Value>.
+The static variables will be used during code generation. ``TheContext``
+is an opaque object that owns a lot of core LLVM data structures, such as
+the type and constant value tables. We don't need to understand it in
+detail, we just need a single instance to pass into APIs that require it.
 
 The ``Builder`` object is a helper object that makes it easy to generate
 LLVM instructions. Instances of the
@@ -94,6 +94,12 @@ LLVM instructions. Instances of the
 class template keep track of the current place to insert instructions
 and has methods to create new instructions.
 
+``TheModule`` is an LLVM construct that contains functions and global
+variables. In many ways, it is the top-level structure that the LLVM IR
+uses to contain code. It will own the memory for all of the IR that we
+generate, which is why the codegen() method returns a raw Value\*,
+rather than a unique_ptr<Value>.
+
 The ``NamedValues`` map keeps track of which values are defined in the
 current scope and what their LLVM representation is. (In other words, it
 is a symbol table for the code). In this form of Kaleidoscope, the only




More information about the llvm-commits mailing list