Add instruction formats & support stuff
[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 class SourceMode<bits<2> val> {
22   bits<2> Value = val;
23 }
24
25 class DestMode<bit val> {
26   bit Value = val;
27 }
28
29 def PseudoFrm   : Format<0>;
30 def SingleOpFrm : Format<1>;
31 def DoubleOpFrm : Format<2>;
32 def CondJumpFrm : Format<3>;
33
34 def DstReg      : DestMode<0>;
35 def DstMem      : DestMode<1>;
36
37 def SrcReg      : SourceMode<0>;
38 def SrcMem      : SourceMode<1>;
39 def SrcIndReg   : SourceMode<2>;
40 def SrcPostInc  : SourceMode<3>;
41 def SrcImm      : SourceMode<3>;
42
43 // Generic MSP430 Format
44 class MSP430Inst<dag outs, dag ins, Format f, string asmstr> : Instruction {
45   field bits<16> Inst;
46
47   let Namespace = "MSP430";
48
49   dag OutOperandList = outs;
50   dag InOperandList  = ins;
51
52   Format Form = f;
53   bits<2> FormBits = Form.Value;
54
55   let AsmString   = asmstr;
56 }
57
58 // FIXME: Create different classes for different addressing modes.
59
60 // MSP430 Double Operand (Format I) Instructions
61 class IForm<bits<4> opcode, DestMode dest, bit bw, SourceMode src,
62             dag outs, dag ins, string asmstr, list<dag> pattern>
63   : MSP430Inst<outs, ins, DoubleOpFrm, asmstr> {
64   let Pattern = pattern;
65
66   DestMode ad = dest;
67   SourceMode  as = src;
68   
69   let Inst{12-15} = opcode;
70   let Inst{7}     = ad.Value;
71   let Inst{6}     = bw;
72   let Inst{4-5}   = as.Value;
73 }
74
75 // 8 bit IForm instructions
76 class IForm8<bits<4> opcode, DestMode dest, SourceMode src,
77              dag outs, dag ins, string asmstr, list<dag> pattern>
78   : IForm<opcode, dest, 1, src, outs, ins, asmstr, pattern>;
79
80 class I8rr<bits<4> opcode,
81            dag outs, dag ins, string asmstr, list<dag> pattern>
82   : IForm8<opcode, DstReg, SrcReg, outs, ins, asmstr, pattern>;
83
84 class I8ri<bits<4> opcode,
85            dag outs, dag ins, string asmstr, list<dag> pattern>
86   : IForm8<opcode, DstReg, SrcImm, outs, ins, asmstr, pattern>;
87
88 class I8rm<bits<4> opcode,
89            dag outs, dag ins, string asmstr, list<dag> pattern>
90   : IForm8<opcode, DstReg, SrcMem, outs, ins, asmstr, pattern>;
91
92 class I8mr<bits<4> opcode,
93            dag outs, dag ins, string asmstr, list<dag> pattern>
94   : IForm8<opcode, DstMem, SrcReg, outs, ins, asmstr, pattern>;
95
96 class I8mi<bits<4> opcode,
97            dag outs, dag ins, string asmstr, list<dag> pattern>
98   : IForm8<opcode, DstMem, SrcImm, outs, ins, asmstr, pattern>;
99
100 class I8mm<bits<4> opcode,
101            dag outs, dag ins, string asmstr, list<dag> pattern>
102   : IForm8<opcode, DstMem, SrcMem, outs, ins, asmstr, pattern>;
103
104 // 16 bit IForm instructions
105 class IForm16<bits<4> opcode, DestMode dest, SourceMode src,
106               dag outs, dag ins, string asmstr, list<dag> pattern>
107   : IForm<opcode, dest, 0, src, outs, ins, asmstr, pattern>;
108
109 class I16rr<bits<4> opcode,
110             dag outs, dag ins, string asmstr, list<dag> pattern>
111   : IForm16<opcode, DstReg, SrcReg, outs, ins, asmstr, pattern>;
112
113 class I16ri<bits<4> opcode,
114             dag outs, dag ins, string asmstr, list<dag> pattern>
115   : IForm16<opcode, DstReg, SrcImm, outs, ins, asmstr, pattern>;
116
117 class I16rm<bits<4> opcode,
118             dag outs, dag ins, string asmstr, list<dag> pattern>
119   : IForm16<opcode, DstReg, SrcMem, outs, ins, asmstr, pattern>;
120
121 class I16mr<bits<4> opcode,
122             dag outs, dag ins, string asmstr, list<dag> pattern>
123   : IForm16<opcode, DstMem, SrcReg, outs, ins, asmstr, pattern>;
124
125 class I16mi<bits<4> opcode,
126             dag outs, dag ins, string asmstr, list<dag> pattern>
127   : IForm16<opcode, DstMem, SrcImm, outs, ins, asmstr, pattern>;
128
129 class I16mm<bits<4> opcode,
130             dag outs, dag ins, string asmstr, list<dag> pattern>
131   : IForm16<opcode, DstMem, SrcMem, outs, ins, asmstr, pattern>;
132
133 // MSP430 Single Operand (Format II) Instructions
134 class IIForm<bits<9> opcode, bit bw, SourceMode src,
135              dag outs, dag ins, string asmstr, list<dag> pattern>
136   : MSP430Inst<outs, ins, SingleOpFrm, asmstr> {
137   let Pattern = pattern;
138   
139   SourceMode as = src;
140
141   let Inst{7-15} = opcode;
142   let Inst{6}    = bw;
143   let Inst{4-5}  = as.Value;
144 }
145
146 // 8 bit IIForm instructions
147 class IIForm8<bits<9> opcode, SourceMode src,
148               dag outs, dag ins, string asmstr, list<dag> pattern>
149   : IIForm<opcode, 1, src, outs, ins, asmstr, pattern>;
150
151 // 16 bit IIForm instructions
152 class IIForm16<bits<9> opcode, SourceMode src,
153                dag outs, dag ins, string asmstr, list<dag> pattern>
154   : IIForm<opcode, 0, src, outs, ins, asmstr, pattern>;
155
156 // MSP430 Conditional Jumps Instructions
157 class CJForm<bits<3> opcode, bits<3> cond, bit s,
158              dag outs, dag ins, string asmstr, list<dag> pattern>
159   : MSP430Inst<outs, ins, CondJumpFrm, asmstr> {
160   let Pattern = pattern;
161   
162   let Inst{13-15} = opcode;
163   let Inst{10-12} = cond;
164   let Inst{9}     = s;
165 }
166
167 // Pseudo instructions
168 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
169   : MSP430Inst<outs, ins, PseudoFrm, asmstr> {
170   let Pattern = pattern;
171   let Inst{15-0} = 0;
172 }