diff options
author | David Greene <greened@obbligato.org> | 2009-05-14 20:54:48 +0000 |
---|---|---|
committer | David Greene <greened@obbligato.org> | 2009-05-14 20:54:48 +0000 |
commit | d418c1b768b5ff26afe05a5ce84d920bbbc99583 (patch) | |
tree | a353f9555d0b125cbeaed9fc9d727545061e65a0 /utils/TableGen/Record.h | |
parent | ccf85ded583167cbdbc20043e698eda8a7c2ed7d (diff) | |
download | external_llvm-d418c1b768b5ff26afe05a5ce84d920bbbc99583.zip external_llvm-d418c1b768b5ff26afe05a5ce84d920bbbc99583.tar.gz external_llvm-d418c1b768b5ff26afe05a5ce84d920bbbc99583.tar.bz2 |
Operation Enhancements
Create an OpInit class to serve as a base for all operation Inits.
Move parsing of operation constructs to separate functions and reference
from multiple places.
Add some commented out new operations. Coming soon.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71789 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.h')
-rw-r--r-- | utils/TableGen/Record.h | 165 |
1 files changed, 154 insertions, 11 deletions
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index f76de7d..b0b4ac1 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -41,7 +41,9 @@ class IntInit; class StringInit; class CodeInit; class ListInit; + //class UnOpInit; class BinOpInit; + //class TernOpInit; class DefInit; class DagInit; class TypedInit; @@ -77,9 +79,15 @@ public: // These methods should only be called from subclasses of Init virtual Init *convertValue( IntInit *II) { return 0; } virtual Init *convertValue(StringInit *SI) { return 0; } virtual Init *convertValue( ListInit *LI) { return 0; } +// virtual Init *convertValue( UnOpInit *UI) { +// return convertValue((TypedInit*)UI); +// } virtual Init *convertValue( BinOpInit *UI) { return convertValue((TypedInit*)UI); } +// virtual Init *convertValue( TernOpInit *UI) { +// return convertValue((TypedInit*)UI); +// } virtual Init *convertValue( CodeInit *CI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } @@ -125,7 +133,9 @@ public: virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; } virtual Init *convertValue( DefInit *DI) { return 0; } virtual Init *convertValue( DagInit *DI) { return 0; } + // virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + //virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( TypedInit *TI); virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} @@ -167,7 +177,9 @@ public: virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } virtual Init *convertValue( DagInit *DI) { return 0; } + //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + //virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( TypedInit *TI); virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} @@ -205,7 +217,9 @@ public: virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } virtual Init *convertValue( DagInit *DI) { return 0; } + //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + //virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( TypedInit *TI); virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} @@ -237,7 +251,10 @@ public: virtual Init *convertValue( IntInit *II) { return 0; } virtual Init *convertValue(StringInit *SI) { return (Init*)SI; } virtual Init *convertValue( ListInit *LI) { return 0; } + //virtual Init *convertValue( UnOpInit *BO); virtual Init *convertValue( BinOpInit *BO); + //virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} + virtual Init *convertValue( CodeInit *CI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } @@ -284,7 +301,9 @@ public: virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } virtual Init *convertValue( DagInit *DI) { return 0; } + //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + //virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( TypedInit *TI); virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} @@ -321,7 +340,9 @@ public: virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } virtual Init *convertValue( DagInit *DI) { return 0; } + //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + //virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( TypedInit *TI); virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} @@ -354,7 +375,9 @@ public: virtual Init *convertValue( CodeInit *CI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } virtual Init *convertValue( DefInit *DI) { return 0; } + //virtual Init *convertValue( UnOpInit *BO); virtual Init *convertValue( BinOpInit *BO); + //virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} virtual Init *convertValue( DagInit *CI) { return (Init*)CI; } virtual Init *convertValue( TypedInit *TI); virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} @@ -395,7 +418,9 @@ public: virtual Init *convertValue( ListInit *LI) { return 0; } virtual Init *convertValue( CodeInit *CI) { return 0; } virtual Init *convertValue(VarBitInit *VB) { return 0; } + //virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} + //virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} virtual Init *convertValue( DefInit *DI); virtual Init *convertValue( DagInit *DI) { return 0; } virtual Init *convertValue( TypedInit *VI); @@ -686,10 +711,73 @@ public: unsigned Elt) = 0; }; +/// OpInit - Base class for operators +/// +class OpInit : public TypedInit { +public: + OpInit(RecTy *Type) : TypedInit(Type) {} + + // Clone - Clone this operator, replacing arguments with the new list + virtual OpInit *clone(std::vector<Init *> &Operands) = 0; + + virtual int getNumOperands(void) const = 0; + virtual Init *getOperand(int i) = 0; + + // Fold - If possible, fold this to a simpler init. Return this if not + // possible to fold. + virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0; + + virtual Init *convertInitializerTo(RecTy *Ty) { + return Ty->convertValue(this); + } + + virtual Init *resolveBitReference(Record &R, const RecordVal *RV, + unsigned Bit); + virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, + unsigned Elt); +}; + + +/// UnOpInit - !op (X) - Transform an init. +/// +// class UnOpInit : public OpInit { +// public: +// enum UnaryOp { CAST }; +// private: +// UnaryOp Opc; +// Init *LHS; +// public: +// UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) : +// OpInit(Type), Opc(opc), LHS(lhs) { +// } + +// // Clone - Clone this operator, replacing arguments with the new list +// virtual OpInit *clone(std::vector<Init *> &Operands) { +// assert(Operands.size() == 1 && "Wrong number of operands for unary operation"); +// return new UnOpInit(getOpcode(), *Operands.begin(), getType()); +// } + +// int getNumOperands(void) const { return 1; } +// Init *getOperand(int i) { +// assert(i == 0 && "Invalid operand id for unary operator"); +// return getOperand(); +// } + +// UnaryOp getOpcode() const { return Opc; } +// Init *getOperand() const { return LHS; } + +// // Fold - If possible, fold this to a simpler init. Return this if not +// // possible to fold. +// Init *Fold(Record *CurRec, MultiClass *CurMultiClass); + +// virtual Init *resolveReferences(Record &R, const RecordVal *RV); + +// virtual std::string getAsString() const; +// }; /// BinOpInit - !op (X, Y) - Combine two inits. /// -class BinOpInit : public TypedInit { +class BinOpInit : public OpInit { public: enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT }; private: @@ -697,9 +785,26 @@ private: Init *LHS, *RHS; public: BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) : - TypedInit(Type), Opc(opc), LHS(lhs), RHS(rhs) { + OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) { } + // Clone - Clone this operator, replacing arguments with the new list + virtual OpInit *clone(std::vector<Init *> &Operands) { + assert(Operands.size() == 2 && "Wrong number of operands for binary operation"); + return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType()); + } + + int getNumOperands(void) const { return 2; } + Init *getOperand(int i) { + assert(i == 0 || i == 1 && "Invalid operand id for binary operator"); + if (i == 0) { + return getLHS(); + } + else { + return getRHS(); + } + } + BinaryOp getOpcode() const { return Opc; } Init *getLHS() const { return LHS; } Init *getRHS() const { return RHS; } @@ -708,20 +813,58 @@ public: // possible to fold. Init *Fold(Record *CurRec, MultiClass *CurMultiClass); - virtual Init *convertInitializerTo(RecTy *Ty) { - return Ty->convertValue(this); - } - - virtual Init *resolveBitReference(Record &R, const RecordVal *RV, - unsigned Bit); - virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, - unsigned Elt); - virtual Init *resolveReferences(Record &R, const RecordVal *RV); virtual std::string getAsString() const; }; +/// TernOpInit - !op (X, Y, Z) - Combine two inits. +/// +// class TernOpInit : public OpInit { +// public: +// enum TernaryOp { SUBST, FOREACH }; +// private: +// TernaryOp Opc; +// Init *LHS, *MHS, *RHS; +// public: +// TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) : +// OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) { +// } + +// // Clone - Clone this operator, replacing arguments with the new list +// virtual OpInit *clone(std::vector<Init *> &Operands) { +// assert(Operands.size() == 3 && "Wrong number of operands for ternary operation"); +// return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2], getType()); +// } + +// int getNumOperands(void) const { return 3; } +// Init *getOperand(int i) { +// assert(i == 0 || i == 1 || i == 2 && "Invalid operand id for ternary operator"); +// if (i == 0) { +// return getLHS(); +// } +// else if (i == 1) { +// return getMHS(); +// } +// else { +// return getRHS(); +// } +// } + +// TernaryOp getOpcode() const { return Opc; } +// Init *getLHS() const { return LHS; } +// Init *getMHS() const { return MHS; } +// Init *getRHS() const { return RHS; } + +// // Fold - If possible, fold this to a simpler init. Return this if not +// // possible to fold. +// Init *Fold(Record *CurRec, MultiClass *CurMultiClass); + +// virtual Init *resolveReferences(Record &R, const RecordVal *RV); + +// virtual std::string getAsString() const; +// }; + /// VarInit - 'Opcode' - Represent a reference to an entire variable object. /// |