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

SCM Repository

[smlnj] Diff of /sml/trunk/src/MLRISC/sparc/emit/sparcAsm.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/sparc/emit/sparcAsm.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 247, Sat Apr 17 18:47:13 1999 UTC revision 411, Fri Sep 3 00:25:03 1999 UTC
# Line 1  Line 1 
1  functor SparcAsmEmitter  (*
2     (structure Instr : SPARCINSTR   * This file was automatically generated by MDGen
3      structure PseudoOps : PSEUDO_OPS   * from the machine description file "sparc/sparc.md".
4      structure Shuffle : SPARCSHUFFLE where I = Instr   *)
5     ) : EMITTER_NEW =  
6    
7    functor SparcAsmEmitter(structure Instr : SPARCINSTR
8                            structure Stream : INSTRUCTION_STREAM
9                            structure Shuffle : SPARCSHUFFLE
10                               where I = Instr
11    
12    (*#line 251.1 "sparc/sparc.md"*)
13                            val V9 : bool
14                           ) : INSTRUCTION_EMITTER =
15  struct  struct
16     structure I = Instr     structure I = Instr
17     structure C = I.C     structure C = I.C
18     structure P = PseudoOps     structure S  = Stream
19     structure R = I.Region     structure P  = S.P
20       structure LE = LabelExp
21     structure Constant = I.Constant     structure Constant = I.Constant
22    
23     fun ms n = if n < 0 then ("-" ^ Int.toString (~n)) else Int.toString n     fun error msg = MLRiscErrorMsg.error("SparcAsm",msg)
24    
25     fun error msg = MLRiscErrorMsg.impossible ("SparcAsmEmitter." ^ msg)     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    
50     fun emit s = TextIO.output(!AsmStream.asmOutStream,s)     fun emit_Y r = (emit (C.showY (regmap r)))
51       and emit_CC r = (emit (C.showCC (regmap r)))
52       and emit_PSR r = (emit (C.showPSR (regmap r)))
53       and emit_GP r = (emit (C.showGP (regmap r)))
54       and emit_FSR r = (emit (C.showFSR (regmap r)))
55       and emit_FP r = (emit (C.showFP (regmap r)))
56    
57       fun asm_store (I.STB) = "stb"
58         | asm_store (I.STH) = "sth"
59         | asm_store (I.ST) = "st"
60         | asm_store (I.STX) = "stx"
61         | asm_store (I.STD) = "std"
62       and emit_store x = (emit (asm_store x))
63       and asm_fsize (I.S) = "s"
64         | asm_fsize (I.D) = "d"
65         | asm_fsize (I.Q) = "q"
66       and emit_fsize x = (emit (asm_fsize x))
67       and asm_rcond (I.RZ) = "rz"
68         | asm_rcond (I.RLEZ) = "rlez"
69         | asm_rcond (I.RLZ) = "rlz"
70         | asm_rcond (I.RNZ) = "rnz"
71         | asm_rcond (I.RGZ) = "rgz"
72         | asm_rcond (I.RGEZ) = "rgez"
73       and emit_rcond x = (emit (asm_rcond x))
74       and asm_fload (I.LDF) = "ldf"
75         | asm_fload (I.LDDF) = "lddf"
76         | asm_fload (I.LDQF) = "ldqf"
77         | asm_fload (I.LDFSR) = "ldfsr"
78         | asm_fload (I.LDXFSR) = "ldxfsr"
79       and emit_fload x = (emit (asm_fload x))
80       and asm_branch (I.BN) = "n"
81         | asm_branch (I.BE) = "e"
82         | asm_branch (I.BLE) = "le"
83         | asm_branch (I.BL) = "l"
84         | asm_branch (I.BLEU) = "leu"
85         | asm_branch (I.BCS) = "cs"
86         | asm_branch (I.BNEG) = "neg"
87         | asm_branch (I.BVS) = "vs"
88         | asm_branch (I.BA) = ""
89         | asm_branch (I.BNE) = "ne"
90         | asm_branch (I.BG) = "g"
91         | asm_branch (I.BGE) = "ge"
92         | asm_branch (I.BGU) = "gu"
93         | asm_branch (I.BCC) = "cc"
94         | asm_branch (I.BPOS) = "pos"
95         | asm_branch (I.BVC) = "vs"
96       and emit_branch x = (emit (asm_branch x))
97       and asm_farith1 (I.FiTOs) = "fitos"
98         | asm_farith1 (I.FiTOd) = "fitod"
99         | asm_farith1 (I.FiTOq) = "fitoq"
100         | asm_farith1 (I.FsTOi) = "fstoi"
101         | asm_farith1 (I.FdTOi) = "fdtoi"
102         | asm_farith1 (I.FqTOi) = "fqtoi"
103         | asm_farith1 (I.FsTOd) = "fstod"
104         | asm_farith1 (I.FsTOq) = "fstoq"
105         | asm_farith1 (I.FdTOs) = "fdtos"
106         | asm_farith1 (I.FdTOq) = "fdtoq"
107         | asm_farith1 (I.FqTOs) = "fqtos"
108         | asm_farith1 (I.FqTOd) = "fqtod"
109         | asm_farith1 (I.FMOVs) = "fmovs"
110         | asm_farith1 (I.FNEGs) = "fnegs"
111         | asm_farith1 (I.FABSs) = "fabss"
112         | asm_farith1 (I.FMOVd) = "fmovd"
113         | asm_farith1 (I.FNEGd) = "fnegd"
114         | asm_farith1 (I.FABSd) = "fabsd"
115         | asm_farith1 (I.FMOVq) = "fmovq"
116         | asm_farith1 (I.FNEGq) = "fnegq"
117         | asm_farith1 (I.FABSq) = "fabsq"
118         | asm_farith1 (I.FSQRTs) = "fsqrts"
119         | asm_farith1 (I.FSQRTd) = "fsqrtd"
120         | asm_farith1 (I.FSQRTq) = "fsqrtq"
121       and emit_farith1 x = (emit (asm_farith1 x))
122       and asm_farith2 (I.FADDs) = "fadds"
123         | asm_farith2 (I.FADDd) = "faddd"
124         | asm_farith2 (I.FADDq) = "faddq"
125         | asm_farith2 (I.FSUBs) = "fsubs"
126         | asm_farith2 (I.FSUBd) = "fsubd"
127         | asm_farith2 (I.FSUBq) = "fsubq"
128         | asm_farith2 (I.FMULs) = "fmuls"
129         | asm_farith2 (I.FMULd) = "fmuld"
130         | asm_farith2 (I.FMULq) = "fmulq"
131         | asm_farith2 (I.FsMULd) = "fsmuld"
132         | asm_farith2 (I.FdMULq) = "fdmulq"
133         | asm_farith2 (I.FDIVs) = "fdivs"
134         | asm_farith2 (I.FDIVd) = "fdivd"
135         | asm_farith2 (I.FDIVq) = "fdivq"
136       and emit_farith2 x = (emit (asm_farith2 x))
137       and asm_shift (I.SLL) = "sll"
138         | asm_shift (I.SRL) = "srl"
139         | asm_shift (I.SRA) = "sra"
140         | asm_shift (I.SLLX) = "sllx"
141         | asm_shift (I.SRLX) = "srlx"
142         | asm_shift (I.SRAX) = "srax"
143       and emit_shift x = (emit (asm_shift x))
144       and asm_arith (I.AND) = "and"
145         | asm_arith (I.ANDCC) = "andcc"
146         | asm_arith (I.ANDN) = "andn"
147         | asm_arith (I.ANDNCC) = "andncc"
148         | asm_arith (I.OR) = "or"
149         | asm_arith (I.ORCC) = "orcc"
150         | asm_arith (I.ORN) = "orn"
151         | asm_arith (I.ORNCC) = "orncc"
152         | asm_arith (I.XOR) = "xor"
153         | asm_arith (I.XORCC) = "xorcc"
154         | asm_arith (I.XNOR) = "xnor"
155         | asm_arith (I.XNORCC) = "xnorcc"
156         | asm_arith (I.ADD) = "add"
157         | asm_arith (I.ADDCC) = "addcc"
158         | asm_arith (I.TADD) = "tadd"
159         | asm_arith (I.TADDCC) = "taddcc"
160         | asm_arith (I.TADDTV) = "taddtv"
161         | asm_arith (I.TADDTVCC) = "taddtvcc"
162         | asm_arith (I.SUB) = "sub"
163         | asm_arith (I.SUBCC) = "subcc"
164         | asm_arith (I.TSUB) = "tsub"
165         | asm_arith (I.TSUBCC) = "tsubcc"
166         | asm_arith (I.TSUBTV) = "tsubtv"
167         | asm_arith (I.TSUBTVCC) = "tsubtvcc"
168         | asm_arith (I.UMUL) = "umul"
169         | asm_arith (I.UMULCC) = "umulcc"
170         | asm_arith (I.SMUL) = "smul"
171         | asm_arith (I.SMULCC) = "smulcc"
172         | asm_arith (I.UDIV) = "udiv"
173         | asm_arith (I.UDIVCC) = "udivcc"
174         | asm_arith (I.SDIV) = "sdiv"
175         | asm_arith (I.SDIVCC) = "sdivcc"
176         | asm_arith (I.MULX) = "mulx"
177         | asm_arith (I.SDIVX) = "sdivx"
178         | asm_arith (I.UDIVX) = "udivx"
179       and emit_arith x = (emit (asm_arith x))
180       and asm_fcmp (I.FCMPs) = "fcmps"
181         | asm_fcmp (I.FCMPd) = "fcmpd"
182         | asm_fcmp (I.FCMPq) = "fcmpq"
183         | asm_fcmp (I.FCMPEs) = "fcmpes"
184         | asm_fcmp (I.FCMPEd) = "fcmped"
185         | asm_fcmp (I.FCMPEq) = "fcmpeq"
186       and emit_fcmp x = (emit (asm_fcmp x))
187       and asm_load (I.LDSB) = "ldsb"
188         | asm_load (I.LDSH) = "ldsh"
189         | asm_load (I.LDUB) = "ldub"
190         | asm_load (I.LDUH) = "lduh"
191         | asm_load (I.LD) = "ld"
192         | asm_load (I.LDX) = "ldx"
193         | asm_load (I.LDD) = "ldd"
194       and emit_load x = (emit (asm_load x))
195       and asm_prediction (I.PT) = "pt"
196         | asm_prediction (I.PN) = "pn"
197       and emit_prediction x = (emit (asm_prediction x))
198       and asm_fbranch (I.FBN) = "fbn"
199         | asm_fbranch (I.FBNE) = "fbne"
200         | asm_fbranch (I.FBLG) = "fblg"
201         | asm_fbranch (I.FBUL) = "fbul"
202         | asm_fbranch (I.FBL) = "fbl"
203         | asm_fbranch (I.FBUG) = "fbug"
204         | asm_fbranch (I.FBG) = "fbg"
205         | asm_fbranch (I.FBU) = "fbu"
206         | asm_fbranch (I.FBA) = "fb"
207         | asm_fbranch (I.FBE) = "fbe"
208         | asm_fbranch (I.FBUE) = "fbue"
209         | asm_fbranch (I.FBGE) = "fbge"
210         | asm_fbranch (I.FBUGE) = "fbuge"
211         | asm_fbranch (I.FBLE) = "fble"
212         | asm_fbranch (I.FBULE) = "fbule"
213         | asm_fbranch (I.FBO) = "fbo"
214       and emit_fbranch x = (emit (asm_fbranch x))
215       and emit_operand (I.REG GP) = (emit_GP GP)
216         | emit_operand (I.IMMED int) = (emit_int int)
217         | emit_operand (I.LAB labexp) = (emit_labexp labexp)
218         | emit_operand (I.LO labexp) =
219           ((emit "%lo(");
220           (emit_labexp labexp);
221           (emit ")"))
222         | emit_operand (I.HI labexp) =
223           ((emit "%hi(");
224           (emit_labexp labexp);
225           (emit ")"))
226         | emit_operand (I.CONST const) = (emit_const const)
227       and asm_fstore (I.STF) = "stf"
228         | asm_fstore (I.STDF) = "stdf"
229         | asm_fstore (I.STFSR) = "stfsr"
230       and emit_fstore x = (emit (asm_fstore x))
231    
232       fun emit_leaf false = ()
233         | emit_leaf true = (emit "l")
234    
235       fun emit_nop false = ()
236         | emit_nop true = (emit "\n\tnop")
237    
238       fun emit_a false = ()
239         | emit_a true = (emit ",a")
240    
241     fun pseudoOp pOp = emit(P.toString pOp)     fun emit_cc false = ()
242         | emit_cc true = (emit "cc")
243    
244     fun defineLabel lab = emit(Label.nameOf lab ^ ":\n")     fun emitInstr instr =
245           ((tab ());
246    
247     fun comment msg = emit ("\t/* " ^ msg ^ " */")         (
248            case instr of
249            I.LOAD{l, d, r, i, mem} =>
250            ((emit_load l);
251            (emit "\t[");
252            (emit_GP r);
253            (emit "+");
254            (emit_operand i);
255            (emit "], ");
256            (emit_GP d);
257            (emit_region mem))
258          | I.STORE{s, d, r, i, mem} =>
259            ((emit_store s);
260            (emit "\t");
261            (emit_GP d);
262            (emit ", [");
263            (emit_GP r);
264            (emit "+");
265            (emit_operand i);
266            (emit "]");
267            (emit_region mem))
268          | I.FLOAD{l, r, i, d, mem} =>
269            ((emit_fload l);
270            (emit "\t[");
271            (emit_GP r);
272            (emit "+");
273            (emit_operand i);
274            (emit "], ");
275            (emit_FP d);
276            (emit_region mem))
277          | I.FSTORE{s, d, r, i, mem} =>
278            ((emit_fstore s);
279            (emit "\t[");
280            (emit_GP r);
281            (emit "+");
282            (emit_operand i);
283            (emit "], ");
284            (emit_FP d);
285            (emit_region mem))
286          | I.SETHI{i, d} =>
287            ((emit "sethi\t%hi(0x");
288            (emit (Word32.toString (Word32.<< ((Word32.fromInt i), 0wxa))));
289            (emit "), ");
290            (emit_GP d))
291          | I.ARITH{a, r, i, d} =>
292            ((emit_arith a);
293            (emit "\t");
294            (emit_GP r);
295            (emit ", ");
296            (emit_operand i);
297            (emit ", ");
298            (emit_GP d))
299          | I.SHIFT{s, r, i, d} =>
300            ((emit_shift s);
301            (emit "\t");
302            (emit_GP r);
303            (emit ", ");
304            (emit_operand i);
305            (emit ", ");
306            (emit_GP d))
307          | I.MOVicc{b, i, d} =>
308            ((emit "mov");
309            (emit_branch b);
310            (emit "\t");
311            (emit_operand i);
312            (emit ", ");
313            (emit_GP d))
314          | I.MOVfcc{b, i, d} =>
315            ((emit "mov");
316            (emit_fbranch b);
317            (emit "\t");
318            (emit_operand i);
319            (emit ", ");
320            (emit_GP d))
321          | I.MOVR{rcond, r, i, d} =>
322            ((emit "movr");
323            (emit_rcond rcond);
324            (emit "\t");
325            (emit_GP r);
326            (emit ", ");
327            (emit_operand i);
328            (emit ", ");
329            (emit_GP d))
330          | I.FMOVicc{sz, b, r, d} =>
331            ((emit "fmov");
332            (emit_fsize sz);
333            (emit_branch b);
334            (emit "\t");
335            (emit_FP r);
336            (emit ", ");
337            (emit_FP d))
338          | I.FMOVfcc{sz, b, r, d} =>
339            ((emit "fmov");
340            (emit_fsize sz);
341            (emit_fbranch b);
342            (emit "\t");
343            (emit_FP r);
344            (emit ", ");
345            (emit_FP d))
346          | I.Bicc{b, a, label, nop} =>
347            ((emit "b");
348            (emit_branch b);
349            (emit_a a);
350            (emit "\t");
351            (emit_label label);
352            (emit_nop nop))
353          | I.FBfcc{b, a, label, nop} =>
354            ((emit_fbranch b);
355            (emit_a a);
356            (emit "\t");
357            (emit_label label);
358            (emit_nop nop))
359          | I.BR{rcond, p, r, a, label, nop} =>
360            ((emit "b");
361            (emit_rcond rcond);
362            (emit_a a);
363            (emit_prediction p);
364            (emit "\t");
365            (emit_GP r);
366            (emit ", ");
367            (emit_label label);
368            (emit_nop nop))
369          | I.BP{b, p, cc, a, label, nop} =>
370            ((emit "bp");
371            (emit_branch b);
372            (emit_a a);
373            (emit_prediction p);
374            (emit "\t%");
375            (emit (if (cc = I.ICC)
376               then "i"
377               else "x"));
378            (emit "cc, ");
379            (emit_label label);
380            (emit_nop nop))
381          | I.JMP{r, i, labs, nop} =>
382            ((emit "jmp\t[");
383            (emit_GP r);
384            (emit "+");
385            (emit_operand i);
386            (emit "]");
387            (emit_nop nop))
388          | I.JMPL{r, i, d, defs, uses, nop, mem} =>
389            ((emit "jmpl\t[");
390            (emit_GP r);
391            (emit "+");
392            (emit_operand i);
393            (emit "], ");
394            (emit_GP d);
395            (emit_region mem);
396            (emit_nop nop))
397          | I.CALL{defs, uses, label, nop, mem} =>
398            ((emit "call\t");
399            (emit_label label);
400            (emit_region mem);
401            (emit_nop nop))
402          | I.Ticc{t, cc, r, i} =>
403            ((emit "t");
404            (emit_branch t);
405            (emit "\t");
406            (if (cc = I.ICC)
407               then ()
408               else (emit "%xcc, "));
409            (emit_GP r);
410            (emit ", ");
411            (emit_operand i))
412          | I.FPop1{a, r, d} => let
413    
414    (*#line 508.1 "sparc/sparc.md"*)
415    
416               fun f (a, r, d) =
417                   ((emit a);
418                   (emit "\t");
419                   (emit_FP r);
420                   (emit ", ");
421                   (emit_FP d))
422    
423    (*#line 510.1 "sparc/sparc.md"*)
424    
425               fun g (a, r, d) = let
426    
427    (*#line 511.1 "sparc/sparc.md"*)
428                      val r = (regmap r)
429                     and d = (regmap d)
430                   in (f (a, r, d));
431                      (emit "\n\t");
432                      (f ("fmovs", (r + 1), (d + 1)))
433                   end
434    
    fun init size = (comment ("Code size = " ^ ms size))  
435    
436     fun emitInstr(instr,regmap) =  (*#line 515.1 "sparc/sparc.md"*)
437     let  
438         fun rmap r     = Intmap.map regmap r handle _ => r             fun h (a, r, d) = let
439         fun eReg i     = emit(I.C.cellToString(rmap i,I.C.GP))  
440         fun eReg' i    = emit(I.C.cellToString(rmap i,I.C.GP))  (*#line 516.1 "sparc/sparc.md"*)
441         fun fReg f     = emit(I.C.cellToString(rmap f,I.C.FP))                    val r = (regmap r)
442         fun fReg' f    = emit(I.C.cellToString(rmap f,I.C.FP))                   and d = (regmap d)
443         fun fReg2 f    = emit(I.C.cellToString(rmap f+1,I.C.FP))                 in (f (a, r, d));
444         fun fReg2' f   = emit(I.C.cellToString(rmap f+1,I.C.FP))                    (emit "\n\t");
445         fun eLabel lab = emit (Label.nameOf lab)                    (f ("fmovs", (r + 1), (d + 1)));
446         fun nl()       = emit "\n"                    (emit "\n\t");
447         fun tab()      = emit "\t"                    (f ("fmovs", (r + 2), (d + 2)));
448         fun comma()    = emit ", "                    (emit "\n\t");
449         fun eInt i     = emit (ms i)                    (f ("fmovs", (r + 3), (d + 3)))
450         fun emita a    = emit (if a then ",a\t" else "\t")                 end
451    
452            in (if V9
453                  then (f ((asm_farith1 a), r, d))
454                  else
455                  (
456                   case a of
457                   I.FMOVd => (g ("fmovs", r, d))
458                 | I.FNEGd => (g ("fnegs", r, d))
459                 | I.FABSd => (g ("fabss", r, d))
460                 | I.FMOVq => (h ("fmovs", r, d))
461                 | I.FNEGq => (h ("fnegs", r, d))
462                 | I.FABSq => (h ("fabss", r, d))
463                 | _ => (f ((asm_farith1 a), r, d))
464                  ))
465            end
466    
        fun emitLExp lexp = emit(LabelExp.toString lexp)  
        fun eOp' f (I.REG r)   = f r  
          | eOp' f (I.IMMED n) = eInt n  
          | eOp' f (I.LO l)    = (emit "%lo("; emitLExp l; emit ")")  
          | eOp' f (I.HI l)    = (emit "%hi("; emitLExp l; emit ")")  
          | eOp' f (I.LAB l)   = emitLExp l  
          | eOp' f (I.CONST c) = emit(Constant.toString c)  
   
        val eOp  = eOp' eReg  
        val eFop = eOp' fReg  
   
        fun eAddr'(r,i) =  
             (eReg r;  
              case i of  
                (I.REG 0 | I.IMMED 0) => ()  
              | I.IMMED n => (if n > 0 then emit "+" else (); eInt n)  
              | i => (emit "+"; eOp i)  
             )  
   
        fun eAddr(r,i) = (emit "["; eAddr'(r,i); emit "]")  
   
        fun arith3(x,cc,r,i,d) =  
           (tab(); emit x; if cc then emit "cc" else ();  
            tab(); eReg r; comma(); eOp i; comma(); eReg' d)  
        fun eLoad(x,r,i,d) =  
           (tab(); emit x; tab(); eAddr(r,i); comma(); eReg' d)  
        fun eStore(x,d,r,i) =  
           (tab(); emit x; tab(); eReg d; comma(); eAddr(r,i))  
        fun eFload(x,r,i,d) =  
           (tab(); emit x; tab(); eAddr(r,i); comma(); fReg' d)  
        fun eFstore(x,d,r,i) =  
           (tab(); emit x; tab(); fReg d; comma(); eAddr(r,i))  
        fun eJump(r,i,0) =  
            (emit "\tjmp\t"; eAddr'(r,i))  
          | eJump(r,i,d) =  
            (emit "\tjmpl\t"; eAddr'(r,i); comma(); eReg' d)  
        fun eMem mem = comment(R.toString mem)  
        fun eDelay false = ()  
          | eDelay true  = emit "\n\tnop"  
   
        fun arith I.ADD  = "add"  
          | arith I.SUB  = "sub"  
          | arith I.UMUL = "umul"  
          | arith I.SMUL = "smul"  
          | arith I.UDIV = "udiv"  
          | arith I.SDIV = "sdiv"  
          | arith I.AND  = "and"  
          | arith I.ANDN = "andn"  
          | arith I.OR   = "or"  
          | arith I.ORN  = "orn"  
          | arith I.XOR  = "xor"  
          | arith I.XNOR = "xnor"  
          | arith I.TADD = "tadd"  
          | arith I.TADDTV = "taddtv"  
        fun shift I.SLL  = "sll"  
          | shift I.SRL  = "srl"  
          | shift I.SRA  = "sra"  
        fun load I.LD   = "ld"  
          | load I.LDD  = "ldd"  
          | load I.LDUB = "ldub"  
          | load I.LDSB = "ldsb"  
          | load I.LDSH = "ldsh"  
          | load I.LDUH = "lduh"  
        fun store I.ST  = "st"  
          | store I.STB = "stb"  
          | store I.STH = "sth"  
          | store I.STD = "std"  
        fun fload I.LDF = "ld"  
          | fload I.LDDF = "ldd"  
          | fload I.LDFSR = "ld"  
        fun fstore I.STF = "st"  
          | fstore I.STDF = "std"  
          | fstore I.STFSR = "st"  
        fun cond I.BA   = "a"  
          | cond I.BN   = "n"  
          | cond I.BNE  = "ne"  
          | cond I.BE   = "e"  
          | cond I.BG   = "g"  
          | cond I.BLE  = "le"  
          | cond I.BGE  = "ge"  
          | cond I.BL   = "l"  
          | cond I.BGU  = "gu"  
          | cond I.BLEU = "leu"  
          | cond I.BCC  = "cc"  
          | cond I.BCS  = "cs"  
          | cond I.BPOS = "pos"  
          | cond I.BNEG = "neg"  
          | cond I.BVC  = "vc"  
          | cond I.BVS  = "vs"  
        fun branch cc = "b"^cond cc  
        fun trap t = "t"^cond t  
        fun fbranch I.FBA   = "fba"  
          | fbranch I.FBN   = "fbn"  
          | fbranch I.FBU   = "fbu"  
          | fbranch I.FBG   = "fbg"  
          | fbranch I.FBUG  = "fbug"  
          | fbranch I.FBL   = "fbl"  
          | fbranch I.FBUL  = "fbul"  
          | fbranch I.FBLG  = "fblg"  
          | fbranch I.FBNE  = "fbne"  
          | fbranch I.FBE   = "fbe"  
          | fbranch I.FBUE  = "fbue"  
          | fbranch I.FBGE  = "fbge"  
          | fbranch I.FBUGE = "fbuge"  
          | fbranch I.FBLE  = "fble"  
          | fbranch I.FBULE = "fbule"  
          | fbranch I.FBO   = "fbo"  
        fun farith1 I.FiTOd = "fitod"  
          | farith1 I.FdTOi = "fdtoi"  
          | farith1 I.FsTOi = "fstoi"  
          | farith1 I.FiTOs = "fitos"  
          | farith1 I.FdTOs = "fdtos"  
          | farith1 I.FsTOd = "fstod"  
          | farith1 I.FMOVs = "fmovs"  
          | farith1 I.FABSs = "fabss"  
          | farith1 I.FNEGs = "fnegs"  
          | farith1 I.FSQRTs = "fsqrts"  
          | farith1 I.FSQRTd = "fsqrtd"  
          | farith1 _       = error "farith1"  
        fun farith2 I.FADDd = "faddd"  
          | farith2 I.FSUBd = "fsubd"  
          | farith2 I.FMULd = "fmuld"  
          | farith2 I.FDIVd = "fdivd"  
          | farith2 I.FADDs = "fadds"  
          | farith2 I.FSUBs = "fsubs"  
          | farith2 I.FMULs = "fmuls"  
          | farith2 I.FDIVs = "fdivs"  
          | farith2 I.FsMULd = "fsmuld"  
        fun fcmp I.FCMPd = "fcmpd"  
          | fcmp I.FCMPEd = "fcmped"  
          | fcmp I.FCMPs = "fcmps"  
          | fcmp I.FCMPEs = "fcmpes"  
    in  
        case instr of  
          I.LOAD{l,r,i,d,mem} => (eLoad(load l,r,i,d); eMem mem)  
        | I.STORE{s,d,r,i,mem} => (eStore(store s,d,r,i); eMem mem)  
        | I.FLOAD{l,r,i,d,mem} => (eFload(fload l,r,i,d); eMem mem)  
        | I.FSTORE{s,d,r,i,mem} => (eFstore(fstore s,d,r,i); eMem mem)  
        | I.SETHI {d=0,i=0} => emit "\tnop"  
        | I.SETHI {d,i} => (emit "\tsethi\t"; eInt i; comma(); eReg' d)  
        | I.ARITH {a=I.OR,cc=false,r=0,i=I.REG r,d} =>  
           (emit "\tmov\t"; eReg r; comma(); eReg' d)  
        | I.ARITH {a=I.OR,cc=false,r=0,i,d} =>  
           (emit "\tset\t"; eOp i; comma(); eReg' d)  
        | I.ARITH {a=I.SUB,cc=true,r,i,d=0} =>  
              (emit "\tcmp\t"; eReg r; comma(); eOp i)  
        | I.ARITH {a=I.TADDTV,cc=true,r,i,d} => arith3("taddcctv",false,r,i,d)  
        | I.ARITH {a,cc,r,i,d} => arith3(arith a,cc,r,i,d)  
        | I.SHIFT {s,r,i,d} => arith3(shift s,false,r,i,d)  
        | I.Bicc { b, a, label, nop} => (tab(); emit(branch b);  
                                     emita a; eLabel label; eDelay nop)  
        | I.FBfcc { b, a, label, nop} => (tab(); emit(fbranch b);  
                                     emita a; eLabel label; eDelay nop)  
        | I.JMP  {r,i,nop,...} => (eJump(r,i,0); eDelay nop)  
        | I.JMPL {d,r,i,nop,...} => (eJump(r,i,d); eDelay nop)  
        | I.CALL {label,nop,...} => (emit "\tcall\t"; eLabel label; eDelay nop)  
        | I.RET{leaf=false,nop} => (emit "\tret"; eDelay nop)  
        | I.RET{leaf=true,nop} => (emit "\tretl"; eDelay nop)  
        | I.Ticc {t,r,i} => (tab();emit(trap t);emit "\t"; eAddr'(r,i))  
        | I.FPop1 {a=I.FMOVd,r,d} =>  
            (emit "\tfmovs\t"; fReg r; comma(); fReg' d; nl();  
             emit "\tfmovs\t"; fReg2 r; comma(); fReg2' d)  
        | I.FPop1 {a=I.FNEGd,r,d} =>  
            (emit "\tfnegs\t"; fReg r; comma(); fReg' d; nl();  
             emit "\tfmovs\t"; fReg2 r; comma(); fReg2' d)  
        | I.FPop1 {a=I.FABSd,r,d} =>  
            (emit "\tfabds\t"; fReg r; comma(); fReg' d; nl();  
             emit "\tfmovs\t"; fReg2 r; comma(); fReg2' d)  
        | I.FPop1 {a,r,d} =>  
            (tab(); emit(farith1 a); tab(); fReg r; comma(); fReg' d)  
467         | I.FPop2 {a,r1,r2,d} =>         | I.FPop2 {a,r1,r2,d} =>
468             (tab(); emit(farith2 a); tab();          ((emit_farith2 a);
469              fReg r1; comma(); fReg r2; comma(); fReg' d)          (emit "\t");
470            (emit_FP r1);
471            (emit ", ");
472            (emit_FP r2);
473            (emit ", ");
474            (emit_FP d))
475         | I.FCMP {cmp,r1,r2,nop} =>         | I.FCMP {cmp,r1,r2,nop} =>
476             (tab(); emit(fcmp cmp); tab();          ((emit_fcmp cmp);
477              fReg r1; comma(); fReg r2; eDelay nop)          (emit "\t");
478         | I.COPY{src,dst,tmp,...} =>          (emit_FP r1);
479             (app (fn i => emitInstr(i,regmap))          (emit ", ");
480                  (Shuffle.shuffle{src=src,dst=dst,temp=tmp,regMap=rmap}))          (emit_FP r2);
481         | I.FCOPY{src,dst,tmp,...} =>          (emit_nop nop))
482             (app (fn i => emitInstr(i,regmap))        | I.COPY{dst, src, impl, tmp} => (emitInstrs (Shuffle.shuffle {regmap=regmap, tmp=tmp, src=src, dst=dst}))
483                  (Shuffle.shufflefp{src=src,dst=dst,temp=tmp,regMap=rmap}))        | I.FCOPY{dst, src, impl, tmp} => (emitInstrs (Shuffle.shufflefp {regmap=regmap, tmp=tmp, src=src, dst=dst}))
484         | I.SAVE{r,i,d} => arith3("save",false,r,i,d)        | I.SAVE{r, i, d} =>
485         | I.RESTORE{r,i,d} => arith3("restore",false,r,i,d)          ((emit "save\t");
486         | I.RDY{d} => (emit "\trd\t%y, "; eReg' d)          (emit_GP r);
487         | I.WRY{r,i} => (emit "\twr\t"; eReg r; comma(); eOp i; emit ", %y")          (emit ", ");
488         (*          (emit_operand i);
489         | I.ANNOTATION(i,a) => (emitInstr(i,regmap); comment(I.A.toString a))          (emit ", ");
490          *)          (emit_GP d))
491         ;        | I.RESTORE{r, i, d} =>
492         nl()          ((emit "restore\t");
493            (emit_GP r);
494            (emit ", ");
495            (emit_operand i);
496            (emit ", ");
497            (emit_GP d))
498          | I.RDY{d} =>
499            ((emit "rd\t%y, ");
500            (emit_GP d))
501          | I.WRY{r, i} =>
502            ((emit "wr\t");
503            (emit_GP r);
504            (emit ", ");
505            (emit_operand i);
506            (emit ", %y"))
507          | I.RET{leaf, nop} =>
508            ((emit "ret");
509            (emit_leaf leaf);
510            (emit_nop nop))
511          | I.ANNOTATION{i, a} =>
512            ((emitInstr i);
513            (comment (Annotations.toString a)))
514          | I.GROUP annotation => (comment (Annotations.toString annotation))
515           );
516           (nl ()))
517              and emitInstrs [] = ()
518                | emitInstrs (i::is) =
519               (emitInstr i; app (fn i => (tab(); emitInstr i)) is)
520          in  emitInstr end
521    
522       in  S.STREAM{init=init,
523                    pseudoOp=pseudoOp,
524                    emit=emitter,
525                    finish=doNothing,
526                    defineLabel=defineLabel,
527                    entryLabel=entryLabel,
528                    comment=comment,
529                    exitBlock=doNothing,
530                    blockName=blockName,
531                    annotation=annotation
532                   }
533     end     end
534  end  end
535    

Legend:
Removed from v.247  
changed lines
  Added in v.411

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