[llvm-commits] CVS: llvm/utils/TableGen/Record.h Record.cpp CodeGenTarget.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Sep 13 14:44:39 PDT 2005



Changes in directory llvm/utils/TableGen:

Record.h updated: 1.51 -> 1.52
Record.cpp updated: 1.44 -> 1.45
CodeGenTarget.cpp updated: 1.36 -> 1.37
---
Log message:

Add a new Record::getValueAsCode method to mirror the other getValueAs*
methods.  Use it to simplify some code.


---
Diffs of the changes:  (+20 -11)

 CodeGenTarget.cpp |   13 ++-----------
 Record.cpp        |   12 ++++++++++++
 Record.h          |    6 ++++++
 3 files changed, 20 insertions(+), 11 deletions(-)


Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.51 llvm/utils/TableGen/Record.h:1.52
--- llvm/utils/TableGen/Record.h:1.51	Fri Aug 19 12:58:49 2005
+++ llvm/utils/TableGen/Record.h	Tue Sep 13 16:44:28 2005
@@ -1023,6 +1023,12 @@
   /// 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);


Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.44 llvm/utils/TableGen/Record.cpp:1.45
--- llvm/utils/TableGen/Record.cpp:1.44	Fri Aug 19 12:58:11 2005
+++ llvm/utils/TableGen/Record.cpp	Tue Sep 13 16:44:28 2005
@@ -773,6 +773,18 @@
         "' 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; }
 


Index: llvm/utils/TableGen/CodeGenTarget.cpp
diff -u llvm/utils/TableGen/CodeGenTarget.cpp:1.36 llvm/utils/TableGen/CodeGenTarget.cpp:1.37
--- llvm/utils/TableGen/CodeGenTarget.cpp:1.36	Thu Sep  8 16:43:21 2005
+++ llvm/utils/TableGen/CodeGenTarget.cpp	Tue Sep 13 16:44:28 2005
@@ -154,17 +154,8 @@
   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) {






More information about the llvm-commits mailing list