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

Unified Diff: src/IceTypes.cpp

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Use non-anonymous structs so that array_lengthof works Created 6 years, 8 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 | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceTypes.cpp
diff --git a/src/IceTypes.cpp b/src/IceTypes.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b54c0d7deb08b9628d631f658bd31fbe95dd102e
--- /dev/null
+++ b/src/IceTypes.cpp
@@ -0,0 +1,74 @@
+//===- subzero/src/IceTypes.cpp - Primitive type properties ---------------===//
+//
+// The Subzero Code Generator
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines a few attributes of Subzero primitive types.
+//
+//===----------------------------------------------------------------------===//
+
+#include "IceDefs.h"
+#include "IceTypes.h"
+
+namespace Ice {
+
+namespace {
+
+const struct {
+ size_t TypeWidthInBytes;
+ size_t TypeAlignInBytes;
+ const char *DisplayString;
+} TypeAttributes[] = {
+#define X(tag, size, align, str) \
+ { size, align, str } \
+ ,
+ ICETYPE_TABLE
+#undef X
+ };
+
+const size_t TypeAttributesSize =
+ sizeof(TypeAttributes) / sizeof(*TypeAttributes);
+
+} // end anonymous namespace
+
+size_t typeWidthInBytes(Type Ty) {
+ size_t Width = 0;
+ size_t Index = static_cast<size_t>(Ty);
+ if (Index < TypeAttributesSize) {
+ Width = TypeAttributes[Index].TypeWidthInBytes;
+ } else {
+ assert(0 && "Invalid type for typeWidthInBytes()");
+ }
+ return Width;
+}
+
+size_t typeAlignInBytes(Type Ty) {
+ size_t Align = 0;
+ size_t Index = static_cast<size_t>(Ty);
+ if (Index < TypeAttributesSize) {
+ Align = TypeAttributes[Index].TypeAlignInBytes;
+ } else {
+ assert(0 && "Invalid type for typeAlignInBytes()");
+ }
+ return Align;
+}
+
+// ======================== Dump routines ======================== //
+
+template <> Ostream &operator<<(Ostream &Str, const Type &Ty) {
+ size_t Index = static_cast<size_t>(Ty);
+ if (Index < TypeAttributesSize) {
+ Str << TypeAttributes[Index].DisplayString;
+ } else {
+ Str << "???";
+ assert(0 && "Invalid type for printing");
+ }
+
+ return Str;
+}
+
+} // end of namespace Ice
« no previous file with comments | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698