| 1 |
(* |
| 2 |
* WARNING: This file was automatically generated by MDLGen (v3.0) |
| 3 |
* from the machine description file "mips/mips.mdl". |
| 4 |
* DO NOT EDIT this file directly |
| 5 |
*) |
| 6 |
|
| 7 |
|
| 8 |
functor MIPSAsmEmitter(structure S : INSTRUCTION_STREAM |
| 9 |
structure Instr : MIPSINSTR |
| 10 |
where T = S.P.T |
| 11 |
structure Shuffle : MIPSSHUFFLE |
| 12 |
where I = Instr |
| 13 |
structure MLTreeEval : MLTREE_EVAL |
| 14 |
where T = Instr.T |
| 15 |
) : INSTRUCTION_EMITTER = |
| 16 |
struct |
| 17 |
structure I = Instr |
| 18 |
structure C = I.C |
| 19 |
structure T = I.T |
| 20 |
structure S = S |
| 21 |
structure P = S.P |
| 22 |
structure Constant = I.Constant |
| 23 |
|
| 24 |
open AsmFlags |
| 25 |
|
| 26 |
fun error msg = MLRiscErrorMsg.error("MIPSAsmEmitter",msg) |
| 27 |
|
| 28 |
fun makeStream formatAnnotations = |
| 29 |
let val stream = !AsmStream.asmOutStream |
| 30 |
fun emit' s = TextIO.output(stream,s) |
| 31 |
val newline = ref true |
| 32 |
val tabs = ref 0 |
| 33 |
fun tabbing 0 = () |
| 34 |
| tabbing n = (emit' "\t"; tabbing(n-1)) |
| 35 |
fun emit s = (tabbing(!tabs); tabs := 0; newline := false; emit' s) |
| 36 |
fun nl() = (tabs := 0; if !newline then () else (newline := true; emit' "\n")) |
| 37 |
fun comma() = emit "," |
| 38 |
fun tab() = tabs := 1 |
| 39 |
fun indent() = tabs := 2 |
| 40 |
fun ms n = let val s = Int.toString n |
| 41 |
in if n<0 then "-"^String.substring(s,1,size s-1) |
| 42 |
else s |
| 43 |
end |
| 44 |
fun emit_label lab = emit(P.Client.AsmPseudoOps.lexpToString(T.LABEL lab)) |
| 45 |
fun emit_labexp le = emit(P.Client.AsmPseudoOps.lexpToString (T.LABEXP le)) |
| 46 |
fun emit_const c = emit(Constant.toString c) |
| 47 |
fun emit_int i = emit(ms i) |
| 48 |
fun paren f = (emit "("; f(); emit ")") |
| 49 |
fun defineLabel lab = emit(P.Client.AsmPseudoOps.defineLabel lab^"\n") |
| 50 |
fun entryLabel lab = defineLabel lab |
| 51 |
fun comment msg = (tab(); emit("/* " ^ msg ^ " */"); nl()) |
| 52 |
fun annotation a = comment(Annotations.toString a) |
| 53 |
fun getAnnotations() = error "getAnnotations" |
| 54 |
fun doNothing _ = () |
| 55 |
fun fail _ = raise Fail "AsmEmitter" |
| 56 |
fun emit_region mem = comment(I.Region.toString mem) |
| 57 |
val emit_region = |
| 58 |
if !show_region then emit_region else doNothing |
| 59 |
fun pseudoOp pOp = (emit(P.toString pOp); emit "\n") |
| 60 |
fun init size = (comment("Code Size = " ^ ms size); nl()) |
| 61 |
val emitCellInfo = AsmFormatUtil.reginfo |
| 62 |
(emit,formatAnnotations) |
| 63 |
fun emitCell r = (emit(CellsBasis.toString r); emitCellInfo r) |
| 64 |
fun emit_cellset(title,cellset) = |
| 65 |
(nl(); comment(title^CellsBasis.CellSet.toString cellset)) |
| 66 |
val emit_cellset = |
| 67 |
if !show_cellset then emit_cellset else doNothing |
| 68 |
fun emit_defs cellset = emit_cellset("defs: ",cellset) |
| 69 |
fun emit_uses cellset = emit_cellset("uses: ",cellset) |
| 70 |
val emit_cutsTo = |
| 71 |
if !show_cutsTo then AsmFormatUtil.emit_cutsTo emit |
| 72 |
else doNothing |
| 73 |
fun emitter instr = |
| 74 |
let |
| 75 |
fun asm_load (I.LD) = "ld" |
| 76 |
| asm_load (I.LW) = "lw" |
| 77 |
| asm_load (I.LH) = "lh" |
| 78 |
| asm_load (I.LHU) = "lhu" |
| 79 |
| asm_load (I.LB) = "lb" |
| 80 |
| asm_load (I.LBU) = "lbu" |
| 81 |
| asm_load (I.LWL) = "lwl" |
| 82 |
| asm_load (I.LWR) = "lwr" |
| 83 |
| asm_load (I.LWU) = "lwu" |
| 84 |
| asm_load (I.LDL) = "ldl" |
| 85 |
| asm_load (I.LDR) = "ldr" |
| 86 |
| asm_load (I.ULH) = "ulh" |
| 87 |
| asm_load (I.ULHU) = "ulhu" |
| 88 |
| asm_load (I.ULW) = "ulw" |
| 89 |
| asm_load (I.ULD) = "uld" |
| 90 |
and emit_load x = emit (asm_load x) |
| 91 |
and asm_store (I.SD) = "sd" |
| 92 |
| asm_store (I.SW) = "sw" |
| 93 |
| asm_store (I.SH) = "sh" |
| 94 |
| asm_store (I.SB) = "sb" |
| 95 |
| asm_store (I.SWL) = "swl" |
| 96 |
| asm_store (I.SWR) = "swr" |
| 97 |
| asm_store (I.SDL) = "sdl" |
| 98 |
| asm_store (I.SDR) = "sdr" |
| 99 |
| asm_store (I.USH) = "ush" |
| 100 |
| asm_store (I.USW) = "usw" |
| 101 |
| asm_store (I.USD) = "usd" |
| 102 |
and emit_store x = emit (asm_store x) |
| 103 |
and asm_fload (I.LDC1) = "ldc1" |
| 104 |
| asm_fload (I.LWC1) = "lwc1" |
| 105 |
and emit_fload x = emit (asm_fload x) |
| 106 |
and asm_fstore (I.SDC1) = "sdc1" |
| 107 |
| asm_fstore (I.SWC1) = "swc1" |
| 108 |
and emit_fstore x = emit (asm_fstore x) |
| 109 |
and asm_fcond (I.FF) = "f" |
| 110 |
| asm_fcond (I.FUN) = "un" |
| 111 |
| asm_fcond (I.FEQ) = "eq" |
| 112 |
| asm_fcond (I.FUEQ) = "fueq" |
| 113 |
| asm_fcond (I.FOLT) = "folt" |
| 114 |
| asm_fcond (I.FULT) = "ult" |
| 115 |
| asm_fcond (I.FOLE) = "ole" |
| 116 |
| asm_fcond (I.FULE) = "ule" |
| 117 |
| asm_fcond (I.FNGLE) = "ngle" |
| 118 |
| asm_fcond (I.FSP) = "sf" |
| 119 |
| asm_fcond (I.FNGL) = "ngl" |
| 120 |
| asm_fcond (I.FSEQ) = "seq" |
| 121 |
| asm_fcond (I.FLT) = "flt" |
| 122 |
| asm_fcond (I.FNGE) = "fnge" |
| 123 |
| asm_fcond (I.FLE) = "le" |
| 124 |
| asm_fcond (I.FNGT) = "ngt" |
| 125 |
and emit_fcond x = emit (asm_fcond x) |
| 126 |
and asm_cond (I.EQ) = "eq" |
| 127 |
| asm_cond (I.NE) = "ne" |
| 128 |
| asm_cond (I.LEZ) = "lez" |
| 129 |
| asm_cond (I.GTZ) = "gtz" |
| 130 |
| asm_cond (I.LTZ) = "ltz" |
| 131 |
| asm_cond (I.GEZ) = "gez" |
| 132 |
and emit_cond x = emit (asm_cond x) |
| 133 |
and asm_fbranch (I.BC1T) = "bc1t" |
| 134 |
| asm_fbranch (I.BC1F) = "bc1f" |
| 135 |
and emit_fbranch x = emit (asm_fbranch x) |
| 136 |
and asm_likely (I.LIKELY) = "l" |
| 137 |
| asm_likely (I.UNLIKELY) = "" |
| 138 |
and emit_likely x = emit (asm_likely x) |
| 139 |
and asm_arith (I.ADD) = "add" |
| 140 |
| asm_arith (I.ADDU) = "addu" |
| 141 |
| asm_arith (I.AND) = "and" |
| 142 |
| asm_arith (I.XOR) = "xor" |
| 143 |
| asm_arith (I.MUL) = "mul" |
| 144 |
| asm_arith (I.MULO) = "mulo" |
| 145 |
| asm_arith (I.MULOU) = "mulou" |
| 146 |
| asm_arith (I.NOR) = "nor" |
| 147 |
| asm_arith (I.OR) = "or" |
| 148 |
| asm_arith (I.SEQ) = "seq" |
| 149 |
| asm_arith (I.SGT) = "sgt" |
| 150 |
| asm_arith (I.SGE) = "sge" |
| 151 |
| asm_arith (I.SGEU) = "sgeu" |
| 152 |
| asm_arith (I.SGTU) = "sgtu" |
| 153 |
| asm_arith (I.SLT) = "slt" |
| 154 |
| asm_arith (I.SLE) = "sle" |
| 155 |
| asm_arith (I.SLEU) = "sleu" |
| 156 |
| asm_arith (I.SLTU) = "sltu" |
| 157 |
| asm_arith (I.SNE) = "sne" |
| 158 |
| asm_arith (I.SUB) = "sub" |
| 159 |
| asm_arith (I.SUBU) = "subu" |
| 160 |
| asm_arith (I.REM) = "rem" |
| 161 |
| asm_arith (I.REMU) = "remu" |
| 162 |
| asm_arith (I.SRA) = "sra" |
| 163 |
| asm_arith (I.SLL) = "sll" |
| 164 |
| asm_arith (I.SRL) = "srl" |
| 165 |
| asm_arith (I.ROR) = "ror" |
| 166 |
| asm_arith (I.ROL) = "rol" |
| 167 |
| asm_arith (I.MOVN) = "movn" |
| 168 |
| asm_arith (I.MOVZ) = "movz" |
| 169 |
| asm_arith (I.DADD) = "dadd" |
| 170 |
| asm_arith (I.DADDU) = "daddu" |
| 171 |
| asm_arith (I.DMUL) = "dmul" |
| 172 |
| asm_arith (I.DMULO) = "dmulo" |
| 173 |
| asm_arith (I.DMULOU) = "dmulou" |
| 174 |
| asm_arith (I.DSUB) = "dsub" |
| 175 |
| asm_arith (I.DSUBU) = "dsubu" |
| 176 |
| asm_arith (I.DREM) = "drem" |
| 177 |
| asm_arith (I.DREMU) = "dremu" |
| 178 |
| asm_arith (I.DROL) = "drol" |
| 179 |
| asm_arith (I.DROR) = "dror" |
| 180 |
| asm_arith (I.DSLL) = "dsll" |
| 181 |
| asm_arith (I.DSLL32) = "dsll32" |
| 182 |
| asm_arith (I.DSLLV) = "dsllv" |
| 183 |
| asm_arith (I.DSRA) = "dsra" |
| 184 |
| asm_arith (I.DSRA32) = "dsra32" |
| 185 |
| asm_arith (I.DSRAV) = "dsrav" |
| 186 |
| asm_arith (I.DSRL) = "dsrl" |
| 187 |
| asm_arith (I.DSRL32) = "dsrl32" |
| 188 |
| asm_arith (I.DSRLV) = "dsrlv" |
| 189 |
and emit_arith x = emit (asm_arith x) |
| 190 |
and asm_unary (I.ABS) = "abs" |
| 191 |
| asm_unary (I.NEG) = "neg" |
| 192 |
| asm_unary (I.NEGU) = "negu" |
| 193 |
| asm_unary (I.NOT) = "not" |
| 194 |
| asm_unary (I.DABS) = "dabs" |
| 195 |
| asm_unary (I.DNEG) = "dneg" |
| 196 |
| asm_unary (I.DNEGU) = "dnegu" |
| 197 |
and emit_unary x = emit (asm_unary x) |
| 198 |
and asm_multiply (I.MULT) = "mult" |
| 199 |
| asm_multiply (I.MULTU) = "multu" |
| 200 |
| asm_multiply (I.DMULT) = "dmult" |
| 201 |
| asm_multiply (I.DMULTU) = "dmultu" |
| 202 |
and emit_multiply x = emit (asm_multiply x) |
| 203 |
and asm_divide (I.DIV) = "div" |
| 204 |
| asm_divide (I.DIVU) = "divu" |
| 205 |
| asm_divide (I.DDIV) = "ddiv" |
| 206 |
| asm_divide (I.DDIVU) = "ddivu" |
| 207 |
and emit_divide x = emit (asm_divide x) |
| 208 |
and asm_trap (I.TEQ) = "teq" |
| 209 |
| asm_trap (I.TNE) = "tne" |
| 210 |
| asm_trap (I.TLT) = "tlt" |
| 211 |
| asm_trap (I.TLTU) = "tltu" |
| 212 |
| asm_trap (I.TGE) = "tge" |
| 213 |
| asm_trap (I.TGEU) = "tgeu" |
| 214 |
and emit_trap x = emit (asm_trap x) |
| 215 |
and asm_farith (I.ADD_D) = "add.d" |
| 216 |
| asm_farith (I.ADD_S) = "add.s" |
| 217 |
| asm_farith (I.SUB_D) = "sub.d" |
| 218 |
| asm_farith (I.SUB_S) = "sub.s" |
| 219 |
| asm_farith (I.MUL_D) = "mul.d" |
| 220 |
| asm_farith (I.MUL_S) = "mul.s" |
| 221 |
| asm_farith (I.DIV_D) = "div.d" |
| 222 |
| asm_farith (I.DIV_S) = "div.s" |
| 223 |
and emit_farith x = emit (asm_farith x) |
| 224 |
and asm_funary (I.MOV_D) = "mov.d" |
| 225 |
| asm_funary (I.MOV_S) = "mov.s" |
| 226 |
| asm_funary (I.ABS_D) = "abs.d" |
| 227 |
| asm_funary (I.ABS_S) = "abs.s" |
| 228 |
| asm_funary (I.NEG_D) = "neg.d" |
| 229 |
| asm_funary (I.NEG_S) = "neg.s" |
| 230 |
| asm_funary (I.SQRT_D) = "sqrt.d" |
| 231 |
| asm_funary (I.SQRT_S) = "sqrt.s" |
| 232 |
| asm_funary (I.CVT_SD) = "cvt.s.d" |
| 233 |
| asm_funary (I.CVT_SW) = "cvt.s.w" |
| 234 |
| asm_funary (I.CVT_DS) = "cvt.d.s" |
| 235 |
| asm_funary (I.CVT_DW) = "cvt.d.w" |
| 236 |
| asm_funary (I.CVT_WS) = "cvt.w.s" |
| 237 |
| asm_funary (I.CVT_WD) = "cvt.w.d" |
| 238 |
| asm_funary (I.CVT_SL) = "cvt.s.l" |
| 239 |
| asm_funary (I.CVT_DL) = "cvt.d.l" |
| 240 |
| asm_funary (I.CVT_LS) = "cvt.l.s" |
| 241 |
| asm_funary (I.CVT_LD) = "cvt.l.d" |
| 242 |
and emit_funary x = emit (asm_funary x) |
| 243 |
and asm_cvti2f (I.MTC1) = "mtc1" |
| 244 |
| asm_cvti2f (I.DMTC1) = "dmtc1" |
| 245 |
and emit_cvti2f x = emit (asm_cvti2f x) |
| 246 |
and asm_cvtf2i (I.MFC1) = "mfc1" |
| 247 |
| asm_cvtf2i (I.DMFC1) = "dmfc1" |
| 248 |
and emit_cvtf2i x = emit (asm_cvtf2i x) |
| 249 |
and asm_farith3 (I.MADD_D) = "madd.d" |
| 250 |
| asm_farith3 (I.MADD_S) = "madd.s" |
| 251 |
| asm_farith3 (I.NMADD_D) = "nmadd.d" |
| 252 |
| asm_farith3 (I.NMADD_S) = "nmadd.s" |
| 253 |
| asm_farith3 (I.MSUB_D) = "msub.d" |
| 254 |
| asm_farith3 (I.MSUB_S) = "msub.s" |
| 255 |
| asm_farith3 (I.NMSUB_D) = "nmsub.d" |
| 256 |
| asm_farith3 (I.NMSUB_S) = "nmsub.s" |
| 257 |
and emit_farith3 x = emit (asm_farith3 x) |
| 258 |
and asm_fround (I.TRUNC_WS) = "trunc.w.s" |
| 259 |
| asm_fround (I.TRUNC_WD) = "trunc.w.d" |
| 260 |
| asm_fround (I.ROUND_WS) = "round.w.d" |
| 261 |
| asm_fround (I.ROUND_WD) = "round.w.d" |
| 262 |
| asm_fround (I.CEIL_WD) = "ceil.w.d" |
| 263 |
| asm_fround (I.CEIL_WS) = "ceil.w.s" |
| 264 |
| asm_fround (I.CEILU_WD) = "ceilu.w.d" |
| 265 |
| asm_fround (I.CEILU_WS) = "ceilu.w.s" |
| 266 |
| asm_fround (I.FLOOR_WD) = "floor.w.d" |
| 267 |
| asm_fround (I.FLOOR_WS) = "floor.w.s" |
| 268 |
| asm_fround (I.FLOORU_WD) = "flooru.w.d" |
| 269 |
| asm_fround (I.FLOORU_WS) = "flooru.w.s" |
| 270 |
| asm_fround (I.ROUNDU_WD) = "roundu.w.d" |
| 271 |
| asm_fround (I.ROUNDU_WS) = "roundu.w.s" |
| 272 |
| asm_fround (I.TRUNCU_WD) = "truncu.w.d" |
| 273 |
| asm_fround (I.TRUNCU_WS) = "truncu.w.s" |
| 274 |
| asm_fround (I.TRUNC_LS) = "trunc.l.s" |
| 275 |
| asm_fround (I.TRUNC_LD) = "trunc.l.d" |
| 276 |
| asm_fround (I.ROUND_LS) = "round.l.s" |
| 277 |
| asm_fround (I.ROUND_LD) = "round.l.d" |
| 278 |
| asm_fround (I.CEIL_LS) = "ceil.l.s" |
| 279 |
| asm_fround (I.CEIL_LD) = "ceil.l.d" |
| 280 |
| asm_fround (I.FLOOR_LS) = "floor.l.s" |
| 281 |
| asm_fround (I.FLOOR_LD) = "floor.l.d" |
| 282 |
and emit_fround x = emit (asm_fround x) |
| 283 |
and asm_fmt (I.SINGLE) = "s" |
| 284 |
| asm_fmt (I.DOUBLE) = "d" |
| 285 |
and emit_fmt x = emit (asm_fmt x) |
| 286 |
and emit_operand (I.Imm int) = emit_int int |
| 287 |
| emit_operand (I.Reg GP) = emitCell GP |
| 288 |
| emit_operand (I.Lab labexp) = emit_labexp labexp |
| 289 |
| emit_operand (I.HiLab labexp) = |
| 290 |
( emit "$hi("; |
| 291 |
emit_labexp labexp; |
| 292 |
emit ")" ) |
| 293 |
| emit_operand (I.LoLab labexp) = |
| 294 |
( emit "$lo("; |
| 295 |
emit_labexp labexp; |
| 296 |
emit ")" ) |
| 297 |
|
| 298 |
(*#line 244.7 "mips/mips.mdl"*) |
| 299 |
fun immedSuffix (s, I.Reg _) = s |
| 300 |
| immedSuffix (s, _) = |
| 301 |
let |
| 302 |
(*#line 246.15 "mips/mips.mdl"*) |
| 303 |
val n = String.size s |
| 304 |
in |
| 305 |
(case String.sub (s, n - 1) of |
| 306 |
#"u" => (String.substring (s, 0, n - 1)) ^ "iu" |
| 307 |
| _ => s ^ "i" |
| 308 |
) |
| 309 |
end |
| 310 |
|
| 311 |
(*#line 253.7 "mips/mips.mdl"*) |
| 312 |
fun indexed (s, I.Reg _) = |
| 313 |
let |
| 314 |
(*#line 254.15 "mips/mips.mdl"*) |
| 315 |
val prefix = String.substring (s, 0, 2) |
| 316 |
|
| 317 |
(*#line 255.15 "mips/mips.mdl"*) |
| 318 |
val suffix = String.substring (s, 2, 4) |
| 319 |
in (prefix ^ "x") ^ suffix |
| 320 |
end |
| 321 |
| indexed (s, _) = s |
| 322 |
|
| 323 |
(*#line 260.7 "mips/mips.mdl"*) |
| 324 |
fun emit_nop false = () |
| 325 |
| emit_nop true = emit "\n\tnop" |
| 326 |
fun emitInstr' instr = |
| 327 |
(case instr of |
| 328 |
I.NOP => emit "nop" |
| 329 |
| I.LUI{rt, imm} => |
| 330 |
( emit "lui\t"; |
| 331 |
emitCell rt; |
| 332 |
emit ", "; |
| 333 |
emit_operand imm ) |
| 334 |
| I.LA{rt, b, d} => |
| 335 |
( emit "la\t"; |
| 336 |
emitCell rt; |
| 337 |
emit ", "; |
| 338 |
emitCell b; |
| 339 |
emit ", "; |
| 340 |
emit_operand d ) |
| 341 |
| I.DLA{rt, b, d} => |
| 342 |
( emit "dla\t"; |
| 343 |
emitCell rt; |
| 344 |
emit ", "; |
| 345 |
emitCell b; |
| 346 |
emit ", "; |
| 347 |
emit_operand d ) |
| 348 |
| I.LOAD{l, rt, b, d, mem} => |
| 349 |
( emit_load l; |
| 350 |
emit "\t"; |
| 351 |
emitCell rt; |
| 352 |
emit ", "; |
| 353 |
emit_operand d; |
| 354 |
emit "("; |
| 355 |
emitCell b; |
| 356 |
emit ")"; |
| 357 |
emit_region mem ) |
| 358 |
| I.STORE{s, rs, b, d, mem} => |
| 359 |
( emit_store s; |
| 360 |
emit "\t"; |
| 361 |
emitCell rs; |
| 362 |
emit ", "; |
| 363 |
emit_operand d; |
| 364 |
emit "("; |
| 365 |
emitCell b; |
| 366 |
emit ")"; |
| 367 |
emit_region mem ) |
| 368 |
| I.FLOAD{l, ft, b, d, mem} => |
| 369 |
( indexed (asm_fload l, d); |
| 370 |
emit "\t"; |
| 371 |
emitCell ft; |
| 372 |
emit ", "; |
| 373 |
emit_operand d; |
| 374 |
emit "("; |
| 375 |
emitCell b; |
| 376 |
emit ")"; |
| 377 |
emit_region mem ) |
| 378 |
| I.FSTORE{s, fs, b, d, mem} => |
| 379 |
( indexed (asm_fstore s, d); |
| 380 |
emit "\t"; |
| 381 |
emitCell fs; |
| 382 |
emit ", "; |
| 383 |
emit_operand d; |
| 384 |
emit "("; |
| 385 |
emitCell b; |
| 386 |
emit ")"; |
| 387 |
emit_region mem ) |
| 388 |
| I.FCMP{fcond, fmt, cc, fs1, fs2} => |
| 389 |
( emit "c."; |
| 390 |
emit_fcond fcond; |
| 391 |
emit "."; |
| 392 |
emit_fmt fmt; |
| 393 |
emit "\t"; |
| 394 |
emitCell cc; |
| 395 |
emit ", "; |
| 396 |
emitCell fs1; |
| 397 |
emit ", "; |
| 398 |
emitCell fs2 ) |
| 399 |
| I.TRAP{t, rs, i} => |
| 400 |
( emit_trap t; |
| 401 |
emit "\t"; |
| 402 |
emitCell rs; |
| 403 |
emit ", "; |
| 404 |
emit_operand i ) |
| 405 |
| I.J{lab, nop} => |
| 406 |
( emit "j\t"; |
| 407 |
emit_label lab; |
| 408 |
emit_nop nop ) |
| 409 |
| I.JR{rs, labels, nop} => |
| 410 |
( emit "jr\t"; |
| 411 |
emitCell rs; |
| 412 |
emit_nop nop ) |
| 413 |
| I.JAL{lab, defs, uses, cutsTo, mem, nop} => |
| 414 |
( emit "jal\t"; |
| 415 |
emit_label lab; |
| 416 |
emit_region mem; |
| 417 |
emit_defs defs; |
| 418 |
emit_uses uses; |
| 419 |
emit_cutsTo cutsTo; |
| 420 |
emit_nop nop ) |
| 421 |
| I.JALR{rt, rs, defs, uses, cutsTo, mem, nop} => |
| 422 |
( emit "jalr\t"; |
| 423 |
emitCell rt; |
| 424 |
emit ", "; |
| 425 |
emitCell rs; |
| 426 |
emit_region mem; |
| 427 |
emit_defs defs; |
| 428 |
emit_uses uses; |
| 429 |
emit_cutsTo cutsTo; |
| 430 |
emit_nop nop ) |
| 431 |
| I.RET{nop} => |
| 432 |
( emit "jr\t$31"; |
| 433 |
emit_nop nop ) |
| 434 |
| I.BRANCH{likely, cond, rs, rt, lab, nop} => |
| 435 |
( emit "b"; |
| 436 |
emit_cond cond; |
| 437 |
emit_likely likely; |
| 438 |
emit "\t"; |
| 439 |
emitCell rs; |
| 440 |
emit ", "; |
| 441 |
emitCell rt; |
| 442 |
emit ", "; |
| 443 |
emit_label lab; |
| 444 |
emit_nop nop ) |
| 445 |
| I.FBRANCH{likely, fbranch, cc, lab, nop} => |
| 446 |
( emit_fbranch fbranch; |
| 447 |
emit_likely likely; |
| 448 |
emit "\t"; |
| 449 |
emitCell cc; |
| 450 |
emit ", "; |
| 451 |
emit_label lab; |
| 452 |
emit_nop nop ) |
| 453 |
| I.ARITH{oper, rt, rs, i} => |
| 454 |
( immedSuffix (asm_arith oper, i); |
| 455 |
emit "\t"; |
| 456 |
emitCell rt; |
| 457 |
emit ", "; |
| 458 |
emitCell rs; |
| 459 |
emit ", "; |
| 460 |
emit_operand i ) |
| 461 |
| I.UNARY{oper, rt, rs} => |
| 462 |
( emit_unary oper; |
| 463 |
emit "\t"; |
| 464 |
emitCell rt; |
| 465 |
emit ", "; |
| 466 |
emitCell rs ) |
| 467 |
| I.MULTIPLY{oper, rt, rs} => |
| 468 |
( emit_multiply oper; |
| 469 |
emit "\t"; |
| 470 |
emitCell rt; |
| 471 |
emit ", "; |
| 472 |
emitCell rs ) |
| 473 |
| I.DIVIDE{oper, rt, rs} => |
| 474 |
( emit_divide oper; |
| 475 |
emit "\t"; |
| 476 |
emitCell rt; |
| 477 |
emit ", "; |
| 478 |
emitCell rs ) |
| 479 |
| I.MFLO GP => |
| 480 |
( emit "mflo\t"; |
| 481 |
emitCell GP ) |
| 482 |
| I.MTLO GP => |
| 483 |
( emit "mtlo\t"; |
| 484 |
emitCell GP ) |
| 485 |
| I.MFHI GP => |
| 486 |
( emit "mfhi\t"; |
| 487 |
emitCell GP ) |
| 488 |
| I.MTHI GP => |
| 489 |
( emit "mthi\t"; |
| 490 |
emitCell GP ) |
| 491 |
| I.BREAK int => |
| 492 |
( emit "break\t"; |
| 493 |
emit_int int ) |
| 494 |
| I.FARITH{oper, ft, fs1, fs2} => |
| 495 |
( emit_farith oper; |
| 496 |
emit "\t"; |
| 497 |
emitCell ft; |
| 498 |
emit ", "; |
| 499 |
emitCell fs1; |
| 500 |
emit ", "; |
| 501 |
emitCell fs2 ) |
| 502 |
| I.FUNARY{oper, ft, fs} => |
| 503 |
( emit_funary oper; |
| 504 |
emit "\t"; |
| 505 |
emitCell ft; |
| 506 |
emit ", "; |
| 507 |
emitCell fs ) |
| 508 |
| I.FARITH3{oper, ft, fs1, fs2, fs3} => |
| 509 |
( emit_farith3 oper; |
| 510 |
emit "\t"; |
| 511 |
emitCell ft; |
| 512 |
emit ", "; |
| 513 |
emitCell fs1; |
| 514 |
emit ", "; |
| 515 |
emitCell fs2; |
| 516 |
emit ", "; |
| 517 |
emitCell fs3 ) |
| 518 |
| I.FROUND{oper, ft, fs1, rs2} => |
| 519 |
( emit_fround oper; |
| 520 |
emit "\t"; |
| 521 |
emitCell ft; |
| 522 |
emit ", "; |
| 523 |
emitCell fs1; |
| 524 |
emit ", "; |
| 525 |
emitCell fs1; |
| 526 |
emit ", "; |
| 527 |
emitCell rs2 ) |
| 528 |
| I.CVTI2F{cvt, rs, ft} => |
| 529 |
( emit_cvti2f cvt; |
| 530 |
emit "\t"; |
| 531 |
emitCell ft; |
| 532 |
emit ", "; |
| 533 |
emitCell rs ) |
| 534 |
| I.CVTF2I{cvt, fs, rt} => |
| 535 |
( emit_cvtf2i cvt; |
| 536 |
emit "\t"; |
| 537 |
emitCell rt; |
| 538 |
emit ", "; |
| 539 |
emitCell fs ) |
| 540 |
| I.COPY{dst, src, impl, tmp} => emitInstrs (Shuffle.shuffle {tmp=tmp, |
| 541 |
src=src, dst=dst}) |
| 542 |
| I.FCOPY{dst, src, impl, tmp} => emitInstrs (Shuffle.shufflefp {tmp=tmp, |
| 543 |
src=src, dst=dst}) |
| 544 |
| I.ANNOTATION{i, a} => |
| 545 |
( comment (Annotations.toString a); |
| 546 |
nl (); |
| 547 |
emitInstr i ) |
| 548 |
| I.PHI{} => emit "phi" |
| 549 |
| I.SOURCE{} => emit "source" |
| 550 |
| I.SINK{} => emit "sink" |
| 551 |
) |
| 552 |
in tab(); emitInstr' instr; nl() |
| 553 |
end (* emitter *) |
| 554 |
and emitInstrIndented i = (indent(); emitInstr i; nl()) |
| 555 |
and emitInstrs instrs = |
| 556 |
app (if !indent_copies then emitInstrIndented |
| 557 |
else emitInstr) instrs |
| 558 |
|
| 559 |
and emitInstr(I.ANNOTATION{i,a}) = |
| 560 |
( comment(Annotations.toString a); |
| 561 |
nl(); |
| 562 |
emitInstr i ) |
| 563 |
| emitInstr(I.LIVE{regs, spilled}) = |
| 564 |
comment("live= " ^ CellsBasis.CellSet.toString regs ^ |
| 565 |
"spilled= " ^ CellsBasis.CellSet.toString spilled) |
| 566 |
| emitInstr(I.KILL{regs, spilled}) = |
| 567 |
comment("killed:: " ^ CellsBasis.CellSet.toString regs ^ |
| 568 |
"spilled:: " ^ CellsBasis.CellSet.toString spilled) |
| 569 |
| emitInstr(I.INSTR i) = emitter i |
| 570 |
| emitInstr(I.COPY{k=CellsBasis.GP, sz, src, dst, tmp}) = |
| 571 |
emitInstrs(Shuffle.shuffle{tmp=tmp, src=src, dst=dst}) |
| 572 |
| emitInstr(I.COPY{k=CellsBasis.FP, sz, src, dst, tmp}) = |
| 573 |
emitInstrs(Shuffle.shufflefp{tmp=tmp, src=src, dst=dst}) |
| 574 |
| emitInstr _ = error "emitInstr" |
| 575 |
|
| 576 |
in S.STREAM{beginCluster=init, |
| 577 |
pseudoOp=pseudoOp, |
| 578 |
emit=emitInstr, |
| 579 |
endCluster=fail, |
| 580 |
defineLabel=defineLabel, |
| 581 |
entryLabel=entryLabel, |
| 582 |
comment=comment, |
| 583 |
exitBlock=doNothing, |
| 584 |
annotation=annotation, |
| 585 |
getAnnotations=getAnnotations |
| 586 |
} |
| 587 |
end |
| 588 |
end |
| 589 |
|