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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/x86/emit/x86MC.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/x86/emit/x86MC.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 797 - (view) (download)

1 : monnier 429 (*
2 : leunga 744 * WARNING: This file was automatically generated by MDLGen (v3.0)
3 :     * from the machine description file "x86/x86.mdl".
4 :     * DO NOT EDIT this file directly
5 : monnier 247 *)
6 :    
7 :    
8 : monnier 429 functor X86MCEmitter(structure Instr : X86INSTR
9 :     structure CodeString : CODE_STRING
10 :     ) : INSTRUCTION_EMITTER =
11 :     struct
12 :     structure I = Instr
13 :     structure C = I.C
14 : leunga 775 structure LabelExp = I.LabelExp
15 : monnier 429 structure Constant = I.Constant
16 : leunga 775 structure T = I.T
17 :     structure S = T.Stream
18 : monnier 429 structure P = S.P
19 :     structure W = Word32
20 :    
21 : george 545 (* X86 is little endian *)
22 : monnier 429
23 :     fun error msg = MLRiscErrorMsg.error("X86MC",msg)
24 :     fun makeStream _ =
25 :     let infix && || << >> ~>>
26 :     val op << = W.<<
27 :     val op >> = W.>>
28 :     val op ~>> = W.~>>
29 :     val op || = W.orb
30 :     val op && = W.andb
31 :     val itow = W.fromInt
32 :     fun emit_bool false = 0w0 : W.word
33 :     | emit_bool true = 0w1 : W.word
34 :     val emit_int = itow
35 :     fun emit_word w = w
36 :     fun emit_label l = itow(Label.addrOf l)
37 :     fun emit_labexp le = itow(LabelExp.valueOf le)
38 :     fun emit_const c = itow(Constant.valueOf c)
39 :     val loc = ref 0
40 :    
41 :     (* emit a byte *)
42 :     fun eByte b =
43 :     let val i = !loc in loc := i + 1; CodeString.update(i,b) end
44 :    
45 :     (* emit the low order byte of a word *)
46 :     (* note: fromLargeWord strips the high order bits! *)
47 :     fun eByteW w =
48 :     let val i = !loc
49 :     in loc := i + 1; CodeString.update(i,Word8.fromLargeWord w) end
50 :    
51 :     fun doNothing _ = ()
52 :    
53 :     fun pseudoOp pOp = P.emitValue{pOp=pOp, loc= !loc,emit=eByte}
54 :    
55 :     fun init n = (CodeString.init n; loc := 0)
56 :    
57 :    
58 : leunga 744 fun eWord8 w =
59 :     let val b8 = w
60 : leunga 583 in eByteW b8
61 :     end
62 : leunga 744 and eWord16 w =
63 :     let val b8 = w
64 :     val w = w >> 0wx8
65 :     val b16 = w
66 : leunga 583 in
67 :     ( eByteW b8;
68 : leunga 744 eByteW b16 )
69 : leunga 583 end
70 : leunga 744 and eWord32 w =
71 :     let val b8 = w
72 :     val w = w >> 0wx8
73 :     val b16 = w
74 :     val w = w >> 0wx8
75 :     val b24 = w
76 :     val w = w >> 0wx8
77 :     val b32 = w
78 :     in
79 :     ( eByteW b8;
80 :     eByteW b16;
81 :     eByteW b24;
82 :     eByteW b32 )
83 :     end
84 :     fun emit_GP r = itow (C.physicalRegisterNum r)
85 :     and emit_FP r = itow (C.physicalRegisterNum r)
86 :     and emit_CC r = itow (C.physicalRegisterNum r)
87 :     and emit_EFLAGS r = itow (C.physicalRegisterNum r)
88 :     and emit_FFLAGS r = itow (C.physicalRegisterNum r)
89 :     and emit_MEM r = itow (C.physicalRegisterNum r)
90 :     and emit_CTRL r = itow (C.physicalRegisterNum r)
91 :     and emit_CELLSET r = itow (C.physicalRegisterNum r)
92 :     fun emit_cond (I.EQ) = (0wx4 : Word32.word)
93 :     | emit_cond (I.NE) = (0wx5 : Word32.word)
94 :     | emit_cond (I.LT) = (0wxc : Word32.word)
95 :     | emit_cond (I.LE) = (0wxe : Word32.word)
96 :     | emit_cond (I.GT) = (0wxf : Word32.word)
97 :     | emit_cond (I.GE) = (0wxd : Word32.word)
98 :     | emit_cond (I.B) = (0wx2 : Word32.word)
99 :     | emit_cond (I.BE) = (0wx6 : Word32.word)
100 :     | emit_cond (I.A) = (0wx7 : Word32.word)
101 :     | emit_cond (I.AE) = (0wx3 : Word32.word)
102 :     | emit_cond (I.C) = (0wx2 : Word32.word)
103 :     | emit_cond (I.NC) = (0wx3 : Word32.word)
104 :     | emit_cond (I.P) = (0wxa : Word32.word)
105 :     | emit_cond (I.NP) = (0wxb : Word32.word)
106 :     | emit_cond (I.O) = (0wx0 : Word32.word)
107 :     | emit_cond (I.NO) = (0wx1 : Word32.word)
108 :     and emit_fibinOp (I.FIADDS) = (0wxde, 0)
109 :     | emit_fibinOp (I.FIMULS) = (0wxde, 1)
110 :     | emit_fibinOp (I.FICOMS) = (0wxde, 2)
111 :     | emit_fibinOp (I.FICOMPS) = (0wxde, 3)
112 :     | emit_fibinOp (I.FISUBS) = (0wxde, 4)
113 :     | emit_fibinOp (I.FISUBRS) = (0wxde, 5)
114 :     | emit_fibinOp (I.FIDIVS) = (0wxde, 6)
115 :     | emit_fibinOp (I.FIDIVRS) = (0wxde, 7)
116 :     | emit_fibinOp (I.FIADDL) = (0wxda, 0)
117 :     | emit_fibinOp (I.FIMULL) = (0wxda, 1)
118 :     | emit_fibinOp (I.FICOML) = (0wxda, 2)
119 :     | emit_fibinOp (I.FICOMPL) = (0wxda, 3)
120 :     | emit_fibinOp (I.FISUBL) = (0wxda, 4)
121 :     | emit_fibinOp (I.FISUBRL) = (0wxda, 5)
122 :     | emit_fibinOp (I.FIDIVL) = (0wxda, 6)
123 :     | emit_fibinOp (I.FIDIVRL) = (0wxda, 7)
124 :     and emit_funOp (I.FCHS) = (0wxe0 : Word32.word)
125 :     | emit_funOp (I.FABS) = (0wxe1 : Word32.word)
126 :     | emit_funOp (I.FTST) = (0wxe4 : Word32.word)
127 :     | emit_funOp (I.FXAM) = (0wxe5 : Word32.word)
128 :     | emit_funOp (I.FPTAN) = (0wxf2 : Word32.word)
129 :     | emit_funOp (I.FPATAN) = (0wxf3 : Word32.word)
130 :     | emit_funOp (I.FXTRACT) = (0wxf4 : Word32.word)
131 :     | emit_funOp (I.FPREM1) = (0wxf5 : Word32.word)
132 :     | emit_funOp (I.FDECSTP) = (0wxf6 : Word32.word)
133 :     | emit_funOp (I.FINCSTP) = (0wxf7 : Word32.word)
134 :     | emit_funOp (I.FPREM) = (0wxf8 : Word32.word)
135 :     | emit_funOp (I.FYL2XP1) = (0wxf9 : Word32.word)
136 :     | emit_funOp (I.FSQRT) = (0wxfa : Word32.word)
137 :     | emit_funOp (I.FSINCOS) = (0wxfb : Word32.word)
138 :     | emit_funOp (I.FRNDINT) = (0wxfc : Word32.word)
139 :     | emit_funOp (I.FSCALE) = (0wxfd : Word32.word)
140 :     | emit_funOp (I.FSIN) = (0wxfe : Word32.word)
141 :     | emit_funOp (I.FCOS) = (0wxff : Word32.word)
142 : leunga 583 fun modrm {mod, reg, rm} = eWord8 ((op mod << 0wx6) + ((reg << 0wx3) + rm))
143 : leunga 731 and reg {opc, reg} = eWord8 ((opc << 0wx3) + reg)
144 : leunga 583 and sib {ss, index, base} = eWord8 ((ss << 0wx6) + ((index << 0wx3) + base))
145 :     and immed8 {imm} = eWord8 imm
146 :     and immed32 {imm} = eWord32 imm
147 : leunga 744 and immedOpnd {opnd} =
148 :     (case opnd of
149 :     I.Immed i32 => i32
150 :     | I.ImmedLabel le => lexp le
151 :     | I.LabelEA le => lexp le
152 :     | _ => error "immedOpnd"
153 :     )
154 :     and extension {opc, opnd} =
155 :     (case opnd of
156 :     I.Direct r => modrm {mod=3, reg=opc, rm=r}
157 :     | I.MemReg _ => extension {opc=opc, opnd=memReg opnd}
158 :     | I.FDirect _ => extension {opc=opc, opnd=memReg opnd}
159 :     | I.Displace{base, disp, ...} =>
160 :     let
161 : leunga 797 (*#line 470.13 "x86/x86.mdl"*)
162 : leunga 744 val immed = immedOpnd {opnd=disp}
163 :     in ()
164 :     end
165 :     | I.Indexed{base=NONE, index, scale, disp, ...} => ()
166 :     | I.Indexed{base=SOME b, index, scale, disp, ...} => ()
167 :     | _ => error "immedExt"
168 :     )
169 :     and encodeST {prefix, opc, st} =
170 :     let val st = emit_FP st
171 :     in eWord16 ((prefix << 0wx8) + ((opc << 0wx3) + st))
172 :     end
173 :     and encodeReg {prefix, reg, opnd} =
174 :     let val reg = emit_GP reg
175 :     in
176 :     ( emit prefix;
177 :     immedExt {opc=reg, opnd=opnd})
178 :     end
179 :     and arith {opc1, opc2, src, dst} =
180 :     (case (src, dst) of
181 :     (I.ImmedLabel le, dst) => arith {opc1=opc1, opc2=opc2, src=I.Immed (lexp le),
182 :     dst=dst}
183 :     | (I.LabelEA le, dst) => arith {opc1=opc1, opc2=opc2, src=I.Immed (lexp le),
184 :     dst=dst}
185 :     | (I.Immed i, dst) => ()
186 :     | (src, I.Direct r) => encodeReg {prefix=opc1 + op3, reg=reg, opnd=src}
187 :     | (I.Direct r, dst) => encodeReg {prefix=opc1 + 0wx1, reg=reg, opnd=dst}
188 :     | _ => error "arith"
189 :     )
190 :     fun emitter instr =
191 :     let
192 : george 545 fun emitInstr (I.NOP) = error "NOP"
193 : leunga 744 | emitInstr (I.JMP(operand, list)) = error "JMP"
194 : george 545 | emitInstr (I.JCC{cond, opnd}) = error "JCC"
195 : leunga 796 | emitInstr (I.CALL{opnd, defs, uses, cutsTo, mem}) = error "CALL"
196 : leunga 594 | emitInstr (I.ENTER{src1, src2}) = error "ENTER"
197 : george 545 | emitInstr (I.LEAVE) = error "LEAVE"
198 : leunga 744 | emitInstr (I.RET option) = error "RET"
199 : george 545 | emitInstr (I.MOVE{mvOp, src, dst}) = error "MOVE"
200 :     | emitInstr (I.LEA{r32, addr}) = error "LEA"
201 :     | emitInstr (I.CMPL{lsrc, rsrc}) = error "CMPL"
202 :     | emitInstr (I.CMPW{lsrc, rsrc}) = error "CMPW"
203 :     | emitInstr (I.CMPB{lsrc, rsrc}) = error "CMPB"
204 :     | emitInstr (I.TESTL{lsrc, rsrc}) = error "TESTL"
205 :     | emitInstr (I.TESTW{lsrc, rsrc}) = error "TESTW"
206 :     | emitInstr (I.TESTB{lsrc, rsrc}) = error "TESTB"
207 : leunga 646 | emitInstr (I.BITOP{bitOp, lsrc, rsrc}) = error "BITOP"
208 : george 545 | emitInstr (I.BINARY{binOp, src, dst}) = error "BINARY"
209 : leunga 797 | emitInstr (I.CMPXCHG{lock, sz, src, dst}) = error "CMPXCHG"
210 : george 545 | emitInstr (I.MULTDIV{multDivOp, src}) = error "MULTDIV"
211 :     | emitInstr (I.MUL3{dst, src2, src1}) = error "MUL3"
212 :     | emitInstr (I.UNARY{unOp, opnd}) = error "UNARY"
213 :     | emitInstr (I.SET{cond, opnd}) = error "SET"
214 :     | emitInstr (I.CMOV{cond, src, dst}) = error "CMOV"
215 :     | emitInstr (I.PUSHL operand) = error "PUSHL"
216 :     | emitInstr (I.PUSHW operand) = error "PUSHW"
217 :     | emitInstr (I.PUSHB operand) = error "PUSHB"
218 :     | emitInstr (I.POP operand) = error "POP"
219 :     | emitInstr (I.CDQ) = error "CDQ"
220 :     | emitInstr (I.INTO) = error "INTO"
221 : leunga 744 | emitInstr (I.COPY{dst, src, tmp}) = emitInstrs (Shuffle.shuffle {tmp=tmp,
222 :     dst=dst, src=src})
223 :     | emitInstr (I.FCOPY{dst, src, tmp}) = emitInstrs (Shuffle.shuffle {tmp=tmp,
224 :     dst=dst, src=src})
225 : george 545 | emitInstr (I.FBINARY{binOp, src, dst}) = error "FBINARY"
226 : leunga 583 | emitInstr (I.FIBINARY{binOp, src}) = error "FIBINARY"
227 : george 545 | emitInstr (I.FUNARY funOp) = error "FUNARY"
228 : leunga 731 | emitInstr (I.FUCOM operand) = error "FUCOM"
229 :     | emitInstr (I.FUCOMP operand) = error "FUCOMP"
230 : george 545 | emitInstr (I.FUCOMPP) = error "FUCOMPP"
231 :     | emitInstr (I.FCOMPP) = error "FCOMPP"
232 :     | emitInstr (I.FXCH{opnd}) = error "FXCH"
233 :     | emitInstr (I.FSTPL operand) = error "FSTPL"
234 :     | emitInstr (I.FSTPS operand) = error "FSTPS"
235 : george 555 | emitInstr (I.FSTPT operand) = error "FSTPT"
236 : leunga 583 | emitInstr (I.FSTL operand) = error "FSTL"
237 :     | emitInstr (I.FSTS operand) = error "FSTS"
238 :     | emitInstr (I.FLD1) = error "FLD1"
239 :     | emitInstr (I.FLDL2E) = error "FLDL2E"
240 :     | emitInstr (I.FLDL2T) = error "FLDL2T"
241 :     | emitInstr (I.FLDLG2) = error "FLDLG2"
242 :     | emitInstr (I.FLDLN2) = error "FLDLN2"
243 :     | emitInstr (I.FLDPI) = error "FLDPI"
244 :     | emitInstr (I.FLDZ) = error "FLDZ"
245 : george 545 | emitInstr (I.FLDL operand) = error "FLDL"
246 :     | emitInstr (I.FLDS operand) = error "FLDS"
247 : george 555 | emitInstr (I.FLDT operand) = error "FLDT"
248 : george 545 | emitInstr (I.FILD operand) = error "FILD"
249 : leunga 583 | emitInstr (I.FILDL operand) = error "FILDL"
250 :     | emitInstr (I.FILDLL operand) = error "FILDLL"
251 : george 545 | emitInstr (I.FNSTSW) = error "FNSTSW"
252 :     | emitInstr (I.FENV{fenvOp, opnd}) = error "FENV"
253 : leunga 731 | emitInstr (I.FMOVE{fsize, src, dst}) = error "FMOVE"
254 :     | emitInstr (I.FILOAD{isize, ea, dst}) = error "FILOAD"
255 :     | emitInstr (I.FBINOP{fsize, binOp, lsrc, rsrc, dst}) = error "FBINOP"
256 :     | emitInstr (I.FIBINOP{isize, binOp, lsrc, rsrc, dst}) = error "FIBINOP"
257 :     | emitInstr (I.FUNOP{fsize, unOp, src, dst}) = error "FUNOP"
258 :     | emitInstr (I.FCMP{fsize, lsrc, rsrc}) = error "FCMP"
259 : george 545 | emitInstr (I.SAHF) = error "SAHF"
260 :     | emitInstr (I.ANNOTATION{i, a}) = error "ANNOTATION"
261 : leunga 624 | emitInstr (I.SOURCE{}) = ()
262 :     | emitInstr (I.SINK{}) = ()
263 :     | emitInstr (I.PHI{}) = ()
264 : monnier 247 in
265 : leunga 744 emitInstr instr
266 : monnier 247 end
267 : monnier 429
268 :     in S.STREAM{beginCluster=init,
269 :     pseudoOp=pseudoOp,
270 :     emit=emitter,
271 :     endCluster=doNothing,
272 :     defineLabel=doNothing,
273 :     entryLabel=doNothing,
274 :     comment=doNothing,
275 :     exitBlock=doNothing,
276 : leunga 744 annotation=doNothing
277 : monnier 429 }
278 :     end
279 :     end
280 : monnier 247

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0