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 size_t TypeAlignInBytes; |
| 24 const char *DisplayString; |
| 25 } TypeAttributes[] = { |
| 26 #define X(tag, size, align, str) \ |
| 27 { size, align, str } \ |
| 28 , |
| 29 ICETYPE_TABLE |
| 30 #undef X |
| 31 }; |
| 32 |
| 33 const size_t TypeAttributesSize = |
| 34 sizeof(TypeAttributes) / sizeof(*TypeAttributes); |
| 35 |
| 36 } // end anonymous namespace |
| 37 |
| 38 size_t typeWidthInBytes(Type Ty) { |
| 39 size_t Width = 0; |
| 40 size_t Index = static_cast<size_t>(Ty); |
| 41 if (Index < TypeAttributesSize) { |
| 42 Width = TypeAttributes[Index].TypeWidthInBytes; |
| 43 } else { |
| 44 assert(0 && "Invalid type for typeWidthInBytes()"); |
| 45 } |
| 46 return Width; |
| 47 } |
| 48 |
| 49 size_t typeAlignInBytes(Type Ty) { |
| 50 size_t Align = 0; |
| 51 size_t Index = static_cast<size_t>(Ty); |
| 52 if (Index < TypeAttributesSize) { |
| 53 Align = TypeAttributes[Index].TypeAlignInBytes; |
| 54 } else { |
| 55 assert(0 && "Invalid type for typeAlignInBytes()"); |
| 56 } |
| 57 return Align; |
| 58 } |
| 59 |
| 60 // ======================== Dump routines ======================== // |
| 61 |
| 62 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { |
| 63 size_t Index = static_cast<size_t>(Ty); |
| 64 if (Index < TypeAttributesSize) { |
| 65 Str << TypeAttributes[Index].DisplayString; |
| 66 } else { |
| 67 Str << "???"; |
| 68 assert(0 && "Invalid type for printing"); |
| 69 } |
| 70 |
| 71 return Str; |
| 72 } |
| 73 |
| 74 } // end of namespace Ice |
OLD | NEW |