Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1 | //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===// |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | d303203 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 8adcd9f | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | d303203 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file defines the main TableGen data structures, including the TableGen |
| 11 | // types, values, and high-level data structures. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef RECORD_H |
| 16 | #define RECORD_H |
| 17 | |
Chris Lattner | 1b30e1ac | 2009-06-21 03:36:54 +0000 | [diff] [blame] | 18 | #include "llvm/Support/SourceMgr.h" |
Michael J. Spencer | ab425d8 | 2010-11-29 18:47:54 +0000 | [diff] [blame] | 19 | #include "llvm/Support/DataTypes.h" |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 21 | #include <map> |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 22 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 23 | namespace llvm { |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 24 | class raw_ostream; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 25 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 26 | // RecTy subclasses. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 27 | class BitRecTy; |
| 28 | class BitsRecTy; |
| 29 | class IntRecTy; |
| 30 | class StringRecTy; |
| 31 | class ListRecTy; |
| 32 | class CodeRecTy; |
| 33 | class DagRecTy; |
| 34 | class RecordRecTy; |
| 35 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 36 | // Init subclasses. |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 37 | struct Init; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 38 | class UnsetInit; |
| 39 | class BitInit; |
| 40 | class BitsInit; |
| 41 | class IntInit; |
| 42 | class StringInit; |
| 43 | class CodeInit; |
| 44 | class ListInit; |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 45 | class UnOpInit; |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 46 | class BinOpInit; |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 47 | class TernOpInit; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 48 | class DefInit; |
| 49 | class DagInit; |
| 50 | class TypedInit; |
| 51 | class VarInit; |
| 52 | class FieldInit; |
| 53 | class VarBitInit; |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 54 | class VarListElementInit; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 55 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 56 | // Other classes. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 57 | class Record; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 58 | class RecordVal; |
Bob Wilson | 56d86254 | 2009-04-30 17:35:11 +0000 | [diff] [blame] | 59 | struct MultiClass; |
Chris Lattner | 77d369c | 2010-12-13 00:23:57 +0000 | [diff] [blame^] | 60 | class RecordKeeper; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 61 | |
| 62 | //===----------------------------------------------------------------------===// |
| 63 | // Type Classes |
| 64 | //===----------------------------------------------------------------------===// |
| 65 | |
| 66 | struct RecTy { |
| 67 | virtual ~RecTy() {} |
| 68 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 69 | virtual std::string getAsString() const = 0; |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 70 | void print(raw_ostream &OS) const { OS << getAsString(); } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 71 | void dump() const; |
| 72 | |
| 73 | /// typeIsConvertibleTo - Return true if all values of 'this' type can be |
| 74 | /// converted to the specified type. |
| 75 | virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0; |
| 76 | |
| 77 | public: // These methods should only be called from subclasses of Init |
| 78 | virtual Init *convertValue( UnsetInit *UI) { return 0; } |
| 79 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 80 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 81 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 82 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 83 | virtual Init *convertValue( ListInit *LI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 84 | virtual Init *convertValue( UnOpInit *UI) { |
| 85 | return convertValue((TypedInit*)UI); |
| 86 | } |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 87 | virtual Init *convertValue( BinOpInit *UI) { |
| 88 | return convertValue((TypedInit*)UI); |
| 89 | } |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 90 | virtual Init *convertValue( TernOpInit *UI) { |
| 91 | return convertValue((TypedInit*)UI); |
| 92 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 93 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 94 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 95 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 96 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 97 | virtual Init *convertValue( TypedInit *TI) { return 0; } |
| 98 | virtual Init *convertValue( VarInit *VI) { |
| 99 | return convertValue((TypedInit*)VI); |
| 100 | } |
| 101 | virtual Init *convertValue( FieldInit *FI) { |
| 102 | return convertValue((TypedInit*)FI); |
| 103 | } |
| 104 | |
| 105 | public: // These methods should only be called by subclasses of RecTy. |
| 106 | // baseClassOf - These virtual methods should be overloaded to return true iff |
| 107 | // all values of type 'RHS' can be converted to the 'this' type. |
| 108 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 109 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 110 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 111 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 112 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 113 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 114 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 115 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 116 | }; |
| 117 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 118 | inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 119 | Ty.print(OS); |
| 120 | return OS; |
| 121 | } |
| 122 | |
| 123 | |
| 124 | /// BitRecTy - 'bit' - Represent a single bit |
| 125 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 126 | class BitRecTy : public RecTy { |
| 127 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 128 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 129 | virtual Init *convertValue( BitInit *BI) { return (Init*)BI; } |
| 130 | virtual Init *convertValue( BitsInit *BI); |
| 131 | virtual Init *convertValue( IntInit *II); |
| 132 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 133 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 134 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 135 | virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; } |
| 136 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 137 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 138 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 139 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 140 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 141 | virtual Init *convertValue( TypedInit *TI); |
| 142 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 143 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 144 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 145 | std::string getAsString() const { return "bit"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 146 | |
| 147 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 148 | return RHS->baseClassOf(this); |
| 149 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 150 | virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } |
| 151 | virtual bool baseClassOf(const BitsRecTy *RHS) const; |
| 152 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 153 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 154 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 155 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 156 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 157 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 158 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 162 | // BitsRecTy - 'bits<n>' - Represent a fixed number of bits |
| 163 | /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 164 | /// |
| 165 | class BitsRecTy : public RecTy { |
| 166 | unsigned Size; |
| 167 | public: |
Dan Gohman | 56e3f63 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 168 | explicit BitsRecTy(unsigned Sz) : Size(Sz) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 169 | |
| 170 | unsigned getNumBits() const { return Size; } |
| 171 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 172 | virtual Init *convertValue( UnsetInit *UI); |
| 173 | virtual Init *convertValue( BitInit *UI); |
| 174 | virtual Init *convertValue( BitsInit *BI); |
| 175 | virtual Init *convertValue( IntInit *II); |
| 176 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 177 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 178 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 179 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 180 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 181 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 182 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 183 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 184 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 185 | virtual Init *convertValue( TypedInit *TI); |
| 186 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 187 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 188 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 189 | std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 190 | |
| 191 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 192 | return RHS->baseClassOf(this); |
| 193 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 194 | virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; } |
| 195 | virtual bool baseClassOf(const BitsRecTy *RHS) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 196 | return RHS->Size == Size; |
| 197 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 198 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 199 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 200 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 201 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 202 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 203 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 204 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
| 207 | |
| 208 | /// IntRecTy - 'int' - Represent an integer value of no particular size |
| 209 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 210 | class IntRecTy : public RecTy { |
| 211 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 212 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 213 | virtual Init *convertValue( BitInit *BI); |
| 214 | virtual Init *convertValue( BitsInit *BI); |
| 215 | virtual Init *convertValue( IntInit *II) { return (Init*)II; } |
| 216 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 217 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 218 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 219 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 220 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 221 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 222 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 223 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 224 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 225 | virtual Init *convertValue( TypedInit *TI); |
| 226 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 227 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 228 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 229 | std::string getAsString() const { return "int"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 230 | |
| 231 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 232 | return RHS->baseClassOf(this); |
| 233 | } |
| 234 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 235 | virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } |
| 236 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; } |
| 237 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 238 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 239 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 240 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 241 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 242 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 243 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | /// StringRecTy - 'string' - Represent an string value |
| 247 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 248 | class StringRecTy : public RecTy { |
| 249 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 250 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 251 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 252 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 253 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 254 | virtual Init *convertValue(StringInit *SI) { return (Init*)SI; } |
| 255 | virtual Init *convertValue( ListInit *LI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 256 | virtual Init *convertValue( UnOpInit *BO); |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 257 | virtual Init *convertValue( BinOpInit *BO); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 258 | virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 259 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 260 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 261 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 262 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 263 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 264 | virtual Init *convertValue( TypedInit *TI); |
| 265 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 266 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 267 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 268 | std::string getAsString() const { return "string"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 269 | |
| 270 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 271 | return RHS->baseClassOf(this); |
| 272 | } |
| 273 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 274 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 275 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 276 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 277 | virtual bool baseClassOf(const StringRecTy *RHS) const { return true; } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 278 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 279 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 280 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 281 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 282 | }; |
| 283 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 284 | // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of |
| 285 | // the specified type. |
| 286 | /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must |
| 287 | /// be of the specified type. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 288 | /// |
| 289 | class ListRecTy : public RecTy { |
| 290 | RecTy *Ty; |
| 291 | public: |
Dan Gohman | 56e3f63 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 292 | explicit ListRecTy(RecTy *T) : Ty(T) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 293 | |
| 294 | RecTy *getElementType() const { return Ty; } |
| 295 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 296 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 297 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 298 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 299 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 300 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 301 | virtual Init *convertValue( ListInit *LI); |
| 302 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 303 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 304 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 305 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 306 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 307 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 308 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 309 | virtual Init *convertValue( TypedInit *TI); |
| 310 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 311 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 312 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 313 | std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 314 | |
| 315 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 316 | return RHS->baseClassOf(this); |
| 317 | } |
| 318 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 319 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 320 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 321 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 322 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 323 | virtual bool baseClassOf(const ListRecTy *RHS) const { |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 324 | return RHS->getElementType()->typeIsConvertibleTo(Ty); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 325 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 326 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 327 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 328 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | /// CodeRecTy - 'code' - Represent an code fragment, function or method. |
| 332 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 333 | class CodeRecTy : public RecTy { |
| 334 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 335 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 336 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 337 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 338 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 339 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 340 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 341 | virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; } |
| 342 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 343 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 344 | virtual Init *convertValue( DagInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 345 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 346 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 347 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 348 | virtual Init *convertValue( TypedInit *TI); |
| 349 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 350 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 351 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 352 | std::string getAsString() const { return "code"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 353 | |
| 354 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 355 | return RHS->baseClassOf(this); |
| 356 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 357 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 358 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 359 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 360 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 361 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 362 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; } |
| 363 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 364 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | /// DagRecTy - 'dag' - Represent a dag fragment |
| 368 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 369 | class DagRecTy : public RecTy { |
| 370 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 371 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 372 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 373 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 374 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 375 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 376 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 377 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 378 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 379 | virtual Init *convertValue( DefInit *DI) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 380 | virtual Init *convertValue( UnOpInit *BO); |
Evan Cheng | a32dee2 | 2007-05-15 01:23:24 +0000 | [diff] [blame] | 381 | virtual Init *convertValue( BinOpInit *BO); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 382 | virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 383 | virtual Init *convertValue( DagInit *CI) { return (Init*)CI; } |
| 384 | virtual Init *convertValue( TypedInit *TI); |
| 385 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 386 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 387 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 388 | std::string getAsString() const { return "dag"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 389 | |
| 390 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 391 | return RHS->baseClassOf(this); |
| 392 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 393 | |
| 394 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 395 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 396 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 397 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 398 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 399 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 400 | virtual bool baseClassOf(const DagRecTy *RHS) const { return true; } |
| 401 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 402 | }; |
| 403 | |
| 404 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 405 | /// RecordRecTy - '[classname]' - Represent an instance of a class, such as: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 406 | /// (R32 X = EAX). |
| 407 | /// |
| 408 | class RecordRecTy : public RecTy { |
| 409 | Record *Rec; |
| 410 | public: |
Dan Gohman | 56e3f63 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 411 | explicit RecordRecTy(Record *R) : Rec(R) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 412 | |
| 413 | Record *getRecord() const { return Rec; } |
| 414 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 415 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 416 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 417 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 418 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 419 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 420 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 421 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 422 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 423 | virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 424 | virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);} |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 425 | virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);} |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 426 | virtual Init *convertValue( DefInit *DI); |
| 427 | virtual Init *convertValue( DagInit *DI) { return 0; } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 428 | virtual Init *convertValue( TypedInit *VI); |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 429 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 430 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 431 | |
Chris Lattner | 8b9ecda | 2007-11-20 22:25:16 +0000 | [diff] [blame] | 432 | std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 433 | |
| 434 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 435 | return RHS->baseClassOf(this); |
| 436 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 437 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 438 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 439 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 440 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 441 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 442 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 443 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 444 | virtual bool baseClassOf(const RecordRecTy *RHS) const; |
| 445 | }; |
| 446 | |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 447 | /// resolveTypes - Find a common type that T1 and T2 convert to. |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 448 | /// Return 0 if no such type exists. |
| 449 | /// |
| 450 | RecTy *resolveTypes(RecTy *T1, RecTy *T2); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 451 | |
| 452 | //===----------------------------------------------------------------------===// |
| 453 | // Initializer Classes |
| 454 | //===----------------------------------------------------------------------===// |
| 455 | |
| 456 | struct Init { |
| 457 | virtual ~Init() {} |
| 458 | |
| 459 | /// isComplete - This virtual method should be overridden by values that may |
| 460 | /// not be completely specified yet. |
| 461 | virtual bool isComplete() const { return true; } |
| 462 | |
| 463 | /// print - Print out this value. |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 464 | void print(raw_ostream &OS) const { OS << getAsString(); } |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 465 | |
| 466 | /// getAsString - Convert this value to a string form. |
| 467 | virtual std::string getAsString() const = 0; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 468 | |
| 469 | /// dump - Debugging method that may be called through a debugger, just |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 470 | /// invokes print on stderr. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 471 | void dump() const; |
| 472 | |
| 473 | /// convertInitializerTo - This virtual function is a simple call-back |
| 474 | /// function that should be overridden to call the appropriate |
| 475 | /// RecTy::convertValue method. |
| 476 | /// |
| 477 | virtual Init *convertInitializerTo(RecTy *Ty) = 0; |
| 478 | |
| 479 | /// convertInitializerBitRange - This method is used to implement the bitrange |
| 480 | /// selection operator. Given an initializer, it selects the specified bits |
| 481 | /// out, returning them as a new init of bits type. If it is not legal to use |
| 482 | /// the bit subscript operator on this initializer, return null. |
| 483 | /// |
| 484 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) { |
| 485 | return 0; |
| 486 | } |
| 487 | |
Chris Lattner | 8bf9e06 | 2004-07-26 23:21:34 +0000 | [diff] [blame] | 488 | /// convertInitListSlice - This method is used to implement the list slice |
| 489 | /// selection operator. Given an initializer, it selects the specified list |
| 490 | /// elements, returning them as a new init of list type. If it is not legal |
| 491 | /// to take a slice of this, return null. |
| 492 | /// |
| 493 | virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) { |
| 494 | return 0; |
| 495 | } |
| 496 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 497 | /// getFieldType - This method is used to implement the FieldInit class. |
| 498 | /// Implementors of this method should return the type of the named field if |
| 499 | /// they are of record type. |
| 500 | /// |
| 501 | virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; } |
| 502 | |
| 503 | /// getFieldInit - This method complements getFieldType to return the |
| 504 | /// initializer for the specified field. If getFieldType returns non-null |
| 505 | /// this method should return non-null, otherwise it returns null. |
| 506 | /// |
Jakob Stoklund Olesen | 0e45762 | 2010-03-25 06:23:34 +0000 | [diff] [blame] | 507 | virtual Init *getFieldInit(Record &R, const RecordVal *RV, |
| 508 | const std::string &FieldName) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 509 | return 0; |
| 510 | } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 511 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 512 | /// resolveReferences - This method is used by classes that refer to other |
Bob Wilson | 159905a | 2009-11-21 22:44:20 +0000 | [diff] [blame] | 513 | /// variables which may not be defined at the time the expression is formed. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 514 | /// If a value is set for the variable later, this method will be called on |
| 515 | /// users of the value to allow the value to propagate out. |
| 516 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 517 | virtual Init *resolveReferences(Record &R, const RecordVal *RV) { |
| 518 | return this; |
| 519 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 520 | }; |
| 521 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 522 | inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 523 | I.print(OS); return OS; |
| 524 | } |
| 525 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 526 | /// TypedInit - This is the common super-class of types that have a specific, |
| 527 | /// explicit, type. |
| 528 | /// |
| 529 | class TypedInit : public Init { |
| 530 | RecTy *Ty; |
| 531 | public: |
| 532 | explicit TypedInit(RecTy *T) : Ty(T) {} |
| 533 | |
| 534 | RecTy *getType() const { return Ty; } |
| 535 | |
| 536 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 537 | virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements); |
| 538 | |
David Greene | 2a9de4d | 2010-09-03 21:00:49 +0000 | [diff] [blame] | 539 | /// getFieldType - This method is used to implement the FieldInit class. |
| 540 | /// Implementors of this method should return the type of the named field if |
| 541 | /// they are of record type. |
| 542 | /// |
| 543 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
| 544 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 545 | /// resolveBitReference - This method is used to implement |
| 546 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 547 | /// simply return the resolved value, otherwise we return null. |
| 548 | /// |
| 549 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 550 | unsigned Bit) = 0; |
| 551 | |
| 552 | /// resolveListElementReference - This method is used to implement |
| 553 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 554 | /// now, we return the resolved value, otherwise we return null. |
| 555 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 556 | unsigned Elt) = 0; |
| 557 | }; |
| 558 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 559 | |
| 560 | /// UnsetInit - ? - Represents an uninitialized value |
| 561 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 562 | class UnsetInit : public Init { |
| 563 | public: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 564 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 565 | return Ty->convertValue(this); |
| 566 | } |
| 567 | |
| 568 | virtual bool isComplete() const { return false; } |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 569 | virtual std::string getAsString() const { return "?"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | |
| 573 | /// BitInit - true/false - Represent a concrete initializer for a bit. |
| 574 | /// |
| 575 | class BitInit : public Init { |
| 576 | bool Value; |
| 577 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 578 | explicit BitInit(bool V) : Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 579 | |
| 580 | bool getValue() const { return Value; } |
| 581 | |
| 582 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 583 | return Ty->convertValue(this); |
| 584 | } |
| 585 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 586 | virtual std::string getAsString() const { return Value ? "1" : "0"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 587 | }; |
| 588 | |
| 589 | /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value. |
| 590 | /// It contains a vector of bits, whose size is determined by the type. |
| 591 | /// |
| 592 | class BitsInit : public Init { |
| 593 | std::vector<Init*> Bits; |
| 594 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 595 | explicit BitsInit(unsigned Size) : Bits(Size) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 596 | |
| 597 | unsigned getNumBits() const { return Bits.size(); } |
| 598 | |
| 599 | Init *getBit(unsigned Bit) const { |
| 600 | assert(Bit < Bits.size() && "Bit index out of range!"); |
| 601 | return Bits[Bit]; |
| 602 | } |
| 603 | void setBit(unsigned Bit, Init *V) { |
| 604 | assert(Bit < Bits.size() && "Bit index out of range!"); |
| 605 | assert(Bits[Bit] == 0 && "Bit already set!"); |
| 606 | Bits[Bit] = V; |
| 607 | } |
| 608 | |
| 609 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 610 | return Ty->convertValue(this); |
| 611 | } |
| 612 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 613 | |
| 614 | virtual bool isComplete() const { |
| 615 | for (unsigned i = 0; i != getNumBits(); ++i) |
| 616 | if (!getBit(i)->isComplete()) return false; |
| 617 | return true; |
| 618 | } |
Johnny Chen | 4e8bd58 | 2010-04-09 21:01:02 +0000 | [diff] [blame] | 619 | bool allInComplete() const { |
| 620 | for (unsigned i = 0; i != getNumBits(); ++i) |
| 621 | if (getBit(i)->isComplete()) return false; |
| 622 | return true; |
| 623 | } |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 624 | virtual std::string getAsString() const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 625 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 626 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 627 | }; |
| 628 | |
| 629 | |
| 630 | /// IntInit - 7 - Represent an initalization by a literal integer value. |
| 631 | /// |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 632 | class IntInit : public TypedInit { |
Dan Gohman | ca0546f | 2008-10-17 01:33:43 +0000 | [diff] [blame] | 633 | int64_t Value; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 634 | public: |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 635 | explicit IntInit(int64_t V) : TypedInit(new IntRecTy), Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 636 | |
Dan Gohman | ca0546f | 2008-10-17 01:33:43 +0000 | [diff] [blame] | 637 | int64_t getValue() const { return Value; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 638 | |
| 639 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 640 | return Ty->convertValue(this); |
| 641 | } |
| 642 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 643 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 644 | virtual std::string getAsString() const; |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 645 | |
| 646 | /// resolveBitReference - This method is used to implement |
| 647 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 648 | /// simply return the resolved value, otherwise we return null. |
| 649 | /// |
| 650 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 651 | unsigned Bit) { |
| 652 | assert(0 && "Illegal bit reference off int"); |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | /// resolveListElementReference - This method is used to implement |
| 657 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 658 | /// now, we return the resolved value, otherwise we return null. |
| 659 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 660 | unsigned Elt) { |
| 661 | assert(0 && "Illegal element reference off int"); |
| 662 | return 0; |
| 663 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 664 | }; |
| 665 | |
| 666 | |
| 667 | /// StringInit - "foo" - Represent an initialization by a string value. |
| 668 | /// |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 669 | class StringInit : public TypedInit { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 670 | std::string Value; |
| 671 | public: |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 672 | explicit StringInit(const std::string &V) |
| 673 | : TypedInit(new StringRecTy), Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 674 | |
| 675 | const std::string &getValue() const { return Value; } |
| 676 | |
| 677 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 678 | return Ty->convertValue(this); |
| 679 | } |
| 680 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 681 | virtual std::string getAsString() const { return "\"" + Value + "\""; } |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 682 | |
| 683 | /// resolveBitReference - This method is used to implement |
| 684 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 685 | /// simply return the resolved value, otherwise we return null. |
| 686 | /// |
| 687 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 688 | unsigned Bit) { |
| 689 | assert(0 && "Illegal bit reference off string"); |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | /// resolveListElementReference - This method is used to implement |
| 694 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 695 | /// now, we return the resolved value, otherwise we return null. |
| 696 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 697 | unsigned Elt) { |
| 698 | assert(0 && "Illegal element reference off string"); |
| 699 | return 0; |
| 700 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | /// CodeInit - "[{...}]" - Represent a code fragment. |
| 704 | /// |
| 705 | class CodeInit : public Init { |
| 706 | std::string Value; |
| 707 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 708 | explicit CodeInit(const std::string &V) : Value(V) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 709 | |
| 710 | const std::string getValue() const { return Value; } |
| 711 | |
| 712 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 713 | return Ty->convertValue(this); |
| 714 | } |
| 715 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 716 | virtual std::string getAsString() const { return "[{" + Value + "}]"; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 717 | }; |
| 718 | |
| 719 | /// ListInit - [AL, AH, CL] - Represent a list of defs |
| 720 | /// |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 721 | class ListInit : public TypedInit { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 722 | std::vector<Init*> Values; |
| 723 | public: |
David Greene | d571b3c | 2009-05-14 22:38:31 +0000 | [diff] [blame] | 724 | typedef std::vector<Init*>::iterator iterator; |
| 725 | typedef std::vector<Init*>::const_iterator const_iterator; |
| 726 | |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 727 | explicit ListInit(std::vector<Init*> &Vs, RecTy *EltTy) |
| 728 | : TypedInit(new ListRecTy(EltTy)) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 729 | Values.swap(Vs); |
| 730 | } |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 731 | explicit ListInit(iterator Start, iterator End, RecTy *EltTy) |
| 732 | : TypedInit(new ListRecTy(EltTy)), Values(Start, End) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 733 | |
| 734 | unsigned getSize() const { return Values.size(); } |
| 735 | Init *getElement(unsigned i) const { |
| 736 | assert(i < Values.size() && "List element index out of range!"); |
| 737 | return Values[i]; |
| 738 | } |
| 739 | |
Chris Lattner | cbebe46 | 2007-02-27 22:08:27 +0000 | [diff] [blame] | 740 | Record *getElementAsRecord(unsigned i) const; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 741 | |
Chris Lattner | 8bf9e06 | 2004-07-26 23:21:34 +0000 | [diff] [blame] | 742 | Init *convertInitListSlice(const std::vector<unsigned> &Elements); |
| 743 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 744 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 745 | return Ty->convertValue(this); |
| 746 | } |
| 747 | |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 748 | /// resolveReferences - This method is used by classes that refer to other |
| 749 | /// variables which may not be defined at the time they expression is formed. |
| 750 | /// If a value is set for the variable later, this method will be called on |
| 751 | /// users of the value to allow the value to propagate out. |
| 752 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 753 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 754 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 755 | virtual std::string getAsString() const; |
Anton Korobeynikov | e49cc26 | 2008-01-21 22:30:26 +0000 | [diff] [blame] | 756 | |
Anton Korobeynikov | e49cc26 | 2008-01-21 22:30:26 +0000 | [diff] [blame] | 757 | inline iterator begin() { return Values.begin(); } |
| 758 | inline const_iterator begin() const { return Values.begin(); } |
| 759 | inline iterator end () { return Values.end(); } |
| 760 | inline const_iterator end () const { return Values.end(); } |
| 761 | |
| 762 | inline size_t size () const { return Values.size(); } |
| 763 | inline bool empty() const { return Values.empty(); } |
David Greene | 8618f95 | 2009-06-08 20:23:18 +0000 | [diff] [blame] | 764 | |
| 765 | /// resolveBitReference - This method is used to implement |
| 766 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 767 | /// simply return the resolved value, otherwise we return null. |
| 768 | /// |
| 769 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 770 | unsigned Bit) { |
| 771 | assert(0 && "Illegal bit reference off list"); |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | /// resolveListElementReference - This method is used to implement |
| 776 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 777 | /// now, we return the resolved value, otherwise we return null. |
| 778 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 779 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 780 | }; |
| 781 | |
| 782 | |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 783 | /// OpInit - Base class for operators |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 784 | /// |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 785 | class OpInit : public TypedInit { |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 786 | public: |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 787 | OpInit(RecTy *Type) : TypedInit(Type) {} |
| 788 | |
| 789 | // Clone - Clone this operator, replacing arguments with the new list |
| 790 | virtual OpInit *clone(std::vector<Init *> &Operands) = 0; |
| 791 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 792 | virtual int getNumOperands() const = 0; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 793 | virtual Init *getOperand(int i) = 0; |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 794 | |
| 795 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 796 | // possible to fold. |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 797 | virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0; |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 798 | |
| 799 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 800 | return Ty->convertValue(this); |
| 801 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 802 | |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 803 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 804 | unsigned Bit); |
| 805 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 806 | unsigned Elt); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 807 | }; |
| 808 | |
| 809 | |
| 810 | /// UnOpInit - !op (X) - Transform an init. |
| 811 | /// |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 812 | class UnOpInit : public OpInit { |
| 813 | public: |
David Greene | d571b3c | 2009-05-14 22:38:31 +0000 | [diff] [blame] | 814 | enum UnaryOp { CAST, CAR, CDR, LNULL }; |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 815 | private: |
| 816 | UnaryOp Opc; |
| 817 | Init *LHS; |
| 818 | public: |
| 819 | UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) : |
| 820 | OpInit(Type), Opc(opc), LHS(lhs) { |
| 821 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 822 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 823 | // Clone - Clone this operator, replacing arguments with the new list |
| 824 | virtual OpInit *clone(std::vector<Init *> &Operands) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 825 | assert(Operands.size() == 1 && |
| 826 | "Wrong number of operands for unary operation"); |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 827 | return new UnOpInit(getOpcode(), *Operands.begin(), getType()); |
| 828 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 829 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 830 | int getNumOperands() const { return 1; } |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 831 | Init *getOperand(int i) { |
| 832 | assert(i == 0 && "Invalid operand id for unary operator"); |
| 833 | return getOperand(); |
| 834 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 835 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 836 | UnaryOp getOpcode() const { return Opc; } |
| 837 | Init *getOperand() const { return LHS; } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 838 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 839 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 840 | // possible to fold. |
| 841 | Init *Fold(Record *CurRec, MultiClass *CurMultiClass); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 842 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 843 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 844 | |
David Greene | e8f3b27 | 2009-05-14 21:22:49 +0000 | [diff] [blame] | 845 | virtual std::string getAsString() const; |
| 846 | }; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 847 | |
| 848 | /// BinOpInit - !op (X, Y) - Combine two inits. |
| 849 | /// |
| 850 | class BinOpInit : public OpInit { |
| 851 | public: |
Chris Lattner | 9402633 | 2010-10-06 00:19:21 +0000 | [diff] [blame] | 852 | enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ }; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 853 | private: |
| 854 | BinaryOp Opc; |
| 855 | Init *LHS, *RHS; |
| 856 | public: |
| 857 | BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) : |
| 858 | OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) { |
| 859 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 860 | |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 861 | // Clone - Clone this operator, replacing arguments with the new list |
| 862 | virtual OpInit *clone(std::vector<Init *> &Operands) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 863 | assert(Operands.size() == 2 && |
| 864 | "Wrong number of operands for binary operation"); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 865 | return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType()); |
| 866 | } |
| 867 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 868 | int getNumOperands() const { return 2; } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 869 | Init *getOperand(int i) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 870 | assert((i == 0 || i == 1) && "Invalid operand id for binary operator"); |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 871 | if (i == 0) { |
| 872 | return getLHS(); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 873 | } else { |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 874 | return getRHS(); |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | BinaryOp getOpcode() const { return Opc; } |
| 879 | Init *getLHS() const { return LHS; } |
| 880 | Init *getRHS() const { return RHS; } |
| 881 | |
| 882 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 883 | // possible to fold. |
| 884 | Init *Fold(Record *CurRec, MultiClass *CurMultiClass); |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 885 | |
| 886 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 887 | |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 888 | virtual std::string getAsString() const; |
| 889 | }; |
| 890 | |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 891 | /// TernOpInit - !op (X, Y, Z) - Combine two inits. |
| 892 | /// |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 893 | class TernOpInit : public OpInit { |
| 894 | public: |
David Greene | 58a6b76 | 2009-06-09 18:31:17 +0000 | [diff] [blame] | 895 | enum TernaryOp { SUBST, FOREACH, IF }; |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 896 | private: |
| 897 | TernaryOp Opc; |
| 898 | Init *LHS, *MHS, *RHS; |
| 899 | public: |
| 900 | TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) : |
| 901 | OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) { |
| 902 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 903 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 904 | // Clone - Clone this operator, replacing arguments with the new list |
| 905 | virtual OpInit *clone(std::vector<Init *> &Operands) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 906 | assert(Operands.size() == 3 && |
| 907 | "Wrong number of operands for ternary operation"); |
| 908 | return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2], |
| 909 | getType()); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 910 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 911 | |
Dan Gohman | 1432ef8 | 2009-08-12 22:10:57 +0000 | [diff] [blame] | 912 | int getNumOperands() const { return 3; } |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 913 | Init *getOperand(int i) { |
Nick Lewycky | d449e7c | 2009-05-15 03:03:14 +0000 | [diff] [blame] | 914 | assert((i == 0 || i == 1 || i == 2) && |
| 915 | "Invalid operand id for ternary operator"); |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 916 | if (i == 0) { |
| 917 | return getLHS(); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 918 | } else if (i == 1) { |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 919 | return getMHS(); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 920 | } else { |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 921 | return getRHS(); |
| 922 | } |
| 923 | } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 924 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 925 | TernaryOp getOpcode() const { return Opc; } |
| 926 | Init *getLHS() const { return LHS; } |
| 927 | Init *getMHS() const { return MHS; } |
| 928 | Init *getRHS() const { return RHS; } |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 929 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 930 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 931 | // possible to fold. |
| 932 | Init *Fold(Record *CurRec, MultiClass *CurMultiClass); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 933 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 934 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 935 | |
David Greene | 98ed3c7 | 2009-05-14 21:54:42 +0000 | [diff] [blame] | 936 | virtual std::string getAsString() const; |
| 937 | }; |
David Greene | 5d0c051 | 2009-05-14 20:54:48 +0000 | [diff] [blame] | 938 | |
David Greene | 196ac3c | 2009-04-23 21:25:15 +0000 | [diff] [blame] | 939 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 940 | /// VarInit - 'Opcode' - Represent a reference to an entire variable object. |
| 941 | /// |
| 942 | class VarInit : public TypedInit { |
| 943 | std::string VarName; |
| 944 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 945 | explicit VarInit(const std::string &VN, RecTy *T) |
| 946 | : TypedInit(T), VarName(VN) {} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 947 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 948 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 949 | return Ty->convertValue(this); |
| 950 | } |
| 951 | |
| 952 | const std::string &getName() const { return VarName; } |
| 953 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 954 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 955 | unsigned Bit); |
| 956 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 957 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 958 | |
| 959 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
Jakob Stoklund Olesen | 0e45762 | 2010-03-25 06:23:34 +0000 | [diff] [blame] | 960 | virtual Init *getFieldInit(Record &R, const RecordVal *RV, |
| 961 | const std::string &FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 962 | |
| 963 | /// resolveReferences - This method is used by classes that refer to other |
| 964 | /// variables which may not be defined at the time they expression is formed. |
| 965 | /// If a value is set for the variable later, this method will be called on |
| 966 | /// users of the value to allow the value to propagate out. |
| 967 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 968 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 969 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 970 | virtual std::string getAsString() const { return VarName; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 971 | }; |
| 972 | |
| 973 | |
| 974 | /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field. |
| 975 | /// |
| 976 | class VarBitInit : public Init { |
| 977 | TypedInit *TI; |
| 978 | unsigned Bit; |
| 979 | public: |
| 980 | VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) { |
| 981 | assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) && |
| 982 | ((BitsRecTy*)T->getType())->getNumBits() > B && |
| 983 | "Illegal VarBitInit expression!"); |
| 984 | } |
| 985 | |
| 986 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 987 | return Ty->convertValue(this); |
| 988 | } |
| 989 | |
| 990 | TypedInit *getVariable() const { return TI; } |
| 991 | unsigned getBitNum() const { return Bit; } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 992 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 993 | virtual std::string getAsString() const; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 994 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 995 | }; |
| 996 | |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 997 | /// VarListElementInit - List[4] - Represent access to one element of a var or |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 998 | /// field. |
| 999 | class VarListElementInit : public TypedInit { |
| 1000 | TypedInit *TI; |
| 1001 | unsigned Element; |
| 1002 | public: |
| 1003 | VarListElementInit(TypedInit *T, unsigned E) |
| 1004 | : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()), |
| 1005 | TI(T), Element(E) { |
| 1006 | assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) && |
| 1007 | "Illegal VarBitInit expression!"); |
| 1008 | } |
| 1009 | |
| 1010 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1011 | return Ty->convertValue(this); |
| 1012 | } |
| 1013 | |
| 1014 | TypedInit *getVariable() const { return TI; } |
| 1015 | unsigned getElementNum() const { return Element; } |
| 1016 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1017 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1018 | unsigned Bit); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 1019 | |
| 1020 | /// resolveListElementReference - This method is used to implement |
| 1021 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 1022 | /// now, we return the resolved value, otherwise we return null. |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1023 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1024 | unsigned Elt); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 1025 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1026 | virtual std::string getAsString() const; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1027 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 1028 | }; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1029 | |
| 1030 | /// DefInit - AL - Represent a reference to a 'def' in the description |
| 1031 | /// |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1032 | class DefInit : public TypedInit { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1033 | Record *Def; |
| 1034 | public: |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1035 | explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1036 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1037 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1038 | return Ty->convertValue(this); |
| 1039 | } |
| 1040 | |
| 1041 | Record *getDef() const { return Def; } |
| 1042 | |
| 1043 | //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 1044 | |
| 1045 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
Jakob Stoklund Olesen | 0e45762 | 2010-03-25 06:23:34 +0000 | [diff] [blame] | 1046 | virtual Init *getFieldInit(Record &R, const RecordVal *RV, |
| 1047 | const std::string &FieldName) const; |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1048 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1049 | virtual std::string getAsString() const; |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1050 | |
| 1051 | /// resolveBitReference - This method is used to implement |
| 1052 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
| 1053 | /// simply return the resolved value, otherwise we return null. |
| 1054 | /// |
| 1055 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1056 | unsigned Bit) { |
| 1057 | assert(0 && "Illegal bit reference off def"); |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
| 1061 | /// resolveListElementReference - This method is used to implement |
| 1062 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 1063 | /// now, we return the resolved value, otherwise we return null. |
| 1064 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1065 | unsigned Elt) { |
| 1066 | assert(0 && "Illegal element reference off def"); |
| 1067 | return 0; |
| 1068 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1069 | }; |
| 1070 | |
| 1071 | |
| 1072 | /// FieldInit - X.Y - Represent a reference to a subfield of a variable |
| 1073 | /// |
| 1074 | class FieldInit : public TypedInit { |
| 1075 | Init *Rec; // Record we are referring to |
| 1076 | std::string FieldName; // Field we are accessing |
| 1077 | public: |
| 1078 | FieldInit(Init *R, const std::string &FN) |
| 1079 | : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) { |
| 1080 | assert(getType() && "FieldInit with non-record type!"); |
| 1081 | } |
| 1082 | |
| 1083 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1084 | return Ty->convertValue(this); |
| 1085 | } |
| 1086 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1087 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1088 | unsigned Bit); |
| 1089 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1090 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1091 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1092 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1093 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1094 | virtual std::string getAsString() const { |
| 1095 | return Rec->getAsString() + "." + FieldName; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1096 | } |
| 1097 | }; |
| 1098 | |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 1099 | /// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required |
| 1100 | /// to have at least one value then a (possibly empty) list of arguments. Each |
| 1101 | /// argument can have a name associated with it. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1102 | /// |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1103 | class DagInit : public TypedInit { |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 1104 | Init *Val; |
Nate Begeman | dbe3f77 | 2009-03-19 05:21:56 +0000 | [diff] [blame] | 1105 | std::string ValName; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1106 | std::vector<Init*> Args; |
| 1107 | std::vector<std::string> ArgNames; |
| 1108 | public: |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1109 | DagInit(Init *V, std::string VN, |
Nate Begeman | dbe3f77 | 2009-03-19 05:21:56 +0000 | [diff] [blame] | 1110 | const std::vector<std::pair<Init*, std::string> > &args) |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1111 | : TypedInit(new DagRecTy), Val(V), ValName(VN) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1112 | Args.reserve(args.size()); |
| 1113 | ArgNames.reserve(args.size()); |
| 1114 | for (unsigned i = 0, e = args.size(); i != e; ++i) { |
| 1115 | Args.push_back(args[i].first); |
| 1116 | ArgNames.push_back(args[i].second); |
| 1117 | } |
| 1118 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1119 | DagInit(Init *V, std::string VN, const std::vector<Init*> &args, |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 1120 | const std::vector<std::string> &argNames) |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1121 | : TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args), |
| 1122 | ArgNames(argNames) { } |
| 1123 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1124 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 1125 | return Ty->convertValue(this); |
| 1126 | } |
| 1127 | |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 1128 | Init *getOperator() const { return Val; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1129 | |
Nate Begeman | dbe3f77 | 2009-03-19 05:21:56 +0000 | [diff] [blame] | 1130 | const std::string &getName() const { return ValName; } |
| 1131 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1132 | unsigned getNumArgs() const { return Args.size(); } |
| 1133 | Init *getArg(unsigned Num) const { |
| 1134 | assert(Num < Args.size() && "Arg number out of range!"); |
| 1135 | return Args[Num]; |
| 1136 | } |
| 1137 | const std::string &getArgName(unsigned Num) const { |
| 1138 | assert(Num < ArgNames.size() && "Arg number out of range!"); |
| 1139 | return ArgNames[Num]; |
| 1140 | } |
| 1141 | |
| 1142 | void setArg(unsigned Num, Init *I) { |
| 1143 | assert(Num < Args.size() && "Arg number out of range!"); |
| 1144 | Args[Num] = I; |
| 1145 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1146 | |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 1147 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1148 | |
Chris Lattner | 695506c | 2007-11-22 21:05:25 +0000 | [diff] [blame] | 1149 | virtual std::string getAsString() const; |
Anton Korobeynikov | 010bd77 | 2008-01-22 11:00:07 +0000 | [diff] [blame] | 1150 | |
| 1151 | typedef std::vector<Init*>::iterator arg_iterator; |
| 1152 | typedef std::vector<Init*>::const_iterator const_arg_iterator; |
| 1153 | typedef std::vector<std::string>::iterator name_iterator; |
| 1154 | typedef std::vector<std::string>::const_iterator const_name_iterator; |
| 1155 | |
| 1156 | inline arg_iterator arg_begin() { return Args.begin(); } |
| 1157 | inline const_arg_iterator arg_begin() const { return Args.begin(); } |
| 1158 | inline arg_iterator arg_end () { return Args.end(); } |
| 1159 | inline const_arg_iterator arg_end () const { return Args.end(); } |
| 1160 | |
| 1161 | inline size_t arg_size () const { return Args.size(); } |
| 1162 | inline bool arg_empty() const { return Args.empty(); } |
| 1163 | |
| 1164 | inline name_iterator name_begin() { return ArgNames.begin(); } |
| 1165 | inline const_name_iterator name_begin() const { return ArgNames.begin(); } |
| 1166 | inline name_iterator name_end () { return ArgNames.end(); } |
| 1167 | inline const_name_iterator name_end () const { return ArgNames.end(); } |
| 1168 | |
| 1169 | inline size_t name_size () const { return ArgNames.size(); } |
| 1170 | inline bool name_empty() const { return ArgNames.empty(); } |
| 1171 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1172 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 1173 | unsigned Bit) { |
| 1174 | assert(0 && "Illegal bit reference off dag"); |
| 1175 | return 0; |
| 1176 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1177 | |
David Greene | e917fff | 2009-05-14 22:23:47 +0000 | [diff] [blame] | 1178 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 1179 | unsigned Elt) { |
| 1180 | assert(0 && "Illegal element reference off dag"); |
| 1181 | return 0; |
| 1182 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1183 | }; |
| 1184 | |
| 1185 | //===----------------------------------------------------------------------===// |
| 1186 | // High-Level Classes |
| 1187 | //===----------------------------------------------------------------------===// |
| 1188 | |
| 1189 | class RecordVal { |
| 1190 | std::string Name; |
| 1191 | RecTy *Ty; |
| 1192 | unsigned Prefix; |
| 1193 | Init *Value; |
| 1194 | public: |
| 1195 | RecordVal(const std::string &N, RecTy *T, unsigned P); |
| 1196 | |
| 1197 | const std::string &getName() const { return Name; } |
| 1198 | |
| 1199 | unsigned getPrefix() const { return Prefix; } |
| 1200 | RecTy *getType() const { return Ty; } |
| 1201 | Init *getValue() const { return Value; } |
| 1202 | |
| 1203 | bool setValue(Init *V) { |
| 1204 | if (V) { |
| 1205 | Value = V->convertInitializerTo(Ty); |
| 1206 | return Value == 0; |
| 1207 | } |
| 1208 | Value = 0; |
| 1209 | return false; |
| 1210 | } |
| 1211 | |
| 1212 | void dump() const; |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1213 | void print(raw_ostream &OS, bool PrintSem = true) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1214 | }; |
| 1215 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1216 | inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1217 | RV.print(OS << " "); |
| 1218 | return OS; |
| 1219 | } |
| 1220 | |
Chris Lattner | 87a1061 | 2004-10-23 04:58:50 +0000 | [diff] [blame] | 1221 | class Record { |
Daniel Dunbar | ced0081 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 1222 | static unsigned LastID; |
| 1223 | |
| 1224 | // Unique record ID. |
| 1225 | unsigned ID; |
Chris Lattner | f9b2edb | 2005-08-19 17:58:49 +0000 | [diff] [blame] | 1226 | std::string Name; |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1227 | SMLoc Loc; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1228 | std::vector<std::string> TemplateArgs; |
| 1229 | std::vector<RecordVal> Values; |
| 1230 | std::vector<Record*> SuperClasses; |
Chris Lattner | 77d369c | 2010-12-13 00:23:57 +0000 | [diff] [blame^] | 1231 | |
| 1232 | // Tracks Record instances. Not owned by Record. |
| 1233 | RecordKeeper &TrackedRecords; |
| 1234 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1235 | public: |
| 1236 | |
Chris Lattner | 77d369c | 2010-12-13 00:23:57 +0000 | [diff] [blame^] | 1237 | // Constructs a record. See also RecordKeeper::createRecord. |
| 1238 | explicit Record(const std::string &N, SMLoc loc, RecordKeeper& records) : |
| 1239 | ID(LastID++), Name(N), Loc(loc), TrackedRecords(records) {} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1240 | ~Record() {} |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1241 | |
Mikhail Glushenkov | 5be6764 | 2010-09-21 14:59:50 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | d39f75b | 2010-03-01 22:09:11 +0000 | [diff] [blame] | 1243 | static unsigned getNewUID() { return LastID++; } |
Mikhail Glushenkov | 5be6764 | 2010-09-21 14:59:50 +0000 | [diff] [blame] | 1244 | |
| 1245 | |
Daniel Dunbar | ced0081 | 2009-08-23 09:47:37 +0000 | [diff] [blame] | 1246 | unsigned getID() const { return ID; } |
| 1247 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1248 | const std::string &getName() const { return Name; } |
Chris Lattner | ac28425 | 2005-08-19 17:58:11 +0000 | [diff] [blame] | 1249 | void setName(const std::string &Name); // Also updates RecordKeeper. |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1250 | |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1251 | SMLoc getLoc() const { return Loc; } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1252 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1253 | const std::vector<std::string> &getTemplateArgs() const { |
| 1254 | return TemplateArgs; |
| 1255 | } |
| 1256 | const std::vector<RecordVal> &getValues() const { return Values; } |
| 1257 | const std::vector<Record*> &getSuperClasses() const { return SuperClasses; } |
| 1258 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1259 | bool isTemplateArg(StringRef Name) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1260 | for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i) |
| 1261 | if (TemplateArgs[i] == Name) return true; |
| 1262 | return false; |
| 1263 | } |
| 1264 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1265 | const RecordVal *getValue(StringRef Name) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1266 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 1267 | if (Values[i].getName() == Name) return &Values[i]; |
| 1268 | return 0; |
| 1269 | } |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1270 | RecordVal *getValue(StringRef Name) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1271 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 1272 | if (Values[i].getName() == Name) return &Values[i]; |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1276 | void addTemplateArg(StringRef Name) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1277 | assert(!isTemplateArg(Name) && "Template arg already defined!"); |
| 1278 | TemplateArgs.push_back(Name); |
| 1279 | } |
| 1280 | |
| 1281 | void addValue(const RecordVal &RV) { |
| 1282 | assert(getValue(RV.getName()) == 0 && "Value already added!"); |
| 1283 | Values.push_back(RV); |
| 1284 | } |
| 1285 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1286 | void removeValue(StringRef Name) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1287 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 1288 | if (Values[i].getName() == Name) { |
| 1289 | Values.erase(Values.begin()+i); |
| 1290 | return; |
| 1291 | } |
Bob Wilson | 3b793a4 | 2009-11-21 22:39:27 +0000 | [diff] [blame] | 1292 | assert(0 && "Cannot remove an entry that does not exist!"); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1293 | } |
| 1294 | |
Ted Kremenek | 58e3287 | 2009-03-13 22:20:10 +0000 | [diff] [blame] | 1295 | bool isSubClassOf(const Record *R) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1296 | for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) |
| 1297 | if (SuperClasses[i] == R) |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1298 | return true; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1299 | return false; |
| 1300 | } |
| 1301 | |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1302 | bool isSubClassOf(StringRef Name) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1303 | for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) |
| 1304 | if (SuperClasses[i]->getName() == Name) |
| 1305 | return true; |
| 1306 | return false; |
| 1307 | } |
| 1308 | |
| 1309 | void addSuperClass(Record *R) { |
| 1310 | assert(!isSubClassOf(R) && "Already subclassing record!"); |
| 1311 | SuperClasses.push_back(R); |
| 1312 | } |
| 1313 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 1314 | /// resolveReferences - If there are any field references that refer to fields |
| 1315 | /// that have been filled in, we can propagate the values now. |
| 1316 | /// |
| 1317 | void resolveReferences() { resolveReferencesTo(0); } |
| 1318 | |
| 1319 | /// resolveReferencesTo - If anything in this record refers to RV, replace the |
| 1320 | /// reference to RV with the RHS of RV. If RV is null, we resolve all |
| 1321 | /// possible references. |
| 1322 | void resolveReferencesTo(const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1323 | |
Chris Lattner | 77d369c | 2010-12-13 00:23:57 +0000 | [diff] [blame^] | 1324 | RecordKeeper &getRecords() const { |
| 1325 | return(TrackedRecords); |
| 1326 | } |
| 1327 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1328 | void dump() const; |
| 1329 | |
| 1330 | //===--------------------------------------------------------------------===// |
| 1331 | // High-level methods useful to tablegen back-ends |
| 1332 | // |
| 1333 | |
| 1334 | /// getValueInit - Return the initializer for a value with the specified name, |
| 1335 | /// or throw an exception if the field does not exist. |
| 1336 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1337 | Init *getValueInit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1338 | |
| 1339 | /// getValueAsString - This method looks up the specified field and returns |
| 1340 | /// its value as a string, throwing an exception if the field does not exist |
| 1341 | /// or if the value is not a string. |
| 1342 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1343 | std::string getValueAsString(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1344 | |
| 1345 | /// getValueAsBitsInit - This method looks up the specified field and returns |
| 1346 | /// its value as a BitsInit, throwing an exception if the field does not exist |
| 1347 | /// or if the value is not the right type. |
| 1348 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1349 | BitsInit *getValueAsBitsInit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1350 | |
| 1351 | /// getValueAsListInit - This method looks up the specified field and returns |
| 1352 | /// its value as a ListInit, throwing an exception if the field does not exist |
| 1353 | /// or if the value is not the right type. |
| 1354 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1355 | ListInit *getValueAsListInit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1356 | |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 1357 | /// getValueAsListOfDefs - This method looks up the specified field and |
Anton Korobeynikov | a468a11 | 2007-11-11 11:19:37 +0000 | [diff] [blame] | 1358 | /// returns its value as a vector of records, throwing an exception if the |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 1359 | /// field does not exist or if the value is not the right type. |
Jim Laskey | b04feb6 | 2005-10-28 21:46:31 +0000 | [diff] [blame] | 1360 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1361 | std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const; |
Jim Laskey | b04feb6 | 2005-10-28 21:46:31 +0000 | [diff] [blame] | 1362 | |
Mikhail Glushenkov | 5be6764 | 2010-09-21 14:59:50 +0000 | [diff] [blame] | 1363 | /// getValueAsListOfInts - This method looks up the specified field and |
| 1364 | /// returns its value as a vector of integers, throwing an exception if the |
| 1365 | /// field does not exist or if the value is not the right type. |
Anton Korobeynikov | a468a11 | 2007-11-11 11:19:37 +0000 | [diff] [blame] | 1366 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1367 | std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1368 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1369 | /// getValueAsDef - This method looks up the specified field and returns its |
| 1370 | /// value as a Record, throwing an exception if the field does not exist or if |
| 1371 | /// the value is not the right type. |
| 1372 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1373 | Record *getValueAsDef(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1374 | |
| 1375 | /// getValueAsBit - This method looks up the specified field and returns its |
| 1376 | /// value as a bit, throwing an exception if the field does not exist or if |
| 1377 | /// the value is not the right type. |
| 1378 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1379 | bool getValueAsBit(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1380 | |
| 1381 | /// getValueAsInt - This method looks up the specified field and returns its |
Dan Gohman | ca0546f | 2008-10-17 01:33:43 +0000 | [diff] [blame] | 1382 | /// value as an int64_t, throwing an exception if the field does not exist or |
| 1383 | /// if the value is not the right type. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1384 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1385 | int64_t getValueAsInt(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1386 | |
| 1387 | /// getValueAsDag - This method looks up the specified field and returns its |
| 1388 | /// value as an Dag, throwing an exception if the field does not exist or if |
| 1389 | /// the value is not the right type. |
| 1390 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1391 | DagInit *getValueAsDag(StringRef FieldName) const; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1392 | |
Chris Lattner | ae939eb | 2005-09-13 21:44:28 +0000 | [diff] [blame] | 1393 | /// getValueAsCode - This method looks up the specified field and returns |
| 1394 | /// its value as the string data in a CodeInit, throwing an exception if the |
| 1395 | /// field does not exist or if the value is not a code object. |
| 1396 | /// |
Chris Lattner | 42bb0c1 | 2009-09-18 18:31:37 +0000 | [diff] [blame] | 1397 | std::string getValueAsCode(StringRef FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1398 | }; |
| 1399 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1400 | raw_ostream &operator<<(raw_ostream &OS, const Record &R); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1401 | |
David Greene | a9c6c5d | 2009-04-22 20:18:10 +0000 | [diff] [blame] | 1402 | struct MultiClass { |
| 1403 | Record Rec; // Placeholder for template args and Name. |
| 1404 | typedef std::vector<Record*> RecordVector; |
| 1405 | RecordVector DefPrototypes; |
David Greene | 7049e79 | 2009-04-24 16:55:41 +0000 | [diff] [blame] | 1406 | |
| 1407 | void dump() const; |
| 1408 | |
Chris Lattner | 77d369c | 2010-12-13 00:23:57 +0000 | [diff] [blame^] | 1409 | MultiClass(const std::string &Name, SMLoc Loc, RecordKeeper &Records) : |
| 1410 | Rec(Name, Loc, Records) {} |
David Greene | a9c6c5d | 2009-04-22 20:18:10 +0000 | [diff] [blame] | 1411 | }; |
| 1412 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1413 | class RecordKeeper { |
| 1414 | std::map<std::string, Record*> Classes, Defs; |
| 1415 | public: |
| 1416 | ~RecordKeeper() { |
| 1417 | for (std::map<std::string, Record*>::iterator I = Classes.begin(), |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1418 | E = Classes.end(); I != E; ++I) |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1419 | delete I->second; |
| 1420 | for (std::map<std::string, Record*>::iterator I = Defs.begin(), |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1421 | E = Defs.end(); I != E; ++I) |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1422 | delete I->second; |
| 1423 | } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1424 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1425 | const std::map<std::string, Record*> &getClasses() const { return Classes; } |
| 1426 | const std::map<std::string, Record*> &getDefs() const { return Defs; } |
| 1427 | |
| 1428 | Record *getClass(const std::string &Name) const { |
| 1429 | std::map<std::string, Record*>::const_iterator I = Classes.find(Name); |
| 1430 | return I == Classes.end() ? 0 : I->second; |
| 1431 | } |
| 1432 | Record *getDef(const std::string &Name) const { |
| 1433 | std::map<std::string, Record*>::const_iterator I = Defs.find(Name); |
| 1434 | return I == Defs.end() ? 0 : I->second; |
| 1435 | } |
| 1436 | void addClass(Record *R) { |
| 1437 | assert(getClass(R->getName()) == 0 && "Class already exists!"); |
| 1438 | Classes.insert(std::make_pair(R->getName(), R)); |
| 1439 | } |
| 1440 | void addDef(Record *R) { |
| 1441 | assert(getDef(R->getName()) == 0 && "Def already exists!"); |
| 1442 | Defs.insert(std::make_pair(R->getName(), R)); |
| 1443 | } |
| 1444 | |
Chris Lattner | ac28425 | 2005-08-19 17:58:11 +0000 | [diff] [blame] | 1445 | /// removeClass - Remove, but do not delete, the specified record. |
| 1446 | /// |
| 1447 | void removeClass(const std::string &Name) { |
| 1448 | assert(Classes.count(Name) && "Class does not exist!"); |
| 1449 | Classes.erase(Name); |
| 1450 | } |
| 1451 | /// removeDef - Remove, but do not delete, the specified record. |
| 1452 | /// |
| 1453 | void removeDef(const std::string &Name) { |
| 1454 | assert(Defs.count(Name) && "Def does not exist!"); |
| 1455 | Defs.erase(Name); |
| 1456 | } |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1457 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1458 | //===--------------------------------------------------------------------===// |
| 1459 | // High-level helper methods, useful for tablegen backends... |
| 1460 | |
| 1461 | /// getAllDerivedDefinitions - This method returns all concrete definitions |
| 1462 | /// that derive from the specified class name. If a class with the specified |
| 1463 | /// name does not exist, an exception is thrown. |
| 1464 | std::vector<Record*> |
| 1465 | getAllDerivedDefinitions(const std::string &ClassName) const; |
| 1466 | |
Chris Lattner | 77d369c | 2010-12-13 00:23:57 +0000 | [diff] [blame^] | 1467 | // allocates and returns a record. |
| 1468 | Record *createRecord(const std::string &N, SMLoc loc) { |
| 1469 | return(new Record(N, loc, *this)); |
| 1470 | } |
| 1471 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1472 | |
| 1473 | void dump() const; |
| 1474 | }; |
| 1475 | |
Chris Lattner | bd7ccd01 | 2008-08-26 06:43:25 +0000 | [diff] [blame] | 1476 | /// LessRecord - Sorting predicate to sort record pointers by name. |
| 1477 | /// |
| 1478 | struct LessRecord { |
| 1479 | bool operator()(const Record *Rec1, const Record *Rec2) const { |
Jakob Stoklund Olesen | d1d7ed6 | 2010-05-26 21:47:28 +0000 | [diff] [blame] | 1480 | return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0; |
Chris Lattner | bd7ccd01 | 2008-08-26 06:43:25 +0000 | [diff] [blame] | 1481 | } |
| 1482 | }; |
| 1483 | |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1484 | /// LessRecordFieldName - Sorting predicate to sort record pointers by their |
Jim Grosbach | 56938af | 2008-09-11 17:05:32 +0000 | [diff] [blame] | 1485 | /// name field. |
Chris Lattner | bd7ccd01 | 2008-08-26 06:43:25 +0000 | [diff] [blame] | 1486 | /// |
| 1487 | struct LessRecordFieldName { |
| 1488 | bool operator()(const Record *Rec1, const Record *Rec2) const { |
| 1489 | return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name"); |
| 1490 | } |
| 1491 | }; |
| 1492 | |
Chris Lattner | ba42e49 | 2009-03-13 16:25:21 +0000 | [diff] [blame] | 1493 | |
| 1494 | class TGError { |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1495 | SMLoc Loc; |
Chris Lattner | ba42e49 | 2009-03-13 16:25:21 +0000 | [diff] [blame] | 1496 | std::string Message; |
| 1497 | public: |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1498 | TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {} |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1499 | |
Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 1500 | SMLoc getLoc() const { return Loc; } |
Chris Lattner | ba42e49 | 2009-03-13 16:25:21 +0000 | [diff] [blame] | 1501 | const std::string &getMessage() const { return Message; } |
| 1502 | }; |
Bob Wilson | 7248f86 | 2009-11-22 04:24:42 +0000 | [diff] [blame] | 1503 | |
| 1504 | |
Daniel Dunbar | 38a22bf | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 1505 | raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1506 | |
Benjamin Kramer | c758311 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 1507 | void PrintError(SMLoc ErrorLoc, const Twine &Msg); |
Chris Lattner | bd9b921 | 2009-03-13 16:09:24 +0000 | [diff] [blame] | 1508 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 1509 | } // End llvm namespace |
| 1510 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1511 | #endif |