File: deftype.td

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-7
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 1,998,872 kB
  • sloc: cpp: 6,951,694; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,033; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,177; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (70 lines) | stat: -rw-r--r-- 2,380 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// RUN: llvm-tblgen %s | FileCheck %s
// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
// RUN: not llvm-tblgen -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
// RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s

class Class<int v> {
  int value = v;
}

deftype StringAlias    = string;
deftype CodeAlias      = code;
deftype DagAlias       = dag;
deftype Boolean        = bit;
deftype Byte           = bits<8>;
deftype Integer        = int;
deftype IntList        = list<int>;
deftype ByteList       = list<Byte>;
deftype ClassList      = list<Class>;
// The type can be another type alias.
deftype ClassListAlias = ClassList;

// CHECK:      def test {
// CHECK-NEXT:   string str = "string";
// CHECK-NEXT:   string codeStr = "code";
// CHECK-NEXT:   dag dagExpr = ("string" "code");
// CHECK-NEXT:   bit bool = 0;
// CHECK-NEXT:   bits<8> byte = { 0, 1, 1, 1, 1, 0, 1, 1 };
// CHECK-NEXT:   int integer = 123;
// CHECK-NEXT:   list<int> ints = [1, 2, 3];
// 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 }];
// CHECK-NEXT:   list<Class> defs = [anonymous_0, anonymous_1, anonymous_2];
// CHECK-NEXT: }
def test {
  StringAlias    str     = "string";
  CodeAlias      codeStr = "code";
  DagAlias       dagExpr = (str codeStr);
  Boolean        bool    = false;
  Byte           byte    = 123;
  Integer        integer = 123;
  IntList        ints    = [1, 2, 3];
  ByteList       bytes   = [1, 2, 3];
  ClassListAlias defs    = [Class<1>, Class<2>, Class<3>];
}

#ifdef ERROR1
// ERROR1: [[@LINE+1]]:9: error: type of this name 'Byte' already exists
deftype Byte = bits<8>;
#endif

#ifdef ERROR2
// ERROR2: [[@LINE+1]]:9: error: type of this name 'Class' already exists
deftype Class = int;
#endif

#ifdef ERROR3
// ERROR3: [[@LINE+1]]:22: error: cannot define type alias for class type 'Class'
deftype ClassAlias = Class;
#endif

#ifdef ERROR4
// ERROR4: [[@LINE+1]]:7: error: there is already a defined type alias 'Byte'
class Byte; // incomplete class definition.
#endif

#ifdef ERROR5
// ERROR5: [[@LINE+1]]:7: error: there is already a defined type alias 'Byte'
class Byte {}
#endif