Revert 95130.
[oota-llvm.git] / lib / Target / MSP430 / MSP430InstrFormats.td
1 //===- MSP430InstrFormats.td - MSP430 Instruction Formats-----*- tblgen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source 
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 //  Describe MSP430 instructions format here
12 //
13
14 // Format specifies the encoding used by the instruction.  This is part of the
15 // ad-hoc solution used to emit machine instruction encodings by our machine
16 // code emitter.
17 class Format<bits<2> val> {
18   bits<2> Value = val;
19 }
20
21 def PseudoFrm   : Format<0>;
22 def SingleOpFrm : Format<1>;
23 def DoubleOpFrm : Format<2>;
24 def CondJumpFrm : Format<3>;
25
26 class SourceMode<bits<2> val> {
27   bits<2> Value = val;
28 }
29
30 def SrcReg      : SourceMode<0>;
31 def SrcMem      : SourceMode<1>;
32 def SrcIndReg   : SourceMode<2>;
33 def SrcPostInc  : SourceMode<3>;
34 def SrcImm      : SourceMode<3>;
35
36 class DestMode<bit val> {
37   bit Value = val;
38 }
39
40 def DstReg      : DestMode<0>;
41 def DstMem      : DestMode<1>;
42
43 class SizeVal<bits<3> val> {
44   bits<3> Value = val;
45 }
46
47 def SizeUnknown : SizeVal<0>; // Unknown / unset size
48 def SizeSpecial : SizeVal<1>; // Special instruction, e.g. pseudo
49 def Size2Bytes  : SizeVal<2>;
50 def Size4Bytes  : SizeVal<3>;
51 def Size6Bytes  : SizeVal<4>;
52
53 // Generic MSP430 Format
54 class MSP430Inst<dag outs, dag ins, SizeVal sz, Format f,
55                  string asmstr> : Instruction {
56   field bits<16> Inst;
57
58   let Namespace = "MSP430";
59
60   dag OutOperandList = outs;
61   dag InOperandList  = ins;
62
63   Format Form = f;
64   bits<2> FormBits = Form.Value;
65
66   SizeVal Sz = sz;
67   bits<3> Size = Sz.Value;
68
69   let AsmString   = asmstr;
70 }
71
72 // FIXME: Create different classes for different addressing modes.
73
74 // MSP430 Double Operand (Format I) Instructions
75 class IForm<bits<4> opcode, DestMode dest, bit bw, SourceMode src, SizeVal sz,
76             dag outs, dag ins, string asmstr, list<dag> pattern>
77   : MSP430Inst<outs, ins, sz, DoubleOpFrm, asmstr> {
78   let Pattern = pattern;
79
80   DestMode ad = dest;
81   SourceMode as = src;
82   
83   let Inst{12-15} = opcode;
84   let Inst{7}     = ad.Value;
85   let Inst{6}     = bw;
86   let Inst{4-5}   = as.Value;
87 }
88
89 // 8 bit IForm instructions
90 class IForm8<bits<4> opcode, DestMode dest, SourceMode src, SizeVal sz,
91              dag outs, dag ins, string asmstr, list<dag> pattern>
92   : IForm<opcode, dest, 1, src, sz, outs, ins, asmstr, pattern>;
93
94 class I8rr<bits<4> opcode,
95            dag outs, dag ins, string asmstr, list<dag> pattern>
96   : IForm8<opcode, DstReg, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
97
98 class I8ri<bits<4> opcode,
99            dag outs, dag ins, string asmstr, list<dag> pattern>
100   : IForm8<opcode, DstReg, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
101
102 class I8rm<bits<4> opcode,
103            dag outs, dag ins, string asmstr, list<dag> pattern>
104   : IForm8<opcode, DstReg, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
105
106 class I8mr<bits<4> opcode,
107            dag outs, dag ins, string asmstr, list<dag> pattern>
108   : IForm8<opcode, DstMem, SrcReg, Size4Bytes, outs, ins, asmstr, pattern>;
109
110 class I8mi<bits<4> opcode,
111            dag outs, dag ins, string asmstr, list<dag> pattern>
112   : IForm8<opcode, DstMem, SrcImm, Size6Bytes, outs, ins, asmstr, pattern>;
113
114 class I8mm<bits<4> opcode,
115            dag outs, dag ins, string asmstr, list<dag> pattern>
116   : IForm8<opcode, DstMem, SrcMem, Size6Bytes, outs, ins, asmstr, pattern>;
117
118 // 16 bit IForm instructions
119 class IForm16<bits<4> opcode, DestMode dest, SourceMode src, SizeVal sz,
120               dag outs, dag ins, string asmstr, list<dag> pattern>
121   : IForm<opcode, dest, 0, src, sz, outs, ins, asmstr, pattern>;
122
123 class I16rr<bits<4> opcode,
124             dag outs, dag ins, string asmstr, list<dag> pattern>
125   : IForm16<opcode, DstReg, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
126
127 class I16ri<bits<4> opcode,
128             dag outs, dag ins, string asmstr, list<dag> pattern>
129   : IForm16<opcode, DstReg, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
130
131 class I16rm<bits<4> opcode,
132             dag outs, dag ins, string asmstr, list<dag> pattern>
133   : IForm16<opcode, DstReg, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
134
135 class I16mr<bits<4> opcode,
136             dag outs, dag ins, string asmstr, list<dag> pattern>
137   : IForm16<opcode, DstMem, SrcReg, Size4Bytes, outs, ins, asmstr, pattern>;
138
139 class I16mi<bits<4> opcode,
140             dag outs, dag ins, string asmstr, list<dag> pattern>
141   : IForm16<opcode, DstMem, SrcImm, Size6Bytes, outs, ins, asmstr, pattern>;
142
143 class I16mm<bits<4> opcode,
144             dag outs, dag ins, string asmstr, list<dag> pattern>
145   : IForm16<opcode, DstMem, SrcMem, Size6Bytes, outs, ins, asmstr, pattern>;
146
147 // MSP430 Single Operand (Format II) Instructions
148 class IIForm<bits<9> opcode, bit bw, SourceMode src, SizeVal sz,
149              dag outs, dag ins, string asmstr, list<dag> pattern>
150   : MSP430Inst<outs, ins, sz, SingleOpFrm, asmstr> {
151   let Pattern = pattern;
152   
153   SourceMode as = src;
154
155   let Inst{7-15} = opcode;
156   let Inst{6}    = bw;
157   let Inst{4-5}  = as.Value;
158 }
159
160 // 8 bit IIForm instructions
161 class IIForm8<bits<9> opcode, SourceMode src, SizeVal sz,
162               dag outs, dag ins, string asmstr, list<dag> pattern>
163   : IIForm<opcode, 1, src, sz, outs, ins, asmstr, pattern>;
164
165 class II8r<bits<9> opcode,
166            dag outs, dag ins, string asmstr, list<dag> pattern>
167   : IIForm8<opcode, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
168
169 class II8m<bits<9> opcode,
170            dag outs, dag ins, string asmstr, list<dag> pattern>
171   : IIForm8<opcode, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
172
173 class II8i<bits<9> opcode,
174            dag outs, dag ins, string asmstr, list<dag> pattern>
175   : IIForm8<opcode, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
176
177 // 16 bit IIForm instructions
178 class IIForm16<bits<9> opcode, SourceMode src, SizeVal sz,
179                dag outs, dag ins, string asmstr, list<dag> pattern>
180   : IIForm<opcode, 0, src, sz, outs, ins, asmstr, pattern>;
181
182 class II16r<bits<9> opcode,
183             dag outs, dag ins, string asmstr, list<dag> pattern>
184   : IIForm16<opcode, SrcReg, Size2Bytes, outs, ins, asmstr, pattern>;
185
186 class II16m<bits<9> opcode,
187             dag outs, dag ins, string asmstr, list<dag> pattern>
188   : IIForm16<opcode, SrcMem, Size4Bytes, outs, ins, asmstr, pattern>;
189
190 class II16i<bits<9> opcode,
191             dag outs, dag ins, string asmstr, list<dag> pattern>
192   : IIForm16<opcode, SrcImm, Size4Bytes, outs, ins, asmstr, pattern>;
193
194 // MSP430 Conditional Jumps Instructions
195 class CJForm<bits<3> opcode, bits<3> cond,
196              dag outs, dag ins, string asmstr, list<dag> pattern>
197   : MSP430Inst<outs, ins, Size2Bytes, CondJumpFrm, asmstr> {
198   let Pattern = pattern;
199   
200   let Inst{13-15} = opcode;
201   let Inst{10-12} = cond;
202 }
203
204 // Pseudo instructions
205 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
206   : MSP430Inst<outs, ins, SizeSpecial, PseudoFrm, asmstr> {
207   let Pattern = pattern;
208   let Inst{15-0} = 0;
209 }