Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Diff of /sml/trunk/src/ml-burg/example2.burg
 [smlnj] / sml / trunk / src / ml-burg / example2.burg

# Diff of /sml/trunk/src/ml-burg/example2.burg

revision 3, Sat Oct 4 23:33:46 1997 UTC revision 8, Sun Jan 18 01:01:29 1998 UTC
# Line 87  Line 87
87    | DIV of tree * tree    | DIV of tree * tree
88    | NEG of tree    | NEG of tree
89
90    fun termchildren t =    fun opchildren t =
91      case t of      case t of
92        INT _ =>       (T_INT, [])        INT _ =>       (T_INT, [])
93      | VAR _ =>       (T_VAR, [])      | VAR _ =>       (T_VAR, [])
# Line 107  Line 107
107    structure Burm = BurmGen (In)    structure Burm = BurmGen (In)
108    open In    open In
109
110    fun say s = String.print s    fun say s = print s
111
112
113    local    local
114      val num = ref 1      val num = ref 1
115        fun inc iref = iref := (!iref + 1)
116    in    in
117      fun resetreg () = (num := 1)      fun resetreg () = (num := 1)
118      fun newreg () = ("r"^(makestring (!num)) before inc num)      fun newreg () = ("r"^(Int.toString (!num)) before inc num)
119    end    end
120
121
122    fun walk (Burm.R_reg_INT, INT n) =    fun walk (Burm.R_reg_INT, INT n) =
123          let val reg = newreg () in          let val reg = newreg () in
124            say ("ldi "^reg^","^(makestring (n+n+1))^"\n"); reg            say ("ldi "^reg^","^(Int.toString (n+n+1))^"\n"); reg
125          end          end
126      | walk (Burm.R_sreg_INT, INT n) =      | walk (Burm.R_sreg_INT, INT n) =
127          let val reg = newreg () in          let val reg = newreg () in
128            say ("ldi "^reg^","^(makestring (n+n))^"\n"); reg            say ("ldi "^reg^","^(Int.toString (n+n))^"\n"); reg
129          end          end
130      | walk (Burm.R_ureg_INT, INT n) =      | walk (Burm.R_ureg_INT, INT n) =
131          let val reg = newreg () in          let val reg = newreg () in
132            say ("ldi "^reg^","^(makestring n)^"\n"); reg            say ("ldi "^reg^","^(Int.toString n)^"\n"); reg
133          end          end
134      | walk (Burm.R_reg_VAR, VAR v) =      | walk (Burm.R_reg_VAR, VAR v) =
135          let val reg = newreg () in          let val reg = newreg () in
# Line 156  Line 157
157          end          end
159          let val reg' = walk reg in          let val reg' = walk reg in
161          end          end
163          let val reg' = walk reg in          let val reg' = walk reg in
165          end          end
167          let val reg' = walk reg in          let val reg' = walk reg in
169          end          end
171          let val reg' = walk reg in          let val reg' = walk reg in
173          end          end
175          let val reg' = walk reg in          let val reg' = walk reg in
177          end          end
179          let val reg' = walk reg in          let val reg' = walk reg in
181          end          end
182      | walk (Burm.R_r_SUB_r_r (r1,r2), _) =      | walk (Burm.R_r_SUB_r_r (r1,r2), _) =
183          let val (r1',r2') = (walk r1, walk r2) in          let val (r1',r2') = (walk r1, walk r2) in
# Line 184  Line 185
185          end          end
186      | walk (Burm.R_r_SUB_2ipp_r reg, SUB (INT n,_)) =      | walk (Burm.R_r_SUB_2ipp_r reg, SUB (INT n,_)) =
187          let val reg' = walk reg val r = newreg () in          let val reg' = walk reg val r = newreg () in
188             say ("ldi "^r^","^(makestring (n+n+1))^"\n");             say ("ldi "^r^","^(Int.toString (n+n+1))^"\n");
189             say ("sub "^r^","^reg'^"\n");             say ("sub "^r^","^reg'^"\n");
190             r             r
191          end          end
192      | walk (Burm.R_r_SUB_r_2i reg, SUB (_,INT n)) =      | walk (Burm.R_r_SUB_r_2i reg, SUB (_,INT n)) =
193          let val reg' = walk reg in          let val reg' = walk reg in
194            say ("subi "^reg'^","^(makestring (n+n))^"\n"); reg'            say ("subi "^reg'^","^(Int.toString (n+n))^"\n"); reg'
195          end          end
196      | walk (Burm.R_r_SUB_r_2im reg, SUB (_,INT n)) =      | walk (Burm.R_r_SUB_r_2im reg, SUB (_,INT n)) =
197          let val reg' = walk reg in          let val reg' = walk reg in
198            say ("subi "^reg'^","^(makestring (n+n-1))^"\n"); reg'            say ("subi "^reg'^","^(Int.toString (n+n-1))^"\n"); reg'
199          end          end
200      | walk (Burm.R_r_SUB_r_2ip reg, SUB (_,INT n)) =      | walk (Burm.R_r_SUB_r_2ip reg, SUB (_,INT n)) =
201          let val reg' = walk reg in          let val reg' = walk reg in
202            say ("subi "^reg'^","^(makestring (n+n+1))^"\n"); reg'            say ("subi "^reg'^","^(Int.toString (n+n+1))^"\n"); reg'
203          end          end
204      | walk (Burm.R_r_MUL_r_r (r1,r2), _) =      | walk (Burm.R_r_MUL_r_r (r1,r2), _) =
205          let val (r1',r2') = (walk r1, walk r2) in          let val (r1',r2') = (walk r1, walk r2) in
# Line 206  Line 207
207          end          end
208      | walk (Burm.R_r_MUL_i_r reg, MUL (INT n,_)) =      | walk (Burm.R_r_MUL_i_r reg, MUL (INT n,_)) =
209          let val reg' = walk reg in          let val reg' = walk reg in
210            say ("muli "^reg'^","^(makestring (n))^"\n"); reg'            say ("muli "^reg'^","^(Int.toString (n))^"\n"); reg'
211          end          end
212      | walk (Burm.R_r_MUL_r_i reg, MUL (_,INT n)) =      | walk (Burm.R_r_MUL_r_i reg, MUL (_,INT n)) =
213          let val reg' = walk reg in          let val reg' = walk reg in
214            say ("muli "^reg'^","^(makestring (n))^"\n"); reg'            say ("muli "^reg'^","^(Int.toString (n))^"\n"); reg'
215          end          end
216      | walk (Burm.R_r_MUL_2i_r reg, MUL (INT n,_)) =      | walk (Burm.R_r_MUL_2i_r reg, MUL (INT n,_)) =
217          let val reg' = walk reg in          let val reg' = walk reg in
218            say ("muli "^reg'^","^(makestring (n+n))^"\n"); reg'            say ("muli "^reg'^","^(Int.toString (n+n))^"\n"); reg'
219          end          end
220      | walk (Burm.R_r_MUL_r_2i reg, MUL (_,INT n)) =      | walk (Burm.R_r_MUL_r_2i reg, MUL (_,INT n)) =
221          let val reg' = walk reg in          let val reg' = walk reg in
222            say ("muli "^reg'^","^(makestring (n+n))^"\n"); reg'            say ("muli "^reg'^","^(Int.toString (n+n))^"\n"); reg'
223          end          end
224      | walk (Burm.R_r_DIV_r_r (r1,r2), _) =      | walk (Burm.R_r_DIV_r_r (r1,r2), _) =
225          let val (r1',r2') = (walk r1, walk r2) in          let val (r1',r2') = (walk r1, walk r2) in
# Line 226  Line 227
227          end          end
228      | walk (Burm.R_r_DIV_r_i reg, DIV (_,INT n)) =      | walk (Burm.R_r_DIV_r_i reg, DIV (_,INT n)) =
229          let val reg' = walk reg in          let val reg' = walk reg in
230            say ("divi "^reg'^","^(makestring (n))^"\n"); reg'            say ("divi "^reg'^","^(Int.toString (n))^"\n"); reg'
231          end          end
232      | walk (Burm.R_r_NEG_r reg, _) =      | walk (Burm.R_r_NEG_r reg, _) =
233          let val reg' = walk reg in          let val reg' = walk reg in

Legend:
 Removed from v.3 changed lines Added in v.8