From 8e9a9774eb12b5242f74b8ac5b20e0a938ec9c53 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 4 Aug 2003 20:44:17 +0000 Subject: [PATCH] add support for DagInit initializers, which represent DAG patterns git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7576 91177308-0d34-0410-b5e6-96231b3b80d8 --- support/tools/TableGen/Record.cpp | 11 +++++++++++ support/tools/TableGen/Record.h | 24 +++++++++++++++++++++++- utils/TableGen/Record.cpp | 11 +++++++++++ utils/TableGen/Record.h | 24 +++++++++++++++++++++++- 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index 616c790f06b..d47b50c502a 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -434,6 +434,17 @@ Init *FieldInit::resolveReferences(Record &R) { } +void DagInit::print(std::ostream &OS) const { + OS << "(" << NodeTypeDef->getName(); + if (Args.size()) { + OS << " " << *Args[0]; + for (unsigned i = 1, e = Args.size(); i != e; ++i) + OS << ", " << *Args[i]; + } + OS << ")"; +} + + //===----------------------------------------------------------------------===// // Other implementations //===----------------------------------------------------------------------===// diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index cb42f035329..8b37dba44b0 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -34,6 +34,7 @@ class StringInit; class CodeInit; class ListInit; class DefInit; +class DagInit; class TypedInit; class VarInit; class FieldInit; @@ -66,6 +67,7 @@ public: // These methods should only be called from subclasses of Init virtual Init *convertValue( CodeInit *CI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } virtual Init *convertValue( TypedInit *TI) { return 0; } virtual Init *convertValue( VarInit *VI) { return convertValue((TypedInit*)VI); @@ -221,7 +223,7 @@ struct CodeRecTy : public RecTy { /// struct DagRecTy : public RecTy { Init *convertValue(UnsetInit *UI) { return (Init*)UI; } - //Init *convertValue( DagInit *CI) { return (Init*)CI; } + Init *convertValue( DagInit *CI) { return (Init*)CI; } Init *convertValue(TypedInit *TI); void print(std::ostream &OS) const { OS << "dag"; } @@ -582,6 +584,26 @@ public: } }; +/// DagInit - (def a, b) - Represent a DAG tree value. DAG inits are required +/// to have Records for their first value, after that, any legal Init is +/// possible. +/// +class DagInit : public Init { + Record *NodeTypeDef; + std::vector Args; +public: + DagInit(Record *D, std::vector &a) : NodeTypeDef(D) { + Args.swap(a); // DESTRUCTIVELY take the arguments + } + + virtual Init *convertInitializerTo(RecTy *Ty) { + return Ty->convertValue(this); + } + + Record *getNodeType() const { return NodeTypeDef; } + + virtual void print(std::ostream &OS) const; +}; //===----------------------------------------------------------------------===// // High-Level Classes diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 616c790f06b..d47b50c502a 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -434,6 +434,17 @@ Init *FieldInit::resolveReferences(Record &R) { } +void DagInit::print(std::ostream &OS) const { + OS << "(" << NodeTypeDef->getName(); + if (Args.size()) { + OS << " " << *Args[0]; + for (unsigned i = 1, e = Args.size(); i != e; ++i) + OS << ", " << *Args[i]; + } + OS << ")"; +} + + //===----------------------------------------------------------------------===// // Other implementations //===----------------------------------------------------------------------===// diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index cb42f035329..8b37dba44b0 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -34,6 +34,7 @@ class StringInit; class CodeInit; class ListInit; class DefInit; +class DagInit; class TypedInit; class VarInit; class FieldInit; @@ -66,6 +67,7 @@ public: // These methods should only be called from subclasses of Init virtual Init *convertValue( CodeInit *CI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( DagInit *DI) { return 0; } virtual Init *convertValue( TypedInit *TI) { return 0; } virtual Init *convertValue( VarInit *VI) { return convertValue((TypedInit*)VI); @@ -221,7 +223,7 @@ struct CodeRecTy : public RecTy { /// struct DagRecTy : public RecTy { Init *convertValue(UnsetInit *UI) { return (Init*)UI; } - //Init *convertValue( DagInit *CI) { return (Init*)CI; } + Init *convertValue( DagInit *CI) { return (Init*)CI; } Init *convertValue(TypedInit *TI); void print(std::ostream &OS) const { OS << "dag"; } @@ -582,6 +584,26 @@ public: } }; +/// DagInit - (def a, b) - Represent a DAG tree value. DAG inits are required +/// to have Records for their first value, after that, any legal Init is +/// possible. +/// +class DagInit : public Init { + Record *NodeTypeDef; + std::vector Args; +public: + DagInit(Record *D, std::vector &a) : NodeTypeDef(D) { + Args.swap(a); // DESTRUCTIVELY take the arguments + } + + virtual Init *convertInitializerTo(RecTy *Ty) { + return Ty->convertValue(this); + } + + Record *getNodeType() const { return NodeTypeDef; } + + virtual void print(std::ostream &OS) const; +}; //===----------------------------------------------------------------------===// // High-Level Classes