OLD | NEW |
---|---|
1 //===- subzero/crosstest/test_global.cpp - Global variable access tests ---===// | 1 //===- subzero/crosstest/test_global.cpp - Global variable access tests ---===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // Implementation for crosstesting global variable access operations. | 10 // Implementation for crosstesting global variable access operations. |
11 // | 11 // |
12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
13 | 13 |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 #include <cstdlib> | 15 #include <cstdlib> |
16 | 16 |
17 #include "test_global.h" | 17 #include "test_global.h" |
18 | 18 |
19 // Note: The following take advantage of the fact that external global | |
20 // names are not mangled with the --prefix CL argument. Hence, they | |
21 // should have the same relocation value for both clang and Subzero. | |
Jim Stichnoth
2014/10/06 18:16:37
clang --> llc
Karl
2014/10/06 22:44:04
Done.
| |
22 extern uint8_t *ExternName1; | |
23 extern uint8_t *ExternName2; | |
24 extern uint8_t *ExternName3; | |
25 extern uint8_t *ExternName4; | |
26 extern uint8_t *ExternName5; | |
27 | |
19 // Partially initialized array | 28 // Partially initialized array |
20 int ArrayInitPartial[10] = { 60, 70, 80, 90, 100 }; | 29 static int ArrayInitPartial[10] = {60, 70, 80, 90, 100}; |
Jim Stichnoth
2014/10/06 18:16:37
Is it necessary to change all these to static? II
Karl
2014/10/06 22:44:04
Removed static keyword.
| |
21 int ArrayInitFull[] = { 10, 20, 30, 40, 50 }; | 30 static int ArrayInitFull[] = {10, 20, 30, 40, 50}; |
22 const int ArrayConst[] = { -10, -20, -30 }; | 31 static const int ArrayConst[] = {-10, -20, -30}; |
23 static double ArrayDouble[10] = { 0.5, 1.5, 2.5, 3.5 }; | 32 static double ArrayDouble[10] = { 0.5, 1.5, 2.5, 3.5 }; |
24 | 33 |
25 #if 0 | 34 #if 0 |
35 // TODO(kschimpf) Add this example once we know how to not mangle | |
Jim Stichnoth
2014/10/06 18:16:37
Could you add a reference to the part in IceTarget
Karl
2014/10/06 22:44:03
Done.
| |
36 // uninitialized, external globals (so that we can compare that | |
37 // the same, unmangled relocations are used). | |
38 static struct { | |
39 int Array1[5]; | |
40 uint8_t *Pointer1; | |
41 double Array2[3]; | |
42 uint8_t *Pointer2; | |
43 struct { | |
44 uint8_t *Pointer3; | |
45 int Array1[3]; | |
46 uint8_t *Pointer4; | |
47 } NestedStuff; | |
48 uint8_t *Pointer5; | |
49 } StructEx = { | |
50 { 10, 20, 30, 40, 50 }, | |
51 ExternName1, | |
52 { 0.5, 1.5, 2.5 }, | |
53 ExternName4, | |
54 { ExternName3, {1000, 1010, 1020}, ExternName2 }, | |
55 ExternName5, | |
56 }; | |
57 #endif | |
58 | |
26 #define ARRAY(a) \ | 59 #define ARRAY(a) \ |
27 { (uint8_t *)(a), sizeof(a) } | 60 { (uint8_t *)(a), sizeof(a) } |
28 | 61 |
62 // Note: By embedding the array addresses in this table, we are indirectly | |
63 // testing relocations (i.e. getArray would return the wrong address if | |
64 // relocations are broken). | |
29 struct { | 65 struct { |
30 uint8_t *ArrayAddress; | 66 uint8_t *ArrayAddress; |
31 size_t ArraySizeInBytes; | 67 size_t ArraySizeInBytes; |
32 } Arrays[] = { | 68 } Arrays[] = { |
33 ARRAY(ArrayInitPartial), | 69 ARRAY(ArrayInitPartial), |
34 ARRAY(ArrayInitFull), | 70 ARRAY(ArrayInitFull), |
35 ARRAY(ArrayConst), | 71 ARRAY(ArrayConst), |
36 ARRAY(ArrayDouble), | 72 ARRAY(ArrayDouble), |
73 {(uint8_t *)(ArrayInitPartial + 2), | |
74 sizeof(ArrayInitPartial) - 2 * sizeof(int)}, | |
75 // { (uint8_t*)(&StructEx), sizeof(StructEx) }, | |
37 }; | 76 }; |
38 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays); | 77 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays); |
39 #endif // 0 | |
40 | 78 |
41 size_t getNumArrays() { | 79 size_t getNumArrays() { return NumArraysElements; } |
42 return 4; | |
43 // return NumArraysElements; | |
44 } | |
45 | 80 |
46 const uint8_t *getArray(size_t WhichArray, size_t &Len) { | 81 const uint8_t *getArray(size_t WhichArray, size_t &Len) { |
47 // Using a switch statement instead of a table lookup because such a | |
48 // table is represented as a kind of initializer that Subzero | |
49 // doesn't yet support. Specifically, the table becomes constant | |
50 // aggregate data, and it contains relocations. TODO(stichnot): | |
51 // switch over to the cleaner table-based method when global | |
52 // initializers are fully implemented. | |
53 switch (WhichArray) { | |
54 default: | |
55 Len = -1; | |
56 return NULL; | |
57 case 0: | |
58 Len = sizeof(ArrayInitPartial); | |
59 return (uint8_t *)&ArrayInitPartial; | |
60 case 1: | |
61 Len = sizeof(ArrayInitFull); | |
62 return (uint8_t *)&ArrayInitFull; | |
63 case 2: | |
64 Len = sizeof(ArrayConst); | |
65 return (uint8_t *)&ArrayConst; | |
66 case 3: | |
67 Len = sizeof(ArrayDouble); | |
68 return (uint8_t *)&ArrayDouble; | |
69 } | |
70 #if 0 | |
71 if (WhichArray >= NumArraysElements) { | 82 if (WhichArray >= NumArraysElements) { |
72 Len = -1; | 83 Len = -1; |
73 return NULL; | 84 return NULL; |
74 } | 85 } |
75 Len = Arrays[WhichArray].ArraySizeInBytes; | 86 Len = Arrays[WhichArray].ArraySizeInBytes; |
76 return Arrays[WhichArray].ArrayAddress; | 87 return Arrays[WhichArray].ArrayAddress; |
77 #endif // 0 | |
78 } | 88 } |
OLD | NEW |