summaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen/Record.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2020-01-17 20:45:01 +0000
committerDimitry Andric <dim@FreeBSD.org>2020-01-17 20:45:01 +0000
commit706b4fc47bbc608932d3b491ae19a3b9cde9497b (patch)
tree4adf86a776049cbf7f69a1929c4babcbbef925eb /llvm/lib/TableGen/Record.cpp
parent7cc9cf2bf09f069cb2dd947ead05d0b54301fb71 (diff)
Notes
Diffstat (limited to 'llvm/lib/TableGen/Record.cpp')
-rw-r--r--llvm/lib/TableGen/Record.cpp57
1 files changed, 54 insertions, 3 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 835ef8c7141b..9db842dc678e 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -788,6 +788,21 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
if (StringInit *LHSs = dyn_cast<StringInit>(LHS))
return IntInit::get(LHSs->getValue().empty());
break;
+
+ case GETOP:
+ if (DagInit *Dag = dyn_cast<DagInit>(LHS)) {
+ DefInit *DI = DefInit::get(Dag->getOperatorAsDef({}));
+ if (!DI->getType()->typeIsA(getType())) {
+ PrintFatalError(CurRec->getLoc(),
+ Twine("Expected type '") +
+ getType()->getAsString() + "', got '" +
+ DI->getType()->getAsString() + "' in: " +
+ getAsString() + "\n");
+ } else {
+ return DI;
+ }
+ }
+ break;
}
return const_cast<UnOpInit *>(this);
}
@@ -809,6 +824,7 @@ std::string UnOpInit::getAsString() const {
case TAIL: Result = "!tail"; break;
case SIZE: Result = "!size"; break;
case EMPTY: Result = "!empty"; break;
+ case GETOP: Result = "!getop"; break;
}
return Result + "(" + LHS->getAsString() + ")";
}
@@ -887,13 +903,18 @@ Init *BinOpInit::Fold(Record *CurRec) const {
if (LHSs && RHSs) {
DefInit *LOp = dyn_cast<DefInit>(LHSs->getOperator());
DefInit *ROp = dyn_cast<DefInit>(RHSs->getOperator());
- if (!LOp || !ROp)
+ if ((!LOp && !isa<UnsetInit>(LHSs->getOperator())) ||
+ (!ROp && !isa<UnsetInit>(RHSs->getOperator())))
break;
- if (LOp->getDef() != ROp->getDef()) {
+ if (LOp && ROp && LOp->getDef() != ROp->getDef()) {
PrintFatalError(Twine("Concatenated Dag operators do not match: '") +
LHSs->getAsString() + "' vs. '" + RHSs->getAsString() +
"'");
}
+ Init *Op = LOp ? LOp : ROp;
+ if (!Op)
+ Op = UnsetInit::get();
+
SmallVector<Init*, 8> Args;
SmallVector<StringInit*, 8> ArgNames;
for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
@@ -904,7 +925,7 @@ Init *BinOpInit::Fold(Record *CurRec) const {
Args.push_back(RHSs->getArg(i));
ArgNames.push_back(RHSs->getArgName(i));
}
- return DagInit::get(LHSs->getOperator(), nullptr, Args, ArgNames);
+ return DagInit::get(Op, nullptr, Args, ArgNames);
}
break;
}
@@ -975,6 +996,20 @@ Init *BinOpInit::Fold(Record *CurRec) const {
break;
}
+ case SETOP: {
+ DagInit *Dag = dyn_cast<DagInit>(LHS);
+ DefInit *Op = dyn_cast<DefInit>(RHS);
+ if (Dag && Op) {
+ SmallVector<Init*, 8> Args;
+ SmallVector<StringInit*, 8> ArgNames;
+ for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) {
+ Args.push_back(Dag->getArg(i));
+ ArgNames.push_back(Dag->getArgName(i));
+ }
+ return DagInit::get(Op, nullptr, Args, ArgNames);
+ }
+ break;
+ }
case ADD:
case MUL:
case AND:
@@ -1037,6 +1072,7 @@ std::string BinOpInit::getAsString() const {
case LISTCONCAT: Result = "!listconcat"; break;
case LISTSPLAT: Result = "!listsplat"; break;
case STRCONCAT: Result = "!strconcat"; break;
+ case SETOP: Result = "!setop"; break;
}
return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
@@ -2277,6 +2313,21 @@ Record *Record::getValueAsDef(StringRef FieldName) const {
FieldName + "' does not have a def initializer!");
}
+Record *Record::getValueAsOptionalDef(StringRef FieldName) const {
+ const RecordVal *R = getValue(FieldName);
+ if (!R || !R->getValue())
+ PrintFatalError(getLoc(), "Record `" + getName() +
+ "' does not have a field named `" + FieldName + "'!\n");
+
+ if (DefInit *DI = dyn_cast<DefInit>(R->getValue()))
+ return DI->getDef();
+ if (isa<UnsetInit>(R->getValue()))
+ return nullptr;
+ PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
+ FieldName + "' does not have either a def initializer or '?'!");
+}
+
+
bool Record::getValueAsBit(StringRef FieldName) const {
const RecordVal *R = getValue(FieldName);
if (!R || !R->getValue())