Add new getValueAsBitsInit 'high-level' method

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7467 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2003-08-01 04:46:24 +00:00
parent 1d1adea493
commit 6f334ad8f5
6 changed files with 50 additions and 18 deletions

View File

@@ -468,6 +468,23 @@ std::string Record::getValueAsString(const std::string &FieldName) const {
"' does not have a string initializer!";
}
/// getValueAsBitsInit - This method looks up the specified field and returns
/// its value as a BitsInit, throwing an exception if the field does not exist
/// or if the value is not the right type.
///
BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
throw "Record '" + R->getName() + "' does not have a field named '" +
FieldName + "!\n";
if (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue()))
return BI;
throw "Record '" + R->getName() + "', field '" + FieldName +
"' does not have a BitsInit initializer!";
}
void RecordKeeper::dump() const { std::cerr << *this; }