llvm.org GIT mirror llvm / abe43b5
tblgen: Twinify PrintFatalError. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205110 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
9 changed file(s) with 62 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
2626 void PrintError(const char *Loc, const Twine &Msg);
2727 void PrintError(const Twine &Msg);
2828
29 LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const std::string &Msg);
29 LLVM_ATTRIBUTE_NORETURN void PrintFatalError(const Twine &Msg);
3030 LLVM_ATTRIBUTE_NORETURN void PrintFatalError(ArrayRef ErrorLoc,
31 const std::string &Msg);
31 const Twine &Msg);
3232
3333 extern SourceMgr SrcMgr;
3434 extern unsigned ErrorsPrinted;
6161 errs() << "error:" << Msg << "\n";
6262 }
6363
64 void PrintFatalError(const std::string &Msg) {
65 PrintError(Twine(Msg));
64 void PrintFatalError(const Twine &Msg) {
65 PrintError(Msg);
6666 std::exit(1);
6767 }
6868
69 void PrintFatalError(ArrayRef ErrorLoc, const std::string &Msg) {
69 void PrintFatalError(ArrayRef ErrorLoc, const Twine &Msg) {
7070 PrintError(ErrorLoc, Msg);
7171 std::exit(1);
7272 }
17851785 const RecordVal *R = getValue(FieldName);
17861786 if (R == 0 || R->getValue() == 0)
17871787 PrintFatalError(getLoc(), "Record `" + getName() +
1788 "' does not have a field named `" + FieldName.str() + "'!\n");
1788 "' does not have a field named `" + FieldName + "'!\n");
17891789 return R->getValue();
17901790 }
17911791
17981798 const RecordVal *R = getValue(FieldName);
17991799 if (R == 0 || R->getValue() == 0)
18001800 PrintFatalError(getLoc(), "Record `" + getName() +
1801 "' does not have a field named `" + FieldName.str() + "'!\n");
1801 "' does not have a field named `" + FieldName + "'!\n");
18021802
18031803 if (StringInit *SI = dyn_cast(R->getValue()))
18041804 return SI->getValue();
18051805 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1806 FieldName.str() + "' does not have a string initializer!");
1806 FieldName + "' does not have a string initializer!");
18071807 }
18081808
18091809 /// getValueAsBitsInit - This method looks up the specified field and returns
18141814 const RecordVal *R = getValue(FieldName);
18151815 if (R == 0 || R->getValue() == 0)
18161816 PrintFatalError(getLoc(), "Record `" + getName() +
1817 "' does not have a field named `" + FieldName.str() + "'!\n");
1817 "' does not have a field named `" + FieldName + "'!\n");
18181818
18191819 if (BitsInit *BI = dyn_cast(R->getValue()))
18201820 return BI;
18211821 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1822 FieldName.str() + "' does not have a BitsInit initializer!");
1822 FieldName + "' does not have a BitsInit initializer!");
18231823 }
18241824
18251825 /// getValueAsListInit - This method looks up the specified field and returns
18301830 const RecordVal *R = getValue(FieldName);
18311831 if (R == 0 || R->getValue() == 0)
18321832 PrintFatalError(getLoc(), "Record `" + getName() +
1833 "' does not have a field named `" + FieldName.str() + "'!\n");
1833 "' does not have a field named `" + FieldName + "'!\n");
18341834
18351835 if (ListInit *LI = dyn_cast(R->getValue()))
18361836 return LI;
18371837 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1838 FieldName.str() + "' does not have a list initializer!");
1838 FieldName + "' does not have a list initializer!");
18391839 }
18401840
18411841 /// getValueAsListOfDefs - This method looks up the specified field and returns
18511851 Defs.push_back(DI->getDef());
18521852 } else {
18531853 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1854 FieldName.str() + "' list is not entirely DefInit!");
1854 FieldName + "' list is not entirely DefInit!");
18551855 }
18561856 }
18571857 return Defs;
18651865 const RecordVal *R = getValue(FieldName);
18661866 if (R == 0 || R->getValue() == 0)
18671867 PrintFatalError(getLoc(), "Record `" + getName() +
1868 "' does not have a field named `" + FieldName.str() + "'!\n");
1868 "' does not have a field named `" + FieldName + "'!\n");
18691869
18701870 if (IntInit *II = dyn_cast(R->getValue()))
18711871 return II->getValue();
18721872 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1873 FieldName.str() + "' does not have an int initializer!");
1873 FieldName + "' does not have an int initializer!");
18741874 }
18751875
18761876 /// getValueAsListOfInts - This method looks up the specified field and returns
18861886 Ints.push_back(II->getValue());
18871887 } else {
18881888 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1889 FieldName.str() + "' does not have a list of ints initializer!");
1889 FieldName + "' does not have a list of ints initializer!");
18901890 }
18911891 }
18921892 return Ints;
19051905 Strings.push_back(II->getValue());
19061906 } else {
19071907 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1908 FieldName.str() + "' does not have a list of strings initializer!");
1908 FieldName + "' does not have a list of strings initializer!");
19091909 }
19101910 }
19111911 return Strings;
19191919 const RecordVal *R = getValue(FieldName);
19201920 if (R == 0 || R->getValue() == 0)
19211921 PrintFatalError(getLoc(), "Record `" + getName() +
1922 "' does not have a field named `" + FieldName.str() + "'!\n");
1922 "' does not have a field named `" + FieldName + "'!\n");
19231923
19241924 if (DefInit *DI = dyn_cast(R->getValue()))
19251925 return DI->getDef();
19261926 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1927 FieldName.str() + "' does not have a def initializer!");
1927 FieldName + "' does not have a def initializer!");
19281928 }
19291929
19301930 /// getValueAsBit - This method looks up the specified field and returns its
19351935 const RecordVal *R = getValue(FieldName);
19361936 if (R == 0 || R->getValue() == 0)
19371937 PrintFatalError(getLoc(), "Record `" + getName() +
1938 "' does not have a field named `" + FieldName.str() + "'!\n");
1938 "' does not have a field named `" + FieldName + "'!\n");
19391939
19401940 if (BitInit *BI = dyn_cast(R->getValue()))
19411941 return BI->getValue();
19421942 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1943 FieldName.str() + "' does not have a bit initializer!");
1943 FieldName + "' does not have a bit initializer!");
19441944 }
19451945
19461946 bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
19571957 if (BitInit *BI = dyn_cast(R->getValue()))
19581958 return BI->getValue();
19591959 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1960 FieldName.str() + "' does not have a bit initializer!");
1960 FieldName + "' does not have a bit initializer!");
19611961 }
19621962
19631963 /// getValueAsDag - This method looks up the specified field and returns its
19681968 const RecordVal *R = getValue(FieldName);
19691969 if (R == 0 || R->getValue() == 0)
19701970 PrintFatalError(getLoc(), "Record `" + getName() +
1971 "' does not have a field named `" + FieldName.str() + "'!\n");
1971 "' does not have a field named `" + FieldName + "'!\n");
19721972
19731973 if (DagInit *DI = dyn_cast(R->getValue()))
19741974 return DI;
19751975 PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
1976 FieldName.str() + "' does not have a dag initializer!");
1976 FieldName + "' does not have a dag initializer!");
19771977 }
19781978
19791979
718718 int DstAsmOperand = findAsmOperandNamed(Ops.second);
719719 if (SrcAsmOperand == -1)
720720 PrintFatalError(TheDef->getLoc(),
721 "unknown source two-operand alias operand '" +
722 Ops.first.str() + "'.");
721 "unknown source two-operand alias operand '" + Ops.first +
722 "'.");
723723 if (DstAsmOperand == -1)
724724 PrintFatalError(TheDef->getLoc(),
725 "unknown destination two-operand alias operand '" +
726 Ops.second.str() + "'.");
725 "unknown destination two-operand alias operand '" +
726 Ops.second + "'.");
727727
728728 // Find the ResOperand that refers to the operand we're aliasing away
729729 // and update it to refer to the combined operand instead.
871871 // FIXME : Check and raise an error if it is a register.
872872 if (Mnemonic[0] == '$')
873873 PrintFatalError(TheDef->getLoc(),
874 "Invalid instruction mnemonic '" + Mnemonic.str() + "'!");
874 "Invalid instruction mnemonic '" + Mnemonic + "'!");
875875
876876 // Remove the first operand, it is tracked in the mnemonic field.
877877 AsmOperands.erase(AsmOperands.begin());
908908 StringRef Tok = AsmOperands[i].Token;
909909 if (Tok[0] == '$' && Tok.find(':') != StringRef::npos)
910910 PrintFatalError(TheDef->getLoc(),
911 "matchable with operand modifier '" + Tok.str() +
912 "' not supported by asm matcher. Mark isCodeGenOnly!");
911 "matchable with operand modifier '" + Tok +
912 "' not supported by asm matcher. Mark isCodeGenOnly!");
913913
914914 // Verify that any operand is only mentioned once.
915915 // We reject aliases and ignore instructions for now.
916916 if (Tok[0] == '$' && !OperandNames.insert(Tok).second) {
917917 if (!Hack)
918918 PrintFatalError(TheDef->getLoc(),
919 "ERROR: matchable with tied operand '" + Tok.str() +
920 "' can never be matched!");
919 "ERROR: matchable with tied operand '" + Tok +
920 "' can never be matched!");
921921 // FIXME: Should reject these. The ARM backend hits this with $lane in a
922922 // bunch of instructions. It is unclear what the right answer is.
923923 DEBUG({
924924 errs() << "warning: '" << TheDef->getName() << "': "
925925 << "ignoring instruction with tied operand '"
926 << Tok.str() << "'\n";
926 << Tok << "'\n";
927927 });
928928 return false;
929929 }
14991499 // Map this token to an operand.
15001500 unsigned Idx;
15011501 if (!Operands.hasOperandNamed(OperandName, Idx))
1502 PrintFatalError(II->TheDef->getLoc(), "error: unable to find operand: '" +
1503 OperandName.str() + "'");
1502 PrintFatalError(II->TheDef->getLoc(),
1503 "error: unable to find operand: '" + OperandName + "'");
15041504
15051505 // If the instruction operand has multiple suboperands, but the parser
15061506 // match class for the asm operand is still the default "ImmAsmOperand",
15721572 return;
15731573 }
15741574
1575 PrintFatalError(II->TheDef->getLoc(), "error: unable to find operand: '" +
1576 OperandName.str() + "'");
1575 PrintFatalError(II->TheDef->getLoc(),
1576 "error: unable to find operand: '" + OperandName + "'");
15771577 }
15781578
15791579 void MatchableInfo::buildInstructionResultOperands() {
546546 Reg.TheDef->getValueAsListOfStrings("AltNames");
547547 if (AltNames.size() <= Idx)
548548 PrintFatalError(Reg.TheDef->getLoc(),
549 (Twine("Register definition missing alt name for '") +
550 AltName + "'.").str());
549 "Register definition missing alt name for '" +
550 AltName + "'.");
551551 AsmName = AltNames[Idx];
552552 }
553553 }
23262326 /* Resolve all types */;
23272327
23282328 if (TPN->ContainsUnresolvedType()) {
2329 PrintFatalError("Value #" + utostr(i) + " of OperandWithDefaultOps '" +
2330 DefaultOps[i]->getName() +"' doesn't have a concrete type!");
2329 PrintFatalError("Value #" + Twine(i) + " of OperandWithDefaultOps '" +
2330 DefaultOps[i]->getName() +
2331 "' doesn't have a concrete type!");
23312332 }
23322333 DefaultOpInfo.DefaultOps.push_back(TPN);
23332334 }
105105
106106 // Check that the operand has a name and that it's unique.
107107 if (ArgName.empty())
108 PrintFatalError("In instruction '" + R->getName() + "', operand #" + utostr(i) +
109 " has no name!");
108 PrintFatalError("In instruction '" + R->getName() + "', operand #" +
109 Twine(i) + " has no name!");
110110 if (!OperandNames.insert(ArgName).second)
111 PrintFatalError("In instruction '" + R->getName() + "', operand #" + utostr(i) +
112 " has the same name as a previous operand!");
111 PrintFatalError("In instruction '" + R->getName() + "', operand #" +
112 Twine(i) + " has the same name as a previous operand!");
113113
114114 OperandList.push_back(OperandInfo(Rec, ArgName, PrintMethod, EncoderMethod,
115115 OperandType, MIOperandNo, NumOps,
132132 unsigned CGIOperandList::getOperandNamed(StringRef Name) const {
133133 unsigned OpIdx;
134134 if (hasOperandNamed(Name, OpIdx)) return OpIdx;
135 PrintFatalError("'" + TheDef->getName() + "' does not have an operand named '$" +
136 Name.str() + "'!");
135 PrintFatalError("'" + TheDef->getName() +
136 "' does not have an operand named '$" + Name + "'!");
137137 }
138138
139139 /// hasOperandNamed - Query whether the instruction has an operand of the
441441 // If the operand is a record, it must have a name, and the record type
442442 // must match up with the instruction's argument type.
443443 if (Result->getArgName(AliasOpNo).empty())
444 PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) +
445 " must have a name!");
444 PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
445 " must have a name!");
446446 ResOp = ResultOperand(Result->getArgName(AliasOpNo), ResultRecord);
447447 return true;
448448 }
513513 return false;
514514 // Integer arguments can't have names.
515515 if (!Result->getArgName(AliasOpNo).empty())
516 PrintFatalError(Loc, "result argument #" + utostr(AliasOpNo) +
516 PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
517517 " must not have a name!");
518518 ResOp = ResultOperand(II->getValue());
519519 return true;
626626 ResultInstOperandIndex.push_back(std::make_pair(i, SubOp));
627627 ++AliasOpNo;
628628 } else {
629 PrintFatalError(R->getLoc(), "result argument #" + utostr(AliasOpNo) +
629 PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) +
630630 " does not match instruction operand class " +
631631 (SubOp == 0 ? InstOpRec->getName() :SubRec->getName()));
632632 }
633633 }
634634 continue;
635635 }
636 PrintFatalError(R->getLoc(), "result argument #" + utostr(AliasOpNo) +
636 PrintFatalError(R->getLoc(), "result argument #" + Twine(AliasOpNo) +
637637 " does not match instruction operand class " +
638638 InstOpRec->getName());
639639 }
992992 // Read in register class definitions.
993993 std::vector RCs = Records.getAllDerivedDefinitions("RegisterClass");
994994 if (RCs.empty())
995 PrintFatalError(std::string("No 'RegisterClass' subclasses defined!"));
995 PrintFatalError("No 'RegisterClass' subclasses defined!");
996996
997997 // Allocate user-defined register classes.
998998 RegClasses.reserve(RCs.size());
172172 Record *CodeGenTarget::getAsmParser() const {
173173 std::vector LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
174174 if (AsmParserNum >= LI.size())
175 PrintFatalError("Target does not have an AsmParser #" + utostr(AsmParserNum) + "!");
175 PrintFatalError("Target does not have an AsmParser #" +
176 Twine(AsmParserNum) + "!");
176177 return LI[AsmParserNum];
177178 }
178179
183184 std::vector LI =
184185 TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
185186 if (i >= LI.size())
186 PrintFatalError("Target does not have an AsmParserVariant #" + utostr(i) + "!");
187 PrintFatalError("Target does not have an AsmParserVariant #" + Twine(i) +
188 "!");
187189 return LI[i];
188190 }
189191
201203 Record *CodeGenTarget::getAsmWriter() const {
202204 std::vector LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
203205 if (AsmWriterNum >= LI.size())
204 PrintFatalError("Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!");
206 PrintFatalError("Target does not have an AsmWriter #" +
207 Twine(AsmWriterNum) + "!");
205208 return LI[AsmWriterNum];
206209 }
207210
284287 DenseMap::const_iterator
285288 I = Insts.find(Rec);
286289 if (Rec == 0 || I == Insts.end())
287 PrintFatalError(std::string("Could not find '") + Name + "' instruction!");
290 PrintFatalError(Twine("Could not find '") + Name + "' instruction!");
288291 return I->second;
289292 }
290293