diff options
author | Chris Lattner <sabre@nondot.org> | 2002-12-02 16:42:52 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-12-02 16:42:52 +0000 |
commit | a1651900e1772b05afd2280308e9acc5a58cefb8 (patch) | |
tree | ba05520b00d5f899bcb8d3836113bc7b94712a1f /utils/TableGen | |
parent | d00e8f1f838b9348919b15b7cf9e4fe0ab523051 (diff) | |
download | external_llvm-a1651900e1772b05afd2280308e9acc5a58cefb8.zip external_llvm-a1651900e1772b05afd2280308e9acc5a58cefb8.tar.gz external_llvm-a1651900e1772b05afd2280308e9acc5a58cefb8.tar.bz2 |
Initial support for Field Expressions
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4848 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/Record.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 0d50688..9b3fb2d 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -20,6 +20,7 @@ class ListInit; class VarInit; class VarBitInit; class DefInit; +class FieldInit; class Record; //===----------------------------------------------------------------------===// @@ -38,6 +39,7 @@ struct RecTy { virtual Init *convertValue( VarInit *VI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } + virtual Init *convertValue( FieldInit *FI) { return 0; } virtual void print(std::ostream &OS) const = 0; void dump() const; @@ -122,6 +124,8 @@ class RecordRecTy : public RecTy { public: RecordRecTy(Record *R) : Rec(R) {} + Record *getRecord() const { return Rec; } + Init *convertValue(UnsetInit *UI) { return (Init*)UI; } Init *convertValue( DefInit *DI); @@ -146,6 +150,12 @@ struct Init { return 0; } + /// getFieldType - This method is used to implement the FieldInit class. + /// Implementors of this method should return the type of the named field if + /// they are of record type. + /// + virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; } + virtual Init *resolveReferences(Record &R) { return this; } }; @@ -297,6 +307,8 @@ public: RecTy *getType() const { return Ty; } virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); + + virtual RecTy *getFieldType(const std::string &FieldName) const; virtual bool isComplete() const { return true; } virtual void print(std::ostream &OS) const { OS << VarName; } @@ -346,6 +358,28 @@ public: }; +/// FieldInit - X.Y - Represent a reference to a subfield of a variable +/// +class FieldInit : public Init { + Init *Rec; // Record we are referring to + std::string FieldName; // Field we are accessing + RecTy *Ty; // The type of this expression +public: + FieldInit(Init *R, const std::string &FN) + : Rec(R), FieldName(FN), Ty(R->getFieldType(FN)) { + assert(Ty && "FieldInit with non-record type!"); + } + + virtual Init *convertInitializerTo(RecTy *Ty) { + return Ty->convertValue(this); + } + + virtual bool isComplete() const { return true; } + virtual void print(std::ostream &OS) const { + Rec->print(OS); OS << "." << FieldName; + } +}; + //===----------------------------------------------------------------------===// // High-Level Classes |