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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 TopLevelParser(Ice::Translator &Translator, NaClBitstreamCursor &Cursor, | 230 TopLevelParser(Ice::Translator &Translator, NaClBitstreamCursor &Cursor, |
231 Ice::ErrorCode &ErrorStatus) | 231 Ice::ErrorCode &ErrorStatus) |
232 : NaClBitcodeParser(Cursor), Translator(Translator), | 232 : NaClBitcodeParser(Cursor), Translator(Translator), |
233 ErrorStatus(ErrorStatus), | 233 ErrorStatus(ErrorStatus), |
234 VariableDeclarations(new Ice::VariableDeclarationList()) {} | 234 VariableDeclarations(new Ice::VariableDeclarationList()) {} |
235 | 235 |
236 ~TopLevelParser() override = default; | 236 ~TopLevelParser() override = default; |
237 | 237 |
238 Ice::Translator &getTranslator() const { return Translator; } | 238 Ice::Translator &getTranslator() const { return Translator; } |
239 | 239 |
240 const Ice::ClFlags &getFlags() const { | |
Jim Stichnoth
2016/03/31 21:02:31
Make this static?
Karl
2016/03/31 21:39:48
Done.
| |
241 return Ice::GlobalContext::getFlags(); | |
242 } | |
243 | |
240 /// Generates error with given Message, occurring at BitPosition within the | 244 /// Generates error with given Message, occurring at BitPosition within the |
241 /// bitcode file. Always returns true. | 245 /// bitcode file. Always returns true. |
242 bool ErrorAt(naclbitc::ErrorLevel Level, uint64_t BitPosition, | 246 bool ErrorAt(naclbitc::ErrorLevel Level, uint64_t BitPosition, |
243 const std::string &Message) override; | 247 const std::string &Message) override; |
244 | 248 |
245 /// Generates error message with respect to the current block parser. | 249 /// Generates error message with respect to the current block parser. |
246 bool blockError(const std::string &Message); | 250 bool blockError(const std::string &Message); |
247 | 251 |
248 /// Changes the size of the type list to the given size. | 252 /// Changes the size of the type list to the given size. |
249 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); } | 253 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); } |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 const Ice::ClFlags &getFlags() const { |
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 |