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/branches/SMLNJ/src/MLRISC/x86/emit/x86Asm.sml
ViewVC logotype

Annotation of /sml/branches/SMLNJ/src/MLRISC/x86/emit/x86Asm.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 411 - (view) (download)

1 : monnier 411 (*
2 :     * This file was automatically generated by MDGen
3 :     * from the machine description file "x86/x86.md".
4 : monnier 247 *)
5 :    
6 :    
7 : monnier 411 functor X86AsmEmitter(structure Instr : X86INSTR
8 :     structure Stream : INSTRUCTION_STREAM
9 :     structure Shuffle : X86SHUFFLE
10 :     where I = Instr
11 :    
12 :     (*#line 140.1 "x86/x86.md"*)
13 :     structure MemRegs : MEMORY_REGISTERS where I=Instr
14 :     ) : INSTRUCTION_EMITTER =
15 : monnier 247 struct
16 : monnier 411 structure I = Instr
17 :     structure C = I.C
18 :     structure S = Stream
19 :     structure P = S.P
20 :     structure LE = LabelExp
21 :     structure Constant = I.Constant
22 :    
23 :     fun error msg = MLRiscErrorMsg.error("X86Asm",msg)
24 :    
25 :     fun makeStream() =
26 :     let val stream = !AsmStream.asmOutStream
27 :     fun emit s = TextIO.output(stream,s)
28 :     fun nl() = emit "\n"
29 :     fun comma() = emit ","
30 :     fun tab() = emit "\t"
31 :     fun ms n = if n<0 then "-"^Int.toString(~n)
32 :     else Int.toString n
33 :     fun emit_label lab = emit(Label.nameOf lab)
34 :     fun emit_labexp le = emit(LabelExp.toString le)
35 :     fun emit_const c = emit(Constant.toString c)
36 :     fun emit_int i = emit(ms i)
37 :     fun paren f = (emit "("; f(); emit ")")
38 :     fun defineLabel lab = emit(Label.nameOf lab^":\n")
39 :     fun entryLabel lab = defineLabel lab
40 :     fun comment msg = emit("\t/* " ^ msg ^ " */")
41 :     fun annotation a = (comment(Annotations.toString a); nl())
42 :     fun blockName b = (comment(S.B.toString b); nl())
43 :     fun emit_region mem = comment(I.Region.toString mem)
44 :     fun pseudoOp pOp = emit(P.toString pOp)
45 :     fun init size = (comment("Code Size = " ^ ms size); nl())
46 :     fun doNothing _ = ()
47 :     fun emitter regmap =
48 :     let
49 : monnier 247
50 : monnier 411 fun emit_CC r = (emit (C.showCC (regmap r)))
51 :     and emit_GP r = (emit (C.showGP (regmap r)))
52 :     and emit_FP r = (emit (C.showFP (regmap r)))
53 : monnier 247
54 : monnier 411 fun asm_fbinOp (I.FADDP) = "faddp"
55 :     | asm_fbinOp (I.FADD) = "fadd"
56 :     | asm_fbinOp (I.FMULP) = "fmulp"
57 :     | asm_fbinOp (I.FMUL) = "fmul"
58 :     | asm_fbinOp (I.FSUBP) = "fsubp"
59 :     | asm_fbinOp (I.FSUB) = "fsub"
60 :     | asm_fbinOp (I.FSUBRP) = "fsubrp"
61 :     | asm_fbinOp (I.FSUBR) = "fsubr"
62 :     | asm_fbinOp (I.FDIVP) = "fdivp"
63 :     | asm_fbinOp (I.FDIV) = "fdiv"
64 :     | asm_fbinOp (I.FDIVRP) = "fdivrp"
65 :     | asm_fbinOp (I.FDIVR) = "fdivr"
66 :     and emit_fbinOp x = (emit (asm_fbinOp x))
67 :     and asm_cond (I.EQ) = "eq"
68 :     | asm_cond (I.NE) = "ne"
69 :     | asm_cond (I.LT) = "lt"
70 :     | asm_cond (I.LE) = "le"
71 :     | asm_cond (I.GT) = "gt"
72 :     | asm_cond (I.GE) = "ge"
73 :     | asm_cond (I.B) = "b"
74 :     | asm_cond (I.BE) = "be"
75 :     | asm_cond (I.A) = "a"
76 :     | asm_cond (I.AE) = "ae"
77 :     | asm_cond (I.C) = "c"
78 :     | asm_cond (I.NC) = "nc"
79 :     | asm_cond (I.P) = "p"
80 :     | asm_cond (I.NP) = "np"
81 :     | asm_cond (I.O) = "o"
82 :     | asm_cond (I.NO) = "no"
83 :     and emit_cond x = (emit (asm_cond x))
84 :     and asm_binaryOp (I.ADD) = "add"
85 :     | asm_binaryOp (I.SUB) = "sub"
86 :     | asm_binaryOp (I.AND) = "and"
87 :     | asm_binaryOp (I.OR) = "or"
88 :     | asm_binaryOp (I.XOR) = "xor"
89 :     | asm_binaryOp (I.SHL) = "shl"
90 :     | asm_binaryOp (I.SAR) = "sar"
91 :     | asm_binaryOp (I.SHR) = "shr"
92 :     and emit_binaryOp x = (emit (asm_binaryOp x))
93 :     and asm_unaryOp (I.DEC) = "dec"
94 :     | asm_unaryOp (I.INC) = "inc"
95 :     | asm_unaryOp (I.NEG) = "neg"
96 :     | asm_unaryOp (I.NOT) = "not"
97 :     and emit_unaryOp x = (emit (asm_unaryOp x))
98 :     and asm_move (I.MOVL) = "movl"
99 :     | asm_move (I.MOVZX) = "movzx"
100 :     | asm_move (I.MOVB) = "movb"
101 :     and emit_move x = (emit (asm_move x))
102 :     and asm_funOp (I.FABS) = "fabs"
103 :     | asm_funOp (I.FCHS) = "fchs"
104 :     and emit_funOp x = (emit (asm_funOp x))
105 :     and asm_multDivOp (I.UMUL) = "umul"
106 :     | asm_multDivOp (I.IDIV) = "idiv"
107 :     | asm_multDivOp (I.UDIV) = "udiv"
108 :     and emit_multDivOp x = (emit (asm_multDivOp x))
109 :     val memReg = (MemRegs.memReg regmap)
110 : monnier 247
111 : monnier 411 fun emitInt32 i = (emit (if (i < 0)
112 :     then ("-" ^ (Int32.toString (~ i)))
113 :     else (Int32.toString i)))
114 : monnier 247
115 : monnier 411 fun emit_src2 NONE = ()
116 :     | emit_src2 (SOME i) =
117 :     ((emit "$");
118 :     (emitInt32 i);
119 :     (emit ", "))
120 : monnier 247
121 : monnier 411 fun emitScale 0 = (emit "1")
122 :     | emitScale 1 = (emit "2")
123 :     | emitScale 2 = (emit "4")
124 :     | emitScale 3 = (emit "8")
125 :     | emitScale _ = (error "emitScale")
126 :     and eImmed (I.Immed i) = (emitInt32 i)
127 :     | eImmed (I.Const c) = (emit_const c)
128 :     | eImmed (I.ImmedLabel lexp) = (emit_labexp lexp)
129 :     | eImmed _ = (error "eImmed")
130 :     and emit_operand opn =
131 :     (
132 :     case opn of
133 :     I.Immed i =>
134 :     ((emit "$");
135 :     (emitInt32 i))
136 :     | I.Const c => (emit_const c)
137 :     | I.ImmedLabel lexp =>
138 :     ((emit "$");
139 :     (emit_labexp lexp))
140 :     | I.LabelEA le => (emit_labexp le)
141 :     | I.Relative _ => (error "emit_operand")
142 :     | I.Direct r => (emit_GP r)
143 :     | I.FDirect f => let
144 : monnier 247
145 : monnier 411 (*#line 168.1 "x86/x86.md"*)
146 :     val f' = (regmap f)
147 :     in (if (f' < (32 + 8))
148 :     then (emit_FP f')
149 :     else (emit_operand (memReg opn)))
150 :     end
151 : monnier 247
152 : monnier 411 | I.Displace{base, disp=I.Immed 0, mem, ...} =>
153 :     ((emit "(");
154 :     (emit_GP base);
155 :     (emit ")");
156 :     (emit_region mem))
157 :     | I.Displace{base, disp, mem, ...} =>
158 :     ((eImmed disp);
159 :     (emit "(");
160 :     (emit_GP base);
161 :     (emit ")");
162 :     (emit_region mem))
163 :     | I.Indexed{base=NONE, index, scale, disp, mem, ...} =>
164 :     ((emit "(");
165 :     (emit_GP index);
166 :     (comma ());
167 :     (emitScale scale);
168 :     (emit ")");
169 :     (emit_region mem))
170 :     | I.Indexed{base=SOME base, index, scale, disp, mem, ...} =>
171 :     ((eOptionalDisp disp);
172 :     (emit "(");
173 :     (emit_GP base);
174 :     (comma ());
175 :     (emit_GP index);
176 :     (emitScale scale);
177 :     (emit ")");
178 :     (emit_region mem))
179 :     )
180 :     and eOptionalDisp (I.Immed 0) = ()
181 :     | eOptionalDisp (I.Const c) = (emit (Constant.toString c))
182 :     | eOptionalDisp (I.Immed i) = (emitInt32 i)
183 :     | eOptionalDisp _ = (error "eOptionalDisp")
184 : monnier 247
185 : monnier 411 fun stupidGas (I.ImmedLabel lexp) = (emit_labexp lexp)
186 :     | stupidGas (I.LabelEA _) = (error "stupidGas")
187 :     | stupidGas opnd = (emit_operand opnd)
188 :     val emit_dst = emit_operand
189 :     val emit_src = emit_operand
190 :     val emit_opnd = emit_operand
191 :     val emit_src1 = emit_operand
192 :     val emit_rsrc = emit_operand
193 :     val emit_lsrc = emit_operand
194 :     val emit_addr = emit_operand
195 : monnier 247
196 : monnier 411 fun emitInstr instr =
197 :     ((tab ());
198 :    
199 :     (
200 :     case instr of
201 :     I.NOP => (emit "nop")
202 :     | I.JMP(operand, label) =>
203 :     ((emit "jmp\t");
204 :     (stupidGas operand))
205 : monnier 247 | I.JCC{cond, opnd} =>
206 : monnier 411 ((emit "j");
207 :     (emit_cond cond);
208 :     (emit ", ");
209 :     (stupidGas opnd))
210 :     | I.CALL(operand, cellset1, cellset2, region) =>
211 :     ((emit "call\t");
212 :     (stupidGas operand);
213 :     (emit_region region))
214 :     | I.RET => (emit "ret")
215 : monnier 247 | I.MOVE{mvOp, src, dst} =>
216 : monnier 411 ((emit_move mvOp);
217 :     (emit "\t");
218 :     (emit_src src);
219 :     (emit ", ");
220 :     (emit_dst dst))
221 : monnier 247 | I.LEA{r32, addr} =>
222 : monnier 411 ((emit "leal\t");
223 :     (emit_addr addr);
224 :     (emit ", ");
225 :     (emit_GP r32))
226 : monnier 247 | I.CMP{lsrc, rsrc} =>
227 : monnier 411 ((emit "cmpl\t");
228 :     (emit_rsrc rsrc);
229 :     (emit ", ");
230 :     (emit_lsrc lsrc))
231 :     | I.BINARY{binOp, src, dst} =>
232 :     ((emit_binaryOp binOp);
233 :     (emit "l\t");
234 :     (emit_src src);
235 :     (emit ", ");
236 :     (emit_dst dst))
237 :     | I.MULTDIV{multDivOp, src} =>
238 :     ((emit_multDivOp multDivOp);
239 :     (emit "l\t");
240 :     (emit_src src))
241 :     | I.MUL3{dst, src1, src2} =>
242 :     ((emit "imul\t");
243 :     (emit_src1 src1);
244 :     (emit ", ");
245 :     (emit_src2 src2);
246 :     (emit_int dst))
247 : monnier 247 | I.UNARY{unOp, opnd} =>
248 : monnier 411 ((emit_unaryOp unOp);
249 :     (emit "l\t");
250 :     (emit_opnd opnd))
251 :     | I.PUSH operand =>
252 :     ((emit "pushl\t");
253 :     (emit_operand operand))
254 :     | I.POP operand =>
255 :     ((emit "popl\t");
256 :     (emit_operand operand))
257 :     | I.CDQ => (emit "cdq")
258 :     | I.INTO => (emit "into")
259 :     | I.COPY{dst, src, tmp} => (emitInstrs (Shuffle.shuffle {regmap=regmap, tmp=tmp, dst=dst, src=src}))
260 :     | I.FCOPY{dst, src, tmp} => (emitInstrs (Shuffle.shufflefp {regmap=regmap, tmp=tmp, dst=dst, src=src}))
261 : monnier 247 | I.FBINARY{binOp, src, dst} =>
262 : monnier 411 ((emit_fbinOp binOp);
263 :     (emit "\t");
264 :     (emit_src src);
265 :     (emit ", ");
266 :     (emit_dst dst))
267 :     | I.FUNARY funOp => (emit_funOp funOp)
268 :     | I.FUCOMPP => (emit "fucompp")
269 :     | I.FXCH => (emit "fxch")
270 :     | I.FSTP operand =>
271 :     ((emit "fstp\t");
272 :     (emit_operand operand))
273 :     | I.FLD operand =>
274 :     ((emit "fld\t");
275 :     (emit_operand operand))
276 :     | I.FILD operand =>
277 :     ((emit "fild\t");
278 :     (emit_operand operand))
279 :     | I.FNSTSW => (emit "fnstsw")
280 :     | I.SAHF => (emit "sahf")
281 :     | I.ANNOTATION{i, a} =>
282 :     ((emitInstr i);
283 :     (comment (Annotations.toString a)))
284 :     | I.GROUP annotation => (comment (Annotations.toString annotation))
285 :     );
286 :     (nl ()))
287 :     and emitInstrs [] = ()
288 :     | emitInstrs (i::is) =
289 :     (emitInstr i; app (fn i => (tab(); emitInstr i)) is)
290 :     in emitInstr end
291 :    
292 :     in S.STREAM{init=init,
293 :     pseudoOp=pseudoOp,
294 :     emit=emitter,
295 :     finish=doNothing,
296 :     defineLabel=defineLabel,
297 :     entryLabel=entryLabel,
298 :     comment=comment,
299 :     exitBlock=doNothing,
300 :     blockName=blockName,
301 :     annotation=annotation
302 :     }
303 :     end
304 : monnier 247 end
305 :    

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