OLD | NEW |
(Empty) | |
| 1 //===- subzero/src/IceTypes.cpp - Primitive type properties ---------------===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // This file defines a few attributes of Subzero primitive types. |
| 11 // |
| 12 //===----------------------------------------------------------------------===// |
| 13 |
| 14 #include "IceDefs.h" |
| 15 #include "IceTypes.h" |
| 16 |
| 17 namespace Ice { |
| 18 |
| 19 namespace { |
| 20 |
| 21 const struct { |
| 22 size_t TypeWidthInBytes; |
| 23 const char *DisplayString; |
| 24 } TypeAttributes[] = { |
| 25 #define X(tag, size, str) \ |
| 26 { size, str } \ |
| 27 , |
| 28 ICETYPE_TABLE |
| 29 #undef X |
| 30 }; |
| 31 |
| 32 const size_t TypeAttributesSize = |
| 33 sizeof(TypeAttributes) / sizeof(*TypeAttributes); |
| 34 |
| 35 } // end anonymous namespace |
| 36 |
| 37 size_t typeWidthInBytes(Type Ty) { |
| 38 size_t Width = 0; |
| 39 size_t Index = static_cast<size_t>(Ty); |
| 40 if (Index < TypeAttributesSize) { |
| 41 Width = TypeAttributes[Index].TypeWidthInBytes; |
| 42 } else { |
| 43 assert(0 && "Invalid type for typeWidthInBytes()"); |
| 44 } |
| 45 return Width; |
| 46 } |
| 47 |
| 48 // ======================== Dump routines ======================== // |
| 49 |
| 50 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { |
| 51 size_t Index = static_cast<size_t>(Ty); |
| 52 if (Index < TypeAttributesSize) { |
| 53 Str << TypeAttributes[Index].DisplayString; |
| 54 } else { |
| 55 Str << "???"; |
| 56 assert(0 && "Invalid type for printing"); |
| 57 } |
| 58 |
| 59 return Str; |
| 60 } |
| 61 |
| 62 } // end of namespace Ice |
OLD | NEW |