From fd306bfdd294772560b3a1cf762bc1081f66e6ba Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Fri, 28 Oct 2005 21:46:31 +0000 Subject: [PATCH] Added method to return a vector of records for a ListInit of Def field. This simplifies using list of records. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24069 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/Record.cpp | 19 +++++++++++++++++++ utils/TableGen/Record.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index c5f05657499..109ed392513 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -709,6 +709,25 @@ ListInit *Record::getValueAsListInit(const std::string &FieldName) const { "' does not have a list initializer!"; } +/// getValueAsListDef - This method looks up the specified field and returns +/// its value as a vector of records, throwing an exception if the field does +/// not exist or if the value is not the right type. +/// +std::vector Record::getValueAsListDef(const std::string &FieldName) + const { + ListInit *List = getValueAsListInit(FieldName); + std::vector Defs; + for (unsigned i = 0; i < List->getSize(); i++) { + if (DefInit *DI = dynamic_cast(List->getElement(i))) { + Defs.push_back(DI->getDef()); + } else { + throw "Record `" + getName() + "', field `" + FieldName + + "' list is not entirely DefInit!"; + } + } + return Defs; +} + /// getValueAsInt - This method looks up the specified field and returns its /// value as an int, throwing an exception if the field does not exist or if /// the value is not the right type. diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index edd875afcec..ecd6d7020a8 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -1000,6 +1000,12 @@ public: /// ListInit *getValueAsListInit(const std::string &FieldName) const; + /// getValueAsListDef - This method looks up the specified field and returns + /// its value as a vector of records, throwing an exception if the field does + /// not exist or if the value is not the right type. + /// + std::vector getValueAsListDef(const std::string &FieldName) const; + /// getValueAsDef - This method looks up the specified field and returns its /// value as a Record, throwing an exception if the field does not exist or if /// the value is not the right type.