Jim Stichnoth | 7da431b | 2014-08-05 11:22:37 -0700 | [diff] [blame] | 1 | //===- subzero/crosstest/test_global.cpp - Global variable access tests ---===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Implementation for crosstesting global variable access operations. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 14 | #include <cstdlib> |
Antonio Maiorano | ca8a16e | 2020-11-10 16:56:20 -0500 | [diff] [blame] | 15 | #include <stdint.h> |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 16 | |
| 17 | #include "test_global.h" |
| 18 | |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 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 | |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 28 | // Partially initialized array |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 29 | int ArrayInitPartial[10] = {60, 70, 80, 90, 100}; |
| 30 | int ArrayInitFull[] = {10, 20, 30, 40, 50}; |
| 31 | const int ArrayConst[] = {-10, -20, -30}; |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 32 | static double ArrayDouble[10] = {0.5, 1.5, 2.5, 3.5}; |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 33 | |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 34 | static struct { |
| 35 | int Array1[5]; |
| 36 | uint8_t *Pointer1; |
| 37 | double Array2[3]; |
| 38 | uint8_t *Pointer2; |
| 39 | struct { |
| 40 | uint8_t *Pointer3; |
| 41 | int Array1[3]; |
| 42 | uint8_t *Pointer4; |
| 43 | } NestedStuff; |
| 44 | uint8_t *Pointer5; |
| 45 | } StructEx = { |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 46 | {10, 20, 30, 40, 50}, |
| 47 | ExternName1, |
| 48 | {0.5, 1.5, 2.5}, |
| 49 | ExternName4, |
| 50 | {ExternName3, {1000, 1010, 1020}, ExternName2}, |
| 51 | ExternName5, |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 52 | }; |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 53 | |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 54 | #define ARRAY(a) \ |
| 55 | { (uint8_t *)(a), sizeof(a) } |
| 56 | |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 57 | // Note: By embedding the array addresses in this table, we are indirectly |
| 58 | // testing relocations (i.e. getArray would return the wrong address if |
| 59 | // relocations are broken). |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 60 | struct { |
| 61 | uint8_t *ArrayAddress; |
| 62 | size_t ArraySizeInBytes; |
| 63 | } Arrays[] = { |
Jim Stichnoth | d9dc82e | 2015-03-03 17:06:33 -0800 | [diff] [blame] | 64 | ARRAY(ArrayInitPartial), |
| 65 | ARRAY(ArrayInitFull), |
| 66 | ARRAY(ArrayConst), |
| 67 | ARRAY(ArrayDouble), |
| 68 | {(uint8_t *)(ArrayInitPartial + 2), |
| 69 | sizeof(ArrayInitPartial) - 2 * sizeof(int)}, |
| 70 | {(uint8_t *)(&StructEx), sizeof(StructEx)}, |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 71 | }; |
| 72 | size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays); |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 73 | |
Karl Schimpf | e3f64d0 | 2014-10-07 10:38:22 -0700 | [diff] [blame] | 74 | size_t getNumArrays() { return NumArraysElements; } |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 75 | |
| 76 | const uint8_t *getArray(size_t WhichArray, size_t &Len) { |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 77 | if (WhichArray >= NumArraysElements) { |
| 78 | Len = -1; |
| 79 | return NULL; |
| 80 | } |
| 81 | Len = Arrays[WhichArray].ArraySizeInBytes; |
| 82 | return Arrays[WhichArray].ArrayAddress; |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 83 | } |