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 variants for
71 Once we have that, we recognize the new keywords in the lexer. This is
90 To represent the new expression we add a new AST variant for it:
104 Now that we have the relevant tokens coming from the lexer and we have
106 First we define a new parsing function:
118 Next we hook it up as a primary expression:
133 Now that we have it parsing and building the AST, the final piece is
139 To motivate the code we want to produce, lets take a look at a simple
222 order to use LLVM!". Fortunately, this is not the case, and we strongly
234 variables"), we'll talk about #1 in depth. For now, just believe me that
236 the choice of using the techniques that we will describe for #1, or you
238 really easy to generate the Phi node, so we choose to do it directly.
245 In order to generate code for this, we implement the ``Codegen`` method
259 This code is straightforward and similar to what we saw before. We emit
265 (* Grab the first block so that we might later add the conditional branch
273 As opposed to the `C++ tutorial <LangImpl5.html>`_, we have to build our
274 basic blocks bottom up since we can't have dangling BasicBlocks. We
276 entry block), which we'll need to build a conditional branch later. We
301 Once the insertion point is set, we recursively codegen the "then"
305 issue is that when we create the Phi node in the merge block, we need to
308 of the block in the CFG. Why then, are we getting the current block when
309 we just set it to ThenBB 5 lines above? The problem is that the "Then"
313 the notion of the current block, we are required to get an up-to-date
341 that is done, we need to create the PHI node and set up the block/value
350 Once the blocks are created, we can emit the conditional branch that
353 condition went into. This is why we needed to save the "start" block.
367 To finish off the blocks, we create an unconditional branch to the merge
381 Overall, we now have the ability to execute conditional code in
384 we'll add another useful expression that is familiar from non-functional
390 Now that we know how to add basic control flow constructs to the
391 language, we have the tools to add more powerful things. Lets add
408 it executes its body expression. Because we don't have anything better
409 to return, we'll just define the loop as always returning 0.0. In the
410 future when we have mutable variables, it will get more useful.
412 As before, lets talk about the changes that we need to Kaleidoscope to
494 Now we get to the good part: the LLVM IR we want to generate for this
495 thing. With the simple example above, we get this LLVM IR (note that
525 This loop contains all the same constructs we saw before: a phi node,
532 The first part of Codegen is very simple: we just output the start
561 This code is similar to what we saw for if/then/else. Because we will
562 need it to create the Phi node, we remember the block that falls through
563 into the loop. Once we have that, we create the actual block that starts
575 Now that the "preheader" for the loop is set up, we switch to emitting
576 code for the loop body. To begin with, we move the insertion point and
577 create the PHI node for the loop induction variable. Since we already
578 know the incoming value for the starting value, we add it to the Phi
580 backedge, but we can't set it up yet (because it doesn't exist!).
585 * shadows an existing variable, we have to restore it, so save it
593 * current BB. Note that we ignore the value computed by the body, but
600 before we codegen the body of the loop, we add the loop variable as the
604 entry for VarName) but we choose to allow shadowing of variables. In
605 order to handle this correctly, we remember the Value that we are
626 Now that the body is emitted, we compute the next value of the iteration
640 Finally, we evaluate the exit value of the loop, to determine whether
656 With the code for the body of the loop complete, we just need to finish
678 The final code handles various cleanups: now that we have the
679 "``next_var``" value, we can add the incoming value to the loop PHI
680 node. After that, we remove the loop variable from the symbol table, so
682 the for loop always returns 0.0, so that is what we return from
685 With this, we conclude the "adding control flow to Kaleidoscope" chapter
686 of the tutorial. In this chapter we added two control flow constructs,
689 saga, we will get a bit crazier and add `user-defined
944 * consume it, otherwise we are done. *)
952 (* Okay, we know this is a binop. *)
1067 (* Grab the first block so that we might later add the conditional branch
1132 * shadows an existing variable, we have to restore it, so save it
1140 * current BB. Note that we ignore the value computed by the body, but