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

Side by Side Diff: src/IceGlobalInits.cpp

Issue 1197863003: Subzero: Reduce the amount of #ifdef'd code. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Cleanup Created 5 years, 6 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/IceGlobalInits.h ('k') | src/IceInst.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceGlobalInits.cpp - Global declarations ---------------===// 1 //===- subzero/src/IceGlobalInits.cpp - Global declarations ---------------===//
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 implements the notion of function declarations, global 10 // This file implements the notion of function declarations, global
11 // variable declarations, and the corresponding variable initializers 11 // variable declarations, and the corresponding variable initializers
12 // in Subzero. 12 // in Subzero.
13 // 13 //
14 //===----------------------------------------------------------------------===// 14 //===----------------------------------------------------------------------===//
15 15
16 #include "llvm/ADT/STLExtras.h" 16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/IR/Function.h" 17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Value.h" 18 #include "llvm/IR/Value.h"
19 19
20 #include "IceDefs.h" 20 #include "IceDefs.h"
21 #include "IceGlobalContext.h" 21 #include "IceGlobalContext.h"
22 #include "IceGlobalInits.h" 22 #include "IceGlobalInits.h"
23 #include "IceTypes.h" 23 #include "IceTypes.h"
24 24
25 namespace { 25 namespace {
26 char hexdigit(unsigned X) { return X < 10 ? '0' + X : 'A' + X - 10; } 26 char hexdigit(unsigned X) { return X < 10 ? '0' + X : 'A' + X - 10; }
27 27
28 void dumpLinkage(Ice::Ostream &Stream, 28 void dumpLinkage(Ice::Ostream &Stream,
29 llvm::GlobalValue::LinkageTypes Linkage) { 29 llvm::GlobalValue::LinkageTypes Linkage) {
30 if (!ALLOW_DUMP) 30 if (!Ice::BuildDefs::dump())
31 return; 31 return;
32 switch (Linkage) { 32 switch (Linkage) {
33 case llvm::GlobalValue::ExternalLinkage: 33 case llvm::GlobalValue::ExternalLinkage:
34 Stream << "external"; 34 Stream << "external";
35 return; 35 return;
36 case llvm::GlobalValue::InternalLinkage: 36 case llvm::GlobalValue::InternalLinkage:
37 Stream << "internal"; 37 Stream << "internal";
38 return; 38 return;
39 default: 39 default:
40 break; 40 break;
41 } 41 }
42 std::string Buffer; 42 std::string Buffer;
43 llvm::raw_string_ostream StrBuf(Buffer); 43 llvm::raw_string_ostream StrBuf(Buffer);
44 StrBuf << "Unknown linkage value: " << Linkage; 44 StrBuf << "Unknown linkage value: " << Linkage;
45 llvm::report_fatal_error(StrBuf.str()); 45 llvm::report_fatal_error(StrBuf.str());
46 } 46 }
47 47
48 void dumpCallingConv(Ice::Ostream &, llvm::CallingConv::ID CallingConv) { 48 void dumpCallingConv(Ice::Ostream &, llvm::CallingConv::ID CallingConv) {
49 if (!ALLOW_DUMP) 49 if (!Ice::BuildDefs::dump())
50 return; 50 return;
51 if (CallingConv == llvm::CallingConv::C) 51 if (CallingConv == llvm::CallingConv::C)
52 return; 52 return;
53 std::string Buffer; 53 std::string Buffer;
54 llvm::raw_string_ostream StrBuf(Buffer); 54 llvm::raw_string_ostream StrBuf(Buffer);
55 StrBuf << "Unknown calling convention: " << CallingConv; 55 StrBuf << "Unknown calling convention: " << CallingConv;
56 llvm::report_fatal_error(StrBuf.str()); 56 llvm::report_fatal_error(StrBuf.str());
57 } 57 }
58 58
59 } // end of anonymous namespace 59 } // end of anonymous namespace
60 60
61 namespace Ice { 61 namespace Ice {
62 62
63 void FunctionDeclaration::dumpType(Ostream &Stream) const { 63 void FunctionDeclaration::dumpType(Ostream &Stream) const {
64 if (!ALLOW_DUMP) 64 if (!Ice::BuildDefs::dump())
65 return; 65 return;
66 Stream << Signature; 66 Stream << Signature;
67 } 67 }
68 68
69 void FunctionDeclaration::dump(GlobalContext *Ctx, Ostream &Stream) const { 69 void FunctionDeclaration::dump(GlobalContext *Ctx, Ostream &Stream) const {
70 if (!ALLOW_DUMP) 70 if (!Ice::BuildDefs::dump())
71 return; 71 return;
72 if (IsProto) 72 if (IsProto)
73 Stream << "declare "; 73 Stream << "declare ";
74 ::dumpLinkage(Stream, Linkage); 74 ::dumpLinkage(Stream, Linkage);
75 ::dumpCallingConv(Stream, CallingConv); 75 ::dumpCallingConv(Stream, CallingConv);
76 Stream << Signature.getReturnType() << " @" 76 Stream << Signature.getReturnType() << " @"
77 << (Ctx ? Ctx->mangleName(Name) : Name) << "("; 77 << (Ctx ? Ctx->mangleName(Name) : Name) << "(";
78 bool IsFirst = true; 78 bool IsFirst = true;
79 for (Type ArgTy : Signature.getArgList()) { 79 for (Type ArgTy : Signature.getArgList()) {
80 if (IsFirst) 80 if (IsFirst)
81 IsFirst = false; 81 IsFirst = false;
82 else 82 else
83 Stream << ", "; 83 Stream << ", ";
84 Stream << ArgTy; 84 Stream << ArgTy;
85 } 85 }
86 Stream << ")"; 86 Stream << ")";
87 } 87 }
88 88
89 void VariableDeclaration::dumpType(Ostream &Stream) const { 89 void VariableDeclaration::dumpType(Ostream &Stream) const {
90 if (!ALLOW_DUMP) 90 if (!Ice::BuildDefs::dump())
91 return; 91 return;
92 if (Initializers->size() == 1) { 92 if (Initializers->size() == 1) {
93 Initializers->front()->dumpType(Stream); 93 Initializers->front()->dumpType(Stream);
94 } else { 94 } else {
95 Stream << "<{ "; 95 Stream << "<{ ";
96 bool IsFirst = true; 96 bool IsFirst = true;
97 for (const std::unique_ptr<Initializer> &Init : *Initializers) { 97 for (const std::unique_ptr<Initializer> &Init : *Initializers) {
98 if (IsFirst) { 98 if (IsFirst) {
99 IsFirst = false; 99 IsFirst = false;
100 } else { 100 } else {
101 Stream << ", "; 101 Stream << ", ";
102 } 102 }
103 Init->dumpType(Stream); 103 Init->dumpType(Stream);
104 } 104 }
105 Stream << " }>"; 105 Stream << " }>";
106 } 106 }
107 } 107 }
108 108
109 void VariableDeclaration::dump(GlobalContext *Ctx, Ostream &Stream) const { 109 void VariableDeclaration::dump(GlobalContext *Ctx, Ostream &Stream) const {
110 if (!ALLOW_DUMP) 110 if (!Ice::BuildDefs::dump())
111 return; 111 return;
112 Stream << "@" 112 Stream << "@"
113 << ((Ctx && !getSuppressMangling()) ? Ctx->mangleName(Name) : Name) 113 << ((Ctx && !getSuppressMangling()) ? Ctx->mangleName(Name) : Name)
114 << " = "; 114 << " = ";
115 ::dumpLinkage(Stream, Linkage); 115 ::dumpLinkage(Stream, Linkage);
116 Stream << " " << (IsConstant ? "constant" : "global") << " "; 116 Stream << " " << (IsConstant ? "constant" : "global") << " ";
117 117
118 // Add initializer. 118 // Add initializer.
119 if (Initializers->size() == 1) { 119 if (Initializers->size() == 1) {
120 Initializers->front()->dump(Stream); 120 Initializers->front()->dump(Stream);
(...skipping 12 matching lines...) Expand all
133 Stream << " }>"; 133 Stream << " }>";
134 } 134 }
135 135
136 // Add alignment. 136 // Add alignment.
137 if (Alignment > 0) 137 if (Alignment > 0)
138 Stream << ", align " << Alignment; 138 Stream << ", align " << Alignment;
139 Stream << "\n"; 139 Stream << "\n";
140 } 140 }
141 141
142 void VariableDeclaration::Initializer::dumpType(Ostream &Stream) const { 142 void VariableDeclaration::Initializer::dumpType(Ostream &Stream) const {
143 if (!ALLOW_DUMP) 143 if (!Ice::BuildDefs::dump())
144 return; 144 return;
145 Stream << "[" << getNumBytes() << " x " << Ice::IceType_i8 << "]"; 145 Stream << "[" << getNumBytes() << " x " << Ice::IceType_i8 << "]";
146 } 146 }
147 147
148 void VariableDeclaration::DataInitializer::dump(GlobalContext *, 148 void VariableDeclaration::DataInitializer::dump(GlobalContext *,
149 Ostream &Stream) const { 149 Ostream &Stream) const {
150 if (!ALLOW_DUMP) 150 if (!Ice::BuildDefs::dump())
151 return; 151 return;
152 dumpType(Stream); 152 dumpType(Stream);
153 Stream << " c\""; 153 Stream << " c\"";
154 // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep 154 // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep
155 // the strings in the same format as the .ll file for practical 155 // the strings in the same format as the .ll file for practical
156 // diffing. 156 // diffing.
157 for (uint8_t C : Contents) { 157 for (uint8_t C : Contents) {
158 if (isprint(C) && C != '\\' && C != '"') 158 if (isprint(C) && C != '\\' && C != '"')
159 Stream << C; 159 Stream << C;
160 else 160 else
161 Stream << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); 161 Stream << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
162 } 162 }
163 Stream << "\""; 163 Stream << "\"";
164 } 164 }
165 165
166 void VariableDeclaration::ZeroInitializer::dump(GlobalContext *, 166 void VariableDeclaration::ZeroInitializer::dump(GlobalContext *,
167 Ostream &Stream) const { 167 Ostream &Stream) const {
168 if (!ALLOW_DUMP) 168 if (!Ice::BuildDefs::dump())
169 return; 169 return;
170 dumpType(Stream); 170 dumpType(Stream);
171 Stream << " zeroinitializer"; 171 Stream << " zeroinitializer";
172 } 172 }
173 173
174 void VariableDeclaration::RelocInitializer::dumpType(Ostream &Stream) const { 174 void VariableDeclaration::RelocInitializer::dumpType(Ostream &Stream) const {
175 if (!ALLOW_DUMP) 175 if (!Ice::BuildDefs::dump())
176 return; 176 return;
177 Stream << Ice::IceType_i32; 177 Stream << Ice::IceType_i32;
178 } 178 }
179 179
180 void VariableDeclaration::RelocInitializer::dump(GlobalContext *Ctx, 180 void VariableDeclaration::RelocInitializer::dump(GlobalContext *Ctx,
181 Ostream &Stream) const { 181 Ostream &Stream) const {
182 if (!ALLOW_DUMP) 182 if (!Ice::BuildDefs::dump())
183 return; 183 return;
184 if (Offset != 0) { 184 if (Offset != 0) {
185 dumpType(Stream); 185 dumpType(Stream);
186 Stream << " add ("; 186 Stream << " add (";
187 } 187 }
188 dumpType(Stream); 188 dumpType(Stream);
189 Stream << " ptrtoint ("; 189 Stream << " ptrtoint (";
190 Declaration->dumpType(Stream); 190 Declaration->dumpType(Stream);
191 Stream << "* @"; 191 Stream << "* @";
192 if (Ctx) 192 if (Ctx)
193 Stream << Ctx->mangleName(Declaration->getName()); 193 Stream << Ctx->mangleName(Declaration->getName());
194 else 194 else
195 Stream << Declaration->getName(); 195 Stream << Declaration->getName();
196 Stream << " to "; 196 Stream << " to ";
197 dumpType(Stream); 197 dumpType(Stream);
198 Stream << ")"; 198 Stream << ")";
199 if (Offset != 0) { 199 if (Offset != 0) {
200 Stream << ", "; 200 Stream << ", ";
201 dumpType(Stream); 201 dumpType(Stream);
202 Stream << " " << Offset << ")"; 202 Stream << " " << Offset << ")";
203 } 203 }
204 } 204 }
205 205
206 } // end of namespace Ice 206 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceGlobalInits.h ('k') | src/IceInst.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698