aboutsummaryrefslogtreecommitdiff
path: root/lib/TableGen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/TableGen')
-rw-r--r--lib/TableGen/Error.cpp2
-rw-r--r--lib/TableGen/Main.cpp21
-rw-r--r--lib/TableGen/Record.cpp11
-rw-r--r--lib/TableGen/SetTheory.cpp22
-rw-r--r--lib/TableGen/TGLexer.cpp4
-rw-r--r--lib/TableGen/TGParser.cpp28
6 files changed, 51 insertions, 37 deletions
diff --git a/lib/TableGen/Error.cpp b/lib/TableGen/Error.cpp
index 7523b32ca0e5..54b063cb4f8d 100644
--- a/lib/TableGen/Error.cpp
+++ b/lib/TableGen/Error.cpp
@@ -39,6 +39,8 @@ static void PrintMessage(ArrayRef<SMLoc> Loc, SourceMgr::DiagKind Kind,
"instantiated from multiclass");
}
+void PrintNote(const Twine &Msg) { WithColor::note() << Msg << "\n"; }
+
void PrintNote(ArrayRef<SMLoc> NoteLoc, const Twine &Msg) {
PrintMessage(NoteLoc, SourceMgr::DK_Note, Msg);
}
diff --git a/lib/TableGen/Main.cpp b/lib/TableGen/Main.cpp
index bcd39584e450..48ded6c45a46 100644
--- a/lib/TableGen/Main.cpp
+++ b/lib/TableGen/Main.cpp
@@ -49,6 +49,9 @@ static cl::list<std::string>
MacroNames("D", cl::desc("Name of the macro to be defined"),
cl::value_desc("macro name"), cl::Prefix);
+static cl::opt<bool>
+WriteIfChanged("write-if-changed", cl::desc("Only write output if it changed"));
+
static int reportError(const char *ProgName, Twine Msg) {
errs() << ProgName << ": " << Msg;
errs().flush();
@@ -64,7 +67,7 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
return reportError(argv0, "the option -d must be used together with -o\n");
std::error_code EC;
- ToolOutputFile DepOut(DependFilename, EC, sys::fs::F_Text);
+ ToolOutputFile DepOut(DependFilename, EC, sys::fs::OF_None);
if (EC)
return reportError(argv0, "error opening " + DependFilename + ":" +
EC.message() + "\n");
@@ -114,15 +117,17 @@ int llvm::TableGenMain(char *argv0, TableGenMainFn *MainFn) {
return Ret;
}
- // Only updates the real output file if there are any differences.
- // This prevents recompilation of all the files depending on it if there
- // aren't any.
- if (auto ExistingOrErr = MemoryBuffer::getFile(OutputFilename))
- if (std::move(ExistingOrErr.get())->getBuffer() == Out.str())
- return 0;
+ if (WriteIfChanged) {
+ // Only updates the real output file if there are any differences.
+ // This prevents recompilation of all the files depending on it if there
+ // aren't any.
+ if (auto ExistingOrErr = MemoryBuffer::getFile(OutputFilename))
+ if (std::move(ExistingOrErr.get())->getBuffer() == Out.str())
+ return 0;
+ }
std::error_code EC;
- ToolOutputFile OutFile(OutputFilename, EC, sys::fs::F_Text);
+ ToolOutputFile OutFile(OutputFilename, EC, sys::fs::OF_None);
if (EC)
return reportError(argv0, "error opening " + OutputFilename + ":" +
EC.message() + "\n");
diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp
index 27d1bdc7f4c3..835ef8c7141b 100644
--- a/lib/TableGen/Record.cpp
+++ b/lib/TableGen/Record.cpp
@@ -438,7 +438,7 @@ Init *BitsInit::resolveReferences(Resolver &R) const {
CachedBitVarRef = CurBitVar->getBitVar();
CachedBitVarResolved = CachedBitVarRef->resolveReferences(R);
}
-
+ assert(CachedBitVarResolved && "Unresolved bitvar reference");
NewBit = CachedBitVarResolved->getBit(CurBitVar->getBitNum());
} else {
// getBit(0) implicitly converts int and bits<1> values to bit.
@@ -1616,7 +1616,7 @@ void VarDefInit::Profile(FoldingSetNodeID &ID) const {
DefInit *VarDefInit::instantiate() {
if (!Def) {
RecordKeeper &Records = Class->getRecords();
- auto NewRecOwner = make_unique<Record>(Records.getNewAnonymousName(),
+ auto NewRecOwner = std::make_unique<Record>(Records.getNewAnonymousName(),
Class->getLoc(), Records,
/*IsAnonymous=*/true);
Record *NewRec = NewRecOwner.get();
@@ -1930,6 +1930,13 @@ void DagInit::Profile(FoldingSetNodeID &ID) const {
ProfileDagInit(ID, Val, ValName, makeArrayRef(getTrailingObjects<Init *>(), NumArgs), makeArrayRef(getTrailingObjects<StringInit *>(), NumArgNames));
}
+Record *DagInit::getOperatorAsDef(ArrayRef<SMLoc> Loc) const {
+ if (DefInit *DefI = dyn_cast<DefInit>(Val))
+ return DefI->getDef();
+ PrintFatalError(Loc, "Expected record as operator");
+ return nullptr;
+}
+
Init *DagInit::resolveReferences(Resolver &R) const {
SmallVector<Init*, 8> NewArgs;
NewArgs.reserve(arg_size());
diff --git a/lib/TableGen/SetTheory.cpp b/lib/TableGen/SetTheory.cpp
index a870e41d58f8..5a30ee98cce9 100644
--- a/lib/TableGen/SetTheory.cpp
+++ b/lib/TableGen/SetTheory.cpp
@@ -255,16 +255,16 @@ void SetTheory::Operator::anchor() {}
void SetTheory::Expander::anchor() {}
SetTheory::SetTheory() {
- addOperator("add", llvm::make_unique<AddOp>());
- addOperator("sub", llvm::make_unique<SubOp>());
- addOperator("and", llvm::make_unique<AndOp>());
- addOperator("shl", llvm::make_unique<ShlOp>());
- addOperator("trunc", llvm::make_unique<TruncOp>());
- addOperator("rotl", llvm::make_unique<RotOp>(false));
- addOperator("rotr", llvm::make_unique<RotOp>(true));
- addOperator("decimate", llvm::make_unique<DecimateOp>());
- addOperator("interleave", llvm::make_unique<InterleaveOp>());
- addOperator("sequence", llvm::make_unique<SequenceOp>());
+ addOperator("add", std::make_unique<AddOp>());
+ addOperator("sub", std::make_unique<SubOp>());
+ addOperator("and", std::make_unique<AndOp>());
+ addOperator("shl", std::make_unique<ShlOp>());
+ addOperator("trunc", std::make_unique<TruncOp>());
+ addOperator("rotl", std::make_unique<RotOp>(false));
+ addOperator("rotr", std::make_unique<RotOp>(true));
+ addOperator("decimate", std::make_unique<DecimateOp>());
+ addOperator("interleave", std::make_unique<InterleaveOp>());
+ addOperator("sequence", std::make_unique<SequenceOp>());
}
void SetTheory::addOperator(StringRef Name, std::unique_ptr<Operator> Op) {
@@ -276,7 +276,7 @@ void SetTheory::addExpander(StringRef ClassName, std::unique_ptr<Expander> E) {
}
void SetTheory::addFieldExpander(StringRef ClassName, StringRef FieldName) {
- addExpander(ClassName, llvm::make_unique<FieldExpander>(FieldName));
+ addExpander(ClassName, std::make_unique<FieldExpander>(FieldName));
}
void SetTheory::evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc) {
diff --git a/lib/TableGen/TGLexer.cpp b/lib/TableGen/TGLexer.cpp
index d28c62b3133d..da2286e41fe5 100644
--- a/lib/TableGen/TGLexer.cpp
+++ b/lib/TableGen/TGLexer.cpp
@@ -51,7 +51,7 @@ TGLexer::TGLexer(SourceMgr &SM, ArrayRef<std::string> Macros) : SrcMgr(SM) {
// Pretend that we enter the "top-level" include file.
PrepIncludeStack.push_back(
- make_unique<std::vector<PreprocessorControlDesc>>());
+ std::make_unique<std::vector<PreprocessorControlDesc>>());
// Put all macros defined in the command line into the DefinedMacros set.
std::for_each(Macros.begin(), Macros.end(),
@@ -393,7 +393,7 @@ bool TGLexer::LexInclude() {
CurPtr = CurBuf.begin();
PrepIncludeStack.push_back(
- make_unique<std::vector<PreprocessorControlDesc>>());
+ std::make_unique<std::vector<PreprocessorControlDesc>>());
return false;
}
diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp
index a9ace152d59e..c373e2899a5d 100644
--- a/lib/TableGen/TGParser.cpp
+++ b/lib/TableGen/TGParser.cpp
@@ -378,7 +378,7 @@ bool TGParser::resolve(const ForeachLoop &Loop, SubstStack &Substs,
auto LI = dyn_cast<ListInit>(List);
if (!LI) {
if (!Final) {
- Dest->emplace_back(make_unique<ForeachLoop>(Loop.Loc, Loop.IterVar,
+ Dest->emplace_back(std::make_unique<ForeachLoop>(Loop.Loc, Loop.IterVar,
List));
return resolve(Loop.Entries, Substs, Final, &Dest->back().Loop->Entries,
Loc);
@@ -413,7 +413,7 @@ bool TGParser::resolve(const std::vector<RecordsEntry> &Source,
if (E.Loop) {
Error = resolve(*E.Loop, Substs, Final, Dest);
} else {
- auto Rec = make_unique<Record>(*E.Rec);
+ auto Rec = std::make_unique<Record>(*E.Rec);
if (Loc)
Rec->appendLoc(*Loc);
@@ -1147,9 +1147,9 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
if (!InitList.back()) return nullptr;
// All BinOps require their arguments to be of compatible types.
- TypedInit *TI = dyn_cast<TypedInit>(InitList.back());
+ RecTy *ListType = cast<TypedInit>(InitList.back())->getType();
if (!ArgType) {
- ArgType = TI->getType();
+ ArgType = ListType;
switch (Code) {
case BinOpInit::LISTCONCAT:
@@ -1198,11 +1198,11 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
default: llvm_unreachable("other ops have fixed argument types");
}
} else {
- RecTy *Resolved = resolveTypes(ArgType, TI->getType());
+ RecTy *Resolved = resolveTypes(ArgType, ListType);
if (!Resolved) {
Error(InitLoc, Twine("expected value of type '") +
- ArgType->getAsString() + "', got '" +
- TI->getType()->getAsString() + "'");
+ ArgType->getAsString() + "', got '" +
+ ListType->getAsString() + "'");
return nullptr;
}
if (Code != BinOpInit::ADD && Code != BinOpInit::AND &&
@@ -1330,7 +1330,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
std::unique_ptr<Record> ParseRecTmp;
Record *ParseRec = CurRec;
if (!ParseRec) {
- ParseRecTmp = make_unique<Record>(".parse", ArrayRef<SMLoc>{}, Records);
+ ParseRecTmp = std::make_unique<Record>(".parse", ArrayRef<SMLoc>{}, Records);
ParseRec = ParseRecTmp.get();
}
@@ -1597,7 +1597,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
std::unique_ptr<Record> ParseRecTmp;
Record *ParseRec = CurRec;
if (!ParseRec) {
- ParseRecTmp = make_unique<Record>(".parse", ArrayRef<SMLoc>{}, Records);
+ ParseRecTmp = std::make_unique<Record>(".parse", ArrayRef<SMLoc>{}, Records);
ParseRec = ParseRecTmp.get();
}
@@ -2702,10 +2702,10 @@ bool TGParser::ParseDef(MultiClass *CurMultiClass) {
return true;
if (isa<UnsetInit>(Name))
- CurRec = make_unique<Record>(Records.getNewAnonymousName(), DefLoc, Records,
+ CurRec = std::make_unique<Record>(Records.getNewAnonymousName(), DefLoc, Records,
/*Anonymous=*/true);
else
- CurRec = make_unique<Record>(Name, DefLoc, Records);
+ CurRec = std::make_unique<Record>(Name, DefLoc, Records);
if (ParseObjectBody(CurRec.get()))
return true;
@@ -2783,7 +2783,7 @@ bool TGParser::ParseForeach(MultiClass *CurMultiClass) {
Lex.Lex(); // Eat the in
// Create a loop object and remember it.
- Loops.push_back(llvm::make_unique<ForeachLoop>(Loc, IterName, ListValue));
+ Loops.push_back(std::make_unique<ForeachLoop>(Loc, IterName, ListValue));
if (Lex.getCode() != tgtok::l_brace) {
// FOREACH Declaration IN Object
@@ -2834,7 +2834,7 @@ bool TGParser::ParseClass() {
} else {
// If this is the first reference to this class, create and add it.
auto NewRec =
- llvm::make_unique<Record>(Lex.getCurStrVal(), Lex.getLoc(), Records,
+ std::make_unique<Record>(Lex.getCurStrVal(), Lex.getLoc(), Records,
/*Class=*/true);
CurRec = NewRec.get();
Records.addClass(std::move(NewRec));
@@ -2963,7 +2963,7 @@ bool TGParser::ParseMultiClass() {
auto Result =
MultiClasses.insert(std::make_pair(Name,
- llvm::make_unique<MultiClass>(Name, Lex.getLoc(),Records)));
+ std::make_unique<MultiClass>(Name, Lex.getLoc(),Records)));
if (!Result.second)
return TokError("multiclass '" + Name + "' already defined");