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 |