brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.4 KiB · 0b69a35 Raw
165 lines · plain
1// RUN: llvm-tblgen %s | FileCheck %s2// XFAIL: vg_leak3 4// This file has tests for the list slice suffix.5 6// Test defvars and literal lists.7 8// CHECK: def Rec009// CHECK:   list<int> ShowVar1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]10// CHECK:   int ShowVar2 = 011// CHECK:   list<int> ShowVar3 = [2, 3, 4, 5]12// CHECK:   int ShowVar4 = 213// CHECK:   list<int> ShowVar5 = [2, 3, 4, 5]14 15defvar Var1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];16defvar Var2 = Var1[0];17defvar Var3 = Var1[2...5];18 19defvar Var4 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][2];20defvar Var5 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9][2...5];21 22def Rec00 { // Display the defvars.23  list<int> ShowVar1 = Var1;24  int       ShowVar2 = Var2;25  list<int> ShowVar3 = Var3;26  int       ShowVar4 = Var4;27  list<int> ShowVar5 = Var5;28}29 30// CHECK: def Rec0131// CHECK:   int Zero = 032// CHECK:   list<int> TwoFive = [2, 3, 4, 5]33 34def Rec01 {35  int Zero = Var1[0];36  list<int> TwoFive = Var1[2...5];37}38 39// Test class template arguments.40 41// CHECK: def Rec0242// CHECK:   int Zero = 1043// CHECK:   list<int> TwoFive = [12, 13, 14, 15]44 45class Class1<list<int> ids> {46  int Zero = ids[0];47  list<int> TwoFive = ids[2...5];48}49 50def Rec02 : Class1<[10, 11, 12, 13, 14, 15, 16, 17]>;51 52// Test anonymous record fetches.53 54// CHECK: def Rec0355// CHECK:   int Zero = 2056// CHECK:   list<int> TwoFive = [22, 23, 24, 25]57 58def Rec03 {59  int Zero = Class1<[20, 21, 22, 23, 24, 25, 26]>.Zero;60  list<int> TwoFive = Class1<[20, 21, 22, 23, 24, 25, 26]>.TwoFive;61}62 63// Test multiclass template arguments.64 65// CHECK: def Rec04_MC166// CHECK:   int Zero = 3067// CHECK:   list<int> TwoFive = [32, 33, 34, 35]68// CHECK: def Rec05_MC169// CHECK:   int Zero = 3070// CHECK:   list<int> TwoFive = [32, 33, 34, 35]71 72multiclass MC1<list<int> ids> {73  def _MC1 {74    int Zero = ids[0];75    list<int> TwoFive = ids[2...5];76  }77}78 79defm Rec04 : MC1<[30, 31, 32, 33, 34, 35, 36]>;80defm Rec05 : MC1<[30, 31, 32, 33, 34, 35]>;81 82// Test taking a complex subset of the list items from another record.83 84// CHECK: def Rec0785// CHECK:   list<int> SomeValues = [40, 43, 44, 45, 40, 47, 49, 48, 47, 46, 40]86 87def Rec06 {88  list<int> Values = [40, 41, 42, 43, 44, 45, 46, 47, 48, 49];89}90 91def Rec07 {92  list<int> SomeValues = Rec06.Values[0, 3...5, 0, 7, 9...6, 0];93}94 95// Test a double subscript.96 97// CHECK: def Rec0898// CHECK:   list<list<string>> Array = {{.*}}"foo", "bar", "snork"], ["zoo", "quux", "flarp"]]99// CHECK:   string Flarp = "flarp"100// CHECK:   list<string> ZooQuux = ["zoo", "quux"]101 102def Rec08 {103  list<list<string>> Array = [["foo", "bar", "snork"],104                              ["zoo", "quux", "flarp"]];105  string Flarp = Array[1][2];106  list<string> ZooQuux = Array[1][0...1];107}108 109// Test uninitialized list elements.110 111// CHECK: def Rec09112// CHECK:   int Zero = ?;113// CHECK:   list<int> TwoFive = [2, 3, ?, 5];114// We need CHECK-NEXT for these because otherwise it will match anonymous defs115// that appear later.116// CHECK: def Rec10 {117// CHECK-NEXT:   int Zero = ?;118// CHECK-NEXT:   list<int> TwoFive = [2, 3, ?, 5];119 120def Rec09 : Class1<[?, ?, 2, 3, ?, 5, ?]>;121 122def Rec10 {123  int Zero = Class1<[?, ?, 2, 3, ?, 5, ?]>.Zero;124  list<int> TwoFive = Class1<[?, ?, 2, 3, ?, 5, ?]>.TwoFive;125}126 127// Test list[list] and list[int]128// CHECK: def Rec11129def Rec11 {130  list<int> s5 = Var1[0...4];131 132  // list[expr]133  // CHECK:   list<int> rev = [4, 3, 2, 1, 0];134  list<int> rev = !foreach(i, s5, Var1[!sub(4, i)]);135 136  // Slice by list[foreach]137  // CHECK:   list<int> revf = [4, 3, 2, 1, 0];138  list<int> revf = Var1[!foreach(i, s5, !sub(4, i))];139 140  // Simple slice141  // CHECK:   list<int> rr = [0, 1, 2, 3, 4];142  list<int> rr  = rev[rev];143 144  // Trailing comma is acceptable145  // CHECK:   list<int> rr_ = [0, 1, 2, 3, 4];146  list<int> rr_ = rev[rev,];147 148  // Concatenation in slice149  // CHECK:   list<int> rrr = [1, 2, 4, 3, 2, 1, 0, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 8];150  list<int> empty = [];151  list<int> rrr = Var1[1, 2, rev, 3...6, 7, empty, rr, 8];152 153  // Recognized as slice by the trailing comma154  // CHECK:   list<list<int>> rl1 = {{\[}}[0], [1], [2], [3], [4]];155  list<list<int>> rl1 = !foreach(i, rev, rev[i,]);156 157  // Slice by pair<int,int>158  // CHECK:   list<list<int>> rll = {{\[}}[0, 4], [1, 3], [2, 2], [3, 1], [4, 0]];159  list<list<int>> rll = !foreach(i, rev, rev[i, !sub(4, i)]);160 161  // Slice by dynamic range162  // CHECK:   list<list<int>> rlr = {{\[}}[4, 3, 2, 1, 0], [3, 2, 1], [2], [1, 2, 3], [0, 1, 2, 3, 4]];163  list<list<int>> rlr = !foreach(i, s5, rev[i...!sub(4, i)]);164}165