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 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source 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 | |
| 18 | #include <string> |
| 19 | #include <vector> |
| 20 | #include <map> |
| 21 | #include <iostream> |
| 22 | #include <cassert> |
| 23 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 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; |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 45 | class BinOpInit; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 46 | class DefInit; |
| 47 | class DagInit; |
| 48 | class TypedInit; |
| 49 | class VarInit; |
| 50 | class FieldInit; |
| 51 | class VarBitInit; |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 52 | class VarListElementInit; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 53 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 54 | // Other classes. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 55 | class Record; |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 56 | class RecordVal; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 57 | |
| 58 | //===----------------------------------------------------------------------===// |
| 59 | // Type Classes |
| 60 | //===----------------------------------------------------------------------===// |
| 61 | |
| 62 | struct RecTy { |
| 63 | virtual ~RecTy() {} |
| 64 | |
| 65 | virtual void print(std::ostream &OS) const = 0; |
| 66 | void dump() const; |
| 67 | |
| 68 | /// typeIsConvertibleTo - Return true if all values of 'this' type can be |
| 69 | /// converted to the specified type. |
| 70 | virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0; |
| 71 | |
| 72 | public: // These methods should only be called from subclasses of Init |
| 73 | virtual Init *convertValue( UnsetInit *UI) { return 0; } |
| 74 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 75 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 76 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 77 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 78 | virtual Init *convertValue( ListInit *LI) { return 0; } |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 79 | virtual Init *convertValue( BinOpInit *UI) { return 0; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 80 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 81 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 82 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 83 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 84 | virtual Init *convertValue( TypedInit *TI) { return 0; } |
| 85 | virtual Init *convertValue( VarInit *VI) { |
| 86 | return convertValue((TypedInit*)VI); |
| 87 | } |
| 88 | virtual Init *convertValue( FieldInit *FI) { |
| 89 | return convertValue((TypedInit*)FI); |
| 90 | } |
| 91 | |
| 92 | public: // These methods should only be called by subclasses of RecTy. |
| 93 | // baseClassOf - These virtual methods should be overloaded to return true iff |
| 94 | // all values of type 'RHS' can be converted to the 'this' type. |
| 95 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 96 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 97 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 98 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 99 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 100 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 101 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 102 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 103 | }; |
| 104 | |
| 105 | inline std::ostream &operator<<(std::ostream &OS, const RecTy &Ty) { |
| 106 | Ty.print(OS); |
| 107 | return OS; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /// BitRecTy - 'bit' - Represent a single bit |
| 112 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 113 | class BitRecTy : public RecTy { |
| 114 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 115 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 116 | virtual Init *convertValue( BitInit *BI) { return (Init*)BI; } |
| 117 | virtual Init *convertValue( BitsInit *BI); |
| 118 | virtual Init *convertValue( IntInit *II); |
| 119 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 120 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 121 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 122 | virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; } |
| 123 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 124 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 125 | virtual Init *convertValue( TypedInit *TI); |
| 126 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 127 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 128 | |
| 129 | void print(std::ostream &OS) const { OS << "bit"; } |
| 130 | |
| 131 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 132 | return RHS->baseClassOf(this); |
| 133 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 134 | virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } |
| 135 | virtual bool baseClassOf(const BitsRecTy *RHS) const; |
| 136 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 137 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 138 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 139 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 140 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 141 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 142 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 146 | // BitsRecTy - 'bits<n>' - Represent a fixed number of bits |
| 147 | /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 148 | /// |
| 149 | class BitsRecTy : public RecTy { |
| 150 | unsigned Size; |
| 151 | public: |
| 152 | BitsRecTy(unsigned Sz) : Size(Sz) {} |
| 153 | |
| 154 | unsigned getNumBits() const { return Size; } |
| 155 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 156 | virtual Init *convertValue( UnsetInit *UI); |
| 157 | virtual Init *convertValue( BitInit *UI); |
| 158 | virtual Init *convertValue( BitsInit *BI); |
| 159 | virtual Init *convertValue( IntInit *II); |
| 160 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 161 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 162 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 163 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 164 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 165 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 166 | virtual Init *convertValue( TypedInit *TI); |
| 167 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 168 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 169 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 170 | |
| 171 | void print(std::ostream &OS) const { OS << "bits<" << Size << ">"; } |
| 172 | |
| 173 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 174 | return RHS->baseClassOf(this); |
| 175 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 176 | virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; } |
| 177 | virtual bool baseClassOf(const BitsRecTy *RHS) const { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 178 | return RHS->Size == Size; |
| 179 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 180 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 181 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 182 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 183 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 184 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 185 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 186 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 187 | }; |
| 188 | |
| 189 | |
| 190 | /// IntRecTy - 'int' - Represent an integer value of no particular size |
| 191 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 192 | class IntRecTy : public RecTy { |
| 193 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 194 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 195 | virtual Init *convertValue( BitInit *BI); |
| 196 | virtual Init *convertValue( BitsInit *BI); |
| 197 | virtual Init *convertValue( IntInit *II) { return (Init*)II; } |
| 198 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 199 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 200 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 201 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 202 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 203 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 204 | virtual Init *convertValue( TypedInit *TI); |
| 205 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 206 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 207 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 208 | |
| 209 | void print(std::ostream &OS) const { OS << "int"; } |
| 210 | |
| 211 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 212 | return RHS->baseClassOf(this); |
| 213 | } |
| 214 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 215 | virtual bool baseClassOf(const BitRecTy *RHS) const { return true; } |
| 216 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; } |
| 217 | virtual bool baseClassOf(const IntRecTy *RHS) const { return true; } |
| 218 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 219 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 220 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 221 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 222 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
| 223 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | /// StringRecTy - 'string' - Represent an string value |
| 227 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 228 | class StringRecTy : public RecTy { |
| 229 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 230 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 231 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 232 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 233 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 234 | virtual Init *convertValue(StringInit *SI) { return (Init*)SI; } |
| 235 | virtual Init *convertValue( ListInit *LI) { return 0; } |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 236 | virtual Init *convertValue( BinOpInit *BO); |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 237 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 238 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 239 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 240 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 241 | virtual Init *convertValue( TypedInit *TI); |
| 242 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 243 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 244 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 245 | void print(std::ostream &OS) const { OS << "string"; } |
| 246 | |
| 247 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 248 | return RHS->baseClassOf(this); |
| 249 | } |
| 250 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 251 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 252 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 253 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 254 | virtual bool baseClassOf(const StringRecTy *RHS) const { return true; } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 255 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 256 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 257 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 258 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 259 | }; |
| 260 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 261 | // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of |
| 262 | // the specified type. |
| 263 | /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must |
| 264 | /// be of the specified type. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 265 | /// |
| 266 | class ListRecTy : public RecTy { |
| 267 | RecTy *Ty; |
| 268 | public: |
| 269 | ListRecTy(RecTy *T) : Ty(T) {} |
| 270 | |
| 271 | RecTy *getElementType() const { return Ty; } |
| 272 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 273 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 274 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 275 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 276 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 277 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 278 | virtual Init *convertValue( ListInit *LI); |
| 279 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 280 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 281 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 282 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 283 | virtual Init *convertValue( TypedInit *TI); |
| 284 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 285 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 286 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 287 | void print(std::ostream &OS) const; |
| 288 | |
| 289 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 290 | return RHS->baseClassOf(this); |
| 291 | } |
| 292 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 293 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 294 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 295 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 296 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 297 | virtual bool baseClassOf(const ListRecTy *RHS) const { |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 298 | return RHS->getElementType()->typeIsConvertibleTo(Ty); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 299 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 300 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 301 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 302 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | /// CodeRecTy - 'code' - Represent an code fragment, function or method. |
| 306 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 307 | class CodeRecTy : public RecTy { |
| 308 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 309 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 310 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 311 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 312 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 313 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 314 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 315 | virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; } |
| 316 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 317 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 318 | virtual Init *convertValue( DagInit *DI) { return 0; } |
| 319 | virtual Init *convertValue( TypedInit *TI); |
| 320 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 321 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
| 322 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 323 | |
| 324 | void print(std::ostream &OS) const { OS << "code"; } |
| 325 | |
| 326 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 327 | return RHS->baseClassOf(this); |
| 328 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 329 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 330 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 331 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 332 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 333 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 334 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; } |
| 335 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
| 336 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | /// DagRecTy - 'dag' - Represent a dag fragment |
| 340 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 341 | class DagRecTy : public RecTy { |
| 342 | public: |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 343 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 344 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 345 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 346 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 347 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 348 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 349 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 350 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 351 | virtual Init *convertValue( DefInit *DI) { return 0; } |
| 352 | virtual Init *convertValue( DagInit *CI) { return (Init*)CI; } |
| 353 | virtual Init *convertValue( TypedInit *TI); |
| 354 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 355 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 356 | |
| 357 | void print(std::ostream &OS) const { OS << "dag"; } |
| 358 | |
| 359 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 360 | return RHS->baseClassOf(this); |
| 361 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 362 | |
| 363 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 364 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 365 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 366 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 367 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 368 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 369 | virtual bool baseClassOf(const DagRecTy *RHS) const { return true; } |
| 370 | virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | |
Misha Brukman | b4f20ea | 2004-04-15 15:30:15 +0000 | [diff] [blame] | 374 | /// RecordRecTy - '[classname]' - Represent an instance of a class, such as: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 375 | /// (R32 X = EAX). |
| 376 | /// |
| 377 | class RecordRecTy : public RecTy { |
| 378 | Record *Rec; |
| 379 | public: |
| 380 | RecordRecTy(Record *R) : Rec(R) {} |
| 381 | |
| 382 | Record *getRecord() const { return Rec; } |
| 383 | |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 384 | virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; } |
| 385 | virtual Init *convertValue( BitInit *BI) { return 0; } |
| 386 | virtual Init *convertValue( BitsInit *BI) { return 0; } |
| 387 | virtual Init *convertValue( IntInit *II) { return 0; } |
| 388 | virtual Init *convertValue(StringInit *SI) { return 0; } |
| 389 | virtual Init *convertValue( ListInit *LI) { return 0; } |
| 390 | virtual Init *convertValue( CodeInit *CI) { return 0; } |
| 391 | virtual Init *convertValue(VarBitInit *VB) { return 0; } |
| 392 | virtual Init *convertValue( DefInit *DI); |
| 393 | virtual Init *convertValue( DagInit *DI) { return 0; } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 394 | virtual Init *convertValue( TypedInit *VI); |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 395 | virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);} |
| 396 | virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);} |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 397 | |
| 398 | void print(std::ostream &OS) const; |
| 399 | |
| 400 | bool typeIsConvertibleTo(const RecTy *RHS) const { |
| 401 | return RHS->baseClassOf(this); |
| 402 | } |
Reid Spencer | 1c48c2d | 2004-12-06 23:42:37 +0000 | [diff] [blame] | 403 | virtual bool baseClassOf(const BitRecTy *RHS) const { return false; } |
| 404 | virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; } |
| 405 | virtual bool baseClassOf(const IntRecTy *RHS) const { return false; } |
| 406 | virtual bool baseClassOf(const StringRecTy *RHS) const { return false; } |
| 407 | virtual bool baseClassOf(const ListRecTy *RHS) const { return false; } |
| 408 | virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; } |
| 409 | virtual bool baseClassOf(const DagRecTy *RHS) const { return false; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 410 | virtual bool baseClassOf(const RecordRecTy *RHS) const; |
| 411 | }; |
| 412 | |
| 413 | |
| 414 | |
| 415 | //===----------------------------------------------------------------------===// |
| 416 | // Initializer Classes |
| 417 | //===----------------------------------------------------------------------===// |
| 418 | |
| 419 | struct Init { |
| 420 | virtual ~Init() {} |
| 421 | |
| 422 | /// isComplete - This virtual method should be overridden by values that may |
| 423 | /// not be completely specified yet. |
| 424 | virtual bool isComplete() const { return true; } |
| 425 | |
| 426 | /// print - Print out this value. |
| 427 | virtual void print(std::ostream &OS) const = 0; |
| 428 | |
| 429 | /// dump - Debugging method that may be called through a debugger, just |
| 430 | /// invokes print on cerr. |
| 431 | void dump() const; |
| 432 | |
| 433 | /// convertInitializerTo - This virtual function is a simple call-back |
| 434 | /// function that should be overridden to call the appropriate |
| 435 | /// RecTy::convertValue method. |
| 436 | /// |
| 437 | virtual Init *convertInitializerTo(RecTy *Ty) = 0; |
| 438 | |
| 439 | /// convertInitializerBitRange - This method is used to implement the bitrange |
| 440 | /// selection operator. Given an initializer, it selects the specified bits |
| 441 | /// out, returning them as a new init of bits type. If it is not legal to use |
| 442 | /// the bit subscript operator on this initializer, return null. |
| 443 | /// |
| 444 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) { |
| 445 | return 0; |
| 446 | } |
| 447 | |
Chris Lattner | 8bf9e06 | 2004-07-26 23:21:34 +0000 | [diff] [blame] | 448 | /// convertInitListSlice - This method is used to implement the list slice |
| 449 | /// selection operator. Given an initializer, it selects the specified list |
| 450 | /// elements, returning them as a new init of list type. If it is not legal |
| 451 | /// to take a slice of this, return null. |
| 452 | /// |
| 453 | virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) { |
| 454 | return 0; |
| 455 | } |
| 456 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 457 | /// getFieldType - This method is used to implement the FieldInit class. |
| 458 | /// Implementors of this method should return the type of the named field if |
| 459 | /// they are of record type. |
| 460 | /// |
| 461 | virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; } |
| 462 | |
| 463 | /// getFieldInit - This method complements getFieldType to return the |
| 464 | /// initializer for the specified field. If getFieldType returns non-null |
| 465 | /// this method should return non-null, otherwise it returns null. |
| 466 | /// |
| 467 | virtual Init *getFieldInit(Record &R, const std::string &FieldName) const { |
| 468 | return 0; |
| 469 | } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 470 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 471 | /// resolveReferences - This method is used by classes that refer to other |
| 472 | /// variables which may not be defined at the time they expression is formed. |
| 473 | /// If a value is set for the variable later, this method will be called on |
| 474 | /// users of the value to allow the value to propagate out. |
| 475 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 476 | virtual Init *resolveReferences(Record &R, const RecordVal *RV) { |
| 477 | return this; |
| 478 | } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 479 | }; |
| 480 | |
| 481 | inline std::ostream &operator<<(std::ostream &OS, const Init &I) { |
| 482 | I.print(OS); return OS; |
| 483 | } |
| 484 | |
| 485 | |
| 486 | /// UnsetInit - ? - Represents an uninitialized value |
| 487 | /// |
Chris Lattner | 7dfc2d2 | 2004-10-27 16:14:51 +0000 | [diff] [blame] | 488 | class UnsetInit : public Init { |
| 489 | public: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 490 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 491 | return Ty->convertValue(this); |
| 492 | } |
| 493 | |
| 494 | virtual bool isComplete() const { return false; } |
| 495 | virtual void print(std::ostream &OS) const { OS << "?"; } |
| 496 | }; |
| 497 | |
| 498 | |
| 499 | /// BitInit - true/false - Represent a concrete initializer for a bit. |
| 500 | /// |
| 501 | class BitInit : public Init { |
| 502 | bool Value; |
| 503 | public: |
| 504 | BitInit(bool V) : Value(V) {} |
| 505 | |
| 506 | bool getValue() const { return Value; } |
| 507 | |
| 508 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 509 | return Ty->convertValue(this); |
| 510 | } |
| 511 | |
| 512 | virtual void print(std::ostream &OS) const { OS << (Value ? "1" : "0"); } |
| 513 | }; |
| 514 | |
| 515 | /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value. |
| 516 | /// It contains a vector of bits, whose size is determined by the type. |
| 517 | /// |
| 518 | class BitsInit : public Init { |
| 519 | std::vector<Init*> Bits; |
| 520 | public: |
| 521 | BitsInit(unsigned Size) : Bits(Size) {} |
| 522 | |
| 523 | unsigned getNumBits() const { return Bits.size(); } |
| 524 | |
| 525 | Init *getBit(unsigned Bit) const { |
| 526 | assert(Bit < Bits.size() && "Bit index out of range!"); |
| 527 | return Bits[Bit]; |
| 528 | } |
| 529 | void setBit(unsigned Bit, Init *V) { |
| 530 | assert(Bit < Bits.size() && "Bit index out of range!"); |
| 531 | assert(Bits[Bit] == 0 && "Bit already set!"); |
| 532 | Bits[Bit] = V; |
| 533 | } |
| 534 | |
| 535 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 536 | return Ty->convertValue(this); |
| 537 | } |
| 538 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 539 | |
| 540 | virtual bool isComplete() const { |
| 541 | for (unsigned i = 0; i != getNumBits(); ++i) |
| 542 | if (!getBit(i)->isComplete()) return false; |
| 543 | return true; |
| 544 | } |
| 545 | virtual void print(std::ostream &OS) const; |
| 546 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 547 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 548 | |
| 549 | // printXX - Print this bitstream with the specified format, returning true if |
| 550 | // it is not possible. |
| 551 | bool printInHex(std::ostream &OS) const; |
| 552 | bool printAsVariable(std::ostream &OS) const; |
| 553 | bool printAsUnset(std::ostream &OS) const; |
| 554 | }; |
| 555 | |
| 556 | |
| 557 | /// IntInit - 7 - Represent an initalization by a literal integer value. |
| 558 | /// |
| 559 | class IntInit : public Init { |
| 560 | int Value; |
| 561 | public: |
| 562 | IntInit(int V) : Value(V) {} |
| 563 | |
| 564 | int getValue() const { return Value; } |
| 565 | |
| 566 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 567 | return Ty->convertValue(this); |
| 568 | } |
| 569 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 570 | |
| 571 | virtual void print(std::ostream &OS) const { OS << Value; } |
| 572 | }; |
| 573 | |
| 574 | |
| 575 | /// StringInit - "foo" - Represent an initialization by a string value. |
| 576 | /// |
| 577 | class StringInit : public Init { |
| 578 | std::string Value; |
| 579 | public: |
| 580 | StringInit(const std::string &V) : Value(V) {} |
| 581 | |
| 582 | const std::string &getValue() const { return Value; } |
| 583 | |
| 584 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 585 | return Ty->convertValue(this); |
| 586 | } |
| 587 | |
| 588 | virtual void print(std::ostream &OS) const { OS << "\"" << Value << "\""; } |
| 589 | }; |
| 590 | |
| 591 | /// CodeInit - "[{...}]" - Represent a code fragment. |
| 592 | /// |
| 593 | class CodeInit : public Init { |
| 594 | std::string Value; |
| 595 | public: |
| 596 | CodeInit(const std::string &V) : Value(V) {} |
| 597 | |
| 598 | const std::string getValue() const { return Value; } |
| 599 | |
| 600 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 601 | return Ty->convertValue(this); |
| 602 | } |
| 603 | |
| 604 | virtual void print(std::ostream &OS) const { OS << "[{" << Value << "}]"; } |
| 605 | }; |
| 606 | |
| 607 | /// ListInit - [AL, AH, CL] - Represent a list of defs |
| 608 | /// |
| 609 | class ListInit : public Init { |
| 610 | std::vector<Init*> Values; |
| 611 | public: |
| 612 | ListInit(std::vector<Init*> &Vs) { |
| 613 | Values.swap(Vs); |
| 614 | } |
| 615 | |
| 616 | unsigned getSize() const { return Values.size(); } |
| 617 | Init *getElement(unsigned i) const { |
| 618 | assert(i < Values.size() && "List element index out of range!"); |
| 619 | return Values[i]; |
| 620 | } |
| 621 | |
Chris Lattner | 8bf9e06 | 2004-07-26 23:21:34 +0000 | [diff] [blame] | 622 | Init *convertInitListSlice(const std::vector<unsigned> &Elements); |
| 623 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 624 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 625 | return Ty->convertValue(this); |
| 626 | } |
| 627 | |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 628 | /// resolveReferences - This method is used by classes that refer to other |
| 629 | /// variables which may not be defined at the time they expression is formed. |
| 630 | /// If a value is set for the variable later, this method will be called on |
| 631 | /// users of the value to allow the value to propagate out. |
| 632 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 633 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 634 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 635 | virtual void print(std::ostream &OS) const; |
| 636 | }; |
| 637 | |
Chris Lattner | 51ffbf1 | 2006-03-31 21:53:49 +0000 | [diff] [blame] | 638 | /// BinOpInit - !op (X, Y) - Combine two inits. |
| 639 | /// |
| 640 | class BinOpInit : public Init { |
| 641 | public: |
| 642 | enum BinaryOp { SHL, SRA, SRL, STRCONCAT }; |
| 643 | private: |
| 644 | BinaryOp Opc; |
| 645 | Init *LHS, *RHS; |
| 646 | public: |
| 647 | BinOpInit(BinaryOp opc, Init *lhs, Init *rhs) : Opc(opc), LHS(lhs), RHS(rhs) { |
| 648 | } |
| 649 | |
| 650 | BinaryOp getOpcode() const { return Opc; } |
| 651 | Init *getLHS() const { return LHS; } |
| 652 | Init *getRHS() const { return RHS; } |
| 653 | |
| 654 | // Fold - If possible, fold this to a simpler init. Return this if not |
| 655 | // possible to fold. |
| 656 | Init *Fold(); |
| 657 | |
| 658 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 659 | return Ty->convertValue(this); |
| 660 | } |
| 661 | |
| 662 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
| 663 | |
| 664 | virtual void print(std::ostream &OS) const; |
| 665 | }; |
| 666 | |
| 667 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 668 | |
| 669 | /// TypedInit - This is the common super-class of types that have a specific, |
| 670 | /// explicit, type. |
| 671 | /// |
| 672 | class TypedInit : public Init { |
| 673 | RecTy *Ty; |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 674 | public: |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 675 | TypedInit(RecTy *T) : Ty(T) {} |
| 676 | |
| 677 | RecTy *getType() const { return Ty; } |
| 678 | |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 679 | virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 680 | virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements); |
| 681 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 682 | /// resolveBitReference - This method is used to implement |
| 683 | /// VarBitInit::resolveReferences. If the bit is able to be resolved, we |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 684 | /// simply return the resolved value, otherwise we return null. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 685 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 686 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 687 | unsigned Bit) = 0; |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 688 | |
| 689 | /// resolveListElementReference - This method is used to implement |
| 690 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 691 | /// now, we return the resolved value, otherwise we return null. |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 692 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 693 | unsigned Elt) = 0; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 694 | }; |
| 695 | |
| 696 | /// VarInit - 'Opcode' - Represent a reference to an entire variable object. |
| 697 | /// |
| 698 | class VarInit : public TypedInit { |
| 699 | std::string VarName; |
| 700 | public: |
| 701 | VarInit(const std::string &VN, RecTy *T) : TypedInit(T), VarName(VN) {} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 702 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 703 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 704 | return Ty->convertValue(this); |
| 705 | } |
| 706 | |
| 707 | const std::string &getName() const { return VarName; } |
| 708 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 709 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 710 | unsigned Bit); |
| 711 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 712 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 713 | |
| 714 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
| 715 | virtual Init *getFieldInit(Record &R, const std::string &FieldName) const; |
| 716 | |
| 717 | /// resolveReferences - This method is used by classes that refer to other |
| 718 | /// variables which may not be defined at the time they expression is formed. |
| 719 | /// If a value is set for the variable later, this method will be called on |
| 720 | /// users of the value to allow the value to propagate out. |
| 721 | /// |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 722 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 723 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 724 | virtual void print(std::ostream &OS) const { OS << VarName; } |
| 725 | }; |
| 726 | |
| 727 | |
| 728 | /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field. |
| 729 | /// |
| 730 | class VarBitInit : public Init { |
| 731 | TypedInit *TI; |
| 732 | unsigned Bit; |
| 733 | public: |
| 734 | VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) { |
| 735 | assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) && |
| 736 | ((BitsRecTy*)T->getType())->getNumBits() > B && |
| 737 | "Illegal VarBitInit expression!"); |
| 738 | } |
| 739 | |
| 740 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 741 | return Ty->convertValue(this); |
| 742 | } |
| 743 | |
| 744 | TypedInit *getVariable() const { return TI; } |
| 745 | unsigned getBitNum() const { return Bit; } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 746 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 747 | virtual void print(std::ostream &OS) const { |
| 748 | TI->print(OS); OS << "{" << Bit << "}"; |
| 749 | } |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 750 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 751 | }; |
| 752 | |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 753 | /// VarListElementInit - List[4] - Represent access to one element of a var or |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 754 | /// field. |
| 755 | class VarListElementInit : public TypedInit { |
| 756 | TypedInit *TI; |
| 757 | unsigned Element; |
| 758 | public: |
| 759 | VarListElementInit(TypedInit *T, unsigned E) |
| 760 | : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()), |
| 761 | TI(T), Element(E) { |
| 762 | assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) && |
| 763 | "Illegal VarBitInit expression!"); |
| 764 | } |
| 765 | |
| 766 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 767 | return Ty->convertValue(this); |
| 768 | } |
| 769 | |
| 770 | TypedInit *getVariable() const { return TI; } |
| 771 | unsigned getElementNum() const { return Element; } |
| 772 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 773 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 774 | unsigned Bit); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 775 | |
| 776 | /// resolveListElementReference - This method is used to implement |
| 777 | /// VarListElementInit::resolveReferences. If the list element is resolvable |
| 778 | /// now, we return the resolved value, otherwise we return null. |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 779 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 780 | unsigned Elt); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 781 | |
| 782 | virtual void print(std::ostream &OS) const { |
| 783 | TI->print(OS); OS << "[" << Element << "]"; |
| 784 | } |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 785 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | 577fc3f | 2004-07-27 01:01:21 +0000 | [diff] [blame] | 786 | }; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 787 | |
| 788 | /// DefInit - AL - Represent a reference to a 'def' in the description |
| 789 | /// |
| 790 | class DefInit : public Init { |
| 791 | Record *Def; |
| 792 | public: |
| 793 | DefInit(Record *D) : Def(D) {} |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 794 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 795 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 796 | return Ty->convertValue(this); |
| 797 | } |
| 798 | |
| 799 | Record *getDef() const { return Def; } |
| 800 | |
| 801 | //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits); |
| 802 | |
| 803 | virtual RecTy *getFieldType(const std::string &FieldName) const; |
| 804 | virtual Init *getFieldInit(Record &R, const std::string &FieldName) const; |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 805 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 806 | virtual void print(std::ostream &OS) const; |
| 807 | }; |
| 808 | |
| 809 | |
| 810 | /// FieldInit - X.Y - Represent a reference to a subfield of a variable |
| 811 | /// |
| 812 | class FieldInit : public TypedInit { |
| 813 | Init *Rec; // Record we are referring to |
| 814 | std::string FieldName; // Field we are accessing |
| 815 | public: |
| 816 | FieldInit(Init *R, const std::string &FN) |
| 817 | : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) { |
| 818 | assert(getType() && "FieldInit with non-record type!"); |
| 819 | } |
| 820 | |
| 821 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 822 | return Ty->convertValue(this); |
| 823 | } |
| 824 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 825 | virtual Init *resolveBitReference(Record &R, const RecordVal *RV, |
| 826 | unsigned Bit); |
| 827 | virtual Init *resolveListElementReference(Record &R, const RecordVal *RV, |
| 828 | unsigned Elt); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 829 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 830 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 831 | |
| 832 | virtual void print(std::ostream &OS) const { |
| 833 | Rec->print(OS); OS << "." << FieldName; |
| 834 | } |
| 835 | }; |
| 836 | |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 837 | /// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required |
| 838 | /// to have at least one value then a (possibly empty) list of arguments. Each |
| 839 | /// argument can have a name associated with it. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 840 | /// |
| 841 | class DagInit : public Init { |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 842 | Init *Val; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 843 | std::vector<Init*> Args; |
| 844 | std::vector<std::string> ArgNames; |
| 845 | public: |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 846 | DagInit(Init *V, const std::vector<std::pair<Init*, std::string> > &args) |
| 847 | : Val(V) { |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 848 | Args.reserve(args.size()); |
| 849 | ArgNames.reserve(args.size()); |
| 850 | for (unsigned i = 0, e = args.size(); i != e; ++i) { |
| 851 | Args.push_back(args[i].first); |
| 852 | ArgNames.push_back(args[i].second); |
| 853 | } |
| 854 | } |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 855 | DagInit(Init *V, const std::vector<Init*> &args, |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 856 | const std::vector<std::string> &argNames) |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 857 | : Val(V), Args(args), ArgNames(argNames) { |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 858 | } |
| 859 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 860 | virtual Init *convertInitializerTo(RecTy *Ty) { |
| 861 | return Ty->convertValue(this); |
| 862 | } |
| 863 | |
Chris Lattner | b59cf3c | 2006-03-30 22:50:40 +0000 | [diff] [blame] | 864 | Init *getOperator() const { return Val; } |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 865 | |
| 866 | unsigned getNumArgs() const { return Args.size(); } |
| 867 | Init *getArg(unsigned Num) const { |
| 868 | assert(Num < Args.size() && "Arg number out of range!"); |
| 869 | return Args[Num]; |
| 870 | } |
| 871 | const std::string &getArgName(unsigned Num) const { |
| 872 | assert(Num < ArgNames.size() && "Arg number out of range!"); |
| 873 | return ArgNames[Num]; |
| 874 | } |
| 875 | |
| 876 | void setArg(unsigned Num, Init *I) { |
| 877 | assert(Num < Args.size() && "Arg number out of range!"); |
| 878 | Args[Num] = I; |
| 879 | } |
Chris Lattner | 0d3ef40 | 2006-01-31 06:02:35 +0000 | [diff] [blame] | 880 | |
| 881 | virtual Init *resolveReferences(Record &R, const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 882 | |
| 883 | virtual void print(std::ostream &OS) const; |
| 884 | }; |
| 885 | |
| 886 | //===----------------------------------------------------------------------===// |
| 887 | // High-Level Classes |
| 888 | //===----------------------------------------------------------------------===// |
| 889 | |
| 890 | class RecordVal { |
| 891 | std::string Name; |
| 892 | RecTy *Ty; |
| 893 | unsigned Prefix; |
| 894 | Init *Value; |
| 895 | public: |
| 896 | RecordVal(const std::string &N, RecTy *T, unsigned P); |
| 897 | |
| 898 | const std::string &getName() const { return Name; } |
| 899 | |
| 900 | unsigned getPrefix() const { return Prefix; } |
| 901 | RecTy *getType() const { return Ty; } |
| 902 | Init *getValue() const { return Value; } |
| 903 | |
| 904 | bool setValue(Init *V) { |
| 905 | if (V) { |
| 906 | Value = V->convertInitializerTo(Ty); |
| 907 | return Value == 0; |
| 908 | } |
| 909 | Value = 0; |
| 910 | return false; |
| 911 | } |
| 912 | |
| 913 | void dump() const; |
| 914 | void print(std::ostream &OS, bool PrintSem = true) const; |
| 915 | }; |
| 916 | |
| 917 | inline std::ostream &operator<<(std::ostream &OS, const RecordVal &RV) { |
| 918 | RV.print(OS << " "); |
| 919 | return OS; |
| 920 | } |
| 921 | |
Chris Lattner | 87a1061 | 2004-10-23 04:58:50 +0000 | [diff] [blame] | 922 | class Record { |
Chris Lattner | f9b2edb | 2005-08-19 17:58:49 +0000 | [diff] [blame] | 923 | std::string Name; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 924 | std::vector<std::string> TemplateArgs; |
| 925 | std::vector<RecordVal> Values; |
| 926 | std::vector<Record*> SuperClasses; |
| 927 | public: |
| 928 | |
| 929 | Record(const std::string &N) : Name(N) {} |
| 930 | ~Record() {} |
| 931 | |
| 932 | const std::string &getName() const { return Name; } |
Chris Lattner | ac28425 | 2005-08-19 17:58:11 +0000 | [diff] [blame] | 933 | void setName(const std::string &Name); // Also updates RecordKeeper. |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 934 | const std::vector<std::string> &getTemplateArgs() const { |
| 935 | return TemplateArgs; |
| 936 | } |
| 937 | const std::vector<RecordVal> &getValues() const { return Values; } |
| 938 | const std::vector<Record*> &getSuperClasses() const { return SuperClasses; } |
| 939 | |
| 940 | bool isTemplateArg(const std::string &Name) const { |
| 941 | for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i) |
| 942 | if (TemplateArgs[i] == Name) return true; |
| 943 | return false; |
| 944 | } |
| 945 | |
| 946 | const RecordVal *getValue(const std::string &Name) const { |
| 947 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 948 | if (Values[i].getName() == Name) return &Values[i]; |
| 949 | return 0; |
| 950 | } |
| 951 | RecordVal *getValue(const std::string &Name) { |
| 952 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 953 | if (Values[i].getName() == Name) return &Values[i]; |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | void addTemplateArg(const std::string &Name) { |
| 958 | assert(!isTemplateArg(Name) && "Template arg already defined!"); |
| 959 | TemplateArgs.push_back(Name); |
| 960 | } |
| 961 | |
| 962 | void addValue(const RecordVal &RV) { |
| 963 | assert(getValue(RV.getName()) == 0 && "Value already added!"); |
| 964 | Values.push_back(RV); |
| 965 | } |
| 966 | |
| 967 | void removeValue(const std::string &Name) { |
| 968 | assert(getValue(Name) && "Cannot remove an entry that does not exist!"); |
| 969 | for (unsigned i = 0, e = Values.size(); i != e; ++i) |
| 970 | if (Values[i].getName() == Name) { |
| 971 | Values.erase(Values.begin()+i); |
| 972 | return; |
| 973 | } |
| 974 | assert(0 && "Name does not exist in record!"); |
| 975 | } |
| 976 | |
| 977 | bool isSubClassOf(Record *R) const { |
| 978 | for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) |
| 979 | if (SuperClasses[i] == R) |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 980 | return true; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 981 | return false; |
| 982 | } |
| 983 | |
| 984 | bool isSubClassOf(const std::string &Name) const { |
| 985 | for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i) |
| 986 | if (SuperClasses[i]->getName() == Name) |
| 987 | return true; |
| 988 | return false; |
| 989 | } |
| 990 | |
| 991 | void addSuperClass(Record *R) { |
| 992 | assert(!isSubClassOf(R) && "Already subclassing record!"); |
| 993 | SuperClasses.push_back(R); |
| 994 | } |
| 995 | |
Chris Lattner | ef94374 | 2005-04-19 03:36:21 +0000 | [diff] [blame] | 996 | /// resolveReferences - If there are any field references that refer to fields |
| 997 | /// that have been filled in, we can propagate the values now. |
| 998 | /// |
| 999 | void resolveReferences() { resolveReferencesTo(0); } |
| 1000 | |
| 1001 | /// resolveReferencesTo - If anything in this record refers to RV, replace the |
| 1002 | /// reference to RV with the RHS of RV. If RV is null, we resolve all |
| 1003 | /// possible references. |
| 1004 | void resolveReferencesTo(const RecordVal *RV); |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1005 | |
| 1006 | void dump() const; |
| 1007 | |
| 1008 | //===--------------------------------------------------------------------===// |
| 1009 | // High-level methods useful to tablegen back-ends |
| 1010 | // |
| 1011 | |
| 1012 | /// getValueInit - Return the initializer for a value with the specified name, |
| 1013 | /// or throw an exception if the field does not exist. |
| 1014 | /// |
| 1015 | Init *getValueInit(const std::string &FieldName) const; |
| 1016 | |
| 1017 | /// getValueAsString - This method looks up the specified field and returns |
| 1018 | /// its value as a string, throwing an exception if the field does not exist |
| 1019 | /// or if the value is not a string. |
| 1020 | /// |
| 1021 | std::string getValueAsString(const std::string &FieldName) const; |
| 1022 | |
| 1023 | /// getValueAsBitsInit - This method looks up the specified field and returns |
| 1024 | /// its value as a BitsInit, throwing an exception if the field does not exist |
| 1025 | /// or if the value is not the right type. |
| 1026 | /// |
| 1027 | BitsInit *getValueAsBitsInit(const std::string &FieldName) const; |
| 1028 | |
| 1029 | /// getValueAsListInit - This method looks up the specified field and returns |
| 1030 | /// its value as a ListInit, throwing an exception if the field does not exist |
| 1031 | /// or if the value is not the right type. |
| 1032 | /// |
| 1033 | ListInit *getValueAsListInit(const std::string &FieldName) const; |
| 1034 | |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 1035 | /// getValueAsListOfDefs - This method looks up the specified field and |
| 1036 | /// returnsits value as a vector of records, throwing an exception if the |
| 1037 | /// 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] | 1038 | /// |
Chris Lattner | 7ad0bed | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 1039 | std::vector<Record*> getValueAsListOfDefs(const std::string &FieldName) const; |
Jim Laskey | b04feb6 | 2005-10-28 21:46:31 +0000 | [diff] [blame] | 1040 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1041 | /// getValueAsDef - This method looks up the specified field and returns its |
| 1042 | /// value as a Record, throwing an exception if the field does not exist or if |
| 1043 | /// the value is not the right type. |
| 1044 | /// |
| 1045 | Record *getValueAsDef(const std::string &FieldName) const; |
| 1046 | |
| 1047 | /// getValueAsBit - This method looks up the specified field and returns its |
| 1048 | /// value as a bit, throwing an exception if the field does not exist or if |
| 1049 | /// the value is not the right type. |
| 1050 | /// |
| 1051 | bool getValueAsBit(const std::string &FieldName) const; |
| 1052 | |
| 1053 | /// getValueAsInt - This method looks up the specified field and returns its |
| 1054 | /// value as an int, throwing an exception if the field does not exist or if |
| 1055 | /// the value is not the right type. |
| 1056 | /// |
| 1057 | int getValueAsInt(const std::string &FieldName) const; |
| 1058 | |
| 1059 | /// getValueAsDag - This method looks up the specified field and returns its |
| 1060 | /// value as an Dag, throwing an exception if the field does not exist or if |
| 1061 | /// the value is not the right type. |
| 1062 | /// |
| 1063 | DagInit *getValueAsDag(const std::string &FieldName) const; |
Chris Lattner | ae939eb | 2005-09-13 21:44:28 +0000 | [diff] [blame] | 1064 | |
| 1065 | /// getValueAsCode - This method looks up the specified field and returns |
| 1066 | /// its value as the string data in a CodeInit, throwing an exception if the |
| 1067 | /// field does not exist or if the value is not a code object. |
| 1068 | /// |
| 1069 | std::string getValueAsCode(const std::string &FieldName) const; |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1070 | }; |
| 1071 | |
| 1072 | std::ostream &operator<<(std::ostream &OS, const Record &R); |
| 1073 | |
| 1074 | class RecordKeeper { |
| 1075 | std::map<std::string, Record*> Classes, Defs; |
| 1076 | public: |
| 1077 | ~RecordKeeper() { |
| 1078 | for (std::map<std::string, Record*>::iterator I = Classes.begin(), |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1079 | E = Classes.end(); I != E; ++I) |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1080 | delete I->second; |
| 1081 | for (std::map<std::string, Record*>::iterator I = Defs.begin(), |
Jeff Cohen | 88e7b72 | 2005-04-22 04:13:13 +0000 | [diff] [blame] | 1082 | E = Defs.end(); I != E; ++I) |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1083 | delete I->second; |
| 1084 | } |
Misha Brukman | 650ba8e | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 1085 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1086 | const std::map<std::string, Record*> &getClasses() const { return Classes; } |
| 1087 | const std::map<std::string, Record*> &getDefs() const { return Defs; } |
| 1088 | |
| 1089 | Record *getClass(const std::string &Name) const { |
| 1090 | std::map<std::string, Record*>::const_iterator I = Classes.find(Name); |
| 1091 | return I == Classes.end() ? 0 : I->second; |
| 1092 | } |
| 1093 | Record *getDef(const std::string &Name) const { |
| 1094 | std::map<std::string, Record*>::const_iterator I = Defs.find(Name); |
| 1095 | return I == Defs.end() ? 0 : I->second; |
| 1096 | } |
| 1097 | void addClass(Record *R) { |
| 1098 | assert(getClass(R->getName()) == 0 && "Class already exists!"); |
| 1099 | Classes.insert(std::make_pair(R->getName(), R)); |
| 1100 | } |
| 1101 | void addDef(Record *R) { |
| 1102 | assert(getDef(R->getName()) == 0 && "Def already exists!"); |
| 1103 | Defs.insert(std::make_pair(R->getName(), R)); |
| 1104 | } |
| 1105 | |
Chris Lattner | ac28425 | 2005-08-19 17:58:11 +0000 | [diff] [blame] | 1106 | /// removeClass - Remove, but do not delete, the specified record. |
| 1107 | /// |
| 1108 | void removeClass(const std::string &Name) { |
| 1109 | assert(Classes.count(Name) && "Class does not exist!"); |
| 1110 | Classes.erase(Name); |
| 1111 | } |
| 1112 | /// removeDef - Remove, but do not delete, the specified record. |
| 1113 | /// |
| 1114 | void removeDef(const std::string &Name) { |
| 1115 | assert(Defs.count(Name) && "Def does not exist!"); |
| 1116 | Defs.erase(Name); |
| 1117 | } |
| 1118 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1119 | //===--------------------------------------------------------------------===// |
| 1120 | // High-level helper methods, useful for tablegen backends... |
| 1121 | |
| 1122 | /// getAllDerivedDefinitions - This method returns all concrete definitions |
| 1123 | /// that derive from the specified class name. If a class with the specified |
| 1124 | /// name does not exist, an exception is thrown. |
| 1125 | std::vector<Record*> |
| 1126 | getAllDerivedDefinitions(const std::string &ClassName) const; |
| 1127 | |
| 1128 | |
| 1129 | void dump() const; |
| 1130 | }; |
| 1131 | |
| 1132 | std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK); |
| 1133 | |
| 1134 | extern RecordKeeper Records; |
| 1135 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 1136 | } // End llvm namespace |
| 1137 | |
Chris Lattner | f5bd1b7 | 2003-10-05 19:27:59 +0000 | [diff] [blame] | 1138 | #endif |