From 7cf0ce4b8d122575c3348b5fa4947014c3d8432d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 3 Aug 2003 18:17:22 +0000 Subject: Changes to allow lists of any type git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7519 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/Record.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'utils/TableGen/Record.cpp') diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 309f386e78..ef7d9a044a 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -16,6 +16,10 @@ Init *BitRecTy::convertValue(BitsInit *BI) { return BI->getBit(0); } +bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const { + return RHS->getNumBits() == 1; +} + Init *BitRecTy::convertValue(IntInit *II) { int Val = II->getValue(); if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit! @@ -104,22 +108,27 @@ Init *StringRecTy::convertValue(TypedInit *TI) { } void ListRecTy::print(std::ostream &OS) const { - OS << "list<" << Class->getName() << ">"; + OS << "list<" << *Ty << ">"; } Init *ListRecTy::convertValue(ListInit *LI) { + std::vector Elements; + // Verify that all of the elements of the list are subclasses of the - // appopriate class! + // appropriate class! for (unsigned i = 0, e = LI->getSize(); i != e; ++i) - if (!LI->getElement(i)->isSubClassOf(Class)) + if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty)) + Elements.push_back(CI); + else return 0; - return LI; + + return new ListInit(Elements); } Init *ListRecTy::convertValue(TypedInit *TI) { // Ensure that TI is compatible with our class. if (ListRecTy *LRT = dynamic_cast(TI->getType())) - if (LRT->getElementClass() == getElementClass()) + if (LRT->getElementType()->typeIsConvertibleTo(getElementType())) return TI; return 0; } @@ -144,6 +153,11 @@ Init *RecordRecTy::convertValue(TypedInit *TI) { return 0; } +bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const { + return Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec); +} + + //===----------------------------------------------------------------------===// // Initializer implementations //===----------------------------------------------------------------------===// @@ -263,9 +277,9 @@ Init *IntInit::convertInitializerBitRange(const std::vector &Bits) { void ListInit::print(std::ostream &OS) const { OS << "["; - for (unsigned i = 0, e = Records.size(); i != e; ++i) { + for (unsigned i = 0, e = Values.size(); i != e; ++i) { if (i) OS << ", "; - OS << Records[i]->getName(); + OS << *Values[i]; } OS << "]"; } -- cgit v1.2.3