1 //===- subzero/crosstest/test_global.cpp - Global variable access tests ---===//
3 // The Subzero Code Generator
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implementation for crosstesting global variable access operations.
12 //===----------------------------------------------------------------------===//
17 #include "test_global.h"
19 // Partially initialized array
20 int ArrayInitPartial[10] = { 60, 70, 80, 90, 100 };
21 int ArrayInitFull[] = { 10, 20, 30, 40, 50 };
22 const int ArrayConst[] = { -10, -20, -30 };
23 static double ArrayDouble[10] = { 0.5, 1.5, 2.5, 3.5 };
27 { (uint8_t *)(a), sizeof(a) }
30 uint8_t *ArrayAddress;
31 size_t ArraySizeInBytes;
33 ARRAY(ArrayInitPartial),
38 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays);
41 size_t getNumArrays() {
43 // return NumArraysElements;
46 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.
58 Len = sizeof(ArrayInitPartial);
59 return (uint8_t *)&ArrayInitPartial;
61 Len = sizeof(ArrayInitFull);
62 return (uint8_t *)&ArrayInitFull;
64 Len = sizeof(ArrayConst);
65 return (uint8_t *)&ArrayConst;
67 Len = sizeof(ArrayDouble);
68 return (uint8_t *)&ArrayDouble;
71 if (WhichArray >= NumArraysElements) {
75 Len = Arrays[WhichArray].ArraySizeInBytes;
76 return Arrays[WhichArray].ArrayAddress;