Chromium Code Reviews| 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 { | |
| 18 | |
| 19 const struct { | |
| 20 IceType Type; | |
| 21 size_t TypeWidthInBytes; | |
| 22 IceString DisplayString; | |
| 23 } TypeAttributes[] = { { IceType_void, 0, "void" }, | |
| 24 { IceType_i1, 1, "i1" }, | |
| 25 { IceType_i8, 1, "i8" }, | |
| 26 { IceType_i16, 2, "i16" }, | |
| 27 { IceType_i32, 4, "i32" }, | |
| 28 { IceType_i64, 8, "i64" }, | |
| 29 { IceType_f32, 4, "float" }, | |
| 30 { IceType_f64, 8, "double" }, }; | |
|
JF
2014/04/16 01:27:32
I would still use xmacros here, since it prevents
Jim Stichnoth
2014/04/21 20:26:40
Done.
| |
| 31 const uint32_t TypeAttributesSize = | |
| 32 sizeof(TypeAttributes) / sizeof(*TypeAttributes); | |
| 33 | |
| 34 } // end anonymous namespace | |
| 35 | |
| 36 size_t iceTypeWidthInBytes(IceType Type) { | |
| 37 size_t Width = 0; | |
| 38 uint32_t Index = static_cast<uint32_t>(Type); | |
| 39 if (Index < TypeAttributesSize) { | |
| 40 assert(TypeAttributes[Index].Type == Type); | |
| 41 Width = TypeAttributes[Index].TypeWidthInBytes; | |
| 42 } | |
| 43 assert(Width && "Invalid type for iceTypeWidthInBytes()"); | |
|
JF
2014/04/16 01:27:32
Is it expected that IceType_void asserts here?
Jim Stichnoth
2014/04/21 20:26:40
Yes, at least originally. This function is meant
| |
| 44 return Width; | |
| 45 } | |
| 46 | |
| 47 // ======================== Dump routines ======================== // | |
| 48 | |
| 49 template <> IceOstream &operator<<(IceOstream &Str, const IceType &Type) { | |
| 50 uint32_t Index = static_cast<uint32_t>(Type); | |
| 51 if (Index < TypeAttributesSize) { | |
| 52 assert(TypeAttributes[Index].Type == Type); | |
| 53 Str << TypeAttributes[Index].DisplayString; | |
| 54 } else { | |
| 55 Str << "???"; | |
| 56 assert(0 && "Invalid type for printing"); | |
| 57 } | |
| 58 | |
| 59 return Str; | |
| 60 } | |
| OLD | NEW |