OLD | NEW |
---|---|
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// | 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// |
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 PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 TopLevelParser(const TopLevelParser &) = delete; | 156 TopLevelParser(const TopLevelParser &) = delete; |
157 TopLevelParser &operator=(const TopLevelParser &) = delete; | 157 TopLevelParser &operator=(const TopLevelParser &) = delete; |
158 | 158 |
159 public: | 159 public: |
160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; | 160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; |
161 | 161 |
162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, | 162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, |
163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) | 163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) |
164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), | 164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), |
165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), | 165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), |
166 VariableDeclarations(new Ice::VariableDeclarationList()), | |
166 BlockParser(nullptr), StubbedConstCallValue(nullptr) {} | 167 BlockParser(nullptr), StubbedConstCallValue(nullptr) {} |
167 | 168 |
168 ~TopLevelParser() override {} | 169 ~TopLevelParser() override {} |
169 | 170 |
170 Ice::Translator &getTranslator() { return Translator; } | 171 Ice::Translator &getTranslator() { return Translator; } |
171 | 172 |
172 void setBlockParser(BlockParserBaseClass *NewBlockParser) { | 173 void setBlockParser(BlockParserBaseClass *NewBlockParser) { |
173 BlockParser = NewBlockParser; | 174 BlockParser = NewBlockParser; |
174 } | 175 } |
175 | 176 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 return NextDefiningFunctionID++; | 245 return NextDefiningFunctionID++; |
245 } | 246 } |
246 | 247 |
247 /// Returns the function associated with ID. | 248 /// Returns the function associated with ID. |
248 Ice::FunctionDeclaration *getFunctionByID(unsigned ID) { | 249 Ice::FunctionDeclaration *getFunctionByID(unsigned ID) { |
249 if (ID < FunctionDeclarationList.size()) | 250 if (ID < FunctionDeclarationList.size()) |
250 return FunctionDeclarationList[ID]; | 251 return FunctionDeclarationList[ID]; |
251 return reportGetFunctionByIDError(ID); | 252 return reportGetFunctionByIDError(ID); |
252 } | 253 } |
253 | 254 |
254 /// Returns the list of function declarations. | 255 /// Returns the constant associated with the given global value ID. |
255 const FunctionDeclarationListType &getFunctionDeclarationList() const { | 256 Ice::Constant *getGlobalConstantByID(unsigned ID) { |
256 return FunctionDeclarationList; | 257 assert(ID < ValueIDConstants.size()); |
258 return ValueIDConstants[ID]; | |
257 } | 259 } |
258 | 260 |
259 /// Returns the corresponding constant associated with a global declaration. | 261 /// Install names for all global values without names. Called after |
260 /// (i.e. relocatable). | 262 /// the global value symbol table is processed, but before any |
261 Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) { | 263 /// function blocks are processed. |
262 // TODO(kschimpf): Can this be built when creating global initializers? | 264 void installGlobalNames() { |
263 Ice::Constant *C; | 265 assert(VariableDeclarations.get()); |
Jim Stichnoth
2015/02/10 04:01:04
You should be able to just assert(VariableDeclarat
Karl
2015/02/10 17:19:26
Good point. Didn't realize it had a bool type conv
| |
264 if (ID >= ValueIDConstants.size()) { | 266 installGlobalVarNames(); |
265 C = nullptr; | 267 installFunctionNames(); |
266 unsigned ExpectedSize = | 268 } |
267 FunctionDeclarationList.size() + VariableDeclarations.size(); | |
268 if (ID >= ExpectedSize) | |
269 ExpectedSize = ID; | |
270 ValueIDConstants.resize(ExpectedSize); | |
271 } else { | |
272 C = ValueIDConstants[ID]; | |
273 } | |
274 if (C != nullptr) | |
275 return C; | |
276 | 269 |
277 if (isIRGenerationDisabled()) { | 270 void createValueIDs() { |
278 ValueIDConstants[ID] = nullptr; | 271 assert(VariableDeclarations.get()); |
Jim Stichnoth
2015/02/10 04:01:05
assert(VariableDeclarations);
Karl
2015/02/10 17:19:26
Done.
| |
279 return nullptr; | 272 ValueIDConstants.reserve(VariableDeclarations->size() + |
280 } | 273 FunctionDeclarationList.size()); |
281 | 274 createValueIDsForFunctions(); |
282 // If reached, no such constant exists, create one. | 275 createValueIDsForGlobalVars(); |
283 // TODO(kschimpf) Don't get addresses of intrinsic function declarations. | |
284 Ice::GlobalDeclaration *Decl = nullptr; | |
285 unsigned FcnIDSize = FunctionDeclarationList.size(); | |
286 bool IsUndefined = false; | |
287 if (ID < FcnIDSize) { | |
288 Decl = FunctionDeclarationList[ID]; | |
289 const auto Func = llvm::cast<Ice::FunctionDeclaration>(Decl); | |
290 IsUndefined = Func->isProto(); | |
291 } else if ((ID - FcnIDSize) < VariableDeclarations.size()) { | |
292 Decl = VariableDeclarations[ID - FcnIDSize]; | |
293 const auto Var = llvm::cast<Ice::VariableDeclaration>(Decl); | |
294 IsUndefined = !Var->hasInitializer(); | |
295 } | |
296 Ice::IceString Name; | |
297 bool SuppressMangling; | |
298 if (Decl) { | |
299 Name = Decl->getName(); | |
300 SuppressMangling = Decl->getSuppressMangling(); | |
301 } else { | |
302 std::string Buffer; | |
303 raw_string_ostream StrBuf(Buffer); | |
304 StrBuf << "Reference to global not defined: " << ID; | |
305 BlockError(StrBuf.str()); | |
306 // TODO(kschimpf) Remove error recovery once implementation complete. | |
307 Name = "??"; | |
308 SuppressMangling = false; | |
309 } | |
310 if (IsUndefined) | |
311 C = getTranslator().getContext()->getConstantExternSym(Name); | |
312 else { | |
313 const Ice::RelocOffsetT Offset = 0; | |
314 C = getTranslator().getContext()->getConstantSym(Offset, Name, | |
315 SuppressMangling); | |
316 } | |
317 ValueIDConstants[ID] = C; | |
318 return C; | |
319 } | 276 } |
320 | 277 |
321 /// Returns a defined function reference to be used in place of | 278 /// Returns a defined function reference to be used in place of |
322 /// called constant addresses. Returns the corresponding operand | 279 /// called constant addresses. Returns the corresponding operand |
323 /// to replace the calling address with. Reports an error if | 280 /// to replace the calling address with. Reports an error if |
324 /// a stub could not be found, returning the CallValue. | 281 /// a stub could not be found, returning the CallValue. |
325 Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) { | 282 Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) { |
326 if (StubbedConstCallValue) | 283 if (StubbedConstCallValue) |
327 return StubbedConstCallValue; | 284 return StubbedConstCallValue; |
328 for (unsigned i = 0; i < getNumFunctionIDs(); ++i) { | 285 for (unsigned i = 0; i < getNumFunctionIDs(); ++i) { |
329 Ice::FunctionDeclaration *Func = getFunctionByID(i); | 286 Ice::FunctionDeclaration *Func = getFunctionByID(i); |
330 if (!Func->isProto()) { | 287 if (!Func->isProto()) { |
331 StubbedConstCallValue = getOrCreateGlobalConstantByID(i); | 288 StubbedConstCallValue = getGlobalConstantByID(i); |
332 return StubbedConstCallValue; | 289 return StubbedConstCallValue; |
333 } | 290 } |
334 } | 291 } |
335 Error("Unable to find function definition to stub constant calls with"); | 292 Error("Unable to find function definition to stub constant calls with"); |
336 return CallValue; | 293 return CallValue; |
337 } | 294 } |
338 | 295 |
339 /// Returns the number of function declarations in the bitcode file. | 296 /// Returns the number of function declarations in the bitcode file. |
340 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } | 297 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } |
341 | 298 |
342 /// Returns the number of global declarations (i.e. IDs) defined in | 299 /// Returns the number of global declarations (i.e. IDs) defined in |
343 /// the bitcode file. | 300 /// the bitcode file. |
344 unsigned getNumGlobalIDs() const { | 301 unsigned getNumGlobalIDs() const { |
345 return FunctionDeclarationList.size() + VariableDeclarations.size(); | 302 if (Ice::VariableDeclarationList *Decls = VariableDeclarations.get()) { |
303 return FunctionDeclarationList.size() + Decls->size(); | |
Jim Stichnoth
2015/02/10 04:01:05
if (VariableDeclarations) {
return FunctionDecla
Karl
2015/02/10 17:19:26
Done.
| |
304 } else { | |
305 return ValueIDConstants.size(); | |
306 } | |
346 } | 307 } |
347 | 308 |
348 /// Creates Count global variable declarations. | 309 /// Creates Count global variable declarations. |
349 void CreateGlobalVariables(size_t Count) { | 310 void CreateGlobalVariables(size_t Count) { |
350 assert(VariableDeclarations.empty()); | 311 assert(VariableDeclarations.get()); |
Jim Stichnoth
2015/02/10 04:01:05
assert(VariableDeclarations);
Karl
2015/02/10 17:19:26
Done.
| |
312 assert(VariableDeclarations->empty()); | |
351 for (size_t i = 0; i < Count; ++i) { | 313 for (size_t i = 0; i < Count; ++i) { |
352 VariableDeclarations.push_back(Ice::VariableDeclaration::create()); | 314 VariableDeclarations->push_back(Ice::VariableDeclaration::create()); |
353 } | 315 } |
354 } | 316 } |
355 | 317 |
356 /// Returns the number of global variable declarations in the | 318 /// Returns the number of global variable declarations in the |
357 /// bitcode file. | 319 /// bitcode file. |
358 Ice::SizeT getNumGlobalVariables() const { | 320 Ice::SizeT getNumGlobalVariables() const { |
359 return VariableDeclarations.size(); | 321 if (Ice::VariableDeclarationList *Decls = VariableDeclarations.get()) { |
322 return Decls->size(); | |
Jim Stichnoth
2015/02/10 04:01:04
if (VariableDeclarations) {
return VariableDecla
Karl
2015/02/10 17:19:26
Done.
| |
323 } else { | |
324 return ValueIDConstants.size() - FunctionDeclarationList.size(); | |
325 } | |
360 } | 326 } |
361 | 327 |
362 /// Returns the global variable declaration with the given index. | 328 /// Returns the global variable declaration with the given index. |
363 Ice::VariableDeclaration *getGlobalVariableByID(unsigned Index) { | 329 Ice::VariableDeclaration *getGlobalVariableByID(unsigned Index) { |
364 if (Index < VariableDeclarations.size()) | 330 assert(VariableDeclarations.get()); |
Jim Stichnoth
2015/02/10 04:01:05
assert(VariableDeclarations);
Karl
2015/02/10 17:19:26
Done.
| |
365 return VariableDeclarations[Index]; | 331 if (Index < VariableDeclarations->size()) |
332 return VariableDeclarations->at(Index); | |
366 return reportGetGlobalVariableByIDError(Index); | 333 return reportGetGlobalVariableByIDError(Index); |
367 } | 334 } |
368 | 335 |
369 /// Returns the global declaration (variable or function) with the | 336 /// Returns the global declaration (variable or function) with the |
370 /// given Index. | 337 /// given Index. |
371 Ice::GlobalDeclaration *getGlobalDeclarationByID(size_t Index) { | 338 Ice::GlobalDeclaration *getGlobalDeclarationByID(size_t Index) { |
372 size_t NumFunctionIds = FunctionDeclarationList.size(); | 339 size_t NumFunctionIds = FunctionDeclarationList.size(); |
373 if (Index < NumFunctionIds) | 340 if (Index < NumFunctionIds) |
374 return getFunctionByID(Index); | 341 return getFunctionByID(Index); |
375 else | 342 else |
376 return getGlobalVariableByID(Index - NumFunctionIds); | 343 return getGlobalVariableByID(Index - NumFunctionIds); |
377 } | 344 } |
378 | 345 |
379 /// Returns the list of parsed global variable declarations. | 346 /// Returns the list of parsed global variable declarations. Releases |
380 const Ice::VariableDeclarationList &getGlobalVariables() { | 347 /// ownership of the current list of global variables. |
381 return VariableDeclarations; | 348 Ice::VariableDeclarationList *getGlobalVariables() { |
Jim Stichnoth
2015/02/10 04:01:04
This would be better returning a unique_ptr. The
Karl
2015/02/10 17:19:26
I didn't know how to return a unique_ptr, which wa
| |
349 // Before returning, check that ValidIDConstants has already been | |
350 // build. | |
351 if (Ice::VariableDeclarationList *Decls = VariableDeclarations.get()) { | |
352 assert(Decls->size() <= ValueIDConstants.size()); | |
Jim Stichnoth
2015/02/10 04:01:04
if (VariableDeclarations) {
assert(VariableDecla
Karl
2015/02/10 17:19:26
Done.
| |
353 } | |
354 return VariableDeclarations.release(); | |
382 } | 355 } |
383 | 356 |
384 private: | 357 private: |
385 // The translator associated with the parser. | 358 // The translator associated with the parser. |
386 Ice::Translator &Translator; | 359 Ice::Translator &Translator; |
387 // The bitcode header. | 360 // The bitcode header. |
388 NaClBitcodeHeader &Header; | 361 NaClBitcodeHeader &Header; |
389 // The exit status that should be set to true if an error occurs. | 362 // The exit status that should be set to true if an error occurs. |
390 Ice::ErrorCode &ErrorStatus; | 363 Ice::ErrorCode &ErrorStatus; |
391 // The number of errors reported. | 364 // The number of errors reported. |
392 unsigned NumErrors; | 365 unsigned NumErrors; |
393 // The types associated with each type ID. | 366 // The types associated with each type ID. |
394 std::vector<ExtendedType> TypeIDValues; | 367 std::vector<ExtendedType> TypeIDValues; |
395 // The set of functions (prototype and defined). | 368 // The set of functions (prototype and defined). |
396 FunctionDeclarationListType FunctionDeclarationList; | 369 FunctionDeclarationListType FunctionDeclarationList; |
397 // The ID of the next possible defined function ID in | 370 // The ID of the next possible defined function ID in |
398 // FunctionDeclarationList. FunctionDeclarationList is filled | 371 // FunctionDeclarationList. FunctionDeclarationList is filled |
399 // first. It's the set of functions (either defined or isproto). Then | 372 // first. It's the set of functions (either defined or isproto). Then |
400 // function definitions are encountered/parsed and | 373 // function definitions are encountered/parsed and |
401 // NextDefiningFunctionID is incremented to track the next | 374 // NextDefiningFunctionID is incremented to track the next |
402 // actually-defined function. | 375 // actually-defined function. |
403 size_t NextDefiningFunctionID; | 376 size_t NextDefiningFunctionID; |
404 // The set of global variables. | 377 // The set of global variables. |
405 Ice::VariableDeclarationList VariableDeclarations; | 378 std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; |
406 // Relocatable constants associated with global declarations. | 379 // Relocatable constants associated with global declarations. |
407 std::vector<Ice::Constant *> ValueIDConstants; | 380 std::vector<Ice::Constant *> ValueIDConstants; |
408 // Error recovery value to use when getFuncSigTypeByID fails. | 381 // Error recovery value to use when getFuncSigTypeByID fails. |
409 Ice::FuncSigType UndefinedFuncSigType; | 382 Ice::FuncSigType UndefinedFuncSigType; |
410 // The block parser currently being applied. Used for error | 383 // The block parser currently being applied. Used for error |
411 // reporting. | 384 // reporting. |
412 BlockParserBaseClass *BlockParser; | 385 BlockParserBaseClass *BlockParser; |
413 // Value to use to stub constant calls. | 386 // Value to use to stub constant calls. |
414 Ice::Operand *StubbedConstCallValue; | 387 Ice::Operand *StubbedConstCallValue; |
415 | 388 |
416 bool ParseBlock(unsigned BlockID) override; | 389 bool ParseBlock(unsigned BlockID) override; |
417 | 390 |
418 // Gets extended type associated with the given index, assuming the | 391 // Gets extended type associated with the given index, assuming the |
419 // extended type is of the WantedKind. Generates error message if | 392 // extended type is of the WantedKind. Generates error message if |
420 // corresponding extended type of WantedKind can't be found, and | 393 // corresponding extended type of WantedKind can't be found, and |
421 // returns nullptr. | 394 // returns nullptr. |
422 ExtendedType *getTypeByIDAsKind(unsigned ID, | 395 ExtendedType *getTypeByIDAsKind(unsigned ID, |
423 ExtendedType::TypeKind WantedKind) { | 396 ExtendedType::TypeKind WantedKind) { |
424 ExtendedType *Ty = nullptr; | 397 ExtendedType *Ty = nullptr; |
425 if (ID < TypeIDValues.size()) { | 398 if (ID < TypeIDValues.size()) { |
426 Ty = &TypeIDValues[ID]; | 399 Ty = &TypeIDValues[ID]; |
427 if (Ty->getKind() == WantedKind) | 400 if (Ty->getKind() == WantedKind) |
428 return Ty; | 401 return Ty; |
429 } | 402 } |
430 // Generate an error message and set ErrorStatus. | 403 // Generate an error message and set ErrorStatus. |
431 this->reportBadTypeIDAs(ID, Ty, WantedKind); | 404 this->reportBadTypeIDAs(ID, Ty, WantedKind); |
432 return nullptr; | 405 return nullptr; |
433 } | 406 } |
434 | 407 |
408 // Gives Decl a name if it doesn't already have one. Prefix and | |
409 // NameIndex is used to generate the name. NameIndex is | |
410 // automatically incremented if a new new is created. Context is | |
411 // literal text describing the type of name being created. | |
412 void installDeclarationName(// Ice::Translator &Trans, | |
Jim Stichnoth
2015/02/10 04:01:05
Remove comment in arglist? Same for the two calls
Karl
2015/02/10 17:19:26
Done.
| |
413 Ice::GlobalDeclaration *Decl, | |
414 const Ice::IceString &Prefix, const char *Context, | |
Jim Stichnoth
2015/02/10 04:01:04
Bikeshedding. Maybe rename the Context arg, since
Karl
2015/02/10 17:19:26
Done.
| |
415 uint32_t &NameIndex) { | |
416 if (!Decl->hasName()) { | |
417 Decl->setName(Translator.createUnnamedName(Prefix, NameIndex)); | |
418 ++NameIndex; | |
419 } else { | |
420 Translator.checkIfUnnamedNameSafe(Decl->getName(), Context, Prefix); | |
421 } | |
422 } | |
423 | |
424 // Installs names for global variables without names. | |
425 void installGlobalVarNames() { | |
426 assert(VariableDeclarations.get()); | |
Jim Stichnoth
2015/02/10 04:01:04
assert(VariableDeclarations);
Karl
2015/02/10 17:19:26
Done.
| |
427 const Ice::IceString &GlobalPrefix = | |
428 getTranslator().getFlags().getDefaultGlobalPrefix(); | |
429 if (!GlobalPrefix.empty()) { | |
430 // Ice::Translator &Trans = getTranslator(); | |
Jim Stichnoth
2015/02/10 04:01:05
remove?
Karl
2015/02/10 17:19:26
Done.
| |
431 uint32_t NameIndex = 0; | |
432 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { | |
433 installDeclarationName(/*Trans,*/ Var, GlobalPrefix, "global", NameIndex ); | |
434 } | |
435 } | |
436 } | |
437 | |
438 // Installs names for functions without names. | |
439 void installFunctionNames() { | |
440 const Ice::IceString &FunctionPrefix = | |
441 getTranslator().getFlags().getDefaultFunctionPrefix(); | |
442 if (!FunctionPrefix.empty()) { | |
443 // Ice::Translator &Trans = getTranslator(); | |
Jim Stichnoth
2015/02/10 04:01:04
remove?
Karl
2015/02/10 17:19:26
Done.
| |
444 uint32_t NameIndex = 0; | |
445 for (Ice::FunctionDeclaration *Func : FunctionDeclarationList) { | |
446 installDeclarationName(/*Trans,*/ Func, FunctionPrefix, "function", | |
447 NameIndex); | |
448 } | |
449 } | |
450 } | |
451 | |
452 // Builds a constant symbol named Name, suppressing name mangling if | |
453 // SuppressMangling. IsExternal is true iff the symbol is external. | |
454 Ice::Constant *getConstantSym(const Ice::IceString &Name, | |
455 bool SuppressMangling, bool IsExternal) { | |
456 if (IsExternal) { | |
457 return getTranslator().getContext()->getConstantExternSym(Name); | |
458 } else { | |
459 const Ice::RelocOffsetT Offset = 0; | |
460 return getTranslator().getContext()->getConstantSym(Offset, Name, | |
461 SuppressMangling); | |
462 } | |
463 } | |
464 | |
465 // Converts function declarations into constant value IDs. | |
466 void createValueIDsForFunctions() { | |
467 size_t NumFunctions = FunctionDeclarationList.size(); | |
468 for (size_t i = 0; i < NumFunctions; ++i) { | |
Jim Stichnoth
2015/02/10 04:01:05
Can you use a range-based for loop?
Karl
2015/02/10 17:19:26
I didn't use a range-based loop, since I needed in
| |
469 Ice::Constant *C = nullptr; | |
470 if (!isIRGenerationDisabled()) { | |
471 Ice::FunctionDeclaration *Func = FunctionDeclarationList[i]; | |
472 C = getConstantSym(Func->getName(), Func->getSuppressMangling(), | |
473 Func->isProto()); | |
jvoung (off chromium)
2015/02/10 18:24:58
Thanks for simplifying the IsExternal a bit.
| |
474 } | |
475 ValueIDConstants.push_back(C); | |
476 } | |
477 } | |
478 | |
479 // Converts global variable declarations into constant value IDs. | |
480 void createValueIDsForGlobalVars() { | |
481 size_t NumGlobalVars = VariableDeclarations->size(); | |
482 for (size_t i = 0; i < NumGlobalVars; ++i) { | |
Jim Stichnoth
2015/02/10 04:01:05
Range-based for loop?
Karl
2015/02/10 17:19:26
Done.
| |
483 Ice::Constant *C = nullptr; | |
484 if (!isIRGenerationDisabled()) { | |
485 Ice::VariableDeclaration *Decl = VariableDeclarations->at(i); | |
486 C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(), | |
487 !Decl->hasInitializer()); | |
488 } | |
489 ValueIDConstants.push_back(C); | |
490 } | |
491 } | |
492 | |
435 // Reports that type ID is undefined, or not of the WantedType. | 493 // Reports that type ID is undefined, or not of the WantedType. |
436 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 494 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
437 ExtendedType::TypeKind WantedType); | 495 ExtendedType::TypeKind WantedType); |
438 | 496 |
439 // Reports that there is no function declaration for ID. Returns an | 497 // Reports that there is no function declaration for ID. Returns an |
440 // error recovery value to use. | 498 // error recovery value to use. |
441 Ice::FunctionDeclaration *reportGetFunctionByIDError(unsigned ID); | 499 Ice::FunctionDeclaration *reportGetFunctionByIDError(unsigned ID); |
442 | 500 |
443 // Reports that there is not global variable declaration for | 501 // Reports that there is not global variable declaration for |
444 // ID. Returns an error recovery value to use. | 502 // ID. Returns an error recovery value to use. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 return FunctionDeclarationList[0]; | 545 return FunctionDeclarationList[0]; |
488 report_fatal_error("Unable to continue"); | 546 report_fatal_error("Unable to continue"); |
489 } | 547 } |
490 | 548 |
491 Ice::VariableDeclaration * | 549 Ice::VariableDeclaration * |
492 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { | 550 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { |
493 std::string Buffer; | 551 std::string Buffer; |
494 raw_string_ostream StrBuf(Buffer); | 552 raw_string_ostream StrBuf(Buffer); |
495 StrBuf << "Global index " << Index | 553 StrBuf << "Global index " << Index |
496 << " not allowed. Out of range. Must be less than " | 554 << " not allowed. Out of range. Must be less than " |
497 << VariableDeclarations.size(); | 555 << VariableDeclarations->size(); |
498 BlockError(StrBuf.str()); | 556 BlockError(StrBuf.str()); |
499 // TODO(kschimpf) Remove error recovery once implementation complete. | 557 // TODO(kschimpf) Remove error recovery once implementation complete. |
500 if (!VariableDeclarations.empty()) | 558 if (!VariableDeclarations->empty()) |
501 return VariableDeclarations[0]; | 559 return VariableDeclarations->at(0); |
502 report_fatal_error("Unable to continue"); | 560 report_fatal_error("Unable to continue"); |
503 } | 561 } |
504 | 562 |
505 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { | 563 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { |
506 std::string Buffer; | 564 std::string Buffer; |
507 raw_string_ostream StrBuf(Buffer); | 565 raw_string_ostream StrBuf(Buffer); |
508 StrBuf << "Invalid LLVM type: " << *LLVMTy; | 566 StrBuf << "Invalid LLVM type: " << *LLVMTy; |
509 Error(StrBuf.str()); | 567 Error(StrBuf.str()); |
510 return Ice::IceType_void; | 568 return Ice::IceType_void; |
511 } | 569 } |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 void setNextLocalInstIndex(Ice::Operand *Op) { | 1211 void setNextLocalInstIndex(Ice::Operand *Op) { |
1154 setOperand(NextLocalInstIndex++, Op); | 1212 setOperand(NextLocalInstIndex++, Op); |
1155 } | 1213 } |
1156 | 1214 |
1157 // Set the next constant ID to the given constant C. | 1215 // Set the next constant ID to the given constant C. |
1158 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } | 1216 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
1159 | 1217 |
1160 // Returns the value referenced by the given value Index. | 1218 // Returns the value referenced by the given value Index. |
1161 Ice::Operand *getOperand(uint32_t Index) { | 1219 Ice::Operand *getOperand(uint32_t Index) { |
1162 if (Index < CachedNumGlobalValueIDs) { | 1220 if (Index < CachedNumGlobalValueIDs) { |
1163 return Context->getOrCreateGlobalConstantByID(Index); | 1221 return Context->getGlobalConstantByID(Index); |
1164 } | 1222 } |
1165 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1223 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; |
1166 if (LocalIndex >= LocalOperands.size()) { | 1224 if (LocalIndex >= LocalOperands.size()) { |
1167 std::string Buffer; | 1225 std::string Buffer; |
1168 raw_string_ostream StrBuf(Buffer); | 1226 raw_string_ostream StrBuf(Buffer); |
1169 StrBuf << "Value index " << Index << " not defined!"; | 1227 StrBuf << "Value index " << Index << " not defined!"; |
1170 Error(StrBuf.str()); | 1228 Error(StrBuf.str()); |
1171 report_fatal_error("Unable to continue"); | 1229 report_fatal_error("Unable to continue"); |
1172 } | 1230 } |
1173 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1231 Ice::Operand *Op = LocalOperands[LocalIndex]; |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2801 // True if we have already installed names for unnamed global declarations, | 2859 // True if we have already installed names for unnamed global declarations, |
2802 // and have generated global constant initializers. | 2860 // and have generated global constant initializers. |
2803 bool GlobalDeclarationNamesAndInitializersInstalled; | 2861 bool GlobalDeclarationNamesAndInitializersInstalled; |
2804 | 2862 |
2805 // Generates names for unnamed global addresses (i.e. functions and | 2863 // Generates names for unnamed global addresses (i.e. functions and |
2806 // global variables). Then lowers global variable declaration | 2864 // global variables). Then lowers global variable declaration |
2807 // initializers to the target. May be called multiple times. Only | 2865 // initializers to the target. May be called multiple times. Only |
2808 // the first call will do the installation. | 2866 // the first call will do the installation. |
2809 void InstallGlobalNamesAndGlobalVarInitializers() { | 2867 void InstallGlobalNamesAndGlobalVarInitializers() { |
2810 if (!GlobalDeclarationNamesAndInitializersInstalled) { | 2868 if (!GlobalDeclarationNamesAndInitializersInstalled) { |
2811 Ice::Translator &Trans = getTranslator(); | 2869 Context->installGlobalNames(); |
2812 const Ice::IceString &GlobalPrefix = getFlags().getDefaultGlobalPrefix(); | 2870 Context->createValueIDs(); |
2813 if (!GlobalPrefix.empty()) { | 2871 std::unique_ptr<Ice::VariableDeclarationList> DeclsPtr( |
2814 uint32_t NameIndex = 0; | 2872 Context->getGlobalVariables()); |
Jim Stichnoth
2015/02/10 04:01:04
With the suggested change to the getGlobalVariable
Karl
2015/02/10 17:19:26
Done.
| |
2815 for (Ice::VariableDeclaration *Var : Context->getGlobalVariables()) { | 2873 const Ice::VariableDeclarationList &Decls = *DeclsPtr; |
2816 installDeclarationName(Trans, Var, GlobalPrefix, "global", NameIndex); | 2874 getTranslator().lowerGlobals(Decls); |
2817 } | |
2818 } | |
2819 const Ice::IceString &FunctionPrefix = | |
2820 getFlags().getDefaultFunctionPrefix(); | |
2821 if (!FunctionPrefix.empty()) { | |
2822 uint32_t NameIndex = 0; | |
2823 for (Ice::FunctionDeclaration *Func : | |
2824 Context->getFunctionDeclarationList()) { | |
2825 installDeclarationName(Trans, Func, FunctionPrefix, "function", | |
2826 NameIndex); | |
2827 } | |
2828 } | |
2829 getTranslator().lowerGlobals(Context->getGlobalVariables()); | |
2830 GlobalDeclarationNamesAndInitializersInstalled = true; | 2875 GlobalDeclarationNamesAndInitializersInstalled = true; |
2831 } | 2876 } |
2832 } | 2877 } |
2833 | |
2834 void installDeclarationName(Ice::Translator &Trans, | |
2835 Ice::GlobalDeclaration *Decl, | |
2836 const Ice::IceString &Prefix, const char *Context, | |
2837 uint32_t &NameIndex) { | |
2838 if (!Decl->hasName()) { | |
2839 Decl->setName(Trans.createUnnamedName(Prefix, NameIndex)); | |
2840 ++NameIndex; | |
2841 } else { | |
2842 Trans.checkIfUnnamedNameSafe(Decl->getName(), Context, Prefix); | |
2843 } | |
2844 } | |
2845 | |
2846 bool ParseBlock(unsigned BlockID) override; | 2878 bool ParseBlock(unsigned BlockID) override; |
2847 | 2879 |
2848 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } | 2880 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } |
2849 | 2881 |
2850 void ProcessRecord() override; | 2882 void ProcessRecord() override; |
2851 }; | 2883 }; |
2852 | 2884 |
2853 class ModuleValuesymtabParser : public ValuesymtabParser { | 2885 class ModuleValuesymtabParser : public ValuesymtabParser { |
2854 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; | 2886 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; |
2855 void operator=(const ModuleValuesymtabParser &) = delete; | 2887 void operator=(const ModuleValuesymtabParser &) = delete; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3020 | 3052 |
3021 if (TopLevelBlocks != 1) { | 3053 if (TopLevelBlocks != 1) { |
3022 errs() << IRFilename | 3054 errs() << IRFilename |
3023 << ": Contains more than one module. Found: " << TopLevelBlocks | 3055 << ": Contains more than one module. Found: " << TopLevelBlocks |
3024 << "\n"; | 3056 << "\n"; |
3025 ErrorStatus.assign(EC_Bitcode); | 3057 ErrorStatus.assign(EC_Bitcode); |
3026 } | 3058 } |
3027 } | 3059 } |
3028 | 3060 |
3029 } // end of namespace Ice | 3061 } // end of namespace Ice |
OLD | NEW |