| 1 |
(* |
| 2 |
* WARNING: This file was automatically generated by MDLGen (v3.1) |
| 3 |
* from the machine description file "ppc/ppc.mdl". |
| 4 |
* DO NOT EDIT this file directly |
| 5 |
*) |
| 6 |
|
| 7 |
|
| 8 |
functor PPCAsmEmitter(structure S : INSTRUCTION_STREAM |
| 9 |
structure Instr : PPCINSTR (* where T = S.P.T *) |
| 10 |
where type T.Basis.cond = S.P.T.Basis.cond |
| 11 |
and type T.Basis.div_rounding_mode = S.P.T.Basis.div_rounding_mode |
| 12 |
and type T.Basis.ext = S.P.T.Basis.ext |
| 13 |
and type T.Basis.fcond = S.P.T.Basis.fcond |
| 14 |
and type T.Basis.rounding_mode = S.P.T.Basis.rounding_mode |
| 15 |
and type T.Constant.const = S.P.T.Constant.const |
| 16 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) S.P.T.Extension.ccx |
| 17 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) S.P.T.Extension.fx |
| 18 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) S.P.T.Extension.rx |
| 19 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) S.P.T.Extension.sx |
| 20 |
and type T.I.div_rounding_mode = S.P.T.I.div_rounding_mode |
| 21 |
and type T.Region.region = S.P.T.Region.region |
| 22 |
and type T.ccexp = S.P.T.ccexp |
| 23 |
and type T.fexp = S.P.T.fexp |
| 24 |
(* and type T.labexp = S.P.T.labexp *) |
| 25 |
and type T.mlrisc = S.P.T.mlrisc |
| 26 |
and type T.oper = S.P.T.oper |
| 27 |
and type T.rep = S.P.T.rep |
| 28 |
and type T.rexp = S.P.T.rexp |
| 29 |
and type T.stm = S.P.T.stm |
| 30 |
structure Shuffle : PPCSHUFFLE (* where I = Instr *) |
| 31 |
where type I.Constant.const = Instr.Constant.const |
| 32 |
and type I.Region.region = Instr.Region.region |
| 33 |
and type I.T.Basis.cond = Instr.T.Basis.cond |
| 34 |
and type I.T.Basis.div_rounding_mode = Instr.T.Basis.div_rounding_mode |
| 35 |
and type I.T.Basis.ext = Instr.T.Basis.ext |
| 36 |
and type I.T.Basis.fcond = Instr.T.Basis.fcond |
| 37 |
and type I.T.Basis.rounding_mode = Instr.T.Basis.rounding_mode |
| 38 |
and type ('s,'r,'f,'c) I.T.Extension.ccx = ('s,'r,'f,'c) Instr.T.Extension.ccx |
| 39 |
and type ('s,'r,'f,'c) I.T.Extension.fx = ('s,'r,'f,'c) Instr.T.Extension.fx |
| 40 |
and type ('s,'r,'f,'c) I.T.Extension.rx = ('s,'r,'f,'c) Instr.T.Extension.rx |
| 41 |
and type ('s,'r,'f,'c) I.T.Extension.sx = ('s,'r,'f,'c) Instr.T.Extension.sx |
| 42 |
and type I.T.I.div_rounding_mode = Instr.T.I.div_rounding_mode |
| 43 |
and type I.T.ccexp = Instr.T.ccexp |
| 44 |
and type I.T.fexp = Instr.T.fexp |
| 45 |
(* and type I.T.labexp = Instr.T.labexp *) |
| 46 |
and type I.T.mlrisc = Instr.T.mlrisc |
| 47 |
and type I.T.oper = Instr.T.oper |
| 48 |
and type I.T.rep = Instr.T.rep |
| 49 |
and type I.T.rexp = Instr.T.rexp |
| 50 |
and type I.T.stm = Instr.T.stm |
| 51 |
and type I.arith = Instr.arith |
| 52 |
and type I.arithi = Instr.arithi |
| 53 |
and type I.bit = Instr.bit |
| 54 |
and type I.bo = Instr.bo |
| 55 |
and type I.ccarith = Instr.ccarith |
| 56 |
and type I.cmp = Instr.cmp |
| 57 |
and type I.ea = Instr.ea |
| 58 |
and type I.farith = Instr.farith |
| 59 |
and type I.farith3 = Instr.farith3 |
| 60 |
and type I.fcmp = Instr.fcmp |
| 61 |
and type I.fload = Instr.fload |
| 62 |
and type I.fstore = Instr.fstore |
| 63 |
and type I.funary = Instr.funary |
| 64 |
and type I.instr = Instr.instr |
| 65 |
and type I.instruction = Instr.instruction |
| 66 |
and type I.load = Instr.load |
| 67 |
and type I.operand = Instr.operand |
| 68 |
and type I.rotate = Instr.rotate |
| 69 |
and type I.rotatei = Instr.rotatei |
| 70 |
and type I.spr = Instr.spr |
| 71 |
and type I.store = Instr.store |
| 72 |
and type I.unary = Instr.unary |
| 73 |
and type I.xerbit = Instr.xerbit |
| 74 |
structure MLTreeEval : MLTREE_EVAL (* where T = Instr.T *) |
| 75 |
where type T.Basis.cond = Instr.T.Basis.cond |
| 76 |
and type T.Basis.div_rounding_mode = Instr.T.Basis.div_rounding_mode |
| 77 |
and type T.Basis.ext = Instr.T.Basis.ext |
| 78 |
and type T.Basis.fcond = Instr.T.Basis.fcond |
| 79 |
and type T.Basis.rounding_mode = Instr.T.Basis.rounding_mode |
| 80 |
and type T.Constant.const = Instr.T.Constant.const |
| 81 |
and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) Instr.T.Extension.ccx |
| 82 |
and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) Instr.T.Extension.fx |
| 83 |
and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) Instr.T.Extension.rx |
| 84 |
and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) Instr.T.Extension.sx |
| 85 |
and type T.I.div_rounding_mode = Instr.T.I.div_rounding_mode |
| 86 |
and type T.Region.region = Instr.T.Region.region |
| 87 |
and type T.ccexp = Instr.T.ccexp |
| 88 |
and type T.fexp = Instr.T.fexp |
| 89 |
(* and type T.labexp = Instr.T.labexp *) |
| 90 |
and type T.mlrisc = Instr.T.mlrisc |
| 91 |
and type T.oper = Instr.T.oper |
| 92 |
and type T.rep = Instr.T.rep |
| 93 |
and type T.rexp = Instr.T.rexp |
| 94 |
and type T.stm = Instr.T.stm |
| 95 |
) : INSTRUCTION_EMITTER = |
| 96 |
struct |
| 97 |
structure I = Instr |
| 98 |
structure C = I.C |
| 99 |
structure T = I.T |
| 100 |
structure S = S |
| 101 |
structure P = S.P |
| 102 |
structure Constant = I.Constant |
| 103 |
|
| 104 |
open AsmFlags |
| 105 |
|
| 106 |
fun error msg = MLRiscErrorMsg.error("PPCAsmEmitter",msg) |
| 107 |
|
| 108 |
fun makeStream formatAnnotations = |
| 109 |
let val stream = !AsmStream.asmOutStream |
| 110 |
fun emit' s = TextIO.output(stream,s) |
| 111 |
val newline = ref true |
| 112 |
val tabs = ref 0 |
| 113 |
fun tabbing 0 = () |
| 114 |
| tabbing n = (emit' "\t"; tabbing(n-1)) |
| 115 |
fun emit s = (tabbing(!tabs); tabs := 0; newline := false; emit' s) |
| 116 |
fun nl() = (tabs := 0; if !newline then () else (newline := true; emit' "\n")) |
| 117 |
fun comma() = emit "," |
| 118 |
fun tab() = tabs := 1 |
| 119 |
fun indent() = tabs := 2 |
| 120 |
fun ms n = let val s = Int.toString n |
| 121 |
in if n<0 then "-"^String.substring(s,1,size s-1) |
| 122 |
else s |
| 123 |
end |
| 124 |
fun emit_label lab = emit(P.Client.AsmPseudoOps.lexpToString(T.LABEL lab)) |
| 125 |
fun emit_labexp le = emit(P.Client.AsmPseudoOps.lexpToString (T.LABEXP le)) |
| 126 |
fun emit_const c = emit(Constant.toString c) |
| 127 |
fun emit_int i = emit(ms i) |
| 128 |
fun paren f = (emit "("; f(); emit ")") |
| 129 |
fun defineLabel lab = emit(P.Client.AsmPseudoOps.defineLabel lab^"\n") |
| 130 |
fun entryLabel lab = defineLabel lab |
| 131 |
fun comment msg = (tab(); emit("/* " ^ msg ^ " */"); nl()) |
| 132 |
fun annotation a = comment(Annotations.toString a) |
| 133 |
fun getAnnotations() = error "getAnnotations" |
| 134 |
fun doNothing _ = () |
| 135 |
fun fail _ = raise Fail "AsmEmitter" |
| 136 |
fun emit_region mem = comment(I.Region.toString mem) |
| 137 |
val emit_region = |
| 138 |
if !show_region then emit_region else doNothing |
| 139 |
fun pseudoOp pOp = (emit(P.toString pOp); emit "\n") |
| 140 |
fun init size = (comment("Code Size = " ^ ms size); nl()) |
| 141 |
val emitCellInfo = AsmFormatUtil.reginfo |
| 142 |
(emit,formatAnnotations) |
| 143 |
fun emitCell r = (emit(CellsBasis.toString r); emitCellInfo r) |
| 144 |
fun emit_cellset(title,cellset) = |
| 145 |
(nl(); comment(title^CellsBasis.CellSet.toString cellset)) |
| 146 |
val emit_cellset = |
| 147 |
if !show_cellset then emit_cellset else doNothing |
| 148 |
fun emit_defs cellset = emit_cellset("defs: ",cellset) |
| 149 |
fun emit_uses cellset = emit_cellset("uses: ",cellset) |
| 150 |
val emit_cutsTo = |
| 151 |
if !show_cutsTo then AsmFormatUtil.emit_cutsTo emit |
| 152 |
else doNothing |
| 153 |
fun emitter instr = |
| 154 |
let |
| 155 |
fun asm_spr (I.XER) = "xer" |
| 156 |
| asm_spr (I.LR) = "lr" |
| 157 |
| asm_spr (I.CTR) = "ctr" |
| 158 |
and emit_spr x = emit (asm_spr x) |
| 159 |
and emit_operand (I.RegOp GP) = emitCell GP |
| 160 |
| emit_operand (I.ImmedOp int) = emit_int int |
| 161 |
| emit_operand (I.LabelOp labexp) = emit_labexp labexp |
| 162 |
and asm_load (I.LBZ) = "lbz" |
| 163 |
| asm_load (I.LBZE) = "lbze" |
| 164 |
| asm_load (I.LHZ) = "lhz" |
| 165 |
| asm_load (I.LHZE) = "lhze" |
| 166 |
| asm_load (I.LHA) = "lha" |
| 167 |
| asm_load (I.LHAE) = "lhae" |
| 168 |
| asm_load (I.LWZ) = "lwz" |
| 169 |
| asm_load (I.LWZE) = "lwze" |
| 170 |
| asm_load (I.LDE) = "lde" |
| 171 |
| asm_load (I.LBZU) = "lbzu" |
| 172 |
| asm_load (I.LHZU) = "lhzu" |
| 173 |
| asm_load (I.LHAU) = "lhau" |
| 174 |
| asm_load (I.LWZU) = "lwzu" |
| 175 |
| asm_load (I.LDZU) = "ldzu" |
| 176 |
and emit_load x = emit (asm_load x) |
| 177 |
and asm_store (I.STB) = "stb" |
| 178 |
| asm_store (I.STBE) = "stbe" |
| 179 |
| asm_store (I.STH) = "sth" |
| 180 |
| asm_store (I.STHE) = "sthe" |
| 181 |
| asm_store (I.STW) = "stw" |
| 182 |
| asm_store (I.STWE) = "stwe" |
| 183 |
| asm_store (I.STDE) = "stde" |
| 184 |
| asm_store (I.STBU) = "stbu" |
| 185 |
| asm_store (I.STHU) = "sthu" |
| 186 |
| asm_store (I.STWU) = "stwu" |
| 187 |
| asm_store (I.STDU) = "stdu" |
| 188 |
and emit_store x = emit (asm_store x) |
| 189 |
and asm_fload (I.LFS) = "lfs" |
| 190 |
| asm_fload (I.LFSE) = "lfse" |
| 191 |
| asm_fload (I.LFD) = "lfd" |
| 192 |
| asm_fload (I.LFDE) = "lfde" |
| 193 |
| asm_fload (I.LFSU) = "lfsu" |
| 194 |
| asm_fload (I.LFDU) = "lfdu" |
| 195 |
and emit_fload x = emit (asm_fload x) |
| 196 |
and asm_fstore (I.STFS) = "stfs" |
| 197 |
| asm_fstore (I.STFSE) = "stfse" |
| 198 |
| asm_fstore (I.STFD) = "stfd" |
| 199 |
| asm_fstore (I.STFDE) = "stfde" |
| 200 |
| asm_fstore (I.STFSU) = "stfsu" |
| 201 |
| asm_fstore (I.STFDU) = "stfdu" |
| 202 |
and emit_fstore x = emit (asm_fstore x) |
| 203 |
and asm_cmp (I.CMP) = "cmp" |
| 204 |
| asm_cmp (I.CMPL) = "cmpl" |
| 205 |
and emit_cmp x = emit (asm_cmp x) |
| 206 |
and asm_fcmp (I.FCMPO) = "fcmpo" |
| 207 |
| asm_fcmp (I.FCMPU) = "fcmpu" |
| 208 |
and emit_fcmp x = emit (asm_fcmp x) |
| 209 |
and asm_unary (I.NEG) = "neg" |
| 210 |
| asm_unary (I.EXTSB) = "extsb" |
| 211 |
| asm_unary (I.EXTSH) = "extsh" |
| 212 |
| asm_unary (I.EXTSW) = "extsw" |
| 213 |
| asm_unary (I.CNTLZW) = "cntlzw" |
| 214 |
| asm_unary (I.CNTLZD) = "cntlzd" |
| 215 |
and emit_unary x = emit (asm_unary x) |
| 216 |
and asm_funary (I.FMR) = "fmr" |
| 217 |
| asm_funary (I.FNEG) = "fneg" |
| 218 |
| asm_funary (I.FABS) = "fabs" |
| 219 |
| asm_funary (I.FNABS) = "fnabs" |
| 220 |
| asm_funary (I.FSQRT) = "fsqrt" |
| 221 |
| asm_funary (I.FSQRTS) = "fsqrts" |
| 222 |
| asm_funary (I.FRSP) = "frsp" |
| 223 |
| asm_funary (I.FCTIW) = "fctiw" |
| 224 |
| asm_funary (I.FCTIWZ) = "fctiwz" |
| 225 |
| asm_funary (I.FCTID) = "fctid" |
| 226 |
| asm_funary (I.FCTIDZ) = "fctidz" |
| 227 |
| asm_funary (I.FCFID) = "fcfid" |
| 228 |
and emit_funary x = emit (asm_funary x) |
| 229 |
and asm_farith (I.FADD) = "fadd" |
| 230 |
| asm_farith (I.FSUB) = "fsub" |
| 231 |
| asm_farith (I.FMUL) = "fmul" |
| 232 |
| asm_farith (I.FDIV) = "fdiv" |
| 233 |
| asm_farith (I.FADDS) = "fadds" |
| 234 |
| asm_farith (I.FSUBS) = "fsubs" |
| 235 |
| asm_farith (I.FMULS) = "fmuls" |
| 236 |
| asm_farith (I.FDIVS) = "fdivs" |
| 237 |
and emit_farith x = emit (asm_farith x) |
| 238 |
and asm_farith3 (I.FMADD) = "fmadd" |
| 239 |
| asm_farith3 (I.FMADDS) = "fmadds" |
| 240 |
| asm_farith3 (I.FMSUB) = "fmsub" |
| 241 |
| asm_farith3 (I.FMSUBS) = "fmsubs" |
| 242 |
| asm_farith3 (I.FNMADD) = "fnmadd" |
| 243 |
| asm_farith3 (I.FNMADDS) = "fnmadds" |
| 244 |
| asm_farith3 (I.FNMSUB) = "fnmsub" |
| 245 |
| asm_farith3 (I.FNMSUBS) = "fnmsubs" |
| 246 |
| asm_farith3 (I.FSEL) = "fsel" |
| 247 |
and emit_farith3 x = emit (asm_farith3 x) |
| 248 |
and asm_arith (I.ADD) = "add" |
| 249 |
| asm_arith (I.SUBF) = "subf" |
| 250 |
| asm_arith (I.MULLW) = "mullw" |
| 251 |
| asm_arith (I.MULLD) = "mulld" |
| 252 |
| asm_arith (I.MULHW) = "mulhw" |
| 253 |
| asm_arith (I.MULHWU) = "mulhwu" |
| 254 |
| asm_arith (I.DIVW) = "divw" |
| 255 |
| asm_arith (I.DIVD) = "divd" |
| 256 |
| asm_arith (I.DIVWU) = "divwu" |
| 257 |
| asm_arith (I.DIVDU) = "divdu" |
| 258 |
| asm_arith (I.AND) = "and" |
| 259 |
| asm_arith (I.OR) = "or" |
| 260 |
| asm_arith (I.XOR) = "xor" |
| 261 |
| asm_arith (I.NAND) = "nand" |
| 262 |
| asm_arith (I.NOR) = "nor" |
| 263 |
| asm_arith (I.EQV) = "eqv" |
| 264 |
| asm_arith (I.ANDC) = "andc" |
| 265 |
| asm_arith (I.ORC) = "orc" |
| 266 |
| asm_arith (I.SLW) = "slw" |
| 267 |
| asm_arith (I.SLD) = "sld" |
| 268 |
| asm_arith (I.SRW) = "srw" |
| 269 |
| asm_arith (I.SRD) = "srd" |
| 270 |
| asm_arith (I.SRAW) = "sraw" |
| 271 |
| asm_arith (I.SRAD) = "srad" |
| 272 |
and emit_arith x = emit (asm_arith x) |
| 273 |
and asm_arithi (I.ADDI) = "addi" |
| 274 |
| asm_arithi (I.ADDIS) = "addis" |
| 275 |
| asm_arithi (I.SUBFIC) = "subfic" |
| 276 |
| asm_arithi (I.MULLI) = "mulli" |
| 277 |
| asm_arithi (I.ANDI_Rc) = "andi." |
| 278 |
| asm_arithi (I.ANDIS_Rc) = "andis." |
| 279 |
| asm_arithi (I.ORI) = "ori" |
| 280 |
| asm_arithi (I.ORIS) = "oris" |
| 281 |
| asm_arithi (I.XORI) = "xori" |
| 282 |
| asm_arithi (I.XORIS) = "xoris" |
| 283 |
| asm_arithi (I.SRAWI) = "srawi" |
| 284 |
| asm_arithi (I.SRADI) = "sradi" |
| 285 |
and emit_arithi x = emit (asm_arithi x) |
| 286 |
and asm_rotate (I.RLWNM) = "rlwnm" |
| 287 |
| asm_rotate (I.RLDCL) = "rldcl" |
| 288 |
| asm_rotate (I.RLDCR) = "rldcr" |
| 289 |
and emit_rotate x = emit (asm_rotate x) |
| 290 |
and asm_rotatei (I.RLWINM) = "rlwinm" |
| 291 |
| asm_rotatei (I.RLWIMI) = "rlwimi" |
| 292 |
| asm_rotatei (I.RLDICL) = "rldicl" |
| 293 |
| asm_rotatei (I.RLDICR) = "rldicr" |
| 294 |
| asm_rotatei (I.RLDIC) = "rldic" |
| 295 |
| asm_rotatei (I.RLDIMI) = "rldimi" |
| 296 |
and emit_rotatei x = emit (asm_rotatei x) |
| 297 |
and asm_ccarith (I.CRAND) = "crand" |
| 298 |
| asm_ccarith (I.CROR) = "cror" |
| 299 |
| asm_ccarith (I.CRXOR) = "crxor" |
| 300 |
| asm_ccarith (I.CRNAND) = "crnand" |
| 301 |
| asm_ccarith (I.CRNOR) = "crnor" |
| 302 |
| asm_ccarith (I.CREQV) = "creqv" |
| 303 |
| asm_ccarith (I.CRANDC) = "crandc" |
| 304 |
| asm_ccarith (I.CRORC) = "crorc" |
| 305 |
and emit_ccarith x = emit (asm_ccarith x) |
| 306 |
and asm_bit (I.LT) = "lt" |
| 307 |
| asm_bit (I.GT) = "gt" |
| 308 |
| asm_bit (I.EQ) = "eq" |
| 309 |
| asm_bit (I.SO) = "so" |
| 310 |
| asm_bit (I.FL) = "lt" |
| 311 |
| asm_bit (I.FG) = "gt" |
| 312 |
| asm_bit (I.FE) = "eq" |
| 313 |
| asm_bit (I.FU) = "un" |
| 314 |
| asm_bit (I.FX) = "lt" |
| 315 |
| asm_bit (I.FEX) = "gt" |
| 316 |
| asm_bit (I.VX) = "eq" |
| 317 |
| asm_bit (I.OX) = "so" |
| 318 |
and emit_bit x = emit (asm_bit x) |
| 319 |
|
| 320 |
(*#line 608.7 "ppc/ppc.mdl"*) |
| 321 |
fun emitx (s, I.RegOp _) = (if ((String.sub (s, (size s) - 1)) = #"e") |
| 322 |
then |
| 323 |
( emit (String.substring (s, 0, (size s) - 1)); |
| 324 |
emit "xe" ) |
| 325 |
else |
| 326 |
( emit s; |
| 327 |
emit "x" )) |
| 328 |
| emitx (s, _) = emit s |
| 329 |
|
| 330 |
(*#line 614.7 "ppc/ppc.mdl"*) |
| 331 |
fun eOERc {OE=false, Rc=false} = () |
| 332 |
| eOERc {OE=false, Rc=true} = emit "." |
| 333 |
| eOERc {OE=true, Rc=false} = emit "o" |
| 334 |
| eOERc {OE=true, Rc=true} = emit "o." |
| 335 |
|
| 336 |
(*#line 618.7 "ppc/ppc.mdl"*) |
| 337 |
fun eRc false = "" |
| 338 |
| eRc true = "." |
| 339 |
|
| 340 |
(*#line 619.7 "ppc/ppc.mdl"*) |
| 341 |
fun cr_bit (cr, bit) = (4 * (CellsBasis.physicalRegisterNum cr)) + |
| 342 |
(case bit of |
| 343 |
I.LT => 0 |
| 344 |
| I.GT => 1 |
| 345 |
| I.EQ => 2 |
| 346 |
| I.SO => 3 |
| 347 |
| I.FL => 0 |
| 348 |
| I.FG => 1 |
| 349 |
| I.FE => 2 |
| 350 |
| I.FU => 3 |
| 351 |
| I.FX => 0 |
| 352 |
| I.FEX => 1 |
| 353 |
| I.VX => 2 |
| 354 |
| I.OX => 3 |
| 355 |
) |
| 356 |
|
| 357 |
(*#line 626.7 "ppc/ppc.mdl"*) |
| 358 |
fun eCRbit x = emit (Int.toString (cr_bit x)) |
| 359 |
|
| 360 |
(*#line 627.7 "ppc/ppc.mdl"*) |
| 361 |
fun eLK true = emit "l" |
| 362 |
| eLK false = () |
| 363 |
|
| 364 |
(*#line 628.7 "ppc/ppc.mdl"*) |
| 365 |
fun eI (I.RegOp _) = () |
| 366 |
| eI _ = emit "i" |
| 367 |
|
| 368 |
(*#line 629.7 "ppc/ppc.mdl"*) |
| 369 |
fun eBI (bo, bf, bit) = |
| 370 |
(case (bo, CellsBasis.physicalRegisterNum bf) of |
| 371 |
(I.ALWAYS, _) => () |
| 372 |
| (I.COUNTER{cond=NONE, ...}, _) => () |
| 373 |
| (_, 0) => emit (asm_bit bit) |
| 374 |
| (_, n) => emit ((("4*cr" ^ (Int.toString n)) ^ "+") ^ (asm_bit bit)) |
| 375 |
) |
| 376 |
|
| 377 |
(*#line 635.7 "ppc/ppc.mdl"*) |
| 378 |
fun emit_bo bo = emit |
| 379 |
(case bo of |
| 380 |
I.TRUE => "t" |
| 381 |
| I.FALSE => "f" |
| 382 |
| I.ALWAYS => "" |
| 383 |
| I.COUNTER{eqZero, cond=NONE} => (if eqZero |
| 384 |
then "dz" |
| 385 |
else "dnz") |
| 386 |
| I.COUNTER{eqZero, cond=SOME cc} => (if eqZero |
| 387 |
then "dz" |
| 388 |
else "dnz") ^ (if cc |
| 389 |
then "t" |
| 390 |
else "f") |
| 391 |
) |
| 392 |
|
| 393 |
(*#line 646.7 "ppc/ppc.mdl"*) |
| 394 |
fun eME (SOME me) = |
| 395 |
( emit ", "; |
| 396 |
emit_int me ) |
| 397 |
| eME NONE = () |
| 398 |
|
| 399 |
(*#line 649.7 "ppc/ppc.mdl"*) |
| 400 |
fun addr (ra, I.RegOp rb) = |
| 401 |
( emitCell ra; |
| 402 |
emit ", "; |
| 403 |
emitCell rb ) |
| 404 |
| addr (ra, d) = |
| 405 |
( emit_operand d; |
| 406 |
emit "("; |
| 407 |
emitCell ra; |
| 408 |
emit ")" ) |
| 409 |
fun emitInstr' instr = |
| 410 |
(case instr of |
| 411 |
I.L{ld, rt, ra, d, mem} => |
| 412 |
( emitx (asm_load ld, d); |
| 413 |
emit "\t"; |
| 414 |
emitCell rt; |
| 415 |
emit ", "; |
| 416 |
addr (ra, d); |
| 417 |
emit_region mem ) |
| 418 |
| I.LF{ld, ft, ra, d, mem} => |
| 419 |
( emitx (asm_fload ld, d); |
| 420 |
emit "\t"; |
| 421 |
emitCell ft; |
| 422 |
emit ", "; |
| 423 |
addr (ra, d); |
| 424 |
emit_region mem ) |
| 425 |
| I.ST{st, rs, ra, d, mem} => |
| 426 |
( emitx (asm_store st, d); |
| 427 |
emit "\t"; |
| 428 |
emitCell rs; |
| 429 |
emit ", "; |
| 430 |
addr (ra, d); |
| 431 |
emit_region mem ) |
| 432 |
| I.STF{st, fs, ra, d, mem} => |
| 433 |
( emitx (asm_fstore st, d); |
| 434 |
emit "\t"; |
| 435 |
emitCell fs; |
| 436 |
emit ", "; |
| 437 |
addr (ra, d); |
| 438 |
emit_region mem ) |
| 439 |
| I.UNARY{oper, rt, ra, Rc, OE} => |
| 440 |
( emit_unary oper; |
| 441 |
eOERc {Rc=Rc, OE=OE}; |
| 442 |
emit "\t"; |
| 443 |
emitCell rt; |
| 444 |
emit ", "; |
| 445 |
emitCell ra ) |
| 446 |
| I.ARITH{oper, rt, ra, rb, Rc, OE} => |
| 447 |
( emit_arith oper; |
| 448 |
eOERc {Rc=Rc, OE=OE}; |
| 449 |
emit "\t"; |
| 450 |
emitCell rt; |
| 451 |
emit ", "; |
| 452 |
emitCell ra; |
| 453 |
emit ", "; |
| 454 |
emitCell rb ) |
| 455 |
| I.ARITHI{oper, rt, ra, im} => |
| 456 |
( emit_arithi oper; |
| 457 |
emit "\t"; |
| 458 |
emitCell rt; |
| 459 |
emit ", "; |
| 460 |
emitCell ra; |
| 461 |
emit ", "; |
| 462 |
emit_operand im ) |
| 463 |
| I.ROTATE{oper, ra, rs, sh, mb, me} => |
| 464 |
( emit_rotate oper; |
| 465 |
emit "\t"; |
| 466 |
emitCell ra; |
| 467 |
emit ", "; |
| 468 |
emitCell rs; |
| 469 |
emit ", "; |
| 470 |
emitCell sh; |
| 471 |
emit ", "; |
| 472 |
emit_int mb; |
| 473 |
eME me ) |
| 474 |
| I.ROTATEI{oper, ra, rs, sh, mb, me} => |
| 475 |
( emit_rotatei oper; |
| 476 |
emit "\t"; |
| 477 |
emitCell ra; |
| 478 |
emit ", "; |
| 479 |
emitCell rs; |
| 480 |
emit ", "; |
| 481 |
emit_operand sh; |
| 482 |
emit ", "; |
| 483 |
emit_int mb; |
| 484 |
eME me ) |
| 485 |
| I.COMPARE{cmp, l, bf, ra, rb} => |
| 486 |
( emit_cmp cmp; |
| 487 |
eI rb; |
| 488 |
emit "\t"; |
| 489 |
emitCell bf; |
| 490 |
emit ", "; |
| 491 |
emit (if l |
| 492 |
then "1" |
| 493 |
else "0"); |
| 494 |
emit ", "; |
| 495 |
emitCell ra; |
| 496 |
emit ", "; |
| 497 |
emit_operand rb ) |
| 498 |
| I.FCOMPARE{cmp, bf, fa, fb} => |
| 499 |
( emit_fcmp cmp; |
| 500 |
emit "\t"; |
| 501 |
emitCell bf; |
| 502 |
emit ", "; |
| 503 |
emitCell fa; |
| 504 |
emit ", "; |
| 505 |
emitCell fb ) |
| 506 |
| I.FUNARY{oper, ft, fb, Rc} => |
| 507 |
( emit_funary oper; |
| 508 |
eRc Rc; |
| 509 |
emit "\t"; |
| 510 |
emitCell ft; |
| 511 |
emit ", "; |
| 512 |
emitCell fb ) |
| 513 |
| I.FARITH{oper, ft, fa, fb, Rc} => |
| 514 |
( emit_farith oper; |
| 515 |
eRc Rc; |
| 516 |
emit "\t"; |
| 517 |
emitCell ft; |
| 518 |
emit ", "; |
| 519 |
emitCell fa; |
| 520 |
emit ", "; |
| 521 |
emitCell fb ) |
| 522 |
| I.FARITH3{oper, ft, fa, fb, fc, Rc} => |
| 523 |
( emit_farith3 oper; |
| 524 |
eRc Rc; |
| 525 |
emit "\t"; |
| 526 |
emitCell ft; |
| 527 |
emit ", "; |
| 528 |
emitCell fa; |
| 529 |
emit ", "; |
| 530 |
emitCell fb; |
| 531 |
emit ", "; |
| 532 |
emitCell fc ) |
| 533 |
| I.CCARITH{oper, bt, ba, bb} => |
| 534 |
( emit_ccarith oper; |
| 535 |
emit "\t"; |
| 536 |
eCRbit bt; |
| 537 |
emit ", "; |
| 538 |
eCRbit ba; |
| 539 |
emit ", "; |
| 540 |
eCRbit bb ) |
| 541 |
| I.MCRF{bf, bfa} => |
| 542 |
( emit "mcrf\t"; |
| 543 |
emitCell bf; |
| 544 |
emit ", "; |
| 545 |
emitCell bfa ) |
| 546 |
| I.MTSPR{rs, spr} => |
| 547 |
( emit "mt"; |
| 548 |
emitCell spr; |
| 549 |
emit "\t"; |
| 550 |
emitCell rs ) |
| 551 |
| I.MFSPR{rt, spr} => |
| 552 |
( emit "mf"; |
| 553 |
emitCell spr; |
| 554 |
emit "\t"; |
| 555 |
emitCell rt ) |
| 556 |
| I.LWARX{rt, ra, rb} => |
| 557 |
( emit "lwarx\t"; |
| 558 |
emitCell rt; |
| 559 |
emit ", "; |
| 560 |
emitCell ra; |
| 561 |
emit ", "; |
| 562 |
emitCell rb ) |
| 563 |
| I.STWCX{rs, ra, rb} => |
| 564 |
( emit "stwcx.\t"; |
| 565 |
emitCell rs; |
| 566 |
emit ", "; |
| 567 |
emitCell ra; |
| 568 |
emit ", "; |
| 569 |
emitCell rb ) |
| 570 |
| I.TW{to, ra, si} => |
| 571 |
( emit "tw"; |
| 572 |
eI si; |
| 573 |
emit "\t"; |
| 574 |
emit_int to; |
| 575 |
emit ", "; |
| 576 |
emitCell ra; |
| 577 |
emit ", "; |
| 578 |
emit_operand si ) |
| 579 |
| I.TD{to, ra, si} => |
| 580 |
( emit "td"; |
| 581 |
eI si; |
| 582 |
emit "\t"; |
| 583 |
emit_int to; |
| 584 |
emit ", "; |
| 585 |
emitCell ra; |
| 586 |
emit ", "; |
| 587 |
emit_operand si ) |
| 588 |
| I.BC{bo, bf, bit, addr, LK, fall} => |
| 589 |
( emit "b"; |
| 590 |
emit_bo bo; |
| 591 |
eLK LK; |
| 592 |
emit "\t"; |
| 593 |
eBI (bo, bf, bit); |
| 594 |
emit ", "; |
| 595 |
emit_operand addr ) |
| 596 |
| I.BCLR{bo, bf, bit, LK, labels} => |
| 597 |
( emit "b"; |
| 598 |
emit_bo bo; |
| 599 |
emit "lr"; |
| 600 |
eLK LK; |
| 601 |
emit "\t"; |
| 602 |
eBI (bo, bf, bit)) |
| 603 |
| I.B{addr, LK} => |
| 604 |
( emit "b"; |
| 605 |
eLK LK; |
| 606 |
emit "\t"; |
| 607 |
emit_operand addr ) |
| 608 |
| I.CALL{def, use, cutsTo, mem} => |
| 609 |
( emit "blrl"; |
| 610 |
emit_region mem; |
| 611 |
emit_defs def; |
| 612 |
emit_uses use; |
| 613 |
emit_cutsTo cutsTo ) |
| 614 |
| I.SOURCE{} => emit "source" |
| 615 |
| I.SINK{} => emit "sink" |
| 616 |
| I.PHI{} => emit "phi" |
| 617 |
) |
| 618 |
in tab(); emitInstr' instr; nl() |
| 619 |
end (* emitter *) |
| 620 |
and emitInstrIndented i = (indent(); emitInstr i; nl()) |
| 621 |
and emitInstrs instrs = |
| 622 |
app (if !indent_copies then emitInstrIndented |
| 623 |
else emitInstr) instrs |
| 624 |
|
| 625 |
and emitInstr(I.ANNOTATION{i,a}) = |
| 626 |
( comment(Annotations.toString a); |
| 627 |
nl(); |
| 628 |
emitInstr i ) |
| 629 |
| emitInstr(I.LIVE{regs, spilled}) = |
| 630 |
comment("live= " ^ CellsBasis.CellSet.toString regs ^ |
| 631 |
"spilled= " ^ CellsBasis.CellSet.toString spilled) |
| 632 |
| emitInstr(I.KILL{regs, spilled}) = |
| 633 |
comment("killed:: " ^ CellsBasis.CellSet.toString regs ^ |
| 634 |
"spilled:: " ^ CellsBasis.CellSet.toString spilled) |
| 635 |
| emitInstr(I.INSTR i) = emitter i |
| 636 |
| emitInstr(I.COPY{k=CellsBasis.GP, sz, src, dst, tmp}) = |
| 637 |
emitInstrs(Shuffle.shuffle{tmp=tmp, src=src, dst=dst}) |
| 638 |
| emitInstr(I.COPY{k=CellsBasis.FP, sz, src, dst, tmp}) = |
| 639 |
emitInstrs(Shuffle.shufflefp{tmp=tmp, src=src, dst=dst}) |
| 640 |
| emitInstr _ = error "emitInstr" |
| 641 |
|
| 642 |
in S.STREAM{beginCluster=init, |
| 643 |
pseudoOp=pseudoOp, |
| 644 |
emit=emitInstr, |
| 645 |
endCluster=fail, |
| 646 |
defineLabel=defineLabel, |
| 647 |
entryLabel=entryLabel, |
| 648 |
comment=comment, |
| 649 |
exitBlock=doNothing, |
| 650 |
annotation=annotation, |
| 651 |
getAnnotations=getAnnotations |
| 652 |
} |
| 653 |
end |
| 654 |
end |
| 655 |
|