mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[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
This commit is contained in:
parent
e2db98503c
commit
90a9836da7
@ -73,20 +73,20 @@ parser, which will be used to report errors found during code generation
|
|||||||
|
|
||||||
.. code-block:: c++
|
.. code-block:: c++
|
||||||
|
|
||||||
static std::unique_ptr<Module> *TheModule;
|
static LLVMContext TheContext;
|
||||||
static IRBuilder<> Builder(LLVMContext);
|
static IRBuilder<> Builder(TheContext);
|
||||||
static std::map<std::string, Value*> NamedValues;
|
static std::unique_ptr<Module> TheModule;
|
||||||
|
static std::map<std::string, Value *> NamedValues;
|
||||||
|
|
||||||
Value *LogErrorV(const char *Str) {
|
Value *LogErrorV(const char *Str) {
|
||||||
LogError(Str);
|
LogError(Str);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
The static variables will be used during code generation. ``TheModule``
|
The static variables will be used during code generation. ``TheContext``
|
||||||
is an LLVM construct that contains functions and global variables. In many
|
is an opaque object that owns a lot of core LLVM data structures, such as
|
||||||
ways, it is the top-level structure that the LLVM IR uses to contain code.
|
the type and constant value tables. We don't need to understand it in
|
||||||
It will own the memory for all of the IR that we generate, which is why
|
detail, we just need a single instance to pass into APIs that require it.
|
||||||
the codegen() method returns a raw Value\*, rather than a unique_ptr<Value>.
|
|
||||||
|
|
||||||
The ``Builder`` object is a helper object that makes it easy to generate
|
The ``Builder`` object is a helper object that makes it easy to generate
|
||||||
LLVM instructions. Instances of the
|
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
|
class template keep track of the current place to insert instructions
|
||||||
and has methods to create new 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
|
The ``NamedValues`` map keeps track of which values are defined in the
|
||||||
current scope and what their LLVM representation is. (In other words, it
|
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
|
is a symbol table for the code). In this form of Kaleidoscope, the only
|
||||||
|
Loading…
x
Reference in New Issue
Block a user