Debian Codegraph @

lib/mlrisc-lib/MLRISC/amd64/emit/amd64Asm.sml

raw
1 (*
2 * WARNING: This file was automatically generated by MDLGen (v3.1)
3 * from the machine description file "amd64/amd64.mdl".
4 * DO NOT EDIT this file directly
5 *)
6
7
8 functor AMD64AsmEmitter(structure S : INSTRUCTION_STREAM
9 structure Instr : AMD64INSTR (* 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 : AMD64SHUFFLE (* 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.addressing_mode = Instr.addressing_mode *)
52 and type I.binaryOp = Instr.binaryOp
53 and type I.bitOp = Instr.bitOp
54 and type I.cond = Instr.cond
55 and type I.fbin_op = Instr.fbin_op
56 and type I.fcom_op = Instr.fcom_op
57 and type I.fmove_op = Instr.fmove_op
58 and type I.fsize = Instr.fsize
59 and type I.instr = Instr.instr
60 and type I.instruction = Instr.instruction
61 and type I.isize = Instr.isize
62 and type I.move = Instr.move
63 and type I.multDivOp = Instr.multDivOp
64 and type I.operand = Instr.operand
65 and type I.shiftOp = Instr.shiftOp
66 and type I.unaryOp = Instr.unaryOp
67 structure MLTreeEval : MLTREE_EVAL (* where T = Instr.T *)
68 where type T.Basis.cond = Instr.T.Basis.cond
69 and type T.Basis.div_rounding_mode = Instr.T.Basis.div_rounding_mode
70 and type T.Basis.ext = Instr.T.Basis.ext
71 and type T.Basis.fcond = Instr.T.Basis.fcond
72 and type T.Basis.rounding_mode = Instr.T.Basis.rounding_mode
73 and type T.Constant.const = Instr.T.Constant.const
74 and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) Instr.T.Extension.ccx
75 and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) Instr.T.Extension.fx
76 and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) Instr.T.Extension.rx
77 and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) Instr.T.Extension.sx
78 and type T.I.div_rounding_mode = Instr.T.I.div_rounding_mode
79 and type T.Region.region = Instr.T.Region.region
80 and type T.ccexp = Instr.T.ccexp
81 and type T.fexp = Instr.T.fexp
82 (* and type T.labexp = Instr.T.labexp *)
83 and type T.mlrisc = Instr.T.mlrisc
84 and type T.oper = Instr.T.oper
85 and type T.rep = Instr.T.rep
86 and type T.rexp = Instr.T.rexp
87 and type T.stm = Instr.T.stm
88 ) : INSTRUCTION_EMITTER =
89 struct
90 structure I = Instr
91 structure C = I.C
92 structure T = I.T
93 structure S = S
94 structure P = S.P
95 structure Constant = I.Constant
96
97 open AsmFlags
98
99 fun error msg = MLRiscErrorMsg.error("AMD64AsmEmitter",msg)
100
101 fun makeStream formatAnnotations =
102 let val stream = !AsmStream.asmOutStream
103 fun emit' s = TextIO.output(stream,s)
104 val newline = ref true
105 val tabs = ref 0
106 fun tabbing 0 = ()
107 | tabbing n = (emit' "\t"; tabbing(n-1))
108 fun emit s = (tabbing(!tabs); tabs := 0; newline := false; emit' s)
109 fun nl() = (tabs := 0; if !newline then () else (newline := true; emit' "\n"))
110 fun comma() = emit ","
111 fun tab() = tabs := 1
112 fun indent() = tabs := 2
113 fun ms n = let val s = Int.toString n
114 in if n<0 then "-"^String.substring(s,1,size s-1)
115 else s
116 end
117 fun emit_label lab = emit(P.Client.AsmPseudoOps.lexpToString(T.LABEL lab))
118 fun emit_labexp le = emit(P.Client.AsmPseudoOps.lexpToString (T.LABEXP le))
119 fun emit_const c = emit(Constant.toString c)
120 fun emit_int i = emit(ms i)
121 fun paren f = (emit "("; f(); emit ")")
122 fun defineLabel lab = emit(P.Client.AsmPseudoOps.defineLabel lab^"\n")
123 fun entryLabel lab = defineLabel lab
124 fun comment msg = (tab(); emit("/* " ^ msg ^ " */"); nl())
125 fun annotation a = comment(Annotations.toString a)
126 fun getAnnotations() = error "getAnnotations"
127 fun doNothing _ = ()
128 fun fail _ = raise Fail "AsmEmitter"
129 fun emit_region mem = comment(I.Region.toString mem)
130 val emit_region =
131 if !show_region then emit_region else doNothing
132 fun pseudoOp pOp = (emit(P.toString pOp); emit "\n")
133 fun init size = (comment("Code Size = " ^ ms size); nl())
134 val emitCellInfo = AsmFormatUtil.reginfo
135 (emit,formatAnnotations)
136 fun emitCell r = (emit(CellsBasis.toString r); emitCellInfo r)
137 fun emit_cellset(title,cellset) =
138 (nl(); comment(title^CellsBasis.CellSet.toString cellset))
139 val emit_cellset =
140 if !show_cellset then emit_cellset else doNothing
141 fun emit_defs cellset = emit_cellset("defs: ",cellset)
142 fun emit_uses cellset = emit_cellset("uses: ",cellset)
143 val emit_cutsTo =
144 if !show_cutsTo then AsmFormatUtil.emit_cutsTo emit
145 else doNothing
146 fun emitter instr =
147 let
148 fun asm_cond (I.EQ) = "e"
149 | asm_cond (I.NE) = "ne"
150 | asm_cond (I.LT) = "l"
151 | asm_cond (I.LE) = "le"
152 | asm_cond (I.GT) = "g"
153 | asm_cond (I.GE) = "ge"
154 | asm_cond (I.B) = "b"
155 | asm_cond (I.BE) = "be"
156 | asm_cond (I.A) = "a"
157 | asm_cond (I.AE) = "ae"
158 | asm_cond (I.C) = "c"
159 | asm_cond (I.NC) = "nc"
160 | asm_cond (I.P) = "p"
161 | asm_cond (I.NP) = "np"
162 | asm_cond (I.O) = "o"
163 | asm_cond (I.NO) = "no"
164 and emit_cond x = emit (asm_cond x)
165 and asm_binaryOp (I.ADDQ) = "addq"
166 | asm_binaryOp (I.SUBQ) = "subq"
167 | asm_binaryOp (I.ANDQ) = "andq"
168 | asm_binaryOp (I.ORQ) = "orq"
169 | asm_binaryOp (I.XORQ) = "xorq"
170 | asm_binaryOp (I.SHLQ) = "shlq"
171 | asm_binaryOp (I.SARQ) = "sarq"
172 | asm_binaryOp (I.SHRQ) = "shrq"
173 | asm_binaryOp (I.IMULQ) = "imulq"
174 | asm_binaryOp (I.ADCQ) = "adcq"
175 | asm_binaryOp (I.SBBQ) = "sbbq"
176 | asm_binaryOp (I.ADDL) = "addl"
177 | asm_binaryOp (I.SUBL) = "subl"
178 | asm_binaryOp (I.ANDL) = "andl"
179 | asm_binaryOp (I.ORL) = "orl"
180 | asm_binaryOp (I.XORL) = "xorl"
181 | asm_binaryOp (I.SHLL) = "shll"
182 | asm_binaryOp (I.SARL) = "sarl"
183 | asm_binaryOp (I.SHRL) = "shrl"
184 | asm_binaryOp (I.IMULL) = "imull"
185 | asm_binaryOp (I.ADCL) = "adcl"
186 | asm_binaryOp (I.SBBL) = "sbbl"
187 | asm_binaryOp (I.ADDW) = "addw"
188 | asm_binaryOp (I.SUBW) = "subw"
189 | asm_binaryOp (I.ANDW) = "andw"
190 | asm_binaryOp (I.ORW) = "orw"
191 | asm_binaryOp (I.XORW) = "xorw"
192 | asm_binaryOp (I.SHLW) = "shlw"
193 | asm_binaryOp (I.SARW) = "sarw"
194 | asm_binaryOp (I.SHRW) = "shrw"
195 | asm_binaryOp (I.IMULW) = "imulw"
196 | asm_binaryOp (I.ADDB) = "addb"
197 | asm_binaryOp (I.SUBB) = "subb"
198 | asm_binaryOp (I.ANDB) = "andb"
199 | asm_binaryOp (I.ORB) = "orb"
200 | asm_binaryOp (I.XORB) = "xorb"
201 | asm_binaryOp (I.SHLB) = "shlb"
202 | asm_binaryOp (I.SARB) = "sarb"
203 | asm_binaryOp (I.SHRB) = "shrb"
204 | asm_binaryOp (I.IMULB) = "imulb"
205 | asm_binaryOp (I.BTSW) = "btsw"
206 | asm_binaryOp (I.BTCW) = "btcw"
207 | asm_binaryOp (I.BTRW) = "btrw"
208 | asm_binaryOp (I.BTSL) = "btsl"
209 | asm_binaryOp (I.BTCL) = "btcl"
210 | asm_binaryOp (I.BTRL) = "btrl"
211 | asm_binaryOp (I.ROLW) = "rolw"
212 | asm_binaryOp (I.RORW) = "rorw"
213 | asm_binaryOp (I.ROLL) = "roll"
214 | asm_binaryOp (I.RORL) = "rorl"
215 | asm_binaryOp (I.XCHGB) = "xchgb"
216 | asm_binaryOp (I.XCHGW) = "xchgw"
217 | asm_binaryOp (I.XCHGL) = "xchgl"
218 | asm_binaryOp (I.LOCK_ADCW) = "lock\n\tadcw"
219 | asm_binaryOp (I.LOCK_ADCL) = "lock\n\tadcl"
220 | asm_binaryOp (I.LOCK_ADDW) = "lock\n\taddw"
221 | asm_binaryOp (I.LOCK_ADDL) = "lock\n\taddl"
222 | asm_binaryOp (I.LOCK_ANDW) = "lock\n\tandw"
223 | asm_binaryOp (I.LOCK_ANDL) = "lock\n\tandl"
224 | asm_binaryOp (I.LOCK_BTSW) = "lock\n\tbtsw"
225 | asm_binaryOp (I.LOCK_BTSL) = "lock\n\tbtsl"
226 | asm_binaryOp (I.LOCK_BTRW) = "lock\n\tbtrw"
227 | asm_binaryOp (I.LOCK_BTRL) = "lock\n\tbtrl"
228 | asm_binaryOp (I.LOCK_BTCW) = "lock\n\tbtcw"
229 | asm_binaryOp (I.LOCK_BTCL) = "lock\n\tbtcl"
230 | asm_binaryOp (I.LOCK_ORW) = "lock\n\torw"
231 | asm_binaryOp (I.LOCK_ORL) = "lock\n\torl"
232 | asm_binaryOp (I.LOCK_SBBW) = "lock\n\tsbbw"
233 | asm_binaryOp (I.LOCK_SBBL) = "lock\n\tsbbl"
234 | asm_binaryOp (I.LOCK_SUBW) = "lock\n\tsubw"
235 | asm_binaryOp (I.LOCK_SUBL) = "lock\n\tsubl"
236 | asm_binaryOp (I.LOCK_XORW) = "lock\n\txorw"
237 | asm_binaryOp (I.LOCK_XORL) = "lock\n\txorl"
238 | asm_binaryOp (I.LOCK_XADDB) = "lock\n\txaddb"
239 | asm_binaryOp (I.LOCK_XADDW) = "lock\n\txaddw"
240 | asm_binaryOp (I.LOCK_XADDL) = "lock\n\txaddl"
241 and emit_binaryOp x = emit (asm_binaryOp x)
242 and asm_multDivOp (I.IMULL1) = "imull"
243 | asm_multDivOp (I.MULL1) = "mull"
244 | asm_multDivOp (I.IDIVL1) = "idivl"
245 | asm_multDivOp (I.DIVL1) = "divl"
246 | asm_multDivOp (I.IMULQ1) = "imulq"
247 | asm_multDivOp (I.MULQ1) = "mulq"
248 | asm_multDivOp (I.IDIVQ1) = "idivq"
249 | asm_multDivOp (I.DIVQ1) = "divq"
250 and emit_multDivOp x = emit (asm_multDivOp x)
251 and asm_unaryOp (I.DECQ) = "decq"
252 | asm_unaryOp (I.INCQ) = "incq"
253 | asm_unaryOp (I.NEGQ) = "negq"
254 | asm_unaryOp (I.NOTQ) = "notq"
255 | asm_unaryOp (I.DECL) = "decl"
256 | asm_unaryOp (I.INCL) = "incl"
257 | asm_unaryOp (I.NEGL) = "negl"
258 | asm_unaryOp (I.NOTL) = "notl"
259 | asm_unaryOp (I.DECW) = "decw"
260 | asm_unaryOp (I.INCW) = "incw"
261 | asm_unaryOp (I.NEGW) = "negw"
262 | asm_unaryOp (I.NOTW) = "notw"
263 | asm_unaryOp (I.DECB) = "decb"
264 | asm_unaryOp (I.INCB) = "incb"
265 | asm_unaryOp (I.NEGB) = "negb"
266 | asm_unaryOp (I.NOTB) = "notb"
267 | asm_unaryOp (I.LOCK_DECQ) = "lock\n\tdecq"
268 | asm_unaryOp (I.LOCK_INCQ) = "lock\n\tincq"
269 | asm_unaryOp (I.LOCK_NEGQ) = "lock\n\tnegq"
270 | asm_unaryOp (I.LOCK_NOTQ) = "lock\n\tnotq"
271 and emit_unaryOp x = emit (asm_unaryOp x)
272 and asm_shiftOp (I.SHLDL) = "shldl"
273 | asm_shiftOp (I.SHRDL) = "shrdl"
274 and emit_shiftOp x = emit (asm_shiftOp x)
275 and asm_bitOp (I.BTW) = "btw"
276 | asm_bitOp (I.BTL) = "btl"
277 | asm_bitOp (I.BTQ) = "btq"
278 | asm_bitOp (I.LOCK_BTW) = "lock\n\tbtw"
279 | asm_bitOp (I.LOCK_BTL) = "lock\n\tbtl"
280 and emit_bitOp x = emit (asm_bitOp x)
281 and asm_move (I.MOVQ) = "movq"
282 | asm_move (I.MOVL) = "movl"
283 | asm_move (I.MOVB) = "movb"
284 | asm_move (I.MOVW) = "movw"
285 | asm_move (I.MOVABSQ) = "movabsq"
286 | asm_move (I.MOVSWQ) = "movswq"
287 | asm_move (I.MOVZWQ) = "movzwq"
288 | asm_move (I.MOVSWL) = "movswl"
289 | asm_move (I.MOVZWL) = "movzwl"
290 | asm_move (I.MOVSBQ) = "movsbq"
291 | asm_move (I.MOVZBQ) = "movzbq"
292 | asm_move (I.MOVSBL) = "movsbl"
293 | asm_move (I.MOVZBL) = "movzbl"
294 | asm_move (I.MOVSLQ) = "movslq"
295 | asm_move (I.CVTSD2SI) = "cvtsd2si"
296 | asm_move (I.CVTSS2SI) = "cvtss2si"
297 | asm_move (I.CVTSD2SIQ) = "cvtsd2siq"
298 | asm_move (I.CVTSS2SIQ) = "cvtss2siq"
299 and emit_move x = emit (asm_move x)
300 and asm_fbin_op (I.ADDSS) = "addss"
301 | asm_fbin_op (I.ADDSD) = "addsd"
302 | asm_fbin_op (I.SUBSS) = "subss"
303 | asm_fbin_op (I.SUBSD) = "subsd"
304 | asm_fbin_op (I.MULSS) = "mulss"
305 | asm_fbin_op (I.MULSD) = "mulsd"
306 | asm_fbin_op (I.DIVSS) = "divss"
307 | asm_fbin_op (I.DIVSD) = "divsd"
308 | asm_fbin_op (I.XORPS) = "xorps"
309 | asm_fbin_op (I.XORPD) = "xorpd"
310 | asm_fbin_op (I.ANDPS) = "andps"
311 | asm_fbin_op (I.ANDPD) = "andpd"
312 | asm_fbin_op (I.ORPS) = "orps"
313 | asm_fbin_op (I.ORPD) = "orpd"
314 and emit_fbin_op x = emit (asm_fbin_op x)
315 and asm_fcom_op (I.COMISS) = "comiss"
316 | asm_fcom_op (I.COMISD) = "comisd"
317 | asm_fcom_op (I.UCOMISS) = "ucomiss"
318 | asm_fcom_op (I.UCOMISD) = "ucomisd"
319 and emit_fcom_op x = emit (asm_fcom_op x)
320 and asm_fmove_op (I.MOVSS) = "movss"
321 | asm_fmove_op (I.MOVSD) = "movsd"
322 | asm_fmove_op (I.CVTSS2SD) = "cvtss2sd"
323 | asm_fmove_op (I.CVTSD2SS) = "cvtsd2ss"
324 | asm_fmove_op (I.CVTSI2SS) = "cvtsi2ss"
325 | asm_fmove_op (I.CVTSI2SSQ) = "cvtsi2ssq"
326 | asm_fmove_op (I.CVTSI2SD) = "cvtsi2sd"
327 | asm_fmove_op (I.CVTSI2SDQ) = "cvtsi2sdq"
328 and emit_fmove_op x = emit (asm_fmove_op x)
329 and asm_fsize (I.FP32) = "s"
330 | asm_fsize (I.FP64) = "l"
331 and emit_fsize x = emit (asm_fsize x)
332 and asm_isize (I.I8) = "8"
333 | asm_isize (I.I16) = "16"
334 | asm_isize (I.I32) = "32"
335 | asm_isize (I.I64) = "64"
336 and emit_isize x = emit (asm_isize x)
337
338 (*#line 506.7 "amd64/amd64.mdl"*)
339 fun emitInt32 i =
340 let
341 (*#line 507.11 "amd64/amd64.mdl"*)
342 val s = Int32.toString i
343
344 (*#line 508.11 "amd64/amd64.mdl"*)
345 val s = (if (i >= 0)
346 then s
347 else ("-" ^ (String.substring (s, 1, (size s) - 1))))
348 in emit s
349 end
350
351 (*#line 512.7 "amd64/amd64.mdl"*)
352 fun emitInt64 i =
353 let
354 (*#line 513.11 "amd64/amd64.mdl"*)
355 val s = Int64.toString i
356
357 (*#line 514.11 "amd64/amd64.mdl"*)
358 val s = (if (i >= 0)
359 then s
360 else ("-" ^ (String.substring (s, 1, (size s) - 1))))
361 in emit s
362 end
363
364 (*#line 519.7 "amd64/amd64.mdl"*)
365 val {low=SToffset, ...} = C.cellRange CellsBasis.FP
366
367 (*#line 521.7 "amd64/amd64.mdl"*)
368 fun emitScale 0 = emit "1"
369 | emitScale 1 = emit "2"
370 | emitScale 2 = emit "4"
371 | emitScale 3 = emit "8"
372 | emitScale _ = error "emitScale"
373 and eImmed (I.Immed i) = emitInt32 i
374 | eImmed (I.Immed64 i) = emitInt64 i
375 | eImmed (I.ImmedLabel lexp) = emit_labexp lexp
376 | eImmed _ = error "eImmed"
377 and emit_operand opn =
378 (case opn of
379 I.Immed i =>
380 ( emit "$";
381 emitInt32 i )
382 | I.Immed64 i =>
383 ( emit "$";
384 emitInt64 i )
385 | I.ImmedLabel lexp =>
386 ( emit "$";
387 emit_labexp lexp )
388 | I.LabelEA le => emit_labexp le
389 | I.Relative _ => error "emit_operand"
390 | I.Direct(ty, r) => emit (CellsBasis.toStringWithSize (r, ty))
391 | I.FDirect f => emit (CellsBasis.toString f)
392 | I.Displace{base, disp, mem, ...} =>
393 ( emit_disp disp;
394 emit "(";
395 emitCell base;
396 emit ")";
397 emit_region mem )
398 | I.Indexed{base, index, scale, disp, mem, ...} =>
399 ( emit_disp disp;
400 emit "(";
401
402 (case base of
403 NONE => ()
404 | SOME base => emitCell base
405 );
406 comma ();
407 emitCell index;
408 comma ();
409 emitScale scale;
410 emit ")";
411 emit_region mem )
412 )
413 and emit_operand8 (I.Direct(_, r)) = emit (CellsBasis.toStringWithSize (r,
414 8))
415 | emit_operand8 opn = emit_operand opn
416 and emit_cell (r, sz) = emit (CellsBasis.toStringWithSize (r, sz))
417 and emit_disp (I.Immed 0) = ()
418 | emit_disp (I.Immed i) = emitInt32 i
419 | emit_disp (I.Immed64 0) = ()
420 | emit_disp (I.Immed64 i) = emitInt64 i
421 | emit_disp (I.ImmedLabel lexp) = emit_labexp lexp
422 | emit_disp _ = error "emit_disp"
423
424 (*#line 569.7 "amd64/amd64.mdl"*)
425 fun stupidGas (I.ImmedLabel lexp) = emit_labexp lexp
426 | stupidGas opnd =
427 ( emit "*";
428 emit_operand opnd )
429
430 (*#line 573.7 "amd64/amd64.mdl"*)
431 fun isMemOpnd (I.FDirect f) = true
432 | isMemOpnd (I.LabelEA _) = true
433 | isMemOpnd (I.Displace _) = true
434 | isMemOpnd (I.Indexed _) = true
435 | isMemOpnd _ = false
436
437 (*#line 578.7 "amd64/amd64.mdl"*)
438 fun chop fbinOp =
439 let
440 (*#line 579.15 "amd64/amd64.mdl"*)
441 val n = size fbinOp
442 in
443 (case Char.toLower (String.sub (fbinOp, n - 1)) of
444 (#"s" | #"l") => String.substring (fbinOp, 0, n - 1)
445 | _ => fbinOp
446 )
447 end
448
449 (*#line 585.7 "amd64/amd64.mdl"*)
450 val emit_dst = emit_operand
451
452 (*#line 586.7 "amd64/amd64.mdl"*)
453 val emit_src = emit_operand
454
455 (*#line 587.7 "amd64/amd64.mdl"*)
456 val emit_opnd = emit_operand
457
458 (*#line 588.7 "amd64/amd64.mdl"*)
459 val emit_opnd8 = emit_operand8
460
461 (*#line 589.7 "amd64/amd64.mdl"*)
462 val emit_rsrc = emit_operand
463
464 (*#line 590.7 "amd64/amd64.mdl"*)
465 val emit_lsrc = emit_operand
466
467 (*#line 591.7 "amd64/amd64.mdl"*)
468 val emit_addr = emit_operand
469
470 (*#line 592.7 "amd64/amd64.mdl"*)
471 val emit_src1 = emit_operand
472
473 (*#line 593.7 "amd64/amd64.mdl"*)
474 val emit_ea = emit_operand
475
476 (*#line 594.7 "amd64/amd64.mdl"*)
477 val emit_count = emit_operand
478
479 (*#line 595.7 "amd64/amd64.mdl"*)
480 fun emit_byte b =
481 ( emit "$0x";
482 emit (Word8.toString b))
483 fun emitInstr' instr =
484 (case instr of
485 I.NOP => emit "nop"
486 | I.JMP(operand, list) =>
487 ( emit "jmp\t";
488 stupidGas operand )
489 | I.JCC{cond, opnd} =>
490 ( emit "j";
491 emit_cond cond;
492 emit "\t";
493 stupidGas opnd )
494 | I.CALL{opnd, defs, uses, return, cutsTo, mem, pops} =>
495 ( emit "call\t";
496 stupidGas opnd;
497 emit_region mem;
498 emit_defs defs;
499 emit_uses uses;
500 emit_cellset ("return", return);
501 emit_cutsTo cutsTo )
502 | I.ENTER{src1, src2} =>
503 ( emit "enter\t";
504 emit_operand src1;
505 emit ", ";
506 emit_operand src2 )
507 | I.LEAVE => emit "leave"
508 | I.RET option =>
509 ( emit "ret";
510
511 (case option of
512 NONE => ()
513 | SOME e =>
514 ( emit "\t";
515 emit_operand e )
516 ))
517 | I.MOVE{mvOp, src, dst} =>
518 ( emit_move mvOp;
519 emit "\t";
520 emit_src src;
521 emit ", ";
522 emit_dst dst )
523 | I.LEAL{r32, addr} =>
524 ( emit "leal\t";
525 emit_addr addr;
526 emit ", ";
527 emit_cell (r32, 32))
528 | I.LEAQ{r64, addr} =>
529 ( emit "leaq\t";
530 emit_addr addr;
531 emit ", ";
532 emit_cell (r64, 64))
533 | I.CMPQ{lsrc, rsrc} =>
534 ( emit "cmpq\t";
535 emit_rsrc rsrc;
536 emit ", ";
537 emit_lsrc lsrc )
538 | I.CMPL{lsrc, rsrc} =>
539 ( emit "cmpl\t";
540 emit_rsrc rsrc;
541 emit ", ";
542 emit_lsrc lsrc )
543 | I.CMPW{lsrc, rsrc} =>
544 ( emit "cmpb\t";
545 emit_rsrc rsrc;
546 emit ", ";
547 emit_lsrc lsrc )
548 | I.CMPB{lsrc, rsrc} =>
549 ( emit "cmpb\t";
550 emit_rsrc rsrc;
551 emit ", ";
552 emit_lsrc lsrc )
553 | I.TESTQ{lsrc, rsrc} =>
554 ( emit "testq\t";
555 emit_rsrc rsrc;
556 emit ", ";
557 emit_lsrc lsrc )
558 | I.TESTL{lsrc, rsrc} =>
559 ( emit "testl\t";
560 emit_rsrc rsrc;
561 emit ", ";
562 emit_lsrc lsrc )
563 | I.TESTW{lsrc, rsrc} =>
564 ( emit "testw\t";
565 emit_rsrc rsrc;
566 emit ", ";
567 emit_lsrc lsrc )
568 | I.TESTB{lsrc, rsrc} =>
569 ( emit "testb\t";
570 emit_rsrc rsrc;
571 emit ", ";
572 emit_lsrc lsrc )
573 | I.BITOP{bitOp, lsrc, rsrc} =>
574 ( emit_bitOp bitOp;
575 emit "\t";
576 emit_rsrc rsrc;
577 emit ", ";
578 emit_lsrc lsrc )
579 | I.BINARY{binOp, src, dst} =>
580 (case (src, binOp) of
581 (I.Direct _,
582 ( I.SARQ |
583 I.SHRQ |
584 I.SHLQ |
585 I.SARL |
586 I.SHRL |
587 I.SHLL |
588 I.SARW |
589 I.SHRW |
590 I.SHLW |
591 I.SARB |
592 I.SHRB |
593 I.SHLB )) =>
594 ( emit_binaryOp binOp;
595 emit "\t%cl, ";
596 emit_dst dst )
597 | _ =>
598 ( emit_binaryOp binOp;
599 emit "\t";
600 emit_src src;
601 emit ", ";
602 emit_dst dst )
603 )
604 | I.SHIFT{shiftOp, src, dst, count} =>
605 (case count of
606 I.Direct(ty, ecx) =>
607 ( emit_shiftOp shiftOp;
608 emit "\t";
609 emit_src src;
610 emit ", ";
611 emit_dst dst )
612 | _ =>
613 ( emit_shiftOp shiftOp;
614 emit "\t";
615 emit_src src;
616 emit ", ";
617 emit_count count;
618 emit ", ";
619 emit_dst dst )
620 )
621 | I.MULTDIV{multDivOp, src} =>
622 ( emit_multDivOp multDivOp;
623 emit "\t";
624 emit_src src )
625 | I.MUL3{dst, src2, src1} =>
626 ( emit "imull\t$";
627 emitInt32 src2;
628 emit ", ";
629 emit_src1 src1;
630 emit ", ";
631 emit_cell (dst, 32))
632 | I.MULQ3{dst, src2, src1} =>
633 ( emit "imulq\t$";
634 emitInt32 src2;
635 emit ", ";
636 emit_src1 src1;
637 emit ", ";
638 emit_cell (dst, 64))
639 | I.UNARY{unOp, opnd} =>
640 ( emit_unaryOp unOp;
641 emit "\t";
642 emit_opnd opnd )
643 | I.SET{cond, opnd} =>
644 ( emit "set";
645 emit_cond cond;
646 emit "\t";
647 emit_opnd8 opnd )
648 | I.CMOV{cond, src, dst} =>
649 ( emit "cmov";
650 emit_cond cond;
651 emit "\t";
652 emit_src src;
653 emit ", ";
654 emitCell dst )
655 | I.PUSH operand =>
656 ( emit "pushq\t";
657 emit_operand operand )
658 | I.PUSHFQ => emit "pushfq"
659 | I.POPFQ => emit "popfq"
660 | I.POP operand =>
661 ( emit "popq\t";
662 emit_operand operand )
663 | I.CDQ => emit "cdq"
664 | I.CDO => emit "cdo"
665 | I.INT byte =>
666 ( emit "int\t";
667 emit_byte byte )
668 | I.FMOVE{fmvOp, dst, src} =>
669 ( emit_fmove_op fmvOp;
670 emit "\t ";
671 emit_src src;
672 emit ", ";
673 emit_dst dst )
674 | I.FBINOP{binOp, dst, src} =>
675 ( emit_fbin_op binOp;
676 emit "\t ";
677 emit_src src;
678 emit ", ";
679 emitCell dst )
680 | I.FCOM{comOp, dst, src} =>
681 ( emit_fcom_op comOp;
682 emit "\t ";
683 emit_src src;
684 emit ", ";
685 emitCell dst )
686 | I.FSQRTS{dst, src} =>
687 ( emit "sqrtss\t ";
688 emit_src src;
689 emit ", ";
690 emit_dst dst )
691 | I.FSQRTD{dst, src} =>
692 ( emit "sqrtsd\t ";
693 emit_src src;
694 emit ", ";
695 emit_dst dst )
696 | I.SAHF => emit "sahf"
697 | I.LFENCE => emit "lfence"
698 | I.MFENCE => emit "mfence"
699 | I.SFENCE => emit "sfence"
700 | I.PAUSE => emit "pause"
701 | I.XCHG{lock, sz, src, dst} =>
702 ( (if lock
703 then (emit "lock\n\t")
704 else ());
705 emit "xchg";
706
707 (case sz of
708 I.I8 => emit "b"
709 | I.I16 => emit "w"
710 | I.I32 => emit "l"
711 | I.I64 => emit "q"
712 );
713
714 ( emit "\t";
715 emit_src src;
716 emit ", ";
717 emit_dst dst ) )
718 | I.CMPXCHG{lock, sz, src, dst} =>
719 ( (if lock
720 then (emit "lock\n\t")
721 else ());
722 emit "cmpxchg";
723
724 (case sz of
725 I.I8 => emit "b"
726 | I.I16 => emit "w"
727 | I.I32 => emit "l"
728 | I.I64 => emit "q"
729 );
730
731 ( emit "\t";
732 emit_src src;
733 emit ", ";
734 emit_dst dst ) )
735 | I.XADD{lock, sz, src, dst} =>
736 ( (if lock
737 then (emit "lock\n\t")
738 else ());
739 emit "xadd";
740
741 (case sz of
742 I.I8 => emit "b"
743 | I.I16 => emit "w"
744 | I.I32 => emit "l"
745 | I.I64 => emit "q"
746 );
747
748 ( emit "\t";
749 emit_src src;
750 emit ", ";
751 emit_dst dst ) )
752 | I.RDTSC => emit "rdtsc"
753 | I.RDTSCP => emit "rdtscp"
754 | I.LAHF => emit "lahf"
755 | I.SOURCE{} => emit "source"
756 | I.SINK{} => emit "sink"
757 | I.PHI{} => emit "phi"
758 )
759 in tab(); emitInstr' instr; nl()
760 end (* emitter *)
761 and emitInstrIndented i = (indent(); emitInstr i; nl())
762 and emitInstrs instrs =
763 app (if !indent_copies then emitInstrIndented
764 else emitInstr) instrs
765
766 and emitInstr(I.ANNOTATION{i,a}) =
767 ( comment(Annotations.toString a);
768 nl();
769 emitInstr i )
770 | emitInstr(I.LIVE{regs, spilled}) =
771 comment("live= " ^ CellsBasis.CellSet.toString regs ^
772 "spilled= " ^ CellsBasis.CellSet.toString spilled)
773 | emitInstr(I.KILL{regs, spilled}) =
774 comment("killed:: " ^ CellsBasis.CellSet.toString regs ^
775 "spilled:: " ^ CellsBasis.CellSet.toString spilled)
776 | emitInstr(I.INSTR i) = emitter i
777 | emitInstr(I.COPY{k=CellsBasis.GP, sz, src, dst, tmp}) =
778 emitInstrs(Shuffle.shuffle{tmp=tmp, src=src, dst=dst})
779 | emitInstr(I.COPY{k=CellsBasis.FP, sz, src, dst, tmp}) =
780 emitInstrs(Shuffle.shufflefp{tmp=tmp, src=src, dst=dst})
781 | emitInstr _ = error "emitInstr"
782
783 in S.STREAM{beginCluster=init,
784 pseudoOp=pseudoOp,
785 emit=emitInstr,
786 endCluster=fail,
787 defineLabel=defineLabel,
788 entryLabel=entryLabel,
789 comment=comment,
790 exitBlock=doNothing,
791 annotation=annotation,
792 getAnnotations=getAnnotations
793 }
794 end
795 end
796