1 //===- MSP430InstrFormats.td - MSP430 Instruction Formats-----*- tblgen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
11 // Describe MSP430 instructions format here
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
17 class Format<bits<2> val> {
21 def PseudoFrm : Format<0>;
22 def SingleOpFrm : Format<1>;
23 def DoubleOpFrm : Format<2>;
24 def CondJumpFrm : Format<3>;
26 class SourceMode<bits<2> val> {
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>;
36 class DestMode<bit val> {
40 def DstReg : DestMode<0>;
41 def DstMem : DestMode<1>;
43 class SizeVal<bits<3> val> {
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>;
53 // Generic MSP430 Format
54 class MSP430Inst<dag outs, dag ins, SizeVal sz, Format f,
55 string asmstr> : Instruction {
58 let Namespace = "MSP430";
60 dag OutOperandList = outs;
61 dag InOperandList = ins;
64 bits<2> FormBits = Form.Value;
67 bits<3> Size = Sz.Value;
69 let AsmString = asmstr;
72 // FIXME: Create different classes for different addressing modes.
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;
83 let Inst{12-15} = opcode;
84 let Inst{7} = ad.Value;
86 let Inst{4-5} = as.Value;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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;
155 let Inst{7-15} = opcode;
157 let Inst{4-5} = as.Value;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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>;
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;
200 let Inst{13-15} = opcode;
201 let Inst{10-12} = cond;
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;