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/hppa/hppaAsm.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/hppa/hppaAsm.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 127 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/hppa/hppaAsm.sml

1 : monnier 16 (* hppaAsm.sml
2 :     *
3 :     * COPYRIGHT (c) 1996 Bell Laboratories.
4 :     *
5 :     *)
6 :    
7 :     functor HppaAsmEmitter
8 :     (structure Instr : HPPAINSTR
9 :     structure FlowGraph : FLOWGRAPH
10 :     structure Shuffle : HPPASHUFFLE
11 :     sharing FlowGraph.I = Shuffle.I = Instr) : EMITTER_NEW =
12 :     struct
13 :     structure I = Instr
14 :     structure C = I.C
15 :     structure F = FlowGraph
16 :     structure LE = LabelExp
17 :     structure Constant = I.Constant
18 :     structure Region = I.Region
19 :    
20 :     fun ms n = if n<0 then ("-"^ Int.toString (~n)) else Int.toString n
21 :    
22 :     fun error msg = MLRiscErrorMsg.impossible ("HppaAsEmitter." ^ msg)
23 :    
24 :     fun emit s = TextIO.output(!AsmStream.asmOutStream,s)
25 :    
26 :     fun defineLabel(lab) = emit(Label.nameOf lab ^ "\n")
27 :    
28 :     fun comment msg = emit ("\t/* " ^ msg ^ " */")
29 :     fun region r = comment(Region.toString r)
30 :     fun pseudoOp pOp = emit(F.P.toString pOp)
31 :     fun init size = (comment ("Code Size = " ^ ms size); emit"\n")
32 :    
33 :     fun emitInstr(instr,regmap) = let
34 :     fun rmap r = Intmap.map regmap r handle _ => r
35 :     fun eReg r = emit ("%r" ^ ms(rmap r))
36 :     fun eFreg f = emit ("%f" ^ ms(rmap f))
37 :     fun emitCreg c = emit ("%f" ^ ms c)
38 :     fun eLabel lab = emit (Label.nameOf lab)
39 :     fun comma() = emit ", "
40 :     fun tab() = emit "\t"
41 :     fun newline () = emit "\n"
42 :     fun paren f = (emit "("; f(); emit ")")
43 :     fun prList l = let
44 :     fun pr [] = emit "]"
45 :     | pr [r] = (eReg r; pr [])
46 :     | pr (r::rs) = (eReg r; emit ","; pr rs)
47 :     in emit "["; pr l
48 :     end
49 :     fun cond I.EQ = "="
50 :     | cond I.LT = "<"
51 :     | cond I.LE = "<="
52 :     | cond I.LTU = "<<"
53 :     | cond I.LEU = "<<="
54 :     | cond I.NE = "<>"
55 :     | cond I.GE = ">="
56 :     | cond I.GT = ">"
57 :     | cond I.GTU = ">>"
58 :     | cond I.GEU = ">>="
59 :    
60 : monnier 106 fun fcond I.? = "?"
61 :     | fcond I.!<=> = "!<=>"
62 :     | fcond I.== = "=="
63 :     | fcond I.?= = "?="
64 :     | fcond I.!<> = "!<>"
65 :     | fcond I.!?>= = "!?>="
66 :     | fcond I.< = "<"
67 :     | fcond I.?< = "?<"
68 :     | fcond I.!>= = "!>="
69 :     | fcond I.!?> = "!?>"
70 :     | fcond I.<= = "<="
71 :     | fcond I.?<= = "?<+"
72 :     | fcond I.!> = "!>"
73 :     | fcond I.!?<= = "!?<="
74 : monnier 16 | fcond I.> = ">"
75 :     | fcond I.?> = "?>"
76 : monnier 106 | fcond I.!<= = "!<="
77 :     | fcond I.!?< = "!?<"
78 :     | fcond I.>= = ">="
79 :     | fcond I.?>= = "?>="
80 :     | fcond I.!< = "!<"
81 :     | fcond I.!?= = "!?="
82 : monnier 16 | fcond I.<> = "<>"
83 : monnier 106 | fcond I.!= = "!="
84 :     | fcond I.!? = "!?"
85 :     | fcond I.<=> = "<=>"
86 : monnier 16
87 :     fun emitFieldSel fs =
88 :     emit(case fs
89 :     of I.F => "F'"
90 :     | I.T => ""
91 :     | I.P => "P'"
92 :     | _ => error "emitFieldSel")
93 :    
94 :     fun emitHiFieldSel fs =
95 :     emit(case fs
96 :     of I.F => "L'"
97 :     | I.S => "LS'"
98 :     | I.D => "LD'"
99 :     | I.R => "LR'"
100 :     | I.T => "LT'"
101 :     | I.P => "LP'")
102 :    
103 :     fun emitLoFieldSel fs =
104 :     emit(case fs
105 :     of I.F => "R'"
106 :     | I.S => "RS'"
107 :     | I.D => "RD'"
108 :     | I.R => "RR'"
109 :     | I.T => "RT'"
110 :     | I.P => "RP'")
111 :    
112 :     fun emitLExp lexp = emit(LabelExp.toString lexp)
113 :     fun eOperand(I.IMMED i) = emit (ms i)
114 :     | eOperand(I.LabExp(lexp, fs)) = (emitFieldSel fs; emitLExp lexp)
115 :     | eOperand(I.HILabExp(lexp, fs)) = (emitHiFieldSel fs; emitLExp lexp)
116 :     | eOperand(I.LOLabExp(lexp, fs)) = (emitLoFieldSel fs; emitLExp lexp)
117 :     | eOperand(I.ConstOp c) = emit(Constant.toString c)
118 :    
119 :     fun store(st, b, d, r, mem) =
120 :     (emit st; eReg r; comma(); eOperand d; paren(fn () => eReg b); region mem)
121 :     fun fstore(fst, b, d, r, mem) =
122 :     (emit fst; eFreg r; comma(); emit(ms d); paren(fn () => eReg b);
123 :     region mem)
124 :     fun fstorex(fstx, b, x, r, mem) =
125 :     (emit fstx; eFreg r; eReg x; paren(fn () => eReg b); region mem)
126 :     fun loadx(ld, r1, r2, t, mem) =
127 :     (emit ld; eReg r2; paren(fn () => eReg r1); comma(); eReg t; region mem)
128 :     fun floadx(flx, b, x, t, mem) =
129 :     (emit flx; eReg x; paren(fn () => eReg b); comma(); eFreg t; region mem)
130 :     fun arith(a, r1, r2, t) =
131 :     (emit a; eReg r1; comma(); eReg r2; comma(); eReg t)
132 :     fun loadi(ld, i, r, t, mem) =
133 :     (emit ld; eOperand i; paren(fn () => eReg r); comma(); eReg t; region mem)
134 :     fun fload(fl, b, d, t, mem) =
135 :     (emit fl; emit(ms d); paren(fn () => eReg b); comma(); eFreg t; region mem)
136 :     fun arithi(ai, i, r ,t) =
137 :     (emit ai; eOperand i; comma(); eReg r; comma(); eReg t)
138 :     fun cmp{cc, r1, r2, t} = arith("\tCOMCLR," ^ cond cc ^ "\t", r1, r2, t)
139 :     fun shiftv(sv, r, len, t) =
140 :     (emit sv; eReg r; comma(); emit(ms len); comma(); eReg t)
141 :     fun shift(s, r, p, len, t) =
142 :     (emit s; eReg r; comma();
143 :     emit(ms p); comma();
144 :     emit(ms len); comma(); eReg t)
145 :     fun emitCmp I.COMBT = emit "\tCOMBT,"
146 :     | emitCmp I.COMBF = emit "\tCOMBF,"
147 :     fun emitCmpi I.COMIBT = emit "\tCOMIBT,"
148 :     | emitCmpi I.COMIBF = emit "\tCOMIBF,"
149 :     fun nullify true = emit ",n"
150 :     | nullify false = ()
151 :     fun bcond{cmp, bc, r1, r2, t, f, n} =
152 :     (emitCmp cmp; emit (cond bc); nullify n; emit "\t";
153 : monnier 127 eReg r1; comma(); eReg r2; comma(); eLabel t;
154 :     emit "\n\tNOP" )
155 : monnier 16 fun bcondi{cmpi, bc, i, r2, t, f, n} =
156 :     (emitCmpi cmpi; emit (cond bc); nullify n; emit "\t";
157 : monnier 127 emit(ms i); comma(); eReg r2; comma(); eLabel t;
158 :     emit "\n\tNOP")
159 : monnier 16
160 :     fun farith{fa, r1, r2, t} = let
161 :     val oper = case fa of I.FADD => "\tFADD\t" | I.FSUB => "\tFSUB\t"
162 :     | I.FDIV => "\tFDIV\t" | I.FMPY => "\tFMPY\t"
163 :     | I.XMPYU => "\tXMPYU\t"
164 :     in emit oper; eFreg r1; comma(); eFreg r2; comma(); eFreg t
165 :     end
166 :    
167 :     fun funary(fu, f, t) = (emit fu; eFreg f; comma(); eFreg t)
168 :     in
169 :     case instr
170 :     of I.STORE{st=I.STW, b, d, r, mem} => store("\tSTW\t", b, d, r, mem)
171 :     | I.STORE{st=I.STH, b, d, r, mem} => store("\tSTH\t", b, d, r, mem)
172 :     | I.STORE{st=I.STB, b, d, r, mem} => store("\tSTB\t", b, d, r, mem)
173 :    
174 :     | I.LOAD{l=I.LDWX, r1, r2, t, mem}=> loadx("\tLDWX\t", r1, r2, t, mem)
175 :     | I.LOAD{l=I.LDHX, r1, r2, t, mem}=> loadx("\tLDHX\t", r1, r2, t, mem)
176 :     | I.LOAD{l=I.LDBX, r1, r2, t, mem}=> loadx("\tLDBX\t", r1, r2, t, mem)
177 :     | I.ARITH{a=I.ADD, r1, r2, t} => arith("\tADD\t", r1, r2, t)
178 :     | I.ARITH{a=I.ADDO, r1, r2, t} => arith("\tADDO\t", r1, r2, t)
179 :     | I.ARITH{a=I.SH1ADD, r1, r2, t} => arith("\tSH1ADD\t", r1, r2, t)
180 :     | I.ARITH{a=I.SH1ADDO, r1, r2, t} => arith("\tSH1ADDO\t", r1, r2, t)
181 :     | I.ARITH{a=I.SUB, r1, r2, t} => arith("\tSUB\t", r1, r2, t)
182 :     | I.ARITH{a=I.SUBO, r1, r2, t} => arith("\tSUBO\t", r1, r2, t)
183 :     | I.ARITH{a=I.OR, r1, r2, t} => arith("\tOR\t", r1, r2, t)
184 :     | I.ARITH{a=I.XOR, r1, r2, t} => arith("\tXOR\t", r1, r2, t)
185 :     | I.ARITH{a=I.AND, r1, r2, t} => arith("\tAND\t", r1, r2, t)
186 :    
187 :     | I.LOADI{li=I.LDB, i, r, t, mem} => loadi("\tLDB\t", i, r, t, mem)
188 :     | I.LOADI{li=I.LDH, i, r, t,mem} => loadi("\tLDH\t", i, r, t, mem)
189 :     | I.LOADI{li=I.LDW, i, r, t, mem} => loadi("\tLDW\t", i, r, t, mem)
190 :     | I.ARITHI{ai=I.ADDI, i, r, t} => arithi("\tADDI\t", i, r, t)
191 :     | I.ARITHI{ai=I.ADDIO, i, r, t} => arithi("\tADDIO\t", i, r, t)
192 :     | I.ARITHI{ai=I.ADDIL, i, r, t} => arithi("\tADDIL\t", i, r, t)
193 :     | I.ARITHI{ai=I.SUBI, i, r, t} => arithi("\tSUBI\t", i, r, t)
194 :     | I.ARITHI{ai=I.SUBIO, i, r, t} => arithi("\tSUBIO\t", i, r, t)
195 :    
196 :     | I.COMCLR arg => cmp arg
197 :    
198 :     | I.SHIFTV{sv=I.VEXTRU, r, len, t}=> shiftv("\tVEXTRU\t", r, len, t)
199 :     | I.SHIFTV{sv=I.VEXTRS, r, len, t}=> shiftv("\tVEXTRS\t", r, len, t)
200 :     | I.SHIFTV{sv=I.ZVDEP, r, len, t} => shiftv("\tZVDEP\t", r, len, t)
201 :    
202 :     | I.SHIFT{s=I.EXTRU, r, p, len, t}=> shift("\tEXTRU\t", r, p, len, t)
203 :     | I.SHIFT{s=I.EXTRS, r, p, len, t}=> shift("\tEXTRS\t", r, p, len, t)
204 :     | I.SHIFT{s=I.ZDEP, r, p, len, t} => shift("\tZDEP\t", r, p, len, t)
205 :    
206 :     | I.BCOND arg => bcond arg
207 :     | I.BCONDI arg => bcondi arg
208 :     | I.B{lab,n} => (emit "\tB"; nullify n;
209 : monnier 127 emit "\t"; eLabel lab;
210 :     emit "\n\tNOP" )
211 : monnier 16 | I.FBCC{t,n, ...} => (emit "\tFBCC"; nullify n;
212 : monnier 127 emit "\t"; eLabel t;
213 :     emit "\n\tNOP")
214 : monnier 16
215 :     | I.BLE{d, sr, b, t, ...} =>
216 :     (emit "\tBLE\t"; eOperand d;
217 :     paren(fn () => (emit(ms sr); comma(); eReg b));
218 :     emit "\n\tCOPY %r31,"; eReg t)
219 :     | I.BL{x=I.LabExp(LE.LABEL lab, fs), t, n, ...} =>
220 :     (emit "\tBL"; nullify n;
221 : monnier 127 emit "\t"; emitFieldSel fs; eLabel lab; comma(); eReg t;
222 :     emit "\n\tNOP" )
223 : monnier 16 | I.BL _ => error "emitInstr:bl"
224 :     | I.BV{x, b, n, ...} =>
225 : monnier 127 (emit "\tBV"; nullify n; emit "\t"; eReg x; paren(fn () => eReg b);
226 :     emit "\n\tNOP" )
227 : monnier 16 | I.LDIL{i, t} => (emit "\tLDIL\t"; eOperand i; comma(); eReg t)
228 :     | I.LDO{i,b,t} =>
229 :     (emit "\tLDO\t"; eOperand i; paren(fn () => eReg b);
230 :     comma(); eReg t)
231 :     | I.MTCTL{r,t} => (emit "\tMTCTL\t"; eReg r; emitCreg t)
232 :     | I.FSTORE{fst, b, d, r, mem} =>
233 :     (case fst
234 :     of I.FSTDS => fstore("\tFSTDS\t", b, d, r, mem)
235 :     | I.FSTWS => fstore("\tFSTWS\t", b, d, r, mem)
236 :     (*esac*))
237 :     | I.FSTOREX{fstx, b, x, r, mem} =>
238 :     (case fstx
239 :     of I.FSTDX => fstorex("\tFSTDX\t", b, x, r, mem)
240 :     | I.FSTWX => fstorex("\tFSTWX\t", b, x, r, mem)
241 :     (*esac*))
242 :     | I.FLOAD{fl=I.FLDDS, b, d, t, mem} => fload("\tFLDDS\t", b, d, t, mem)
243 :     | I.FLOAD{fl=I.FLDWS, b, d, t, mem} => fload("\tFLDWS\t", b, d, t, mem)
244 :     | I.FLOADX{flx=I.FLDDX, b, x, t, mem} => floadx("\tFLDDX\t", b, x, t, mem)
245 :     | I.FLOADX{flx=I.FLDWX, b, x, t, mem} => floadx("\tFLDWX\t", b, x, t, mem)
246 :     | I.FARITH arg => farith arg
247 :     | I.FUNARY{fu=I.FCPY, f, t} => funary("\tFCPY\t", f, t)
248 :     | I.FUNARY{fu=I.FABS, f, t} => funary("\tFABS\t", f, t)
249 :     | I.FUNARY{fu=I.FCNVXF, f, t} => funary("\tFCNVXF\t", f, t)
250 :     | I.FCMP(cc,f1,f2) =>
251 :     (emit ("\tFCMP," ^ fcond cc ^"\t"); eFreg f1; comma(); eFreg f2)
252 :     | I.FTEST => emit "\tFTEST"
253 :     | I.BREAK(i, j) => emit ("\tBREAK(" ^ ms i ^ ", " ^ ms j ^ ")")
254 :     | I.NOP => emit "\tNOP"
255 :     | I.COPY{dst, src, tmp, ...} =>
256 :     app (fn I => (emit "\t"; emitInstr(I, regmap)))
257 :     (Shuffle.shuffle {regMap=rmap, temp=tmp, dst=dst, src=src})
258 :     | I.FCOPY{dst, src, tmp, ...} =>
259 :     app (fn I => (emit "\t"; emitInstr(I, regmap)))
260 :     (Shuffle.shufflefp {regMap=rmap, temp=tmp, dst=dst, src=src})
261 :     (*esac*);
262 :     emit "\n"
263 :     end
264 :     end
265 :    
266 :    

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