@@ -244,13 +244,18 @@ type Call =
244244 Arg: Value []
245245 Span: Span }
246246
247+ type Load =
248+ { Target: int
249+ Base: Value
250+ Offset: Value }
251+
247252/// Instrument
248253type Instr =
249254 | Assign of Assign
250255 | Binary of Binary
251256 | Unary of Unary
252257 | Call of Call
253- | Load
258+ | Load of Load
254259 | Store
255260 | Alloc
256261
@@ -260,7 +265,7 @@ type Instr =
260265 | Assign a -> a.Target
261266 | Unary n -> n.Target
262267 | Call c -> c.Target
263- | Load -> failwith " Not Implemented "
268+ | Load l -> l.Target
264269 | Store -> failwith " Not Implemented"
265270 | Alloc -> failwith " Not Implemented"
266271
@@ -273,7 +278,9 @@ type Instr =
273278 | Assign a -> yield a.Value
274279 | Unary u -> yield u.Value
275280 | Call c -> yield ! c.Arg
276- | Load -> failwith " Not Implemented"
281+ | Load l ->
282+ yield l.Base
283+ yield l.Offset
277284 | Store -> failwith " Not Implemented"
278285 | Alloc -> failwith " Not Implemented"
279286 }
@@ -286,18 +293,17 @@ type Branch =
286293 One: int
287294 Span: Span }
288295
289- type Switch =
296+ type Indirect =
290297 { Value: Value
291- Dest: ( int * uint64 )[]
292- Default: int
298+ Dest: int []
293299 Span: Span }
294300
295301type Ret = { Value: Option < Value >; Span: Span }
296302
297303type Transfer =
298304 | Jump of Jump
299305 | Branch of Branch
300- | Switch of Switch
306+ | Indirect of Indirect
301307 | Return of Ret
302308 | Unreachable of Span
303309
@@ -308,11 +314,9 @@ type Transfer =
308314 | Branch b ->
309315 yield b.One
310316 yield b.Zero
311- | Switch s ->
312- for dest, _ in s.Dest do
317+ | Indirect s ->
318+ for dest in s.Dest do
313319 yield dest
314-
315- yield s.Default
316320 | Return _
317321 | Unreachable _ -> ()
318322 }
@@ -341,7 +345,11 @@ type Block =
341345 use_ arg
342346
343347 def c.Target
344- | Load -> failwith " Not Implemented"
348+ | Load l ->
349+ use_ l.Base
350+ use_ l.Offset
351+
352+ def l.Target
345353 | Store -> failwith " Not Implemented"
346354 | Alloc -> failwith " Not Implemented"
347355
@@ -351,7 +359,7 @@ type Block =
351359 match r.Value with
352360 | None -> ()
353361 | Some v -> use_ v
354- | Switch s -> use_ s.Value
362+ | Indirect s -> use_ s.Value
355363 | Jump _
356364 | Unreachable _ -> ()
357365
@@ -379,7 +387,12 @@ type Block =
379387 { c with
380388 Arg = Array.map use_ c.Arg
381389 Target = def c.Target }
382- | Load -> failwith " Not Implemented"
390+ | Load l ->
391+ Load
392+ { l with
393+ Base = use_ l.Base
394+ Offset = use_ l.Offset
395+ Target = def l.Target }
383396 | Store -> failwith " Not Implemented"
384397 | Alloc -> failwith " Not Implemented"
385398
@@ -395,7 +408,7 @@ type Block =
395408 | Some v -> Some( use_ v)
396409
397410 Return { r with Value = value }
398- | Switch s -> Switch { s with Value = use_ s.Value }
411+ | Indirect s -> Indirect { s with Value = use_ s.Value }
399412 | Jump _
400413 | Unreachable _ -> this.Trans
401414
@@ -478,7 +491,7 @@ type Func =
478491 let v = valueToString n.Value
479492 $" ! {v}"
480493 | Call c -> failwith " Not Implemented"
481- | Load -> failwith " Not Implemented"
494+ | Load l -> failwith " Not Implemented"
482495 | Store -> failwith " Not Implemented"
483496 | Alloc -> failwith " Not Implemented"
484497
@@ -500,7 +513,7 @@ type Func =
500513 + match r.Value with
501514 | Some i -> $" {valueToString i}"
502515 | None -> " "
503- | Switch s -> failwith " Not Implemented"
516+ | Indirect s -> failwith " Not Implemented"
504517 | Unreachable _ -> " Unreachable"
505518
506519 tw.WriteLine trans |> ignore
0 commit comments