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

Side by Side Diff: crosstest/test_global.cpp

Issue 358013003: Subzero: Partial implementation of global initializers. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: After rebasing from laster master Created 6 years, 5 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 | « crosstest/test_global.h ('k') | crosstest/test_global_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « crosstest/test_global.h ('k') | crosstest/test_global_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698