diff --git a/include/llvm/TableGen/Error.h b/include/llvm/TableGen/Error.h index 2d0a2b45a96a..17ac41815153 100644 --- a/include/llvm/TableGen/Error.h +++ b/include/llvm/TableGen/Error.h @@ -27,9 +27,9 @@ void PrintError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg); void PrintError(const char *Loc, const Twine &Msg); void PrintError(const Twine &Msg); -LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const std::string &Msg); +LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg); LLVM_ATTRIBUTE_NORETURN void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, - const std::string &Msg); + const Twine &Msg); extern SourceMgr SrcMgr; extern unsigned ErrorsPrinted; diff --git a/lib/TableGen/Error.cpp b/lib/TableGen/Error.cpp index 928b1203cd8f..8d9ae20dd52e 100644 --- a/lib/TableGen/Error.cpp +++ b/lib/TableGen/Error.cpp @@ -62,12 +62,12 @@ void PrintError(const Twine &Msg) { errs() << "error:" << Msg << "\n"; } -void PrintFatalError(const std::string &Msg) { - PrintError(Twine(Msg)); +void PrintFatalError(const Twine &Msg) { + PrintError(Msg); std::exit(1); } -void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const std::string &Msg) { +void PrintFatalError(ArrayRef<SMLoc> ErrorLoc, const Twine &Msg) { PrintError(ErrorLoc, Msg); std::exit(1); } diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 53e6c51bf5c2..a43665bcd85d 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -1786,7 +1786,7 @@ Init *Record::getValueInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); return R->getValue(); } @@ -1799,12 +1799,12 @@ std::string Record::getValueAsString(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (StringInit *SI = dyn_cast<StringInit>(R->getValue())) return SI->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a string initializer!"); + FieldName + "' does not have a string initializer!"); } /// getValueAsBitsInit - This method looks up the specified field and returns @@ -1815,12 +1815,12 @@ BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (BitsInit *BI = dyn_cast<BitsInit>(R->getValue())) return BI; PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a BitsInit initializer!"); + FieldName + "' does not have a BitsInit initializer!"); } /// getValueAsListInit - This method looks up the specified field and returns @@ -1831,12 +1831,12 @@ ListInit *Record::getValueAsListInit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (ListInit *LI = dyn_cast<ListInit>(R->getValue())) return LI; PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a list initializer!"); + FieldName + "' does not have a list initializer!"); } /// getValueAsListOfDefs - This method looks up the specified field and returns @@ -1852,7 +1852,7 @@ Record::getValueAsListOfDefs(StringRef FieldName) const { Defs.push_back(DI->getDef()); } else { PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' list is not entirely DefInit!"); + FieldName + "' list is not entirely DefInit!"); } } return Defs; @@ -1866,12 +1866,12 @@ int64_t Record::getValueAsInt(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (IntInit *II = dyn_cast<IntInit>(R->getValue())) return II->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have an int initializer!"); + FieldName + "' does not have an int initializer!"); } /// getValueAsListOfInts - This method looks up the specified field and returns @@ -1887,7 +1887,7 @@ Record::getValueAsListOfInts(StringRef FieldName) const { Ints.push_back(II->getValue()); } else { PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a list of ints initializer!"); + FieldName + "' does not have a list of ints initializer!"); } } return Ints; @@ -1906,7 +1906,7 @@ Record::getValueAsListOfStrings(StringRef FieldName) const { Strings.push_back(II->getValue()); } else { PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a list of strings initializer!"); + FieldName + "' does not have a list of strings initializer!"); } } return Strings; @@ -1920,12 +1920,12 @@ Record *Record::getValueAsDef(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (DefInit *DI = dyn_cast<DefInit>(R->getValue())) return DI->getDef(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a def initializer!"); + FieldName + "' does not have a def initializer!"); } /// getValueAsBit - This method looks up the specified field and returns its @@ -1936,12 +1936,12 @@ bool Record::getValueAsBit(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (BitInit *BI = dyn_cast<BitInit>(R->getValue())) return BI->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a bit initializer!"); + FieldName + "' does not have a bit initializer!"); } bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const { @@ -1958,7 +1958,7 @@ bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const { if (BitInit *BI = dyn_cast<BitInit>(R->getValue())) return BI->getValue(); PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a bit initializer!"); + FieldName + "' does not have a bit initializer!"); } /// getValueAsDag - This method looks up the specified field and returns its @@ -1969,12 +1969,12 @@ DagInit *Record::getValueAsDag(StringRef FieldName) const { const RecordVal *R = getValue(FieldName); if (R == 0 || R->getValue() == 0) PrintFatalError(getLoc(), "Record `" + getName() + - "' does not have a field named `" + FieldName.str() + "'!\n"); + "' does not have a field named `" + FieldName + "'!\n"); if (DagInit *DI = dyn_cast<DagInit>(R->getValue())) return DI; PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + - FieldName.str() + "' does not have a dag initializer!"); + FieldName + "' does not have a dag initializer!"); } diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index 3cb8974f773b..4169f8d0a8cb 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -719,12 +719,12 @@ void MatchableInfo::formTwoOperandAlias(StringRef Constraint) { int DstAsmOperand = findAsmOperandNamed(Ops.second); if (SrcAsmOperand == -1) PrintFatalError(TheDef->getLoc(), - "unknown source two-operand alias operand '" + - Ops.first.str() + "'."); + "unknown source two-operand alias operand '" + Ops.first + + "'."); if (DstAsmOperand == -1) PrintFatalError(TheDef->getLoc(), - "unknown destination two-operand alias operand '" + - Ops.second.str() + "'."); + "unknown destination two-operand alias operand '" + + Ops.second + "'."); // Find the ResOperand that refers to the operand we're aliasing away // and update it to refer to the combined operand instead. @@ -872,7 +872,7 @@ void MatchableInfo::tokenizeAsmString(const AsmMatcherInfo &Info) { // FIXME : Check and raise an error if it is a register. if (Mnemonic[0] == '$') PrintFatalError(TheDef->getLoc(), - "Invalid instruction mnemonic '" + Mnemonic.str() + "'!"); + "Invalid instruction mnemonic '" + Mnemonic + "'!"); // Remove the first operand, it is tracked in the mnemonic field. AsmOperands.erase(AsmOperands.begin()); @@ -909,22 +909,22 @@ bool MatchableInfo::validate(StringRef CommentDelimiter, bool Hack) const { StringRef Tok = AsmOperands[i].Token; if (Tok[0] == '$' && Tok.find(':') != StringRef::npos) PrintFatalError(TheDef->getLoc(), - "matchable with operand modifier '" + Tok.str() + - "' not supported by asm matcher. Mark isCodeGenOnly!"); + "matchable with operand modifier '" + Tok + + "' not supported by asm matcher. Mark isCodeGenOnly!"); // Verify that any operand is only mentioned once. // We reject aliases and ignore instructions for now. if (Tok[0] == '$' && !OperandNames.insert(Tok).second) { if (!Hack) PrintFatalError(TheDef->getLoc(), - "ERROR: matchable with tied operand '" + Tok.str() + - "' can never be matched!"); + "ERROR: matchable with tied operand '" + Tok + + "' can never be matched!"); // FIXME: Should reject these. The ARM backend hits this with $lane in a // bunch of instructions. It is unclear what the right answer is. DEBUG({ errs() << "warning: '" << TheDef->getName() << "': " << "ignoring instruction with tied operand '" - << Tok.str() << "'\n"; + << Tok << "'\n"; }); return false; } @@ -1500,8 +1500,8 @@ buildInstructionOperandReference(MatchableInfo *II, // Map this token to an operand. unsigned Idx; if (!Operands.hasOperandNamed(OperandName, Idx)) - PrintFatalError(II->TheDef->getLoc(), "error: unable to find operand: '" + - OperandName.str() + "'"); + PrintFatalError(II->TheDef->getLoc(), + "error: unable to find operand: '" + OperandName + "'"); // If the instruction operand has multiple suboperands, but the parser // match class for the asm operand is still the default "ImmAsmOperand", @@ -1573,8 +1573,8 @@ void AsmMatcherInfo::buildAliasOperandReference(MatchableInfo *II, return; } - PrintFatalError(II->TheDef->getLoc(), "error: unable to find operand: '" + - OperandName.str() + "'"); + PrintFatalError(II->TheDef->getLoc(), + "error: unable to find operand: '" + OperandName + "'"); } void MatchableInfo::buildInstructionResultOperands() { diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index eca4c896b160..f9e1990d0553 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -547,8 +547,8 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, Reg.TheDef->getValueAsListOfStrings("AltNames"); if (AltNames.size() <= Idx) PrintFatalError(Reg.TheDef->getLoc(), - (Twine("Register definition missing alt name for '") + - AltName + "'.").str()); + "Register definition missing alt name for '" + + AltName + "'."); AsmName = AltNames[Idx]; } } diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp index f9f3caf126f3..0af7e3d0164c 100644 --- a/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/utils/TableGen/CodeGenDAGPatterns.cpp @@ -2327,8 +2327,9 @@ void CodeGenDAGPatterns::ParseDefaultOperands() { /* Resolve all types */; if (TPN->ContainsUnresolvedType()) { - PrintFatalError("Value #" + utostr(i) + " of OperandWithDefaultOps '" + - DefaultOps[i]->getName() +"' doesn't have a concrete type!"); + PrintFatalError("Value #" + Twine(i) + " of OperandWithDefaultOps '" + + DefaultOps[i]->getName() + + "' doesn't have a concrete type!"); } DefaultOpInfo.DefaultOps.push_back(TPN); } diff --git a/utils/TableGen/CodeGenInstruction.cpp b/utils/TableGen/CodeGenInstruction.cpp index fb4785b601ef..5eebb9176ce4 100644 --- a/utils/TableGen/CodeGenInstruction.cpp +++ b/utils/TableGen/CodeGenInstruction.cpp @@ -106,11 +106,11 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { // Check that the operand has a name and that it's unique. if (ArgName.empty()) - PrintFatalError("In instruction '" + R->getName() + "', operand #" + utostr(i) + - " has no name!"); + PrintFatalError("In instruction '" + R->getName() + "', operand #" + + Twine(i) + " has no name!"); if (!OperandNames.insert(ArgName).second) - PrintFatalError("In instruction '" + R->getName() + "', operand #" + utostr(i) + - " has the same name as a previous operand!"); + PrintFatalError("In instruction '" + R->getName() + "', operand #" + + Twine(i) + " has the same name as a previous operand!"); OperandList.push_back(OperandInfo(Rec, ArgName, PrintMethod, EncoderMethod, OperandType, MIOperandNo, NumOps, @@ -133,8 +133,8 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) { unsigned CGIOperandList::getOperandNamed(StringRef Name) const { unsigned OpIdx; if (hasOperandNamed(Name, OpIdx)) return OpIdx; - PrintFatalError("'" + TheDef->getName() + "' does not have an operand named '$" + - Name.str() + "'!"); + PrintFatalError("'" + TheDef->getName() + + "' does not have an operand named '$" + Name + "'!"); } /// hasOperandNamed - Query whether the instruction has an operand of the @@ -442,8 +442,8 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo, // If the operand is a record, it must have a name, and the record type // must match up with the instruction's argument type. if (Result->getArgName(AliasOpNo).empty()) - PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) + - " must have a name!"); + PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) + + " must have a name!"); ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord); return true; } @@ -514,7 +514,7 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo, return false; // Integer arguments can't have names. if (!Result->getArgName(AliasOpNo).empty()) - PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) + + PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) + " must not have a name!"); ResOp = ResultOperand(II->getValue()); return true; @@ -627,14 +627,14 @@ CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T) : TheDef(R) { ResultInstOperandIndex.push_back(std::make_pair(i, SubOp)); ++AliasOpNo; } else { - PrintFatalError(R->getLoc(), "result argument #" + utostr(AliasOpNo) + + PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) + " does not match instruction operand class " + (SubOp == 0 ? InstOpRec->getName() :SubRec->getName())); } } continue; } - PrintFatalError(R->getLoc(), "result argument #" + utostr(AliasOpNo) + + PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) + " does not match instruction operand class " + InstOpRec->getName()); } diff --git a/utils/TableGen/CodeGenRegisters.cpp b/utils/TableGen/CodeGenRegisters.cpp index b0d398d36535..e0e0b62ebe32 100644 --- a/utils/TableGen/CodeGenRegisters.cpp +++ b/utils/TableGen/CodeGenRegisters.cpp @@ -993,7 +993,7 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) { // Read in register class definitions. std::vector<Record*> RCs = Records.getAllDerivedDefinitions("RegisterClass"); if (RCs.empty()) - PrintFatalError(std::string("No 'RegisterClass' subclasses defined!")); + PrintFatalError("No 'RegisterClass' subclasses defined!"); // Allocate user-defined register classes. RegClasses.reserve(RCs.size()); diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp index 685c4bf07507..dd9c23ce6713 100644 --- a/utils/TableGen/CodeGenTarget.cpp +++ b/utils/TableGen/CodeGenTarget.cpp @@ -173,7 +173,8 @@ Record *CodeGenTarget::getInstructionSet() const { Record *CodeGenTarget::getAsmParser() const { std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers"); if (AsmParserNum >= LI.size()) - PrintFatalError("Target does not have an AsmParser #" + utostr(AsmParserNum) + "!"); + PrintFatalError("Target does not have an AsmParser #" + + Twine(AsmParserNum) + "!"); return LI[AsmParserNum]; } @@ -184,7 +185,8 @@ Record *CodeGenTarget::getAsmParserVariant(unsigned i) const { std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParserVariants"); if (i >= LI.size()) - PrintFatalError("Target does not have an AsmParserVariant #" + utostr(i) + "!"); + PrintFatalError("Target does not have an AsmParserVariant #" + Twine(i) + + "!"); return LI[i]; } @@ -202,7 +204,8 @@ unsigned CodeGenTarget::getAsmParserVariantCount() const { Record *CodeGenTarget::getAsmWriter() const { std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters"); if (AsmWriterNum >= LI.size()) - PrintFatalError("Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!"); + PrintFatalError("Target does not have an AsmWriter #" + + Twine(AsmWriterNum) + "!"); return LI[AsmWriterNum]; } @@ -285,7 +288,7 @@ GetInstByName(const char *Name, DenseMap<const Record*, CodeGenInstruction*>::const_iterator I = Insts.find(Rec); if (Rec == 0 || I == Insts.end()) - PrintFatalError(std::string("Could not find '") + Name + "' instruction!"); + PrintFatalError(Twine("Could not find '") + Name + "' instruction!"); return I->second; }