source: Deliverables/Dissemination/final-review/wp5/Pics/summul_mips_raw.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.8 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 current_color = ref "black"
42let get_current_color () = !current_color
43
44let color_text color text = "\\textcolor{" ^ color () ^ "}{" ^ text ^ "}"
45let color_bftext color text = "\\textcolor{" ^ color () ^ "}{\\bf " ^ text ^ "}"
46let texttt text = "\\texttt{" ^ text ^ "}"
47
48let line lexs =
49  Box.tex (texttt (string_of_list " " (fun s -> s) 
50                     (lexs)))
51
52let code lines =
53  let f (b_prev, b_res) b_line =
54    let b_line = Box.place `Southwest ~pos:`Northwest b_prev b_line in
55    (b_line, b_res @ [b_line])
56  in
57  let (_, b_res) = List.fold_left f (Box.empty (), []) (List.map line lines) in
58  Box.group b_res
59
60let black () = "black"
61let typ = color_text black
62let op = color_bftext black
63let keyword = color_bftext black
64let comment s = [color_text (fun () -> "red") s]
65let jlabel lab = color_text (fun () -> "magenta") lab
66let label lab = [color_text (fun () -> "magenta") (lab ^ ":")]
67let reg i = color_text black ("\\%" ^ (string_of_int i))
68let hreg s = color_text black ("\\$" ^ s)
69let string_id s = color_text (fun () -> "lightviolet") ("\"" ^ s ^ "\"")
70let special = op
71
72let kif = keyword "if"
73let kreturn = keyword "return"
74let kcall f = [special "call" ; string_id f]
75
76let typ_int = typ "int"
77
78let assigns = op "$\\leftarrow$"
79let line_assigns x y = [x ; assigns ; y]
80let nop = [special "nop"]
81let newframe = [special "newframe"]
82let delframe = [special "delframe"]
83
84let preamble =
85  code [comment "\\# begin preamble" ; [".data"] ; label "globals" ;
86        ["\\ \\ .space" ; "0"] ; [".text"] ; label "main" ;
87        line_assigns (hreg "gp") (keyword "globals") ;
88        [special "j" ; keyword "main14"] ; comment "\\# end preamble"]
89
90let colored ls = 
91  ls
92
93let summul =
94  let block1 = 
95    current_color := "red";
96    colored [   
97      line_assigns (hreg "v0") "1" ; 
98      line_assigns (hreg "a1") "1" 
99    ]
100  in
101  let block2 = 
102    current_color := "green";
103    colored [
104      label "summul10" ; line_assigns (hreg "a3") "0" ;
105      [hreg "a2" ; assigns ; hreg "a0" ; "$\\ge$" ; hreg "a1"] ;
106      [hreg "a2" ; assigns ; hreg "a2" ; "==" ; hreg "zero"] ;
107      [hreg "a2" ; op "==" ; hreg "a3" ; "$\\Rightarrow$" ;
108       jlabel "summul6"] 
109    ]
110  in
111  let block3 = 
112    current_color := "blue";
113    colored [
114      [special "jr" ; hreg "ra"] ; 
115    ]
116  in
117  let block4 =
118    current_color := "green";
119    colored [
120      label "summul6" ;
121      [hreg "a2" ; assigns ; hreg "v0" ; "$\\times$" ; hreg "a0"] ;
122      [hreg "v0" ; assigns ; hreg "v0" ; "+" ; hreg "a2"] ;
123      line_assigns (hreg "a2") "1" ;
124      [hreg "a0" ; assigns ; hreg "a0" ; "$-$" ; hreg "a2"] ;
125      [special "j" ; jlabel "summul10"] ; 
126    ]
127  in
128  code (block1 @ block2 @ block3 @ block4)
129
130let main =
131  code [comment "\\# begin main" ; label "main14" ;
132        [hreg "sp" ; assigns ; hreg "sp" ; "$-$" ; "4"] ;
133        line_assigns ((hreg "sp") ^ "[0]") (hreg "ra") ;
134        line_assigns (hreg "a0") "5" ;
135        [special "jal" ; keyword "summul34"] ;
136        line_assigns (hreg "ra") ((hreg "sp") ^ "[0]") ;
137        [hreg "sp" ; assigns ; hreg "sp" ; "$+$" ; "4"] ;
138        [special "jr" ; hreg "ra"] ;
139        comment "\\# end main"]
140
141
142(* Place Text *)
143
144
145(* Strokes and arrows *)
146
147
148(* Main *)
149
150let summul_mips = Box.hbox ~padding:(cm 1.5) ~pos:`Top
151  [summul]
152
153let summul_mips = Box.draw summul_mips
154
155let _ = Metapost.emit "summul_mips_raw" summul_mips
Note: See TracBrowser for help on using the repository browser.