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

Side by Side Diff: src/IceTypes.cpp

Issue 205613002: Initial skeleton of Subzero. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Use non-anonymous structs so that array_lengthof works Created 6 years, 8 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
« no previous file with comments | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698