1// RUN: llvm-tblgen -gen-emitter -I %p/../../include %s | FileCheck %s --check-prefix=ENCODER
2// RUN: llvm-tblgen -gen-disassembler -I %p/../../include %s | FileCheck %s --check-prefix=DECODER
3
4include "llvm/Target/Target.td"
5
6def archInstrInfo : InstrInfo { }
7
8def arch : Target {
9    let InstructionSet = archInstrInfo;
10}
11
12def  Myi32  : Operand<i32> {
13  let DecoderMethod = "DecodeMyi32";
14}
15
16def ModeA : HwMode<"+a">;
17def ModeB : HwMode<"+b">;
18
19
20def fooTypeEncA : InstructionEncoding {
21  let Size = 4;
22  field bits<32> SoftFail = 0;
23  bits<32> Inst;
24  bits<8> factor;
25  let Inst{7-0} = factor;
26  let Inst{3-2} = 0b11;
27  let Inst{1-0} = 0b00;
28}
29
30def fooTypeEncB : InstructionEncoding {
31  let Size = 4;
32  field bits<32> SoftFail = 0;
33  bits<32> Inst;
34  bits<8> factor;
35  let Inst{15-8} = factor;
36  let Inst{1-0} = 0b11;
37}
38
39let OutOperandList = (outs) in {
40def foo : Instruction {
41  let InOperandList = (ins i32imm:$factor);
42  let EncodingInfos = EncodingByHwMode<
43    [ModeA, ModeB], [fooTypeEncA,
44                      fooTypeEncB]
45  >;
46  let AsmString = "foo  $factor";
47}
48
49def bar: Instruction {
50  let InOperandList = (ins i32imm:$factor);
51  let Size = 4;
52  bits<32> Inst;
53  bits<32> SoftFail;
54  bits<8> factor;
55  let Inst{31-24} = factor;
56  let Inst{1-0} = 0b10;
57  let AsmString = "bar  $factor";
58}
59}
60
61// DECODER-LABEL: DecoderTable_ModeA32[] =
62// DECODER-DAG: Opcode: fooTypeEncA:foo
63// DECODER-DAG: Opcode: bar
64// DECODER-LABEL: DecoderTable_ModeB32[] =
65// Note that the comment says fooTypeEncA but this is actually fooTypeEncB; plumbing
66// the correct comment text through the decoder is nontrivial.
67// DECODER-DAG: Opcode: fooTypeEncA:foo
68// DECODER-DAG: Opcode: bar
69
70// ENCODER-LABEL:   static const uint64_t InstBits_ModeA[] = {
71// ENCODER:         UINT64_C(2),        // bar
72// ENCODER:         UINT64_C(12),       // foo
73
74// ENCODER-LABEL:   static const uint64_t InstBits_ModeB[] = {
75// ENCODER:         UINT64_C(2),        // bar
76// ENCODER:         UINT64_C(3),        // foo
77
78// ENCODER:     case ::foo: {
79// ENCODER:      switch (HwMode) {
80// ENCODER:      default: llvm_unreachable("Unhandled HwMode");
81// ENCODER:      case 1: {
82