From 9dc125b0047bb7dd19776b5217b9cd788bb31913 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 7 Jun 2016 05:40:08 +0000 Subject: [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! llvm-svn: 271985 --- llvm/docs/tutorial/LangImpl3.rst | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'llvm/docs/tutorial') diff --git a/llvm/docs/tutorial/LangImpl3.rst b/llvm/docs/tutorial/LangImpl3.rst index a74f874fa4a..e3a3ae99334 100644 --- a/llvm/docs/tutorial/LangImpl3.rst +++ b/llvm/docs/tutorial/LangImpl3.rst @@ -73,20 +73,20 @@ parser, which will be used to report errors found during code generation .. code-block:: c++ - static std::unique_ptr *TheModule; - static IRBuilder<> Builder(LLVMContext); - static std::map NamedValues; + static LLVMContext TheContext; + static IRBuilder<> Builder(TheContext); + static std::unique_ptr TheModule; + static std::map 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. +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. + 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 -- cgit v1.2.3