Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: src/IceTypes.cpp

Issue 353553004: Add support for vector types and vector constants. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Print out types in error messages. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- subzero/src/IceTypes.cpp - Primitive type properties ---------------===// 1 //===- subzero/src/IceTypes.cpp - Primitive type properties ---------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file defines a few attributes of Subzero primitive types. 10 // This file defines a few attributes of Subzero primitive types.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "IceDefs.h" 14 #include "IceDefs.h"
15 #include "IceTypes.h" 15 #include "IceTypes.h"
16 16
17 namespace Ice { 17 namespace Ice {
18 18
19 namespace { 19 namespace {
20 20
21 const struct { 21 const struct {
22 size_t TypeWidthInBytes; 22 size_t TypeWidthInBytes;
23 size_t TypeAlignInBytes; 23 size_t TypeAlignInBytes;
24 size_t TypeNumElements;
25 Type TypeElementType;
24 const char *DisplayString; 26 const char *DisplayString;
25 } TypeAttributes[] = { 27 } TypeAttributes[] = {
26 #define X(tag, size, align, str) \ 28 #define X(tag, size, align, elts, elty, str) \
27 { size, align, str } \ 29 { size, align, elts, elty, str } \
28 , 30 ,
29 ICETYPE_TABLE 31 ICETYPE_TABLE
30 #undef X 32 #undef X
31 }; 33 };
32 34
33 const size_t TypeAttributesSize = 35 const size_t TypeAttributesSize =
34 sizeof(TypeAttributes) / sizeof(*TypeAttributes); 36 sizeof(TypeAttributes) / sizeof(*TypeAttributes);
35 37
36 } // end anonymous namespace 38 } // end anonymous namespace
37 39
(...skipping 12 matching lines...) Expand all
50 size_t Align = 0; 52 size_t Align = 0;
51 size_t Index = static_cast<size_t>(Ty); 53 size_t Index = static_cast<size_t>(Ty);
52 if (Index < TypeAttributesSize) { 54 if (Index < TypeAttributesSize) {
53 Align = TypeAttributes[Index].TypeAlignInBytes; 55 Align = TypeAttributes[Index].TypeAlignInBytes;
54 } else { 56 } else {
55 llvm_unreachable("Invalid type for typeAlignInBytes()"); 57 llvm_unreachable("Invalid type for typeAlignInBytes()");
56 } 58 }
57 return Align; 59 return Align;
58 } 60 }
59 61
62 size_t typeNumElements(Type Ty) {
63 size_t NumElements = 0;
64 size_t Index = static_cast<size_t>(Ty);
65 if (Index < TypeAttributesSize) {
66 NumElements = TypeAttributes[Index].TypeNumElements;
67 } else {
68 llvm_unreachable("Invalid type for typeNumElements()");
69 }
70 return NumElements;
71 }
72
73 Type typeElementType(Type Ty) {
74 Type ElementType = IceType_void;
75 size_t Index = static_cast<size_t>(Ty);
76 if (Index < TypeAttributesSize) {
77 ElementType = TypeAttributes[Index].TypeElementType;
78 } else {
79 llvm_unreachable("Invalid type for typeElementType()");
80 }
81 return ElementType;
82 }
83
60 // ======================== Dump routines ======================== // 84 // ======================== Dump routines ======================== //
61 85
62 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { 86 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) {
63 size_t Index = static_cast<size_t>(Ty); 87 size_t Index = static_cast<size_t>(Ty);
64 if (Index < TypeAttributesSize) { 88 if (Index < TypeAttributesSize) {
65 Str << TypeAttributes[Index].DisplayString; 89 Str << TypeAttributes[Index].DisplayString;
66 } else { 90 } else {
67 Str << "???"; 91 Str << "???";
68 llvm_unreachable("Invalid type for printing"); 92 llvm_unreachable("Invalid type for printing");
69 } 93 }
70 94
71 return Str; 95 return Str;
72 } 96 }
73 97
74 } // end of namespace Ice 98 } // end of namespace Ice
OLDNEW
« src/IceTargetLoweringX8632.cpp ('K') | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698