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/mips/emit/mipsMC.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/mips/emit/mipsMC.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1326 - (view) (download)

1 : allenleung 1326 (*
2 :     * WARNING: This file was automatically generated by MDLGen (v3.0)
3 :     * from the machine description file "mips/mips.mdl".
4 :     * DO NOT EDIT this file directly
5 :     *)
6 :    
7 :    
8 :     functor MIPSMCEmitter(structure Instr : MIPSINSTR
9 :     structure CodeString : CODE_STRING
10 :     ) : INSTRUCTION_EMITTER =
11 :     struct
12 :     structure I = Instr
13 :     structure C = I.C
14 :     structure LabelExp = I.LabelExp
15 :     structure Constant = I.Constant
16 :     structure T = I.T
17 :     structure S = T.Stream
18 :     structure P = S.P
19 :     structure W = Word32
20 :    
21 :     (* MIPS is little endian *)
22 :    
23 :     fun error msg = MLRiscErrorMsg.error("MIPSMC",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 :     fun getAnnotations () = error "getAnnotations"
53 :    
54 :     fun pseudoOp pOp = P.emitValue{pOp=pOp, loc= !loc,emit=eByte}
55 :    
56 :     fun init n = (CodeString.init n; loc := 0)
57 :    
58 :    
59 :     fun eWord32 w =
60 :     let val b8 = w
61 :     val w = w >> 0wx8
62 :     val b16 = w
63 :     val w = w >> 0wx8
64 :     val b24 = w
65 :     val w = w >> 0wx8
66 :     val b32 = w
67 :     in
68 :     ( eByteW b8;
69 :     eByteW b16;
70 :     eByteW b24;
71 :     eByteW b32 )
72 :     end
73 :     fun emit_GP r = itow (C.physicalRegisterNum r)
74 :     and emit_FP r = itow (C.physicalRegisterNum r)
75 :     and emit_CC r = itow (C.physicalRegisterNum r)
76 :     and emit_COND r = itow (C.physicalRegisterNum r)
77 :     and emit_HI r = itow (C.physicalRegisterNum r)
78 :     and emit_LO r = itow (C.physicalRegisterNum r)
79 :     and emit_MEM r = itow (C.physicalRegisterNum r)
80 :     and emit_CTRL r = itow (C.physicalRegisterNum r)
81 :     and emit_CELLSET r = itow (C.physicalRegisterNum r)
82 :     fun Load {l, rt, b, offset} =
83 :     let val rt = emit_GP rt
84 :     val b = emit_GP b
85 :     in eWord32 ((l << 0wx1a) + ((rt << 0wx15) + ((b << 0wx10) + (offset && 0wxffff))))
86 :     end
87 :     and Special {rs, rt, opc} =
88 :     let val rs = emit_GP rs
89 :     val rt = emit_GP rt
90 :     in eWord32 ((rs << 0wx15) + ((rt << 0wx10) + opc))
91 :     end
92 :     fun emitter instr =
93 :     let
94 :     fun emitInstr (I.NOP) = error "NOP"
95 :     | emitInstr (I.LUI{rt, imm}) = error "LUI"
96 :     | emitInstr (I.LA{rt, b, d}) = error "LA"
97 :     | emitInstr (I.DLA{rt, b, d}) = error "DLA"
98 :     | emitInstr (I.LOAD{l, rt, b, d, mem}) = error "LOAD"
99 :     | emitInstr (I.STORE{s, rs, b, d, mem}) = error "STORE"
100 :     | emitInstr (I.FLOAD{l, ft, b, d, mem}) = error "FLOAD"
101 :     | emitInstr (I.FSTORE{s, fs, b, d, mem}) = error "FSTORE"
102 :     | emitInstr (I.FCMP{fcond, fmt, cc, fs1, fs2}) = error "FCMP"
103 :     | emitInstr (I.TRAP{t, rs, i}) = error "TRAP"
104 :     | emitInstr (I.J{lab, nop}) = error "J"
105 :     | emitInstr (I.JR{rs, labels, nop}) = error "JR"
106 :     | emitInstr (I.JAL{lab, defs, uses, cutsTo, mem, nop}) = error "JAL"
107 :     | emitInstr (I.JALR{rt, rs, defs, uses, cutsTo, mem, nop}) = error "JALR"
108 :     | emitInstr (I.RET{nop}) = error "RET"
109 :     | emitInstr (I.BRANCH{likely, cond, rs, rt, lab, nop}) = error "BRANCH"
110 :     | emitInstr (I.FBRANCH{likely, fbranch, cc, lab, nop}) = error "FBRANCH"
111 :     | emitInstr (I.ARITH{oper, rt, rs, i}) = error "ARITH"
112 :     | emitInstr (I.UNARY{oper, rt, rs}) = error "UNARY"
113 :     | emitInstr (I.MULTIPLY{oper, rt, rs}) = error "MULTIPLY"
114 :     | emitInstr (I.DIVIDE{oper, rt, rs}) = error "DIVIDE"
115 :     | emitInstr (I.MFLO GP) = error "MFLO"
116 :     | emitInstr (I.MTLO GP) = error "MTLO"
117 :     | emitInstr (I.MFHI GP) = error "MFHI"
118 :     | emitInstr (I.MTHI GP) = error "MTHI"
119 :     | emitInstr (I.BREAK int) = error "BREAK"
120 :     | emitInstr (I.FARITH{oper, ft, fs1, fs2}) = error "FARITH"
121 :     | emitInstr (I.FUNARY{oper, ft, fs}) = error "FUNARY"
122 :     | emitInstr (I.FARITH3{oper, ft, fs1, fs2, fs3}) = error "FARITH3"
123 :     | emitInstr (I.FROUND{oper, ft, fs1, rs2}) = error "FROUND"
124 :     | emitInstr (I.CVTI2F{cvt, rs, ft}) = error "CVTI2F"
125 :     | emitInstr (I.CVTF2I{cvt, fs, rt}) = error "CVTF2I"
126 :     | emitInstr (I.COPY{dst, src, impl, tmp}) = error "COPY"
127 :     | emitInstr (I.FCOPY{dst, src, impl, tmp}) = error "FCOPY"
128 :     | emitInstr (I.ANNOTATION{i, a}) = emitInstr i
129 :     | emitInstr (I.PHI{}) = ()
130 :     | emitInstr (I.SOURCE{}) = ()
131 :     | emitInstr (I.SINK{}) = ()
132 :     in
133 :     emitInstr instr
134 :     end
135 :    
136 :     in S.STREAM{beginCluster=init,
137 :     pseudoOp=pseudoOp,
138 :     emit=emitter,
139 :     endCluster=doNothing,
140 :     defineLabel=doNothing,
141 :     entryLabel=doNothing,
142 :     comment=doNothing,
143 :     exitBlock=doNothing,
144 :     annotation=doNothing,
145 :     getAnnotations=getAnnotations
146 :     }
147 :     end
148 :     end
149 :    

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