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 17 - (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 :     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 :    
75 :     fun emitFieldSel fs =
76 :     emit(case fs
77 :     of I.F => "F'"
78 :     | I.T => ""
79 :     | I.P => "P'"
80 :     | _ => error "emitFieldSel")
81 :    
82 :     fun emitHiFieldSel fs =
83 :     emit(case fs
84 :     of I.F => "L'"
85 :     | I.S => "LS'"
86 :     | I.D => "LD'"
87 :     | I.R => "LR'"
88 :     | I.T => "LT'"
89 :     | I.P => "LP'")
90 :    
91 :     fun emitLoFieldSel fs =
92 :     emit(case fs
93 :     of I.F => "R'"
94 :     | I.S => "RS'"
95 :     | I.D => "RD'"
96 :     | I.R => "RR'"
97 :     | I.T => "RT'"
98 :     | I.P => "RP'")
99 :    
100 :     fun emitLExp lexp = emit(LabelExp.toString lexp)
101 :     fun eOperand(I.IMMED i) = emit (ms i)
102 :     | eOperand(I.LabExp(lexp, fs)) = (emitFieldSel fs; emitLExp lexp)
103 :     | eOperand(I.HILabExp(lexp, fs)) = (emitHiFieldSel fs; emitLExp lexp)
104 :     | eOperand(I.LOLabExp(lexp, fs)) = (emitLoFieldSel fs; emitLExp lexp)
105 :     | eOperand(I.ConstOp c) = emit(Constant.toString c)
106 :    
107 :     fun store(st, b, d, r, mem) =
108 :     (emit st; eReg r; comma(); eOperand d; paren(fn () => eReg b); region mem)
109 :     fun fstore(fst, b, d, r, mem) =
110 :     (emit fst; eFreg r; comma(); emit(ms d); paren(fn () => eReg b);
111 :     region mem)
112 :     fun fstorex(fstx, b, x, r, mem) =
113 :     (emit fstx; eFreg r; eReg x; paren(fn () => eReg b); region mem)
114 :     fun loadx(ld, r1, r2, t, mem) =
115 :     (emit ld; eReg r2; paren(fn () => eReg r1); comma(); eReg t; region mem)
116 :     fun floadx(flx, b, x, t, mem) =
117 :     (emit flx; eReg x; paren(fn () => eReg b); comma(); eFreg t; region mem)
118 :     fun arith(a, r1, r2, t) =
119 :     (emit a; eReg r1; comma(); eReg r2; comma(); eReg t)
120 :     fun loadi(ld, i, r, t, mem) =
121 :     (emit ld; eOperand i; paren(fn () => eReg r); comma(); eReg t; region mem)
122 :     fun fload(fl, b, d, t, mem) =
123 :     (emit fl; emit(ms d); paren(fn () => eReg b); comma(); eFreg t; region mem)
124 :     fun arithi(ai, i, r ,t) =
125 :     (emit ai; eOperand i; comma(); eReg r; comma(); eReg t)
126 :     fun cmp{cc, r1, r2, t} = arith("\tCOMCLR," ^ cond cc ^ "\t", r1, r2, t)
127 :     fun shiftv(sv, r, len, t) =
128 :     (emit sv; eReg r; comma(); emit(ms len); comma(); eReg t)
129 :     fun shift(s, r, p, len, t) =
130 :     (emit s; eReg r; comma();
131 :     emit(ms p); comma();
132 :     emit(ms len); comma(); eReg t)
133 :     fun emitCmp I.COMBT = emit "\tCOMBT,"
134 :     | emitCmp I.COMBF = emit "\tCOMBF,"
135 :     fun emitCmpi I.COMIBT = emit "\tCOMIBT,"
136 :     | emitCmpi I.COMIBF = emit "\tCOMIBF,"
137 :     fun nullify true = emit ",n"
138 :     | nullify false = ()
139 :     fun bcond{cmp, bc, r1, r2, t, f, n} =
140 :     (emitCmp cmp; emit (cond bc); nullify n; emit "\t";
141 :     eReg r1; comma(); eReg r2; comma(); eLabel t
142 :     (* emit "\n\tNOP" *))
143 :     fun bcondi{cmpi, bc, i, r2, t, f, n} =
144 :     (emitCmpi cmpi; emit (cond bc); nullify n; emit "\t";
145 :     emit(ms i); comma(); eReg r2; comma(); eLabel t
146 :     (* emit "\n\tNOP" *))
147 :    
148 :     fun farith{fa, r1, r2, t} = let
149 :     val oper = case fa of I.FADD => "\tFADD\t" | I.FSUB => "\tFSUB\t"
150 :     | I.FDIV => "\tFDIV\t" | I.FMPY => "\tFMPY\t"
151 :     | I.XMPYU => "\tXMPYU\t"
152 :     in emit oper; eFreg r1; comma(); eFreg r2; comma(); eFreg t
153 :     end
154 :    
155 :     fun funary(fu, f, t) = (emit fu; eFreg f; comma(); eFreg t)
156 :     in
157 :     case instr
158 :     of I.STORE{st=I.STW, b, d, r, mem} => store("\tSTW\t", b, d, r, mem)
159 :     | I.STORE{st=I.STH, b, d, r, mem} => store("\tSTH\t", b, d, r, mem)
160 :     | I.STORE{st=I.STB, b, d, r, mem} => store("\tSTB\t", b, d, r, mem)
161 :    
162 :     | I.LOAD{l=I.LDWX, r1, r2, t, mem}=> loadx("\tLDWX\t", r1, r2, t, mem)
163 :     | I.LOAD{l=I.LDHX, r1, r2, t, mem}=> loadx("\tLDHX\t", r1, r2, t, mem)
164 :     | I.LOAD{l=I.LDBX, r1, r2, t, mem}=> loadx("\tLDBX\t", r1, r2, t, mem)
165 :     | I.ARITH{a=I.ADD, r1, r2, t} => arith("\tADD\t", r1, r2, t)
166 :     | I.ARITH{a=I.ADDO, r1, r2, t} => arith("\tADDO\t", r1, r2, t)
167 :     | I.ARITH{a=I.SH1ADD, r1, r2, t} => arith("\tSH1ADD\t", r1, r2, t)
168 :     | I.ARITH{a=I.SH1ADDO, r1, r2, t} => arith("\tSH1ADDO\t", r1, r2, t)
169 :     | I.ARITH{a=I.SUB, r1, r2, t} => arith("\tSUB\t", r1, r2, t)
170 :     | I.ARITH{a=I.SUBO, r1, r2, t} => arith("\tSUBO\t", r1, r2, t)
171 :     | I.ARITH{a=I.OR, r1, r2, t} => arith("\tOR\t", r1, r2, t)
172 :     | I.ARITH{a=I.XOR, r1, r2, t} => arith("\tXOR\t", r1, r2, t)
173 :     | I.ARITH{a=I.AND, r1, r2, t} => arith("\tAND\t", r1, r2, t)
174 :    
175 :     | I.LOADI{li=I.LDB, i, r, t, mem} => loadi("\tLDB\t", i, r, t, mem)
176 :     | I.LOADI{li=I.LDH, i, r, t,mem} => loadi("\tLDH\t", i, r, t, mem)
177 :     | I.LOADI{li=I.LDW, i, r, t, mem} => loadi("\tLDW\t", i, r, t, mem)
178 :     | I.ARITHI{ai=I.ADDI, i, r, t} => arithi("\tADDI\t", i, r, t)
179 :     | I.ARITHI{ai=I.ADDIO, i, r, t} => arithi("\tADDIO\t", i, r, t)
180 :     | I.ARITHI{ai=I.ADDIL, i, r, t} => arithi("\tADDIL\t", i, r, t)
181 :     | I.ARITHI{ai=I.SUBI, i, r, t} => arithi("\tSUBI\t", i, r, t)
182 :     | I.ARITHI{ai=I.SUBIO, i, r, t} => arithi("\tSUBIO\t", i, r, t)
183 :    
184 :     | I.COMCLR arg => cmp arg
185 :    
186 :     | I.SHIFTV{sv=I.VEXTRU, r, len, t}=> shiftv("\tVEXTRU\t", r, len, t)
187 :     | I.SHIFTV{sv=I.VEXTRS, r, len, t}=> shiftv("\tVEXTRS\t", r, len, t)
188 :     | I.SHIFTV{sv=I.ZVDEP, r, len, t} => shiftv("\tZVDEP\t", r, len, t)
189 :    
190 :     | I.SHIFT{s=I.EXTRU, r, p, len, t}=> shift("\tEXTRU\t", r, p, len, t)
191 :     | I.SHIFT{s=I.EXTRS, r, p, len, t}=> shift("\tEXTRS\t", r, p, len, t)
192 :     | I.SHIFT{s=I.ZDEP, r, p, len, t} => shift("\tZDEP\t", r, p, len, t)
193 :    
194 :     | I.BCOND arg => bcond arg
195 :     | I.BCONDI arg => bcondi arg
196 :     | I.B{lab,n} => (emit "\tB"; nullify n;
197 :     emit "\t"; eLabel lab
198 :     (* emit "\n\tNOP" *))
199 :     | I.FBCC{t,n, ...} => (emit "\tFBCC"; nullify n;
200 :     emit "\t"; eLabel t
201 :     (* emit "\n\tNOP" *))
202 :    
203 :     | I.BLE{d, sr, b, t, ...} =>
204 :     (emit "\tBLE\t"; eOperand d;
205 :     paren(fn () => (emit(ms sr); comma(); eReg b));
206 :     emit "\n\tCOPY %r31,"; eReg t)
207 :     | I.BL{x=I.LabExp(LE.LABEL lab, fs), t, n, ...} =>
208 :     (emit "\tBL"; nullify n;
209 :     emit "\t"; emitFieldSel fs; eLabel lab; comma(); eReg t
210 :     (* emit "\n\tNOP" *))
211 :     | I.BL _ => error "emitInstr:bl"
212 :     | I.BV{x, b, n, ...} =>
213 :     (emit "\tBV"; nullify n; emit "\t"; eReg x; paren(fn () => eReg b)
214 :     (* ; emit "\n\tNOP" *))
215 :     | I.LDIL{i, t} => (emit "\tLDIL\t"; eOperand i; comma(); eReg t)
216 :     | I.LDO{i,b,t} =>
217 :     (emit "\tLDO\t"; eOperand i; paren(fn () => eReg b);
218 :     comma(); eReg t)
219 :     | I.MTCTL{r,t} => (emit "\tMTCTL\t"; eReg r; emitCreg t)
220 :     | I.FSTORE{fst, b, d, r, mem} =>
221 :     (case fst
222 :     of I.FSTDS => fstore("\tFSTDS\t", b, d, r, mem)
223 :     | I.FSTWS => fstore("\tFSTWS\t", b, d, r, mem)
224 :     (*esac*))
225 :     | I.FSTOREX{fstx, b, x, r, mem} =>
226 :     (case fstx
227 :     of I.FSTDX => fstorex("\tFSTDX\t", b, x, r, mem)
228 :     | I.FSTWX => fstorex("\tFSTWX\t", b, x, r, mem)
229 :     (*esac*))
230 :     | I.FLOAD{fl=I.FLDDS, b, d, t, mem} => fload("\tFLDDS\t", b, d, t, mem)
231 :     | I.FLOAD{fl=I.FLDWS, b, d, t, mem} => fload("\tFLDWS\t", b, d, t, mem)
232 :     | I.FLOADX{flx=I.FLDDX, b, x, t, mem} => floadx("\tFLDDX\t", b, x, t, mem)
233 :     | I.FLOADX{flx=I.FLDWX, b, x, t, mem} => floadx("\tFLDWX\t", b, x, t, mem)
234 :     | I.FARITH arg => farith arg
235 :     | I.FUNARY{fu=I.FCPY, f, t} => funary("\tFCPY\t", f, t)
236 :     | I.FUNARY{fu=I.FABS, f, t} => funary("\tFABS\t", f, t)
237 :     | I.FUNARY{fu=I.FCNVXF, f, t} => funary("\tFCNVXF\t", f, t)
238 :     | I.FCMP(cc,f1,f2) =>
239 :     (emit ("\tFCMP," ^ fcond cc ^"\t"); eFreg f1; comma(); eFreg f2)
240 :     | I.FTEST => emit "\tFTEST"
241 :     | I.BREAK(i, j) => emit ("\tBREAK(" ^ ms i ^ ", " ^ ms j ^ ")")
242 :     | I.NOP => emit "\tNOP"
243 :     | I.COPY{dst, src, tmp, ...} =>
244 :     app (fn I => (emit "\t"; emitInstr(I, regmap)))
245 :     (Shuffle.shuffle {regMap=rmap, temp=tmp, dst=dst, src=src})
246 :     | I.FCOPY{dst, src, tmp, ...} =>
247 :     app (fn I => (emit "\t"; emitInstr(I, regmap)))
248 :     (Shuffle.shufflefp {regMap=rmap, temp=tmp, dst=dst, src=src})
249 :     (*esac*);
250 :     emit "\n"
251 :     end
252 :     end
253 :    
254 :    
255 :     (*
256 :     * $Log: hppaAsm.sml,v $
257 :     * Revision 1.7 1998/02/17 02:50:02 george
258 :     * Added the nullify bit to all branch instructions -- leunga
259 :     *
260 :     * Revision 1.6 1998/02/16 13:58:12 george
261 :     * A register allocated temp is now associated with parallel COPYs
262 :     * instead of a dedicated register. The temp is used to break cycles.
263 :     *
264 :     * Revision 1.5 1998/02/15 19:39:32 jhr
265 :     * Deleted unused references to System.Tags.
266 :     *
267 :     * Revision 1.4 1997/09/29 20:58:28 george
268 :     * Propagate region information through instruction set
269 :     *
270 :     # Revision 1.3 1997/07/17 12:27:08 george
271 :     # The regmap is now represented as an int map rather than using arrays.
272 :     #
273 :     # Revision 1.2 1997/07/03 13:53:38 george
274 :     # Added support for FCOPY.
275 :     #
276 :     # Revision 1.1.1.1 1997/04/19 18:14:22 george
277 :     # Version 109.27
278 :     #
279 :     *)

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