Lines Matching refs:we

18 of "build that compiler", we'll extend Kaleidoscope to have an
30 Before we get going on "how" we add this extension, lets talk about
31 "what" we want. The basic idea is that we want to be able to write this
44 like any other. Since we're using a mostly functional form, we'll have
57 Now that we know what we "want", lets break this down into its
63 The lexer extensions are straightforward. First we add new enum values
71 Once we have that, we recognize the new keywords in the lexer. This is
87 To represent the new expression we add a new AST node for it:
105 Now that we have the relevant tokens coming from the lexer and we have
107 First we define a new parsing function:
137 Next we hook it up as a primary expression:
154 Now that we have it parsing and building the AST, the final piece is
160 To motivate the code we want to produce, lets take a look at a simple
242 order to use LLVM!". Fortunately, this is not the case, and we strongly
254 we'll talk about #1 in depth. For now, just believe me that you don't
256 of using the techniques that we will describe for #1, or you can insert
258 easy to generate the Phi node, so we choose to do it directly.
265 In order to generate code for this, we implement the ``Codegen`` method
279 This code is straightforward and similar to what we saw before. We emit
308 Once the blocks are created, we can emit the conditional branch that
328 After the conditional branch is inserted, we move the builder to start
334 Once the insertion point is set, we recursively codegen the "then"
335 expression from the AST. To finish off the "then" block, we create an
345 issue is that when we create the Phi node in the merge block, we need to
348 of the block in the CFG. Why then, are we getting the current block when
349 we just set it to ThenBB 5 lines above? The problem is that the "Then"
353 the notion of the current block, we are required to get an up-to-date
373 'then' and 'else' blocks are emitted, we can finish up with the merge
392 created code will go into the "merge" block. Once that is done, we need
400 Overall, we now have the ability to execute conditional code in
403 we'll add another useful expression that is familiar from non-functional
409 Now that we know how to add basic control flow constructs to the
410 language, we have the tools to add more powerful things. Lets add
427 it executes its body expression. Because we don't have anything better
428 to return, we'll just define the loop as always returning 0.0. In the
429 future when we have mutable variables, it will get more useful.
431 As before, lets talk about the changes that we need to Kaleidoscope to
530 Now we get to the good part: the LLVM IR we want to generate for this
531 thing. With the simple example above, we get this LLVM IR (note that
561 This loop contains all the same constructs we saw before: a phi node,
568 The first part of Codegen is very simple: we just output the start
595 This code is similar to what we saw for if/then/else. Because we will
596 need it to create the Phi node, we remember the block that falls through
597 into the loop. Once we have that, we create the actual block that starts
610 Now that the "preheader" for the loop is set up, we switch to emitting
611 code for the loop body. To begin with, we move the insertion point and
612 create the PHI node for the loop induction variable. Since we already
613 know the incoming value for the starting value, we add it to the Phi
615 backedge, but we can't set it up yet (because it doesn't exist!).
620 // shadows an existing variable, we have to restore it, so save it now.
625 // current BB. Note that we ignore the value computed by the body, but don't
633 before we codegen the body of the loop, we add the loop variable as the
637 entry for VarName) but we choose to allow shadowing of variables. In
638 order to handle this correctly, we remember the Value that we are
661 Now that the body is emitted, we compute the next value of the iteration
677 Finally, we evaluate the exit value of the loop, to determine whether
693 With the code for the body of the loop complete, we just need to finish
716 The final code handles various cleanups: now that we have the "NextVar"
717 value, we can add the incoming value to the loop PHI node. After that,
718 we remove the loop variable from the symbol table, so that it isn't in
720 always returns 0.0, so that is what we return from
723 With this, we conclude the "adding control flow to Kaleidoscope" chapter
724 of the tutorial. In this chapter we added two control flow constructs,
727 saga, we will get a bit crazier and add `user-defined