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 #define X(tag, size, str) \ | |
22 { size, str } \ | |
23 , | |
24 | |
25 const struct { | |
26 size_t TypeWidthInBytes; | |
27 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.
| |
28 } TypeAttributes[] = { ICETYPE_TABLE }; | |
29 | |
30 #undef X | |
31 | |
32 const size_t TypeAttributesSize = | |
33 sizeof(TypeAttributes) / sizeof(*TypeAttributes); | |
34 | |
35 } // end anonymous namespace | |
36 | |
37 size_t typeWidthInBytes(IceType Type) { | |
38 size_t Width = 0; | |
39 size_t Index = static_cast<size_t>(Type); | |
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 <> IceOstream &operator<<(IceOstream &Str, const IceType &Type) { | |
51 size_t Index = static_cast<size_t>(Type); | |
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 |