Implement stack layout (Unfinished)
Signed-off-by: Mariano Uvalle <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
5e418a8603
commit
7c61a62e13
1 changed files with 23 additions and 1 deletions
|
|
@ -87,6 +87,10 @@ let lookup m x = List.assoc x m
|
||||||
|
|
||||||
TODO: The section below still reads like giberish,
|
TODO: The section below still reads like giberish,
|
||||||
mabye reading the rest of the code/tests will help.
|
mabye reading the rest of the code/tests will help.
|
||||||
|
Update: This makes sense now, whenever you're adding two numbers together
|
||||||
|
or performing any operations on them, you need them to be in registers.
|
||||||
|
All locals in this compilation strategy are in the stack, so when
|
||||||
|
operating on them we need to move them to registers...
|
||||||
|
|
||||||
One strategy for compiling instruction operands is to use a
|
One strategy for compiling instruction operands is to use a
|
||||||
designated register (or registers) for holding the values being
|
designated register (or registers) for holding the values being
|
||||||
|
|
@ -309,7 +313,25 @@ let arg_loc (n : int) : operand =
|
||||||
- see the discussion about locals
|
- see the discussion about locals
|
||||||
*)
|
*)
|
||||||
let stack_layout (args : uid list) ((block, lbled_blocks) : cfg) : layout =
|
let stack_layout (args : uid list) ((block, lbled_blocks) : cfg) : layout =
|
||||||
failwith "stack_layout not implemented"
|
(* offset is in quad unitsf.
|
||||||
|
We start at 0, but rbp already contains a values (rbp of the calling
|
||||||
|
function) so we don't count it as a valid slot, consumers should decrement
|
||||||
|
it before using it.
|
||||||
|
*)
|
||||||
|
let open Int64 in
|
||||||
|
let next_offset =
|
||||||
|
let offset = ref 0 in
|
||||||
|
let next_offset' _ =
|
||||||
|
offset := !offset - 1;
|
||||||
|
!offset
|
||||||
|
in
|
||||||
|
next_offset'
|
||||||
|
in
|
||||||
|
let op_from_offset o = Ind3 (Lit (mul 8L (of_int o)), Rbp) in
|
||||||
|
let layout_args =
|
||||||
|
List.fold_left (fun acc arg -> (arg, op_from_offset (next_offset ())) :: acc) [] args
|
||||||
|
in
|
||||||
|
layout_args
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(* The code for the entry-point of a function must do several things:
|
(* The code for the entry-point of a function must do several things:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue