llvm.org GIT mirror llvm / 8abe734
[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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271985 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 3 years ago
1 changed file(s) with 14 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
7272
7373 .. code-block:: c++
7474
75 static std::unique_ptr *TheModule;
76 static IRBuilder<> Builder(LLVMContext);
77 static std::map NamedValues;
75 static LLVMContext TheContext;
76 static IRBuilder<> Builder(TheContext);
77 static std::unique_ptr TheModule;
78 static std::map NamedValues;
7879
7980 Value *LogErrorV(const char *Str) {
8081 LogError(Str);
8182 return nullptr;
8283 }
8384
84 The static variables will be used during code generation. ``TheModule``
85 is an LLVM construct that contains functions and global variables. In many
86 ways, it is the top-level structure that the LLVM IR uses to contain code.
87 It will own the memory for all of the IR that we generate, which is why
88 the codegen() method returns a raw Value\*, rather than a unique_ptr.
85 The static variables will be used during code generation. ``TheContext``
86 is an opaque object that owns a lot of core LLVM data structures, such as
87 the type and constant value tables. We don't need to understand it in
88 detail, we just need a single instance to pass into APIs that require it.
8989
9090 The ``Builder`` object is a helper object that makes it easy to generate
9191 LLVM instructions. Instances of the
9292 `IRBuilder `_
9393 class template keep track of the current place to insert instructions
9494 and has methods to create new instructions.
95
96 ``TheModule`` is an LLVM construct that contains functions and global
97 variables. In many ways, it is the top-level structure that the LLVM IR
98 uses to contain code. It will own the memory for all of the IR that we
99 generate, which is why the codegen() method returns a raw Value\*,
100 rather than a unique_ptr.
95101
96102 The ``NamedValues`` map keeps track of which values are defined in the
97103 current scope and what their LLVM representation is. (In other words, it