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

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: Fix omissions from previous patchset. 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
« src/IceInst.cpp ('K') | « src/IceTypes.h ('k') | src/llvm2ice.cpp » ('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..1bc960887e97ce8d909b96d9845e7c27bb9eb303
--- /dev/null
+++ b/src/IceTypes.cpp
@@ -0,0 +1,62 @@
+//===- 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 {
+
+#define X(tag, size, str) \
+ { size, str } \
+ ,
+
+const struct {
+ size_t TypeWidthInBytes;
+ IceString DisplayString;
JF 2014/04/23 03:51:28 This should be a POD since it's global, const char
Jim Stichnoth 2014/04/26 15:02:11 Done.
+} TypeAttributes[] = { ICETYPE_TABLE };
+
+#undef X
+
+const size_t TypeAttributesSize =
+ sizeof(TypeAttributes) / sizeof(*TypeAttributes);
+
+} // end anonymous namespace
+
+size_t typeWidthInBytes(IceType Type) {
+ size_t Width = 0;
+ size_t Index = static_cast<size_t>(Type);
+ if (Index < TypeAttributesSize) {
+ Width = TypeAttributes[Index].TypeWidthInBytes;
+ } else {
+ assert(0 && "Invalid type for typeWidthInBytes()");
+ }
+ return Width;
+}
+
+// ======================== Dump routines ======================== //
+
+template <> IceOstream &operator<<(IceOstream &Str, const IceType &Type) {
+ size_t Index = static_cast<size_t>(Type);
+ if (Index < TypeAttributesSize) {
+ Str << TypeAttributes[Index].DisplayString;
+ } else {
+ Str << "???";
+ assert(0 && "Invalid type for printing");
+ }
+
+ return Str;
+}
+
+} // end of namespace Ice
« src/IceInst.cpp ('K') | « src/IceTypes.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698