diff options
author | Lang Hames <lhames@gmail.com> | 2016-06-07 05:40:08 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-06-07 05:40:08 +0000 |
commit | 9dc125b0047bb7dd19776b5217b9cd788bb31913 (patch) | |
tree | f2110a86529246fc50181a27fe88bec86090818f /llvm/docs/tutorial | |
parent | fd6d0821ebfe990a3b4ebdfb9c2c9561a6b594eb (diff) | |
download | bcm5719-llvm-9dc125b0047bb7dd19776b5217b9cd788bb31913.tar.gz bcm5719-llvm-9dc125b0047bb7dd19776b5217b9cd788bb31913.zip |
[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
Diffstat (limited to 'llvm/docs/tutorial')
-rw-r--r-- | llvm/docs/tutorial/LangImpl3.rst | 22 |
1 files changed, 14 insertions, 8 deletions
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<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 |