blob: d80140ef241b1b724bff64f34334a5d7e99e749b [file] [log] [blame]
Sean Silvad7fb3962012-12-05 00:26:32 +00001========================================
2Kaleidoscope: Code generation to LLVM IR
3========================================
4
5.. contents::
6 :local:
7
Sean Silvad7fb3962012-12-05 00:26:32 +00008Chapter 3 Introduction
9======================
10
11Welcome to Chapter 3 of the "`Implementing a language with
12LLVM <index.html>`_" tutorial. This chapter shows you how to transform
13the `Abstract Syntax Tree <LangImpl2.html>`_, built in Chapter 2, into
14LLVM IR. This will teach you a little bit about how LLVM does things, as
15well as demonstrate how easy it is to use. It's much more work to build
16a lexer and parser than it is to generate LLVM IR code. :)
17
18**Please note**: the code in this chapter and later require LLVM 2.2 or
19later. LLVM 2.1 and before will not work with it. Also note that you
20need to use a version of this tutorial that matches your LLVM release:
21If you are using an official LLVM release, use the version of the
22documentation included with your release or on the `llvm.org releases
23page <http://llvm.org/releases/>`_.
24
25Code Generation Setup
26=====================
27
28In order to generate LLVM IR, we want some simple setup to get started.
29First we define virtual code generation (codegen) methods in each AST
30class:
31
32.. code-block:: c++
33
34 /// ExprAST - Base class for all expression nodes.
35 class ExprAST {
36 public:
37 virtual ~ExprAST() {}
38 virtual Value *Codegen() = 0;
39 };
40
41 /// NumberExprAST - Expression class for numeric literals like "1.0".
42 class NumberExprAST : public ExprAST {
43 double Val;
Lang Hames59b0da82015-08-19 18:15:58 +000044
Sean Silvad7fb3962012-12-05 00:26:32 +000045 public:
Lang Hames09bf4c12015-08-18 18:11:06 +000046 NumberExprAST(double Val) : Val(Val) {}
Sean Silvad7fb3962012-12-05 00:26:32 +000047 virtual Value *Codegen();
48 };
49 ...
50
51The Codegen() method says to emit IR for that AST node along with all
52the things it depends on, and they all return an LLVM Value object.
53"Value" is the class used to represent a "`Static Single Assignment
54(SSA) <http://en.wikipedia.org/wiki/Static_single_assignment_form>`_
55register" or "SSA value" in LLVM. The most distinct aspect of SSA values
56is that their value is computed as the related instruction executes, and
57it does not get a new value until (and if) the instruction re-executes.
58In other words, there is no way to "change" an SSA value. For more
59information, please read up on `Static Single
60Assignment <http://en.wikipedia.org/wiki/Static_single_assignment_form>`_
61- the concepts are really quite natural once you grok them.
62
63Note that instead of adding virtual methods to the ExprAST class
64hierarchy, it could also make sense to use a `visitor
65pattern <http://en.wikipedia.org/wiki/Visitor_pattern>`_ or some other
66way to model this. Again, this tutorial won't dwell on good software
67engineering practices: for our purposes, adding a virtual method is
68simplest.
69
70The second thing we want is an "Error" method like we used for the
71parser, which will be used to report errors found during code generation
72(for example, use of an undeclared parameter):
73
74.. code-block:: c++
75
Lang Hames59b0da82015-08-19 18:15:58 +000076 Value *ErrorV(const char *Str) {
77 Error(Str);
78 return nullptr;
79 }
Sean Silvad7fb3962012-12-05 00:26:32 +000080
81 static Module *TheModule;
82 static IRBuilder<> Builder(getGlobalContext());
83 static std::map<std::string, Value*> NamedValues;
84
85The static variables will be used during code generation. ``TheModule``
86is the LLVM construct that contains all of the functions and global
87variables in a chunk of code. In many ways, it is the top-level
88structure that the LLVM IR uses to contain code.
89
90The ``Builder`` object is a helper object that makes it easy to generate
91LLVM instructions. Instances of the
Sean Silva78da1a52015-03-17 21:02:37 +000092`IRBuilder <http://llvm.org/doxygen/IRBuilder_8h-source.html>`_
Sean Silvad7fb3962012-12-05 00:26:32 +000093class template keep track of the current place to insert instructions
94and has methods to create new instructions.
95
96The ``NamedValues`` map keeps track of which values are defined in the
97current scope and what their LLVM representation is. (In other words, it
98is a symbol table for the code). In this form of Kaleidoscope, the only
99things that can be referenced are function parameters. As such, function
100parameters will be in this map when generating code for their function
101body.
102
103With these basics in place, we can start talking about how to generate
104code for each expression. Note that this assumes that the ``Builder``
105has been set up to generate code *into* something. For now, we'll assume
106that this has already been done, and we'll just use it to emit code.
107
108Expression Code Generation
109==========================
110
111Generating LLVM code for expression nodes is very straightforward: less
112than 45 lines of commented code for all four of our expression nodes.
113First we'll do numeric literals:
114
115.. code-block:: c++
116
117 Value *NumberExprAST::Codegen() {
118 return ConstantFP::get(getGlobalContext(), APFloat(Val));
119 }
120
121In the LLVM IR, numeric constants are represented with the
122``ConstantFP`` class, which holds the numeric value in an ``APFloat``
123internally (``APFloat`` has the capability of holding floating point
124constants of Arbitrary Precision). This code basically just creates
125and returns a ``ConstantFP``. Note that in the LLVM IR that constants
126are all uniqued together and shared. For this reason, the API uses the
127"foo::get(...)" idiom instead of "new foo(..)" or "foo::Create(..)".
128
129.. code-block:: c++
130
131 Value *VariableExprAST::Codegen() {
132 // Look this variable up in the function.
133 Value *V = NamedValues[Name];
Lang Hames596aec92015-08-19 18:32:58 +0000134 if (!V)
135 ErrorV("Unknown variable name");
136 return V;
Sean Silvad7fb3962012-12-05 00:26:32 +0000137 }
138
139References to variables are also quite simple using LLVM. In the simple
140version of Kaleidoscope, we assume that the variable has already been
141emitted somewhere and its value is available. In practice, the only
142values that can be in the ``NamedValues`` map are function arguments.
143This code simply checks to see that the specified name is in the map (if
144not, an unknown variable is being referenced) and returns the value for
145it. In future chapters, we'll add support for `loop induction
146variables <LangImpl5.html#for>`_ in the symbol table, and for `local
147variables <LangImpl7.html#localvars>`_.
148
149.. code-block:: c++
150
151 Value *BinaryExprAST::Codegen() {
152 Value *L = LHS->Codegen();
153 Value *R = RHS->Codegen();
Lang Hames59b0da82015-08-19 18:15:58 +0000154 if (!L || !R)
155 return nullptr;
Sean Silvad7fb3962012-12-05 00:26:32 +0000156
157 switch (Op) {
Lang Hames59b0da82015-08-19 18:15:58 +0000158 case '+':
159 return Builder.CreateFAdd(L, R, "addtmp");
160 case '-':
161 return Builder.CreateFSub(L, R, "subtmp");
162 case '*':
163 return Builder.CreateFMul(L, R, "multmp");
Sean Silvad7fb3962012-12-05 00:26:32 +0000164 case '<':
165 L = Builder.CreateFCmpULT(L, R, "cmptmp");
166 // Convert bool 0/1 to double 0.0 or 1.0
167 return Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
168 "booltmp");
Lang Hames59b0da82015-08-19 18:15:58 +0000169 default:
170 return ErrorV("invalid binary operator");
Sean Silvad7fb3962012-12-05 00:26:32 +0000171 }
172 }
173
174Binary operators start to get more interesting. The basic idea here is
175that we recursively emit code for the left-hand side of the expression,
176then the right-hand side, then we compute the result of the binary
177expression. In this code, we do a simple switch on the opcode to create
178the right LLVM instruction.
179
180In the example above, the LLVM builder class is starting to show its
181value. IRBuilder knows where to insert the newly created instruction,
182all you have to do is specify what instruction to create (e.g. with
183``CreateFAdd``), which operands to use (``L`` and ``R`` here) and
184optionally provide a name for the generated instruction.
185
186One nice thing about LLVM is that the name is just a hint. For instance,
187if the code above emits multiple "addtmp" variables, LLVM will
188automatically provide each one with an increasing, unique numeric
189suffix. Local value names for instructions are purely optional, but it
190makes it much easier to read the IR dumps.
191
192`LLVM instructions <../LangRef.html#instref>`_ are constrained by strict
193rules: for example, the Left and Right operators of an `add
194instruction <../LangRef.html#i_add>`_ must have the same type, and the
195result type of the add must match the operand types. Because all values
196in Kaleidoscope are doubles, this makes for very simple code for add,
197sub and mul.
198
199On the other hand, LLVM specifies that the `fcmp
200instruction <../LangRef.html#i_fcmp>`_ always returns an 'i1' value (a
201one bit integer). The problem with this is that Kaleidoscope wants the
202value to be a 0.0 or 1.0 value. In order to get these semantics, we
203combine the fcmp instruction with a `uitofp
204instruction <../LangRef.html#i_uitofp>`_. This instruction converts its
205input integer into a floating point value by treating the input as an
206unsigned value. In contrast, if we used the `sitofp
207instruction <../LangRef.html#i_sitofp>`_, the Kaleidoscope '<' operator
208would return 0.0 and -1.0, depending on the input value.
209
210.. code-block:: c++
211
212 Value *CallExprAST::Codegen() {
213 // Look up the name in the global module table.
214 Function *CalleeF = TheModule->getFunction(Callee);
Lang Hames59b0da82015-08-19 18:15:58 +0000215 if (!CalleeF)
Sean Silvad7fb3962012-12-05 00:26:32 +0000216 return ErrorV("Unknown function referenced");
217
218 // If argument mismatch error.
219 if (CalleeF->arg_size() != Args.size())
220 return ErrorV("Incorrect # arguments passed");
221
Lang Hames59b0da82015-08-19 18:15:58 +0000222 std::vector<Value *> ArgsV;
Sean Silvad7fb3962012-12-05 00:26:32 +0000223 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
224 ArgsV.push_back(Args[i]->Codegen());
Lang Hames59b0da82015-08-19 18:15:58 +0000225 if (!ArgsV.back())
226 return nullptr;
Sean Silvad7fb3962012-12-05 00:26:32 +0000227 }
228
229 return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
230 }
231
232Code generation for function calls is quite straightforward with LLVM.
233The code above initially does a function name lookup in the LLVM
234Module's symbol table. Recall that the LLVM Module is the container that
235holds all of the functions we are JIT'ing. By giving each function the
236same name as what the user specifies, we can use the LLVM symbol table
237to resolve function names for us.
238
239Once we have the function to call, we recursively codegen each argument
240that is to be passed in, and create an LLVM `call
241instruction <../LangRef.html#i_call>`_. Note that LLVM uses the native C
242calling conventions by default, allowing these calls to also call into
243standard library functions like "sin" and "cos", with no additional
244effort.
245
246This wraps up our handling of the four basic expressions that we have so
247far in Kaleidoscope. Feel free to go in and add some more. For example,
248by browsing the `LLVM language reference <../LangRef.html>`_ you'll find
249several other interesting instructions that are really easy to plug into
250our basic framework.
251
252Function Code Generation
253========================
254
255Code generation for prototypes and functions must handle a number of
256details, which make their code less beautiful than expression code
257generation, but allows us to illustrate some important points. First,
258lets talk about code generation for prototypes: they are used both for
259function bodies and external function declarations. The code starts
260with:
261
262.. code-block:: c++
263
264 Function *PrototypeAST::Codegen() {
265 // Make the function type: double(double,double) etc.
266 std::vector<Type*> Doubles(Args.size(),
267 Type::getDoubleTy(getGlobalContext()));
Lang Hames59b0da82015-08-19 18:15:58 +0000268 FunctionType *FT =
269 FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
Sean Silvad7fb3962012-12-05 00:26:32 +0000270
Lang Hames59b0da82015-08-19 18:15:58 +0000271 Function *F =
272 Function::Create(FT, Function::ExternalLinkage, Name, TheModule);
Sean Silvad7fb3962012-12-05 00:26:32 +0000273
274This code packs a lot of power into a few lines. Note first that this
275function returns a "Function\*" instead of a "Value\*". Because a
276"prototype" really talks about the external interface for a function
277(not the value computed by an expression), it makes sense for it to
278return the LLVM Function it corresponds to when codegen'd.
279
280The call to ``FunctionType::get`` creates the ``FunctionType`` that
281should be used for a given Prototype. Since all function arguments in
282Kaleidoscope are of type double, the first line creates a vector of "N"
283LLVM double types. It then uses the ``Functiontype::get`` method to
284create a function type that takes "N" doubles as arguments, returns one
285double as a result, and that is not vararg (the false parameter
286indicates this). Note that Types in LLVM are uniqued just like Constants
287are, so you don't "new" a type, you "get" it.
288
289The final line above actually creates the function that the prototype
290will correspond to. This indicates the type, linkage and name to use, as
291well as which module to insert into. "`external
292linkage <../LangRef.html#linkage>`_" means that the function may be
293defined outside the current module and/or that it is callable by
294functions outside the module. The Name passed in is the name the user
295specified: since "``TheModule``" is specified, this name is registered
296in "``TheModule``"s symbol table, which is used by the function call
297code above.
298
299.. code-block:: c++
300
301 // If F conflicted, there was already something named 'Name'. If it has a
302 // body, don't allow redefinition or reextern.
303 if (F->getName() != Name) {
304 // Delete the one we just made and get the existing one.
305 F->eraseFromParent();
306 F = TheModule->getFunction(Name);
307
308The Module symbol table works just like the Function symbol table when
309it comes to name conflicts: if a new function is created with a name
310that was previously added to the symbol table, the new function will get
311implicitly renamed when added to the Module. The code above exploits
312this fact to determine if there was a previous definition of this
313function.
314
315In Kaleidoscope, I choose to allow redefinitions of functions in two
316cases: first, we want to allow 'extern'ing a function more than once, as
317long as the prototypes for the externs match (since all arguments have
318the same type, we just have to check that the number of arguments
319match). Second, we want to allow 'extern'ing a function and then
320defining a body for it. This is useful when defining mutually recursive
321functions.
322
323In order to implement this, the code above first checks to see if there
324is a collision on the name of the function. If so, it deletes the
325function we just created (by calling ``eraseFromParent``) and then
326calling ``getFunction`` to get the existing function with the specified
327name. Note that many APIs in LLVM have "erase" forms and "remove" forms.
328The "remove" form unlinks the object from its parent (e.g. a Function
329from a Module) and returns it. The "erase" form unlinks the object and
330then deletes it.
331
332.. code-block:: c++
333
334 // If F already has a body, reject this.
335 if (!F->empty()) {
336 ErrorF("redefinition of function");
Lang Hames59b0da82015-08-19 18:15:58 +0000337 return nullptr;
Sean Silvad7fb3962012-12-05 00:26:32 +0000338 }
339
340 // If F took a different number of args, reject.
341 if (F->arg_size() != Args.size()) {
342 ErrorF("redefinition of function with different # args");
Lang Hames59b0da82015-08-19 18:15:58 +0000343 return nullptr;
Sean Silvad7fb3962012-12-05 00:26:32 +0000344 }
345 }
346
347In order to verify the logic above, we first check to see if the
348pre-existing function is "empty". In this case, empty means that it has
349no basic blocks in it, which means it has no body. If it has no body, it
350is a forward declaration. Since we don't allow anything after a full
351definition of the function, the code rejects this case. If the previous
352reference to a function was an 'extern', we simply verify that the
353number of arguments for that definition and this one match up. If not,
354we emit an error.
355
356.. code-block:: c++
357
358 // Set names for all arguments.
359 unsigned Idx = 0;
360 for (Function::arg_iterator AI = F->arg_begin(); Idx != Args.size();
361 ++AI, ++Idx) {
362 AI->setName(Args[Idx]);
363
364 // Add arguments to variable symbol table.
365 NamedValues[Args[Idx]] = AI;
366 }
Lang Hames59b0da82015-08-19 18:15:58 +0000367
Sean Silvad7fb3962012-12-05 00:26:32 +0000368 return F;
369 }
370
371The last bit of code for prototypes loops over all of the arguments in
372the function, setting the name of the LLVM Argument objects to match,
373and registering the arguments in the ``NamedValues`` map for future use
374by the ``VariableExprAST`` AST node. Once this is set up, it returns the
375Function object to the caller. Note that we don't check for conflicting
376argument names here (e.g. "extern foo(a b a)"). Doing so would be very
377straight-forward with the mechanics we have already used above.
378
379.. code-block:: c++
380
381 Function *FunctionAST::Codegen() {
382 NamedValues.clear();
383
384 Function *TheFunction = Proto->Codegen();
Lang Hames59b0da82015-08-19 18:15:58 +0000385 if (!TheFunction)
386 return nullptr;
Sean Silvad7fb3962012-12-05 00:26:32 +0000387
388Code generation for function definitions starts out simply enough: we
389just codegen the prototype (Proto) and verify that it is ok. We then
390clear out the ``NamedValues`` map to make sure that there isn't anything
391in it from the last function we compiled. Code generation of the
392prototype ensures that there is an LLVM Function object that is ready to
393go for us.
394
395.. code-block:: c++
396
397 // Create a new basic block to start insertion into.
398 BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
399 Builder.SetInsertPoint(BB);
400
401 if (Value *RetVal = Body->Codegen()) {
402
403Now we get to the point where the ``Builder`` is set up. The first line
404creates a new `basic block <http://en.wikipedia.org/wiki/Basic_block>`_
405(named "entry"), which is inserted into ``TheFunction``. The second line
406then tells the builder that new instructions should be inserted into the
407end of the new basic block. Basic blocks in LLVM are an important part
408of functions that define the `Control Flow
409Graph <http://en.wikipedia.org/wiki/Control_flow_graph>`_. Since we
410don't have any control flow, our functions will only contain one block
411at this point. We'll fix this in `Chapter 5 <LangImpl5.html>`_ :).
412
413.. code-block:: c++
414
415 if (Value *RetVal = Body->Codegen()) {
416 // Finish off the function.
417 Builder.CreateRet(RetVal);
418
419 // Validate the generated code, checking for consistency.
420 verifyFunction(*TheFunction);
421
422 return TheFunction;
423 }
424
425Once the insertion point is set up, we call the ``CodeGen()`` method for
426the root expression of the function. If no error happens, this emits
427code to compute the expression into the entry block and returns the
428value that was computed. Assuming no error, we then create an LLVM `ret
429instruction <../LangRef.html#i_ret>`_, which completes the function.
430Once the function is built, we call ``verifyFunction``, which is
431provided by LLVM. This function does a variety of consistency checks on
432the generated code, to determine if our compiler is doing everything
433right. Using this is important: it can catch a lot of bugs. Once the
434function is finished and validated, we return it.
435
436.. code-block:: c++
437
438 // Error reading body, remove function.
439 TheFunction->eraseFromParent();
Lang Hames59b0da82015-08-19 18:15:58 +0000440 return nullptr;
Sean Silvad7fb3962012-12-05 00:26:32 +0000441 }
442
443The only piece left here is handling of the error case. For simplicity,
444we handle this by merely deleting the function we produced with the
445``eraseFromParent`` method. This allows the user to redefine a function
446that they incorrectly typed in before: if we didn't delete it, it would
447live in the symbol table, with a body, preventing future redefinition.
448
449This code does have a bug, though. Since the ``PrototypeAST::Codegen``
450can return a previously defined forward declaration, our code can
451actually delete a forward declaration. There are a number of ways to fix
452this bug, see what you can come up with! Here is a testcase:
453
454::
455
456 extern foo(a b); # ok, defines foo.
457 def foo(a b) c; # error, 'c' is invalid.
458 def bar() foo(1, 2); # error, unknown function "foo"
459
460Driver Changes and Closing Thoughts
461===================================
462
463For now, code generation to LLVM doesn't really get us much, except that
464we can look at the pretty IR calls. The sample code inserts calls to
465Codegen into the "``HandleDefinition``", "``HandleExtern``" etc
466functions, and then dumps out the LLVM IR. This gives a nice way to look
467at the LLVM IR for simple functions. For example:
468
469::
470
471 ready> 4+5;
472 Read top-level expression:
473 define double @0() {
474 entry:
475 ret double 9.000000e+00
476 }
477
478Note how the parser turns the top-level expression into anonymous
479functions for us. This will be handy when we add `JIT
480support <LangImpl4.html#jit>`_ in the next chapter. Also note that the
481code is very literally transcribed, no optimizations are being performed
482except simple constant folding done by IRBuilder. We will `add
483optimizations <LangImpl4.html#trivialconstfold>`_ explicitly in the next
484chapter.
485
486::
487
488 ready> def foo(a b) a*a + 2*a*b + b*b;
489 Read function definition:
490 define double @foo(double %a, double %b) {
491 entry:
492 %multmp = fmul double %a, %a
493 %multmp1 = fmul double 2.000000e+00, %a
494 %multmp2 = fmul double %multmp1, %b
495 %addtmp = fadd double %multmp, %multmp2
496 %multmp3 = fmul double %b, %b
497 %addtmp4 = fadd double %addtmp, %multmp3
498 ret double %addtmp4
499 }
500
501This shows some simple arithmetic. Notice the striking similarity to the
502LLVM builder calls that we use to create the instructions.
503
504::
505
506 ready> def bar(a) foo(a, 4.0) + bar(31337);
507 Read function definition:
508 define double @bar(double %a) {
509 entry:
510 %calltmp = call double @foo(double %a, double 4.000000e+00)
511 %calltmp1 = call double @bar(double 3.133700e+04)
512 %addtmp = fadd double %calltmp, %calltmp1
513 ret double %addtmp
514 }
515
516This shows some function calls. Note that this function will take a long
517time to execute if you call it. In the future we'll add conditional
518control flow to actually make recursion useful :).
519
520::
521
522 ready> extern cos(x);
523 Read extern:
524 declare double @cos(double)
525
526 ready> cos(1.234);
527 Read top-level expression:
528 define double @1() {
529 entry:
530 %calltmp = call double @cos(double 1.234000e+00)
531 ret double %calltmp
532 }
533
534This shows an extern for the libm "cos" function, and a call to it.
535
536.. TODO:: Abandon Pygments' horrible `llvm` lexer. It just totally gives up
537 on highlighting this due to the first line.
538
539::
540
541 ready> ^D
542 ; ModuleID = 'my cool jit'
543
544 define double @0() {
545 entry:
546 %addtmp = fadd double 4.000000e+00, 5.000000e+00
547 ret double %addtmp
548 }
549
550 define double @foo(double %a, double %b) {
551 entry:
552 %multmp = fmul double %a, %a
553 %multmp1 = fmul double 2.000000e+00, %a
554 %multmp2 = fmul double %multmp1, %b
555 %addtmp = fadd double %multmp, %multmp2
556 %multmp3 = fmul double %b, %b
557 %addtmp4 = fadd double %addtmp, %multmp3
558 ret double %addtmp4
559 }
560
561 define double @bar(double %a) {
562 entry:
563 %calltmp = call double @foo(double %a, double 4.000000e+00)
564 %calltmp1 = call double @bar(double 3.133700e+04)
565 %addtmp = fadd double %calltmp, %calltmp1
566 ret double %addtmp
567 }
568
569 declare double @cos(double)
570
571 define double @1() {
572 entry:
573 %calltmp = call double @cos(double 1.234000e+00)
574 ret double %calltmp
575 }
576
577When you quit the current demo, it dumps out the IR for the entire
578module generated. Here you can see the big picture with all the
579functions referencing each other.
580
581This wraps up the third chapter of the Kaleidoscope tutorial. Up next,
582we'll describe how to `add JIT codegen and optimizer
583support <LangImpl4.html>`_ to this so we can actually start running
584code!
585
586Full Code Listing
587=================
588
589Here is the complete code listing for our running example, enhanced with
590the LLVM code generator. Because this uses the LLVM libraries, we need
591to link them in. To do this, we use the
592`llvm-config <http://llvm.org/cmds/llvm-config.html>`_ tool to inform
593our makefile/command line about which options to use:
594
595.. code-block:: bash
596
597 # Compile
Lang Hamesaa0f6732014-11-06 00:31:04 +0000598 clang++ -g -O3 toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core` -o toy
Sean Silvad7fb3962012-12-05 00:26:32 +0000599 # Run
600 ./toy
601
602Here is the code:
603
Logan Chien855b17d2013-06-08 09:03:03 +0000604.. literalinclude:: ../../examples/Kaleidoscope/Chapter3/toy.cpp
605 :language: c++
Sean Silvad7fb3962012-12-05 00:26:32 +0000606
607`Next: Adding JIT and Optimizer Support <LangImpl4.html>`_
608