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 /// \file | 10 /// \file |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 size_t NextDefiningFunctionID = 0; | 439 size_t NextDefiningFunctionID = 0; |
440 // The set of global variables. | 440 // The set of global variables. |
441 std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; | 441 std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; |
442 // Relocatable constants associated with global declarations. | 442 // Relocatable constants associated with global declarations. |
443 Ice::ConstantList ValueIDConstants; | 443 Ice::ConstantList ValueIDConstants; |
444 // Error recovery value to use when getFuncSigTypeByID fails. | 444 // Error recovery value to use when getFuncSigTypeByID fails. |
445 Ice::FuncSigType UndefinedFuncSigType; | 445 Ice::FuncSigType UndefinedFuncSigType; |
446 // Defines if a module block has already been parsed. | 446 // Defines if a module block has already been parsed. |
447 bool ParsedModuleBlock = false; | 447 bool ParsedModuleBlock = false; |
448 | 448 |
| 449 static const Ice::ClFlags &getFlags() { |
| 450 return Ice::GlobalContext::getFlags(); |
| 451 } |
| 452 |
449 bool ParseBlock(unsigned BlockID) override; | 453 bool ParseBlock(unsigned BlockID) override; |
450 | 454 |
451 // Gets extended type associated with the given index, assuming the extended | 455 // Gets extended type associated with the given index, assuming the extended |
452 // type is of the WantedKind. Generates error message if corresponding | 456 // type is of the WantedKind. Generates error message if corresponding |
453 // extended type of WantedKind can't be found, and returns nullptr. | 457 // extended type of WantedKind can't be found, and returns nullptr. |
454 ExtendedType *getTypeByIDAsKind(NaClBcIndexSize_t ID, | 458 ExtendedType *getTypeByIDAsKind(NaClBcIndexSize_t ID, |
455 ExtendedType::TypeKind WantedKind) { | 459 ExtendedType::TypeKind WantedKind) { |
456 ExtendedType *Ty = nullptr; | 460 ExtendedType *Ty = nullptr; |
457 if (ID < TypeIDValues.size()) { | 461 if (ID < TypeIDValues.size()) { |
458 Ty = &TypeIDValues[ID]; | 462 Ty = &TypeIDValues[ID]; |
(...skipping 23 matching lines...) Expand all Loading... |
482 } else { | 486 } else { |
483 Decl->setName(Ctx); | 487 Decl->setName(Ctx); |
484 } | 488 } |
485 ++NameIndex; | 489 ++NameIndex; |
486 } | 490 } |
487 } | 491 } |
488 | 492 |
489 // Installs names for global variables without names. | 493 // Installs names for global variables without names. |
490 void installGlobalVarNames() { | 494 void installGlobalVarNames() { |
491 assert(VariableDeclarations); | 495 assert(VariableDeclarations); |
492 const std::string &GlobalPrefix = | 496 const std::string &GlobalPrefix = getFlags().getDefaultGlobalPrefix(); |
493 getTranslator().getFlags().getDefaultGlobalPrefix(); | |
494 if (!GlobalPrefix.empty()) { | 497 if (!GlobalPrefix.empty()) { |
495 NaClBcIndexSize_t NameIndex = 0; | 498 NaClBcIndexSize_t NameIndex = 0; |
496 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { | 499 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { |
497 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); | 500 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); |
498 } | 501 } |
499 } | 502 } |
500 } | 503 } |
501 | 504 |
502 // Installs names for functions without names. | 505 // Installs names for functions without names. |
503 void installFunctionNames() { | 506 void installFunctionNames() { |
504 const std::string &FunctionPrefix = | 507 const std::string &FunctionPrefix = getFlags().getDefaultFunctionPrefix(); |
505 getTranslator().getFlags().getDefaultFunctionPrefix(); | |
506 if (!FunctionPrefix.empty()) { | 508 if (!FunctionPrefix.empty()) { |
507 NaClBcIndexSize_t NameIndex = 0; | 509 NaClBcIndexSize_t NameIndex = 0; |
508 for (Ice::FunctionDeclaration *Func : FunctionDeclarations) { | 510 for (Ice::FunctionDeclaration *Func : FunctionDeclarations) { |
509 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); | 511 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); |
510 } | 512 } |
511 } | 513 } |
512 } | 514 } |
513 | 515 |
514 // Builds a constant symbol named Name. IsExternal is true iff the symbol is | 516 // Builds a constant symbol named Name. IsExternal is true iff the symbol is |
515 // external. | 517 // external. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 { | 583 { |
582 std::unique_lock<Ice::GlobalLockType> _(ErrorReportingLock); | 584 std::unique_lock<Ice::GlobalLockType> _(ErrorReportingLock); |
583 ErrorStatus.assign(Ice::EC_Bitcode); | 585 ErrorStatus.assign(Ice::EC_Bitcode); |
584 } | 586 } |
585 { // Lock while printing out error message. | 587 { // Lock while printing out error message. |
586 Ice::OstreamLocker L(Context); | 588 Ice::OstreamLocker L(Context); |
587 raw_ostream &OldErrStream = setErrStream(Context->getStrError()); | 589 raw_ostream &OldErrStream = setErrStream(Context->getStrError()); |
588 NaClBitcodeParser::ErrorAt(Level, Bit, Message); | 590 NaClBitcodeParser::ErrorAt(Level, Bit, Message); |
589 setErrStream(OldErrStream); | 591 setErrStream(OldErrStream); |
590 } | 592 } |
591 if (Level >= naclbitc::Error && | 593 if (Level >= naclbitc::Error && !getFlags().getAllowErrorRecovery()) |
592 !Translator.getFlags().getAllowErrorRecovery()) | |
593 Fatal(); | 594 Fatal(); |
594 return true; | 595 return true; |
595 } | 596 } |
596 | 597 |
597 void TopLevelParser::reportBadTypeIDAs(NaClBcIndexSize_t ID, | 598 void TopLevelParser::reportBadTypeIDAs(NaClBcIndexSize_t ID, |
598 const ExtendedType *Ty, | 599 const ExtendedType *Ty, |
599 ExtendedType::TypeKind WantedType) { | 600 ExtendedType::TypeKind WantedType) { |
600 std::string Buffer; | 601 std::string Buffer; |
601 raw_string_ostream StrBuf(Buffer); | 602 raw_string_ostream StrBuf(Buffer); |
602 if (Ty == nullptr) { | 603 if (Ty == nullptr) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 bool BlockHasError = false; | 687 bool BlockHasError = false; |
687 | 688 |
688 // Constructor for nested block parsers. | 689 // Constructor for nested block parsers. |
689 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 690 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
690 : NaClBitcodeParser(BlockID, EnclosingParser), | 691 : NaClBitcodeParser(BlockID, EnclosingParser), |
691 Context(EnclosingParser->Context) {} | 692 Context(EnclosingParser->Context) {} |
692 | 693 |
693 // Gets the translator associated with the bitcode parser. | 694 // Gets the translator associated with the bitcode parser. |
694 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 695 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
695 | 696 |
696 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 697 static const Ice::ClFlags &getFlags() { |
| 698 return Ice::GlobalContext::getFlags(); |
| 699 } |
697 | 700 |
698 // Default implementation. Reports that block is unknown and skips its | 701 // Default implementation. Reports that block is unknown and skips its |
699 // contents. | 702 // contents. |
700 bool ParseBlock(unsigned BlockID) override; | 703 bool ParseBlock(unsigned BlockID) override; |
701 | 704 |
702 // Default implementation. Reports that the record is not understood. | 705 // Default implementation. Reports that the record is not understood. |
703 void ProcessRecord() override; | 706 void ProcessRecord() override; |
704 | 707 |
705 // Checks if the size of the record is Size. Return true if valid. Otherwise | 708 // Checks if the size of the record is Size. Return true if valid. Otherwise |
706 // generates an error and returns false. | 709 // generates an error and returns false. |
(...skipping 2462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3169 } | 3172 } |
3170 Ctx->optQueueBlockingPush(Ice::makeUnique<CfgParserWorkItem>( | 3173 Ctx->optQueueBlockingPush(Ice::makeUnique<CfgParserWorkItem>( |
3171 BlockID, FcnId, this, std::move(Buffer), BufferSize, StartBit, | 3174 BlockID, FcnId, this, std::move(Buffer), BufferSize, StartBit, |
3172 SeqNumber)); | 3175 SeqNumber)); |
3173 return false; | 3176 return false; |
3174 } else { | 3177 } else { |
3175 FunctionParser Parser(BlockID, this, FcnId); | 3178 FunctionParser Parser(BlockID, this, FcnId); |
3176 std::unique_ptr<Ice::Cfg> Func = Parser.parseFunction(SeqNumber); | 3179 std::unique_ptr<Ice::Cfg> Func = Parser.parseFunction(SeqNumber); |
3177 bool Failed = Func->hasError(); | 3180 bool Failed = Func->hasError(); |
3178 getTranslator().translateFcn(std::move(Func)); | 3181 getTranslator().translateFcn(std::move(Func)); |
3179 return Failed && !getTranslator().getFlags().getAllowErrorRecovery(); | 3182 return Failed && !getFlags().getAllowErrorRecovery(); |
3180 } | 3183 } |
3181 } | 3184 } |
3182 default: | 3185 default: |
3183 return BlockParserBaseClass::ParseBlock(BlockID); | 3186 return BlockParserBaseClass::ParseBlock(BlockID); |
3184 } | 3187 } |
3185 } | 3188 } |
3186 | 3189 |
3187 void ModuleParser::ProcessRecord() { | 3190 void ModuleParser::ProcessRecord() { |
3188 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 3191 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
3189 switch (Record.GetCode()) { | 3192 switch (Record.GetCode()) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3298 raw_string_ostream StrBuf(Buffer); | 3301 raw_string_ostream StrBuf(Buffer); |
3299 StrBuf << IRFilename << ": Does not contain a module!"; | 3302 StrBuf << IRFilename << ": Does not contain a module!"; |
3300 llvm::report_fatal_error(StrBuf.str()); | 3303 llvm::report_fatal_error(StrBuf.str()); |
3301 } | 3304 } |
3302 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3305 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
3303 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); | 3306 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
3304 } | 3307 } |
3305 } | 3308 } |
3306 | 3309 |
3307 } // end of namespace Ice | 3310 } // end of namespace Ice |
OLD | NEW |