From ce3d64025b32d10dbaf9c77f5b1b56a09bc88f82 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 28 Jul 2003 03:39:57 +0000 Subject: [PATCH] Allow initializing variable initializers with variables git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7354 91177308-0d34-0410-b5e6-96231b3b80d8 --- support/tools/TableGen/Record.cpp | 9 +++++++++ support/tools/TableGen/Record.h | 3 ++- utils/TableGen/Record.cpp | 9 +++++++++ utils/TableGen/Record.h | 3 ++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index 469faa9b01b..2aabef408dd 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -127,6 +127,15 @@ Init *RecordRecTy::convertValue(DefInit *DI) { return DI; } +Init *RecordRecTy::convertValue(TypedInit *VI) { + // Ensure that VI is compatible with Rec. + if (RecordRecTy *RRT = dynamic_cast(VI->getType())) + if (RRT->getRecord()->isSubClassOf(getRecord()) || + RRT->getRecord() == getRecord()) + return VI; + return 0; +} + //===----------------------------------------------------------------------===// // Initializer implementations //===----------------------------------------------------------------------===// diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index 73b5c741022..72123cb5205 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -136,7 +136,8 @@ public: Record *getRecord() const { return Rec; } Init *convertValue(UnsetInit *UI) { return (Init*)UI; } - Init *convertValue( DefInit *DI); + Init *convertValue( DefInit *DI); + Init *convertValue(TypedInit *VI); void print(std::ostream &OS) const; }; diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 469faa9b01b..2aabef408dd 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -127,6 +127,15 @@ Init *RecordRecTy::convertValue(DefInit *DI) { return DI; } +Init *RecordRecTy::convertValue(TypedInit *VI) { + // Ensure that VI is compatible with Rec. + if (RecordRecTy *RRT = dynamic_cast(VI->getType())) + if (RRT->getRecord()->isSubClassOf(getRecord()) || + RRT->getRecord() == getRecord()) + return VI; + return 0; +} + //===----------------------------------------------------------------------===// // Initializer implementations //===----------------------------------------------------------------------===// diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 73b5c741022..72123cb5205 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -136,7 +136,8 @@ public: Record *getRecord() const { return Rec; } Init *convertValue(UnsetInit *UI) { return (Init*)UI; } - Init *convertValue( DefInit *DI); + Init *convertValue( DefInit *DI); + Init *convertValue(TypedInit *VI); void print(std::ostream &OS) const; };