Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: crosstest/test_global.cpp

Issue 624663002: Introduce model of global initializers in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Makefile.standalone ('k') | pydir/crosstest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 llc and Subzero.
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 int ArrayInitPartial[10] = {60, 70, 80, 90, 100};
21 int ArrayInitFull[] = { 10, 20, 30, 40, 50 }; 30 int ArrayInitFull[] = {10, 20, 30, 40, 50};
22 const int ArrayConst[] = { -10, -20, -30 }; 31 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
36 // uninitialized, external globals (so that we can compare that
37 // the same, unmangled relocations are used). See comment in
38 // TargetGlobalInitX8632::lower in IceTargetLoweringX8632.cpp for
39 // details.
40 static struct {
41 int Array1[5];
42 uint8_t *Pointer1;
43 double Array2[3];
44 uint8_t *Pointer2;
45 struct {
46 uint8_t *Pointer3;
47 int Array1[3];
48 uint8_t *Pointer4;
49 } NestedStuff;
50 uint8_t *Pointer5;
51 } StructEx = {
52 { 10, 20, 30, 40, 50 },
53 ExternName1,
54 { 0.5, 1.5, 2.5 },
55 ExternName4,
56 { ExternName3, {1000, 1010, 1020}, ExternName2 },
57 ExternName5,
58 };
59 #endif
60
26 #define ARRAY(a) \ 61 #define ARRAY(a) \
27 { (uint8_t *)(a), sizeof(a) } 62 { (uint8_t *)(a), sizeof(a) }
28 63
64 // Note: By embedding the array addresses in this table, we are indirectly
65 // testing relocations (i.e. getArray would return the wrong address if
66 // relocations are broken).
29 struct { 67 struct {
30 uint8_t *ArrayAddress; 68 uint8_t *ArrayAddress;
31 size_t ArraySizeInBytes; 69 size_t ArraySizeInBytes;
32 } Arrays[] = { 70 } Arrays[] = {
33 ARRAY(ArrayInitPartial), 71 ARRAY(ArrayInitPartial),
34 ARRAY(ArrayInitFull), 72 ARRAY(ArrayInitFull),
35 ARRAY(ArrayConst), 73 ARRAY(ArrayConst),
36 ARRAY(ArrayDouble), 74 ARRAY(ArrayDouble),
75 {(uint8_t *)(ArrayInitPartial + 2),
76 sizeof(ArrayInitPartial) - 2 * sizeof(int)},
77 // { (uint8_t*)(&StructEx), sizeof(StructEx) },
37 }; 78 };
38 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays); 79 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays);
39 #endif // 0
40 80
41 size_t getNumArrays() { 81 size_t getNumArrays() { return NumArraysElements; }
42 return 4;
43 // return NumArraysElements;
44 }
45 82
46 const uint8_t *getArray(size_t WhichArray, size_t &Len) { 83 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) { 84 if (WhichArray >= NumArraysElements) {
72 Len = -1; 85 Len = -1;
73 return NULL; 86 return NULL;
74 } 87 }
75 Len = Arrays[WhichArray].ArraySizeInBytes; 88 Len = Arrays[WhichArray].ArraySizeInBytes;
76 return Arrays[WhichArray].ArrayAddress; 89 return Arrays[WhichArray].ArrayAddress;
77 #endif // 0
78 } 90 }
OLDNEW
« no previous file with comments | « Makefile.standalone ('k') | pydir/crosstest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698