@@ -123,27 +123,27 @@ These concepts are sufficiently general that they're applicable to JITing as
123123well as native object files (more discussion below!), and ` Module ` provides an
124124interface which abstracts over both.
125125
126- Once we've [ initialized the JIT data structures] ( ./src/jit.rs#L29 ) , we then use
127- our ` JIT ` to [ compile] ( ./src/jit.rs#L42 ) some functions.
126+ Once we've [ initialized the JIT data structures] ( ./src/jit.rs#L28 ) , we then use
127+ our ` JIT ` to [ compile] ( ./src/jit.rs#L52 ) some functions.
128128
129129The ` JIT ` 's ` compile ` function takes a string containing a function in the toy
130- language. It [ parses] ( ./src/jit.rs#L44 ) the string into an AST, and then
131- [ translates] ( ./src/jit.rs#L48 ) the AST into Cranelift IR.
130+ language. It [ parses] ( ./src/jit.rs#L55 ) the string into an AST, and then
131+ [ translates] ( ./src/jit.rs#L58 ) the AST into Cranelift IR.
132132
133133Our toy language only supports one type, so we start by [ declaring that
134- type] ( ./src/jit.rs#L133 ) for convenience.
134+ type] ( ./src/jit.rs#L123 ) for convenience.
135135
136136We then start translating the function by adding [ the function
137- parameters] ( ./src/jit.rs#L115 ) and [ return types] ( ./src/jit.rs#L121 ) to the
137+ parameters] ( ./src/jit.rs#L125 ) and [ return types] ( ./src/jit.rs#L131 ) to the
138138Cranelift function signature.
139139
140- Then we [ create] ( ./src/jit.rs#L124 ) a
140+ Then we [ create] ( ./src/jit.rs#L134 ) a
141141[ FunctionBuilder] ( https://docs.rs/cranelift-frontend/latest/cranelift_frontend/struct.FunctionBuilder.html )
142142which is a utility for building up the contents of a Cranelift IR function. As
143143we'll see below, ` FunctionBuilder ` includes functionality for constructing SSA
144144form automatically so that users don't have to worry about it.
145145
146- Next, we [ start] ( ./src/jit.rs#L127 ) an initial basic block (block), which is the
146+ Next, we [ start] ( ./src/jit.rs#L137 ) an initial basic block (block), which is the
147147entry block of the function, and the place where we'll insert some code.
148148
149149 - A basic block is a sequence of IR instructions which have a single entry
@@ -173,10 +173,10 @@ need to worry about them, though one place they do come up is that incoming
173173arguments to a function are represented as block parameters to the entry
174174block. We must tell Cranelift to add the parameters, using
175175[ ` append_block_params_for_function_params ` ] ( https://docs.rs/cranelift-frontend/latest/cranelift_frontend/struct.FunctionBuilder.html#method.append_block_params_for_function_params )
176- like [ so] ( ./src/jit.rs#L133 ) .
176+ like [ so] ( ./src/jit.rs#L143 ) .
177177
178178The ` FunctionBuilder ` keeps track of a "current" block that new instructions are
179- to be inserted into; we next [ inform] ( ./src/jit.rs#L136 ) it of our new block,
179+ to be inserted into; we next [ inform] ( ./src/jit.rs#L146 ) it of our new block,
180180using
181181[ ` switch_to_block ` ] ( https://docs.rs/cranelift-frontend/latest/cranelift_frontend/struct.FunctionBuilder.html#method.switch_to_block ) ,
182182so that we can start inserting instructions into it.
@@ -185,23 +185,23 @@ The one major concept about blocks is that the `FunctionBuilder` wants to know w
185185all branches which could branch to a block have been seen, at which point it can
186186* seal* the block, which allows it to perform SSA construction. All blocks must be
187187sealed by the end of the function. We
188- [ seal] ( ./src/jit.rs#L141 )
188+ [ seal] ( ./src/jit.rs#L151 )
189189a block with
190190[ ` seal_block ` ] ( https://docs.rs/cranelift-frontend/latest/cranelift_frontend/struct.FunctionBuilder.html#method.seal_block ) .
191191
192192Next, our toy language doesn't have explicit variable declarations, so we walk the
193193AST to discover all the variables, so that we can
194- [ declare] ( ./src/jit.rs#L146 )
195- then to the ` FunctionBuilder ` . These variables need not be in SSA form; the
194+ [ declare] ( ./src/jit.rs#L156 )
195+ them to the ` FunctionBuilder ` . These variables need not be in SSA form; the
196196` FunctionBuilder ` will take care of constructing SSA form internally.
197197
198198For convenience when walking the function body, the demo here
199- [ uses] ( ./src/jit.rs#L176 )
199+ [ uses] ( ./src/jit.rs#L159 )
200200 a ` FunctionTranslator ` object, which holds the ` FunctionBuilder ` , the current
201201` Module ` , as well as the symbol table for looking up variables. Now we can start
202- [ walking the function body] ( ./src/jit.rs#L156 ) .
202+ [ walking the function body] ( ./src/jit.rs#L166 ) .
203203
204- [ AST translation] ( ./src/jit.rs#L186 ) utilizes the instruction-building features
204+ [ AST translation] ( ./src/jit.rs#L196 ) utilizes the instruction-building features
205205of ` FunctionBuilder ` . Let's start with a simple example translating integer
206206literals:
207207
@@ -218,14 +218,14 @@ is the builder line:
218218 - The ` .ins() ` returns an "insertion object", which allows inserting an
219219 instruction at the end of the currently active block.
220220 - ` iconst ` is the name of the builder routine for creating [ integer
221- constants] ( https://docs.rs/cranelift-codegen/0.66.0 /cranelift_codegen/ir/trait.InstBuilder.html#method.iconst )
221+ constants] ( https://docs.rs/cranelift-codegen/latest /cranelift_codegen/ir/trait.InstBuilder.html#method.iconst )
222222 in Cranelift. Every instruction in the IR can be created directly through
223223 such a function call.
224224
225- Translation of [ Add nodes] ( ./src/jit.rs#L193 ) and other arithmetic operations is
225+ Translation of [ Add nodes] ( ./src/jit.rs#L203 ) and other arithmetic operations is
226226similarly straightforward.
227227
228- Translation of [ variable references] ( ./src/jit.rs#L230 ) is mostly handled by
228+ Translation of [ variable references] ( ./src/jit.rs#L235 ) is mostly handled by
229229` FunctionBuilder ` 's ` use_var ` function:
230230
231231``` rust
@@ -253,7 +253,7 @@ variable, which we use to implement assignment:
253253 }
254254```
255255
256- Next, let's dive into [ if-else] ( ./src/jit.rs#L231 ) expressions. In order to
256+ Next, let's dive into [ if-else] ( ./src/jit.rs#L241 ) expressions. In order to
257257demonstrate explicit SSA construction, this demo gives if-else expressions
258258return values. The way this looks in Cranelift is that the true and false arms
259259of the if-else both have branches to a common merge point, and they each pass
@@ -302,7 +302,7 @@ block3(v3: i64):
302302}
303303```
304304
305- The [ while loop] ( ./src/jit.rs#L314 ) translation is also straightforward.
305+ The [ while loop] ( ./src/jit.rs#L323 ) translation is also straightforward.
306306
307307Here's the Cranelift IR for the function named [ iterative_fib] ( ./src/toy.rs#L94 )
308308in the demo program, which contains a while loop:
@@ -352,11 +352,11 @@ block3(v5: i64, v23: i64):
352352}
353353```
354354
355- For [ calls] ( ./src/jit.rs#L345 ) , the basic steps are to determine the call
355+ For [ calls] ( ./src/jit.rs#L355 ) , the basic steps are to determine the call
356356signature, declare the function to be called, put the values to be passed in an
357357array, and then call the ` call ` function.
358358
359- The translation for [ global data symbols] ( ./src/jit.rs#L373 ) , is similar; first
359+ The translation for [ global data symbols] ( ./src/jit.rs#L381 ) , is similar; first
360360declare the symbol to the module, then declare it to the current function, and
361361then use the ` symbol_value ` instruction to produce the value.
362362
@@ -366,8 +366,8 @@ of calls and control flow.
366366
367367And there's a hello world example which demonstrates several other features.
368368
369- This program needs to allocate some [ data] ( ./src/toy.rs#L35 ) to hold the string
370- data. Inside jit.rs, [ ` create_data ` ] ( ./src/jit.rs#L85 ) we initialize a
369+ This program needs to allocate some [ data] ( ./src/toy.rs#L33 ) to hold the string
370+ data. Inside jit.rs, [ ` create_data ` ] ( ./src/jit.rs#L95 ) we initialize a
371371` DataContext ` with the contents of the hello string, and also declare a data
372372object. Then we use the ` DataContext ` object to define the object. At that
373373point, we're done with the ` DataContext ` object and can clear it. We then call
0 commit comments