1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Add a new Record::getValueAsCode method to mirror the other getValueAs*

methods.  Use it to simplify some code.

llvm-svn: 23336
This commit is contained in:
Chris Lattner 2005-09-13 21:44:28 +00:00
parent 4e59482982
commit 0dd99c9aaf
3 changed files with 20 additions and 11 deletions

View File

@ -154,17 +154,8 @@ CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) {
SpillAlignment = R->getValueAsInt("Alignment");
VT = getValueType(R->getValueAsDef("RegType"));
if (CodeInit *CI = dynamic_cast<CodeInit*>(R->getValueInit("MethodBodies")))
MethodBodies = CI->getValue();
else
throw "Expected 'code' fragment for 'MethodBodies' value in register "
"class '" + getName() + "'!";
if (CodeInit *CI = dynamic_cast<CodeInit*>(R->getValueInit("MethodProtos")))
MethodProtos = CI->getValue();
else
throw "Expected 'code' fragment for 'MethodProtos' value in register "
"class '" + getName() + "'!";
MethodBodies = R->getValueAsCode("MethodBodies");
MethodProtos = R->getValueAsCode("MethodProtos");
ListInit *RegList = R->getValueAsListInit("MemberList");
for (unsigned i = 0, e = RegList->getSize(); i != e; ++i) {

View File

@ -773,6 +773,18 @@ DagInit *Record::getValueAsDag(const std::string &FieldName) const {
"' does not have a dag initializer!";
}
std::string Record::getValueAsCode(const std::string &FieldName) const {
const RecordVal *R = getValue(FieldName);
if (R == 0 || R->getValue() == 0)
throw "Record `" + getName() + "' does not have a field named `" +
FieldName + "'!\n";
if (const CodeInit *CI = dynamic_cast<const CodeInit*>(R->getValue()))
return CI->getValue();
throw "Record `" + getName() + "', field `" + FieldName +
"' does not have a code initializer!";
}
void RecordKeeper::dump() const { std::cerr << *this; }

View File

@ -1023,6 +1023,12 @@ public:
/// the value is not the right type.
///
DagInit *getValueAsDag(const std::string &FieldName) const;
/// getValueAsCode - This method looks up the specified field and returns
/// its value as the string data in a CodeInit, throwing an exception if the
/// field does not exist or if the value is not a code object.
///
std::string getValueAsCode(const std::string &FieldName) const;
};
std::ostream &operator<<(std::ostream &OS, const Record &R);