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 *)
22 let word_size_bits = 32
23 let word_size_bytes = word_size_bits / 8
24 let word_size = word_size_bytes
29 let formals {formals; _} =
32 let alloc offset_from_frame_pointer ~escapes =
34 InFrame {offset_from_frame_pointer}
36 InReg {register = Temp.Temp.gen ()}
38 let alloc_local _ ~escapes =
39 (* FIXME: offset_from_frame_pointer. With neither mutation nor new frame? *)
40 let offset_from_frame_pointer = 0 in
41 alloc offset_from_frame_pointer ~escapes
43 let make ~name ~formals =
44 (* p.136: For each formal parameter, "newFrame" must calculate two things:
45 * - How the parameter will be seen from inside the function
46 * (in a register, or in a frame location);
47 * - What instructions must be produced to implement the "view shift"
49 let formals, locals_count =
50 (* TODO: What should offset increment be? Word? *)
51 List.fold_left formals ~init:([], 0) ~f:(fun (formals, offset) escapes ->
52 ((alloc offset ~escapes) :: formals, succ offset)
58 ; instructions = () (* TODO: instructions for view shift *)