Implement and test arg_loc

Signed-off-by: Mariano Uvalle <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-02-14 11:48:44 -08:00
parent ea32e468a3
commit bbd068f936
2 changed files with 30 additions and 5 deletions

View file

@ -287,7 +287,18 @@ let compile_lbl_block fn lbl ctxt blk : elem =
[ NOTE: the first six arguments are numbered 0 .. 5 ]
*)
let arg_loc (n : int) : operand = failwith "arg_loc not implemented"
let arg_loc (n : int) : operand =
let n64 = Int64.of_int n in
let rbp_offset = Int64.mul 8L (Int64.sub n64 4L) in
match n with
| 0 -> Reg Rdi
| 1 -> Reg Rsi
| 2 -> Reg Rdx
| 3 -> Reg Rcx
| 4 -> Reg R08
| 5 -> Reg R09
| _ -> Ind3 (Lit rbp_offset, Rbp)
;;
(* We suggest that you create a helper function that computes the
stack layout for a given function declaration.