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

Side by Side Diff: src/PNaClTranslator.cpp

Issue 1848303003: Simplify references to command line flags. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. Created 4 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/IceTranslator.h ('k') | unittest/BitcodeMunge.h » ('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/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
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
453 bool ParseBlock(unsigned BlockID) override; 449 bool ParseBlock(unsigned BlockID) override;
454 450
455 // Gets extended type associated with the given index, assuming the extended 451 // Gets extended type associated with the given index, assuming the extended
456 // type is of the WantedKind. Generates error message if corresponding 452 // type is of the WantedKind. Generates error message if corresponding
457 // extended type of WantedKind can't be found, and returns nullptr. 453 // extended type of WantedKind can't be found, and returns nullptr.
458 ExtendedType *getTypeByIDAsKind(NaClBcIndexSize_t ID, 454 ExtendedType *getTypeByIDAsKind(NaClBcIndexSize_t ID,
459 ExtendedType::TypeKind WantedKind) { 455 ExtendedType::TypeKind WantedKind) {
460 ExtendedType *Ty = nullptr; 456 ExtendedType *Ty = nullptr;
461 if (ID < TypeIDValues.size()) { 457 if (ID < TypeIDValues.size()) {
462 Ty = &TypeIDValues[ID]; 458 Ty = &TypeIDValues[ID];
(...skipping 23 matching lines...) Expand all
486 } else { 482 } else {
487 Decl->setName(Ctx); 483 Decl->setName(Ctx);
488 } 484 }
489 ++NameIndex; 485 ++NameIndex;
490 } 486 }
491 } 487 }
492 488
493 // Installs names for global variables without names. 489 // Installs names for global variables without names.
494 void installGlobalVarNames() { 490 void installGlobalVarNames() {
495 assert(VariableDeclarations); 491 assert(VariableDeclarations);
496 const std::string &GlobalPrefix = getFlags().getDefaultGlobalPrefix(); 492 const std::string &GlobalPrefix = Ice::getFlags().getDefaultGlobalPrefix();
497 if (!GlobalPrefix.empty()) { 493 if (!GlobalPrefix.empty()) {
498 NaClBcIndexSize_t NameIndex = 0; 494 NaClBcIndexSize_t NameIndex = 0;
499 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { 495 for (Ice::VariableDeclaration *Var : *VariableDeclarations) {
500 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); 496 installDeclarationName(Var, GlobalPrefix, "global", NameIndex);
501 } 497 }
502 } 498 }
503 } 499 }
504 500
505 // Installs names for functions without names. 501 // Installs names for functions without names.
506 void installFunctionNames() { 502 void installFunctionNames() {
507 const std::string &FunctionPrefix = getFlags().getDefaultFunctionPrefix(); 503 const std::string &FunctionPrefix =
504 Ice::getFlags().getDefaultFunctionPrefix();
508 if (!FunctionPrefix.empty()) { 505 if (!FunctionPrefix.empty()) {
509 NaClBcIndexSize_t NameIndex = 0; 506 NaClBcIndexSize_t NameIndex = 0;
510 for (Ice::FunctionDeclaration *Func : FunctionDeclarations) { 507 for (Ice::FunctionDeclaration *Func : FunctionDeclarations) {
511 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); 508 installDeclarationName(Func, FunctionPrefix, "function", NameIndex);
512 } 509 }
513 } 510 }
514 } 511 }
515 512
516 // Builds a constant symbol named Name. IsExternal is true iff the symbol is 513 // Builds a constant symbol named Name. IsExternal is true iff the symbol is
517 // external. 514 // external.
(...skipping 24 matching lines...) Expand all
542 for (const Ice::FunctionDeclaration *Func : FunctionDeclarations) { 539 for (const Ice::FunctionDeclaration *Func : FunctionDeclarations) {
543 if (!Func->verifyLinkageCorrect(Ctx)) 540 if (!Func->verifyLinkageCorrect(Ctx))
544 reportLinkageError("Function", *Func); 541 reportLinkageError("Function", *Func);
545 Ice::Constant *C = getConstantSym(Func->getName(), Func->isProto()); 542 Ice::Constant *C = getConstantSym(Func->getName(), Func->isProto());
546 ValueIDConstants.push_back(C); 543 ValueIDConstants.push_back(C);
547 } 544 }
548 } 545 }
549 546
550 // Converts global variable declarations into constant value IDs. 547 // Converts global variable declarations into constant value IDs.
551 void createValueIDsForGlobalVars() { 548 void createValueIDsForGlobalVars() {
552 Ice::GlobalContext *Ctx = getTranslator().getContext();
553 for (const Ice::VariableDeclaration *Decl : *VariableDeclarations) { 549 for (const Ice::VariableDeclaration *Decl : *VariableDeclarations) {
554 if (!Decl->verifyLinkageCorrect(Ctx)) 550 if (!Decl->verifyLinkageCorrect())
555 reportLinkageError("Global", *Decl); 551 reportLinkageError("Global", *Decl);
556 Ice::Constant *C = 552 Ice::Constant *C =
557 getConstantSym(Decl->getName(), !Decl->hasInitializer()); 553 getConstantSym(Decl->getName(), !Decl->hasInitializer());
558 ValueIDConstants.push_back(C); 554 ValueIDConstants.push_back(C);
559 } 555 }
560 } 556 }
561 557
562 // Reports that type ID is undefined, or not of the WantedType. 558 // Reports that type ID is undefined, or not of the WantedType.
563 void reportBadTypeIDAs(NaClBcIndexSize_t ID, const ExtendedType *Ty, 559 void reportBadTypeIDAs(NaClBcIndexSize_t ID, const ExtendedType *Ty,
564 ExtendedType::TypeKind WantedType); 560 ExtendedType::TypeKind WantedType);
(...skipping 18 matching lines...) Expand all
583 { 579 {
584 std::unique_lock<Ice::GlobalLockType> _(ErrorReportingLock); 580 std::unique_lock<Ice::GlobalLockType> _(ErrorReportingLock);
585 ErrorStatus.assign(Ice::EC_Bitcode); 581 ErrorStatus.assign(Ice::EC_Bitcode);
586 } 582 }
587 { // Lock while printing out error message. 583 { // Lock while printing out error message.
588 Ice::OstreamLocker L(Context); 584 Ice::OstreamLocker L(Context);
589 raw_ostream &OldErrStream = setErrStream(Context->getStrError()); 585 raw_ostream &OldErrStream = setErrStream(Context->getStrError());
590 NaClBitcodeParser::ErrorAt(Level, Bit, Message); 586 NaClBitcodeParser::ErrorAt(Level, Bit, Message);
591 setErrStream(OldErrStream); 587 setErrStream(OldErrStream);
592 } 588 }
593 if (Level >= naclbitc::Error && !getFlags().getAllowErrorRecovery()) 589 if (Level >= naclbitc::Error && !Ice::getFlags().getAllowErrorRecovery())
594 Fatal(); 590 Fatal();
595 return true; 591 return true;
596 } 592 }
597 593
598 void TopLevelParser::reportBadTypeIDAs(NaClBcIndexSize_t ID, 594 void TopLevelParser::reportBadTypeIDAs(NaClBcIndexSize_t ID,
599 const ExtendedType *Ty, 595 const ExtendedType *Ty,
600 ExtendedType::TypeKind WantedType) { 596 ExtendedType::TypeKind WantedType) {
601 std::string Buffer; 597 std::string Buffer;
602 raw_string_ostream StrBuf(Buffer); 598 raw_string_ostream StrBuf(Buffer);
603 if (Ty == nullptr) { 599 if (Ty == nullptr) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 bool BlockHasError = false; 683 bool BlockHasError = false;
688 684
689 // Constructor for nested block parsers. 685 // Constructor for nested block parsers.
690 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) 686 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser)
691 : NaClBitcodeParser(BlockID, EnclosingParser), 687 : NaClBitcodeParser(BlockID, EnclosingParser),
692 Context(EnclosingParser->Context) {} 688 Context(EnclosingParser->Context) {}
693 689
694 // Gets the translator associated with the bitcode parser. 690 // Gets the translator associated with the bitcode parser.
695 Ice::Translator &getTranslator() const { return Context->getTranslator(); } 691 Ice::Translator &getTranslator() const { return Context->getTranslator(); }
696 692
697 static const Ice::ClFlags &getFlags() {
698 return Ice::GlobalContext::getFlags();
699 }
700
701 // Default implementation. Reports that block is unknown and skips its 693 // Default implementation. Reports that block is unknown and skips its
702 // contents. 694 // contents.
703 bool ParseBlock(unsigned BlockID) override; 695 bool ParseBlock(unsigned BlockID) override;
704 696
705 // Default implementation. Reports that the record is not understood. 697 // Default implementation. Reports that the record is not understood.
706 void ProcessRecord() override; 698 void ProcessRecord() override;
707 699
708 // Checks if the size of the record is Size. Return true if valid. Otherwise 700 // Checks if the size of the record is Size. Return true if valid. Otherwise
709 // generates an error and returns false. 701 // generates an error and returns false.
710 bool isValidRecordSize(size_t Size, const char *RecordName) { 702 bool isValidRecordSize(size_t Size, const char *RecordName) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 758
767 // Generates an error Message with the bit address prefixed to it. 759 // Generates an error Message with the bit address prefixed to it.
768 bool BlockParserBaseClass::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, 760 bool BlockParserBaseClass::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit,
769 const std::string &Message) { 761 const std::string &Message) {
770 BlockHasError = true; 762 BlockHasError = true;
771 std::string Buffer; 763 std::string Buffer;
772 raw_string_ostream StrBuf(Buffer); 764 raw_string_ostream StrBuf(Buffer);
773 // Note: If dump routines have been turned off, the error messages will not 765 // Note: If dump routines have been turned off, the error messages will not
774 // be readable. Hence, replace with simple error. We also use the simple form 766 // be readable. Hence, replace with simple error. We also use the simple form
775 // for unit tests. 767 // for unit tests.
776 if (getFlags().getGenerateUnitTestMessages()) { 768 if (Ice::getFlags().getGenerateUnitTestMessages()) {
777 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); 769 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode();
778 for (const uint64_t Val : Record.GetValues()) { 770 for (const uint64_t Val : Record.GetValues()) {
779 StrBuf << " " << Val; 771 StrBuf << " " << Val;
780 } 772 }
781 StrBuf << ">"; 773 StrBuf << ">";
782 } else { 774 } else {
783 StrBuf << Message; 775 StrBuf << Message;
784 } 776 }
785 return Context->ErrorAt(Level, Bit, StrBuf.str()); 777 return Context->ErrorAt(Level, Bit, StrBuf.str());
786 } 778 }
(...skipping 2205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2992 class ModuleParser final : public BlockParserBaseClass { 2984 class ModuleParser final : public BlockParserBaseClass {
2993 ModuleParser() = delete; 2985 ModuleParser() = delete;
2994 ModuleParser(const ModuleParser &) = delete; 2986 ModuleParser(const ModuleParser &) = delete;
2995 ModuleParser &operator=(const ModuleParser &) = delete; 2987 ModuleParser &operator=(const ModuleParser &) = delete;
2996 2988
2997 public: 2989 public:
2998 ModuleParser(unsigned BlockID, TopLevelParser *Context) 2990 ModuleParser(unsigned BlockID, TopLevelParser *Context)
2999 : BlockParserBaseClass(BlockID, Context), 2991 : BlockParserBaseClass(BlockID, Context),
3000 Timer(Ice::TimerStack::TT_parseModule, 2992 Timer(Ice::TimerStack::TT_parseModule,
3001 Context->getTranslator().getContext()), 2993 Context->getTranslator().getContext()),
3002 IsParseParallel(Ice::GlobalContext::Flags.isParseParallel()) {} 2994 IsParseParallel(Ice::getFlags().isParseParallel()) {}
3003 ~ModuleParser() override = default; 2995 ~ModuleParser() override = default;
3004 const char *getBlockName() const override { return "module"; } 2996 const char *getBlockName() const override { return "module"; }
3005 NaClBitstreamCursor &getCursor() const { return Record.GetCursor(); } 2997 NaClBitstreamCursor &getCursor() const { return Record.GetCursor(); }
3006 2998
3007 private: 2999 private:
3008 Ice::TimerMarker Timer; 3000 Ice::TimerMarker Timer;
3009 // True if we have already installed names for unnamed global declarations, 3001 // True if we have already installed names for unnamed global declarations,
3010 // and have generated global constant initializers. 3002 // and have generated global constant initializers.
3011 bool GlobalDeclarationNamesAndInitializersInstalled = false; 3003 bool GlobalDeclarationNamesAndInitializersInstalled = false;
3012 // True if we have already processed the symbol table for the module. 3004 // True if we have already processed the symbol table for the module.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
3172 } 3164 }
3173 Ctx->optQueueBlockingPush(Ice::makeUnique<CfgParserWorkItem>( 3165 Ctx->optQueueBlockingPush(Ice::makeUnique<CfgParserWorkItem>(
3174 BlockID, FcnId, this, std::move(Buffer), BufferSize, StartBit, 3166 BlockID, FcnId, this, std::move(Buffer), BufferSize, StartBit,
3175 SeqNumber)); 3167 SeqNumber));
3176 return false; 3168 return false;
3177 } else { 3169 } else {
3178 FunctionParser Parser(BlockID, this, FcnId); 3170 FunctionParser Parser(BlockID, this, FcnId);
3179 std::unique_ptr<Ice::Cfg> Func = Parser.parseFunction(SeqNumber); 3171 std::unique_ptr<Ice::Cfg> Func = Parser.parseFunction(SeqNumber);
3180 bool Failed = Func->hasError(); 3172 bool Failed = Func->hasError();
3181 getTranslator().translateFcn(std::move(Func)); 3173 getTranslator().translateFcn(std::move(Func));
3182 return Failed && !getFlags().getAllowErrorRecovery(); 3174 return Failed && !Ice::getFlags().getAllowErrorRecovery();
3183 } 3175 }
3184 } 3176 }
3185 default: 3177 default:
3186 return BlockParserBaseClass::ParseBlock(BlockID); 3178 return BlockParserBaseClass::ParseBlock(BlockID);
3187 } 3179 }
3188 } 3180 }
3189 3181
3190 void ModuleParser::ProcessRecord() { 3182 void ModuleParser::ProcessRecord() {
3191 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); 3183 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues();
3192 switch (Record.GetCode()) { 3184 switch (Record.GetCode()) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
3301 raw_string_ostream StrBuf(Buffer); 3293 raw_string_ostream StrBuf(Buffer);
3302 StrBuf << IRFilename << ": Does not contain a module!"; 3294 StrBuf << IRFilename << ": Does not contain a module!";
3303 llvm::report_fatal_error(StrBuf.str()); 3295 llvm::report_fatal_error(StrBuf.str());
3304 } 3296 }
3305 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { 3297 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3306 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); 3298 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
3307 } 3299 }
3308 } 3300 }
3309 3301
3310 } // end of namespace Ice 3302 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTranslator.h ('k') | unittest/BitcodeMunge.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698