xref: /llvm-project/llvm/test/TableGen/deftype.td (revision acf6811d0f2b6b453be46ddf7e046e1346991c98)
1// RUN: llvm-tblgen %s | FileCheck %s
2// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
3// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
4// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
5// RUN: not llvm-tblgen -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
6// RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
7
8class Class<int v> {
9  int value = v;
10}
11
12deftype StringAlias    = string;
13deftype CodeAlias      = code;
14deftype DagAlias       = dag;
15deftype Boolean        = bit;
16deftype Byte           = bits<8>;
17deftype Integer        = int;
18deftype IntList        = list<int>;
19deftype ByteList       = list<Byte>;
20deftype ClassList      = list<Class>;
21// The type can be another type alias.
22deftype ClassListAlias = ClassList;
23
24// CHECK:      def test {
25// CHECK-NEXT:   string str = "string";
26// CHECK-NEXT:   string codeStr = "code";
27// CHECK-NEXT:   dag dagExpr = ("string" "code");
28// CHECK-NEXT:   bit bool = 0;
29// CHECK-NEXT:   bits<8> byte = { 0, 1, 1, 1, 1, 0, 1, 1 };
30// CHECK-NEXT:   int integer = 123;
31// CHECK-NEXT:   list<int> ints = [1, 2, 3];
32// CHECK-NEXT:   list<bits<8>> bytes = [{ 0, 0, 0, 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 0, 0, 0, 0, 1, 1 }];
33// CHECK-NEXT:   list<Class> defs = [anonymous_0, anonymous_1, anonymous_2];
34// CHECK-NEXT: }
35def test {
36  StringAlias    str     = "string";
37  CodeAlias      codeStr = "code";
38  DagAlias       dagExpr = (str codeStr);
39  Boolean        bool    = false;
40  Byte           byte    = 123;
41  Integer        integer = 123;
42  IntList        ints    = [1, 2, 3];
43  ByteList       bytes   = [1, 2, 3];
44  ClassListAlias defs    = [Class<1>, Class<2>, Class<3>];
45}
46
47#ifdef ERROR1
48// ERROR1: [[@LINE+1]]:9: error: type of this name 'Byte' already exists
49deftype Byte = bits<8>;
50#endif
51
52#ifdef ERROR2
53// ERROR2: [[@LINE+1]]:9: error: type of this name 'Class' already exists
54deftype Class = int;
55#endif
56
57#ifdef ERROR3
58// ERROR3: [[@LINE+1]]:22: error: cannot define type alias for class type 'Class'
59deftype ClassAlias = Class;
60#endif
61
62#ifdef ERROR4
63// ERROR4: [[@LINE+1]]:7: error: there is already a defined type alias 'Byte'
64class Byte; // incomplete class definition.
65#endif
66
67#ifdef ERROR5
68// ERROR5: [[@LINE+1]]:7: error: there is already a defined type alias 'Byte'
69class Byte {}
70#endif
71