1 module List = ListLabels
3 module Temp = Tiger_temp
6 | InFrame of {offset_from_frame_pointer : int}
7 | InReg of {register : Temp.Temp.t}
10 (* p.136 Frame.t is a data structure holding:
11 * - the locations of all the formals
12 * - instructions required to implement the "view shift"
13 * - the number of locals allocated so far
14 * - the `label` at which the function's machine code is to begin (see p.140)
17 ; formals : access list
19 ; instructions : unit (* TODO: instructions for view shift *)
25 let formals {formals; _} =
28 let alloc offset_from_frame_pointer ~escapes =
30 InFrame {offset_from_frame_pointer}
32 InReg {register = Temp.Temp.gen ()}
34 let alloc_local _ ~escapes =
35 (* FIXME: offset_from_frame_pointer. With neither mutation nor new frame? *)
36 let offset_from_frame_pointer = 0 in
37 alloc offset_from_frame_pointer ~escapes
39 let make ~name ~formals =
40 (* p.136: For each formal parameter, "newFrame" must calculate two things:
41 * - How the parameter will be seen from inside the function
42 * (in a register, or in a frame location);
43 * - What instructions must be produced to implement the "view shift"
45 let formals, locals_count =
46 (* TODO: What should offset increment be? Word? *)
47 List.fold_left formals ~init:([], 0) ~f:(fun (formals, offset) escapes ->
48 ((alloc offset ~escapes) :: formals, succ offset)
54 ; instructions = () (* TODO: instructions for view shift *)