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
73 Once we have that, we recognize the new keywords in the lexer. This is
94 To represent the new expression we add a new AST node for it:
114 Now that we have the relevant tokens coming from the lexer and we have
116 First we define a new parsing function:
150 Next we hook it up as a primary expression:
172 Now that we have it parsing and building the AST, the final piece is
178 To motivate the code we want to produce, lets take a look at a simple
260 order to use LLVM!". Fortunately, this is not the case, and we strongly
272 we'll talk about #1 in depth. For now, just believe me that you don't
274 of using the techniques that we will describe for #1, or you can insert
276 easy to generate the Phi node, so we choose to do it directly.
283 In order to generate code for this, we implement the ``codegen`` method
297 This code is straightforward and similar to what we saw before. We emit
327 Once the blocks are created, we can emit the conditional branch that
348 After the conditional branch is inserted, we move the builder to start
354 Once the insertion point is set, we recursively codegen the "then"
355 expression from the AST. To finish off the "then" block, we create an
365 issue is that when we create the Phi node in the merge block, we need to
368 of the block in the CFG. Why then, are we getting the current block when
369 we just set it to ThenBB 5 lines above? The problem is that the "Then"
373 the notion of the current block, we are required to get an up-to-date
394 'then' and 'else' blocks are emitted, we can finish up with the merge
413 created code will go into the "merge" block. Once that is done, we need
421 Overall, we now have the ability to execute conditional code in
424 we'll add another useful expression that is familiar from non-functional
430 Now that we know how to add basic control flow constructs to the
431 language, we have the tools to add more powerful things. Lets add
448 it executes its body expression. Because we don't have anything better
449 to return, we'll just define the loop as always returning 0.0. In the
450 future when we have mutable variables, it will get more useful.
452 As before, lets talk about the changes that we need to Kaleidoscope to
567 Now we get to the good part: the LLVM IR we want to generate for this
568 thing. With the simple example above, we get this LLVM IR (note that
598 This loop contains all the same constructs we saw before: a phi node,
605 The first part of codegen is very simple: we just output the start
633 This code is similar to what we saw for if/then/else. Because we will
634 need it to create the Phi node, we remember the block that falls through
635 into the loop. Once we have that, we create the actual block that starts
649 Now that the "preheader" for the loop is set up, we switch to emitting
650 code for the loop body. To begin with, we move the insertion point and
651 create the PHI node for the loop induction variable. Since we already
652 know the incoming value for the starting value, we add it to the Phi
654 backedge, but we can't set it up yet (because it doesn't exist!).
659 // shadows an existing variable, we have to restore it, so save it now.
664 // current BB. Note that we ignore the value computed by the body, but don't
672 before we codegen the body of the loop, we add the loop variable as the
676 entry for VarName) but we choose to allow shadowing of variables. In
677 order to handle this correctly, we remember the Value that we are
701 Now that the body is emitted, we compute the next value of the iteration
717 Finally, we evaluate the exit value of the loop, to determine whether
734 With the code for the body of the loop complete, we just need to finish
757 The final code handles various cleanups: now that we have the "NextVar"
758 value, we can add the incoming value to the loop PHI node. After that,
759 we remove the loop variable from the symbol table, so that it isn't in
761 always returns 0.0, so that is what we return from
764 With this, we conclude the "adding control flow to Kaleidoscope" chapter
765 of the tutorial. In this chapter we added two control flow constructs,
768 saga, we will get a bit crazier and add `user-defined