source: Deliverables/Dissemination/final-review/wp5/Pics/summul_result_erased_mips.ml @ 3282

Last change on this file since 3282 was 3282, checked in by regisgia, 7 years ago
  • WP5 slides for the final review.
File size: 3.6 KB
Line 
1
2open Mlpost;;
3open Box;;
4open Arrow;;
5open Path;;
6open Command;;
7open Num;;
8open Dash;;
9open Color;;
10open Pen;;
11open Point;;
12open Picture;;
13
14
15let box = Box.box ~stroke:None ~dx:zero ~dy:zero
16let path = Box.path ~stroke:None ~dx:zero ~dy:zero
17let pic = Box.pic ~stroke:None ~dx:zero ~dy:zero
18
19(* Helpers *)
20
21let string_of_list sep f =
22  let rec aux = function
23    | [] -> ""
24    | [e] -> f e
25    | e :: l -> (f e) ^ sep ^ (aux l)
26  in
27  aux
28
29let mapi f =
30  let rec aux i = function
31    | [] -> []
32    | e :: l -> (f i e) :: (aux (i+1) l)
33  in
34  aux 0
35
36let cell = Box.rect ~stroke:None
37
38
39(* Text *)
40
41let color_text color text = "\\textcolor{" ^ color ^ "}{" ^ text ^ "}"
42let color_bftext color text = "\\textcolor{" ^ color ^ "}{\\bf " ^ text ^ "}"
43let texttt text = "\\texttt{" ^ text ^ "}"
44
45let line lexs =
46  Box.tex (texttt (string_of_list " " (fun s -> s) lexs))
47
48let code lines =
49  let f (b_prev, b_res) b_line =
50    let b_line = Box.place `Southwest ~pos:`Northwest b_prev b_line in
51    (b_line, b_res @ [b_line])
52  in
53  let (_, b_res) = List.fold_left f (Box.empty (), []) (List.map line lines) in
54  Box.group b_res
55
56let typ = color_text "black"
57let op = color_text "black"
58let keyword = color_bftext "black"
59let comment s = [color_text "red" s]
60let label lab = [color_bftext "black" (lab ^ ":")]
61(* let emit_label lab = [keyword "emit"; color_text "magenta" lab] *)
62let emit_label lab = [ "\\textcolor{lightgray}{\\textbf{emit} {" ^ lab ^ "}}" ]
63let reg i = color_text "black" ("\\%" ^ (string_of_int i))
64let hreg s = color_text "black" ("\\$" ^ s)
65let string_id s = color_text "black" ("\"" ^ s ^ "\"")
66let special = op
67
68let kif = keyword "if"
69let kreturn = keyword "return"
70let kcall f = [special "call" ; string_id f]
71
72let typ_int = typ "int"
73
74let assigns = op "$\\leftarrow$"
75let line_assigns x y = [x ; assigns ; y]
76let nop = [special "nop"]
77let newframe = [special "newframe"]
78let delframe = [special "delframe"]
79
80let preamble =
81  code [comment "\\# begin preamble" ; [".data"] ; label "globals" ;
82        ["\\ \\ .space" ; "0"] ; [".text"] ; label "main" ;
83        line_assigns (hreg "gp") (keyword "globals") ;
84        [special "j" ; keyword "main14"] ; comment "\\# end preamble"]
85
86let summul =
87  code [
88(*        comment "\\# begin summul" ; label "summul34" ; *)
89        emit_label "\\_cost2" ;
90        line_assigns (hreg "v0") "1" ; line_assigns (hreg "a1") "1" ;
91        label "summul10" ; line_assigns (hreg "a3") "0" ;
92        [hreg "a2" ; assigns ; hreg "a0" ; "$\\ge$" ; hreg "a1"] ;
93        [hreg "a2" ; assigns ; hreg "a2" ; "==" ; hreg "zero"] ;
94        [hreg "a2" ; op "==" ; hreg "a3" ; "$\\Rightarrow$" ;
95         keyword "summul6"] ; 
96        emit_label "\\_cost4" ; [special "jr" ; hreg "ra"] ;
97        label "summul6" ;
98        emit_label "\\_cost3" ;
99        [hreg "a2" ; assigns ; hreg "v0" ; "$\\times$" ; hreg "a0"] ;
100        [hreg "v0" ; assigns ; hreg "v0" ; "+" ; hreg "a2"] ;
101        line_assigns (hreg "a2") "1" ;
102        [hreg "a0" ; assigns ; hreg "a0" ; "$-$" ; hreg "a2"] ;
103        [special "j" ; keyword "summul10"] ; 
104        (* comment "\\# end summul" *)]
105
106let main =
107  code [comment "\\# begin main" ; label "main14" ;
108        [hreg "sp" ; assigns ; hreg "sp" ; "$-$" ; "4"] ;
109        line_assigns ((hreg "sp") ^ "[0]") (hreg "ra") ;
110        label "\\_cost1" ;
111        line_assigns (hreg "a0") "5" ;
112        [special "jal" ; keyword "summul34"] ;
113        line_assigns (hreg "ra") ((hreg "sp") ^ "[0]") ;
114        [hreg "sp" ; assigns ; hreg "sp" ; "$+$" ; "4"] ;
115        [special "jr" ; hreg "ra"] ;
116        comment "\\# end main"]
117
118
119(* Place Text *)
120
121
122(* Strokes and arrows *)
123
124
125(* Main *)
126
127let summul_result_mips = Box.hbox ~padding:(cm 1.5) ~pos:`Top
128  [summul ]
129
130let summul_result_mips = Box.draw summul_result_mips
131
132let _ = Metapost.emit "summul_result_erased_mips" summul_result_mips
Note: See TracBrowser for help on using the repository browser.