OSDN Git Service

Subzero: Fix and clean up some cross tests.
[android-x86/external-swiftshader.git] / crosstest / test_global.cpp
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
14 #include <stdint.h>
15 #include <cstdlib>
16
17 #include "test_global.h"
18
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 };
24
25 #if 0
26 #define ARRAY(a)                                                               \
27   { (uint8_t *)(a), sizeof(a) }
28
29 struct {
30   uint8_t *ArrayAddress;
31   size_t ArraySizeInBytes;
32 } Arrays[] = {
33   ARRAY(ArrayInitPartial),
34   ARRAY(ArrayInitFull),
35   ARRAY(ArrayConst),
36   ARRAY(ArrayDouble),
37 };
38 size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays);
39 #endif // 0
40
41 size_t getNumArrays() {
42   return 4;
43   // return NumArraysElements;
44 }
45
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.
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) {
72     Len = -1;
73     return NULL;
74   }
75   Len = Arrays[WhichArray].ArraySizeInBytes;
76   return Arrays[WhichArray].ArrayAddress;
77 #endif // 0
78 }