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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « crosstest/test_global.h ('k') | crosstest/test_global_main.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crosstest/test_global.cpp
diff --git a/crosstest/test_global.cpp b/crosstest/test_global.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a5a2f610a5bc78c632f00e9f18ea7964ca773433
--- /dev/null
+++ b/crosstest/test_global.cpp
@@ -0,0 +1,65 @@
+#include <stdint.h>
+#include <cstdlib>
+
+#include "test_global.h"
+
+// Partially initialized array
+int ArrayInitPartial[10] = { 60, 70, 80, 90, 100 };
+int ArrayInitFull[] = { 10, 20, 30, 40, 50 };
+const int ArrayConst[] = { -10, -20, -30 };
+static double ArrayDouble[10] = { 0.5, 1.5, 2.5, 3.5 };
+
+#if 0
+#define ARRAY(a) \
+ { (uint8_t *)(a), sizeof(a) }
+
+struct {
+ uint8_t *ArrayAddress;
+ size_t ArraySizeInBytes;
+} Arrays[] = {
+ ARRAY(ArrayInitPartial),
+ ARRAY(ArrayInitFull),
+ ARRAY(ArrayConst),
+ ARRAY(ArrayDouble),
+};
+size_t NumArraysElements = sizeof(Arrays) / sizeof(*Arrays);
+#endif // 0
+
+size_t getNumArrays() {
+ return 4;
+ // return NumArraysElements;
+}
+
+const uint8_t *getArray(size_t WhichArray, size_t &Len) {
+ // Using a switch statement instead of a table lookup because such a
+ // table is represented as a kind of initializer that Subzero
+ // doesn't yet support. Specifically, the table becomes constant
+ // aggregate data, and it contains relocations. TODO(stichnot):
+ // switch over to the cleaner table-based method when global
+ // initializers are fully implemented.
+ switch (WhichArray) {
+ default:
+ Len = -1;
+ return NULL;
+ case 0:
+ Len = sizeof(ArrayInitPartial);
+ return (uint8_t *)&ArrayInitPartial;
+ case 1:
+ Len = sizeof(ArrayInitFull);
+ return (uint8_t *)&ArrayInitFull;
+ case 2:
+ Len = sizeof(ArrayConst);
+ return (uint8_t *)&ArrayConst;
+ case 3:
+ Len = sizeof(ArrayDouble);
+ return (uint8_t *)&ArrayDouble;
+ }
+#if 0
+ if (WhichArray >= NumArraysElements) {
+ Len = -1;
+ return NULL;
+ }
+ Len = Arrays[WhichArray].ArraySizeInBytes;
+ return Arrays[WhichArray].ArrayAddress;
+#endif // 0
+}
« 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