[TableGen] Use getValueInit
to reduce code duplication (NFC) (#153167)
This commit is contained in:
parent
89ea9df6a2
commit
c69355e7d1
@ -3064,11 +3064,11 @@ const Init *Record::getValueInit(StringRef FieldName) const {
|
||||
}
|
||||
|
||||
StringRef Record::getValueAsString(StringRef FieldName) const {
|
||||
std::optional<StringRef> S = getValueAsOptionalString(FieldName);
|
||||
if (!S)
|
||||
PrintFatalError(getLoc(), "Record `" + getName() +
|
||||
"' does not have a field named `" + FieldName + "'!\n");
|
||||
return *S;
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *SI = dyn_cast<StringInit>(I))
|
||||
return SI->getValue();
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName +
|
||||
"' exists but does not have a string value");
|
||||
}
|
||||
|
||||
std::optional<StringRef>
|
||||
@ -3088,24 +3088,16 @@ Record::getValueAsOptionalString(StringRef FieldName) const {
|
||||
}
|
||||
|
||||
const BitsInit *Record::getValueAsBitsInit(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 (const auto *BI = dyn_cast<BitsInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *BI = dyn_cast<BitsInit>(I))
|
||||
return BI;
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName +
|
||||
"' exists but does not have a bits value");
|
||||
}
|
||||
|
||||
const ListInit *Record::getValueAsListInit(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 (const auto *LI = dyn_cast<ListInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *LI = dyn_cast<ListInit>(I))
|
||||
return LI;
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" + FieldName +
|
||||
"' exists but does not have a list value");
|
||||
@ -3127,17 +3119,13 @@ Record::getValueAsListOfDefs(StringRef FieldName) const {
|
||||
}
|
||||
|
||||
int64_t Record::getValueAsInt(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 (const auto *II = dyn_cast<IntInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *II = dyn_cast<IntInit>(I))
|
||||
return II->getValue();
|
||||
PrintFatalError(getLoc(), Twine("Record `") + getName() + "', field `" +
|
||||
FieldName +
|
||||
"' exists but does not have an int value: " +
|
||||
R->getValue()->getAsString());
|
||||
PrintFatalError(
|
||||
getLoc(),
|
||||
Twine("Record `") + getName() + "', field `" + FieldName +
|
||||
"' exists but does not have an int value: " + I->getAsString());
|
||||
}
|
||||
|
||||
std::vector<int64_t>
|
||||
@ -3173,67 +3161,47 @@ Record::getValueAsListOfStrings(StringRef FieldName) const {
|
||||
}
|
||||
|
||||
const Record *Record::getValueAsDef(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 (const auto *DI = dyn_cast<DefInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *DI = dyn_cast<DefInit>(I))
|
||||
return DI->getDef();
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
|
||||
FieldName + "' does not have a def initializer!");
|
||||
}
|
||||
|
||||
const 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 (const auto *DI = dyn_cast<DefInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *DI = dyn_cast<DefInit>(I))
|
||||
return DI->getDef();
|
||||
if (isa<UnsetInit>(R->getValue()))
|
||||
if (isa<UnsetInit>(I))
|
||||
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())
|
||||
PrintFatalError(getLoc(), "Record `" + getName() +
|
||||
"' does not have a field named `" + FieldName + "'!\n");
|
||||
|
||||
if (const auto *BI = dyn_cast<BitInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *BI = dyn_cast<BitInit>(I))
|
||||
return BI->getValue();
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
|
||||
FieldName + "' does not have a bit initializer!");
|
||||
}
|
||||
|
||||
bool Record::getValueAsBitOrUnset(StringRef FieldName, bool &Unset) const {
|
||||
const RecordVal *R = getValue(FieldName);
|
||||
if (!R || !R->getValue())
|
||||
PrintFatalError(getLoc(), "Record `" + getName() +
|
||||
"' does not have a field named `" + FieldName.str() + "'!\n");
|
||||
|
||||
if (isa<UnsetInit>(R->getValue())) {
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (isa<UnsetInit>(I)) {
|
||||
Unset = true;
|
||||
return false;
|
||||
}
|
||||
Unset = false;
|
||||
if (const auto *BI = dyn_cast<BitInit>(R->getValue()))
|
||||
if (const auto *BI = dyn_cast<BitInit>(I))
|
||||
return BI->getValue();
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
|
||||
FieldName + "' does not have a bit initializer!");
|
||||
}
|
||||
|
||||
const DagInit *Record::getValueAsDag(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 (const auto *DI = dyn_cast<DagInit>(R->getValue()))
|
||||
const Init *I = getValueInit(FieldName);
|
||||
if (const auto *DI = dyn_cast<DagInit>(I))
|
||||
return DI;
|
||||
PrintFatalError(getLoc(), "Record `" + getName() + "', field `" +
|
||||
FieldName + "' does not have a dag initializer!");
|
||||
|
Loading…
x
Reference in New Issue
Block a user