Debian Codegraph @

lib/mlrisc-lib/MLRISC/mips/emit/mipsMC.sml

raw
1 (*
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 MLTreeEval : MLTREE_EVAL where T = Instr.T
10 structure Stream : INSTRUCTION_STREAM
11 structure CodeString : CODE_STRING
12 ) : INSTRUCTION_EMITTER =
13 struct
14 structure I = Instr
15 structure C = I.C
16 structure Constant = I.Constant
17 structure T = I.T
18 structure S = Stream
19 structure P = S.P
20 structure W = Word32
21
22 (* MIPS is little endian *)
23
24 fun error msg = MLRiscErrorMsg.error("MIPSMC",msg)
25 fun makeStream _ =
26 let infix && || << >> ~>>
27 val op << = W.<<
28 val op >> = W.>>
29 val op ~>> = W.~>>
30 val op || = W.orb
31 val op && = W.andb
32 val itow = W.fromInt
33 fun emit_bool false = 0w0 : W.word
34 | emit_bool true = 0w1 : W.word
35 val emit_int = itow
36 fun emit_word w = w
37 fun emit_label l = itow(Label.addrOf l)
38 fun emit_labexp le = itow(MLTreeEval.valueOf le)
39 fun emit_const c = itow(Constant.valueOf c)
40 val loc = ref 0
41
42 (* emit a byte *)
43 fun eByte b =
44 let val i = !loc in loc := i + 1; CodeString.update(i,b) end
45
46 (* emit the low order byte of a word *)
47 (* note: fromLargeWord strips the high order bits! *)
48 fun eByteW w =
49 let val i = !loc
50 in loc := i + 1; CodeString.update(i,Word8.fromLargeWord w) end
51
52 fun doNothing _ = ()
53 fun fail _ = raise Fail "MCEmitter"
54 fun getAnnotations () = error "getAnnotations"
55
56 fun pseudoOp pOp = P.emitValue{pOp=pOp, loc= !loc,emit=eByte}
57
58 fun init n = (CodeString.init n; loc := 0)
59
60
61 fun eWord32 w =
62 let val b8 = w
63 val w = w >> 0wx8
64 val b16 = w
65 val w = w >> 0wx8
66 val b24 = w
67 val w = w >> 0wx8
68 val b32 = w
69 in
70 ( eByteW b8;
71 eByteW b16;
72 eByteW b24;
73 eByteW b32 )
74 end
75 fun emit_GP r = itow (CellsBasis.physicalRegisterNum r)
76 and emit_FP r = itow (CellsBasis.physicalRegisterNum r)
77 and emit_CC r = itow (CellsBasis.physicalRegisterNum r)
78 and emit_COND r = itow (CellsBasis.physicalRegisterNum r)
79 and emit_HI r = itow (CellsBasis.physicalRegisterNum r)
80 and emit_LO r = itow (CellsBasis.physicalRegisterNum r)
81 and emit_MEM r = itow (CellsBasis.physicalRegisterNum r)
82 and emit_CTRL r = itow (CellsBasis.physicalRegisterNum r)
83 and emit_CELLSET r = itow (CellsBasis.physicalRegisterNum r)
84 fun Load {l, rt, b, offset} =
85 let val rt = emit_GP rt
86 val b = emit_GP b
87 in eWord32 ((l << 0wx1a) + ((rt << 0wx15) + ((b << 0wx10) + (offset && 0wxffff))))
88 end
89 and Special {rs, rt, opc} =
90 let val rs = emit_GP rs
91 val rt = emit_GP rt
92 in eWord32 ((rs << 0wx15) + ((rt << 0wx10) + opc))
93 end
94 fun emitter instr =
95 let
96 fun emitInstr (I.NOP) = error "NOP"
97 | emitInstr (I.LUI{rt, imm}) = error "LUI"
98 | emitInstr (I.LA{rt, b, d}) = error "LA"
99 | emitInstr (I.DLA{rt, b, d}) = error "DLA"
100 | emitInstr (I.LOAD{l, rt, b, d, mem}) = error "LOAD"
101 | emitInstr (I.STORE{s, rs, b, d, mem}) = error "STORE"
102 | emitInstr (I.FLOAD{l, ft, b, d, mem}) = error "FLOAD"
103 | emitInstr (I.FSTORE{s, fs, b, d, mem}) = error "FSTORE"
104 | emitInstr (I.FCMP{fcond, fmt, cc, fs1, fs2}) = error "FCMP"
105 | emitInstr (I.TRAP{t, rs, i}) = error "TRAP"
106 | emitInstr (I.J{lab, nop}) = error "J"
107 | emitInstr (I.JR{rs, labels, nop}) = error "JR"
108 | emitInstr (I.JAL{lab, defs, uses, cutsTo, mem, nop}) = error "JAL"
109 | emitInstr (I.JALR{rt, rs, defs, uses, cutsTo, mem, nop}) = error "JALR"
110 | emitInstr (I.RET{nop}) = error "RET"
111 | emitInstr (I.BRANCH{likely, cond, rs, rt, lab, nop}) = error "BRANCH"
112 | emitInstr (I.FBRANCH{likely, fbranch, cc, lab, nop}) = error "FBRANCH"
113 | emitInstr (I.ARITH{oper, rt, rs, i}) = error "ARITH"
114 | emitInstr (I.UNARY{oper, rt, rs}) = error "UNARY"
115 | emitInstr (I.MULTIPLY{oper, rt, rs}) = error "MULTIPLY"
116 | emitInstr (I.DIVIDE{oper, rt, rs}) = error "DIVIDE"
117 | emitInstr (I.MFLO GP) = error "MFLO"
118 | emitInstr (I.MTLO GP) = error "MTLO"
119 | emitInstr (I.MFHI GP) = error "MFHI"
120 | emitInstr (I.MTHI GP) = error "MTHI"
121 | emitInstr (I.BREAK int) = error "BREAK"
122 | emitInstr (I.FARITH{oper, ft, fs1, fs2}) = error "FARITH"
123 | emitInstr (I.FUNARY{oper, ft, fs}) = error "FUNARY"
124 | emitInstr (I.FARITH3{oper, ft, fs1, fs2, fs3}) = error "FARITH3"
125 | emitInstr (I.FROUND{oper, ft, fs1, rs2}) = error "FROUND"
126 | emitInstr (I.CVTI2F{cvt, rs, ft}) = error "CVTI2F"
127 | emitInstr (I.CVTF2I{cvt, fs, rt}) = error "CVTF2I"
128 | emitInstr (I.COPY{dst, src, impl, tmp}) = error "COPY"
129 | emitInstr (I.FCOPY{dst, src, impl, tmp}) = error "FCOPY"
130 | emitInstr (I.ANNOTATION{i, a}) = emitInstr i
131 | emitInstr (I.PHI{}) = ()
132 | emitInstr (I.SOURCE{}) = ()
133 | emitInstr (I.SINK{}) = ()
134 in
135 emitInstr instr
136 end
137
138 fun emitInstruction(I.ANNOTATION{i, ...}) = emitInstruction(i)
139 | emitInstruction(I.INSTR(i)) = emitter(i)
140 | emitInstruction(I.LIVE _) = ()
141 | emitInstruction(I.KILL _) = ()
142 | emitInstruction _ = error "emitInstruction"
143
144 in S.STREAM{beginCluster=init,
145 pseudoOp=pseudoOp,
146 emit=emitInstruction,
147 endCluster=fail,
148 defineLabel=doNothing,
149 entryLabel=doNothing,
150 comment=doNothing,
151 exitBlock=doNothing,
152 annotation=doNothing,
153 getAnnotations=getAnnotations
154 }
155 end
156 end
157