OLD | NEW |
(Empty) | |
| 1 #include <stdint.h> |
| 2 #include <cstdlib> |
| 3 |
| 4 #include "test_global.h" |
| 5 |
| 6 // Partially initialized array |
| 7 int ArrayInitPartial[10] = { 60, 70, 80, 90, 100 }; |
| 8 int ArrayInitFull[] = { 10, 20, 30, 40, 50 }; |
| 9 const int ArrayConst[] = { -10, -20, -30 }; |
| 10 static double ArrayDouble[10] = { 0.5, 1.5, 2.5, 3.5 }; |
| 11 |
| 12 #if 0 |
| 13 #define ARRAY(a) \ |
| 14 { (uint8_t *)(a), sizeof(a) } |
| 15 |
| 16 struct { |
| 17 uint8_t *ArrayAddress; |
| 18 size_t ArraySizeInBytes; |
| 19 } Arrays[] = { |
| 20 ARRAY(ArrayInitPartial), |
| 21 ARRAY(ArrayInitFull), |
| 22 ARRAY(ArrayConst), |
| 23 ARRAY(ArrayDouble), |
| 24 }; |
| 25 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays); |
| 26 #endif // 0 |
| 27 |
| 28 size_t getNumArrays() { |
| 29 return 4; |
| 30 // return NumArraysElements; |
| 31 } |
| 32 |
| 33 const uint8_t *getArray(size_t WhichArray, size_t &Len) { |
| 34 // Using a switch statement instead of a table lookup because such a |
| 35 // table is represented as a kind of initializer that Subzero |
| 36 // doesn't yet support. Specifically, the table becomes constant |
| 37 // aggregate data, and it contains relocations. TODO(stichnot): |
| 38 // switch over to the cleaner table-based method when global |
| 39 // initializers are fully implemented. |
| 40 switch (WhichArray) { |
| 41 default: |
| 42 Len = -1; |
| 43 return NULL; |
| 44 case 0: |
| 45 Len = sizeof(ArrayInitPartial); |
| 46 return (uint8_t *)&ArrayInitPartial; |
| 47 case 1: |
| 48 Len = sizeof(ArrayInitFull); |
| 49 return (uint8_t *)&ArrayInitFull; |
| 50 case 2: |
| 51 Len = sizeof(ArrayConst); |
| 52 return (uint8_t *)&ArrayConst; |
| 53 case 3: |
| 54 Len = sizeof(ArrayDouble); |
| 55 return (uint8_t *)&ArrayDouble; |
| 56 } |
| 57 #if 0 |
| 58 if (WhichArray >= NumArraysElements) { |
| 59 Len = -1; |
| 60 return NULL; |
| 61 } |
| 62 Len = Arrays[WhichArray].ArraySizeInBytes; |
| 63 return Arrays[WhichArray].ArrayAddress; |
| 64 #endif // 0 |
| 65 } |
OLD | NEW |