1 //===- Record.h - Classes to represent Table Records ------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the main TableGen data structures, including the TableGen
11 // types, values, and high-level data structures.
13 //===----------------------------------------------------------------------===//
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/Support/SourceMgr.h"
20 #include "llvm/Support/DataTypes.h"
21 #include "llvm/Support/raw_ostream.h"
55 class VarListElementInit;
63 //===----------------------------------------------------------------------===//
65 //===----------------------------------------------------------------------===//
70 RecTy() : ListTy(0) {}
73 virtual std::string getAsString() const = 0;
74 void print(raw_ostream &OS) const { OS << getAsString(); }
77 /// typeIsConvertibleTo - Return true if all values of 'this' type can be
78 /// converted to the specified type.
79 virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
81 /// getListTy - Returns the type representing list<this>.
82 ListRecTy *getListTy();
84 public: // These methods should only be called from subclasses of Init
85 virtual const Init *convertValue( const UnsetInit *UI) { return 0; }
86 virtual const Init *convertValue( const BitInit *BI) { return 0; }
87 virtual const Init *convertValue( const BitsInit *BI) { return 0; }
88 virtual const Init *convertValue( const IntInit *II) { return 0; }
89 virtual const Init *convertValue(const StringInit *SI) { return 0; }
90 virtual const Init *convertValue( const ListInit *LI) { return 0; }
91 virtual const Init *convertValue( const UnOpInit *UI) {
92 return convertValue((const TypedInit*)UI);
94 virtual const Init *convertValue( const BinOpInit *UI) {
95 return convertValue((const TypedInit*)UI);
97 virtual const Init *convertValue( const TernOpInit *UI) {
98 return convertValue((const TypedInit*)UI);
100 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
101 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
102 virtual const Init *convertValue( const DefInit *DI) { return 0; }
103 virtual const Init *convertValue( const DagInit *DI) { return 0; }
104 virtual const Init *convertValue( const TypedInit *TI) { return 0; }
105 virtual const Init *convertValue( const VarInit *VI) {
106 return convertValue((const TypedInit*)VI);
108 virtual const Init *convertValue( const FieldInit *FI) {
109 return convertValue((const TypedInit*)FI);
112 public: // These methods should only be called by subclasses of RecTy.
113 // baseClassOf - These virtual methods should be overloaded to return true iff
114 // all values of type 'RHS' can be converted to the 'this' type.
115 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
116 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
117 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
118 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
119 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
120 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
121 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
122 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
125 inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
131 /// BitRecTy - 'bit' - Represent a single bit
133 class BitRecTy : public RecTy {
134 static BitRecTy Shared;
137 static BitRecTy *get() { return &Shared; }
139 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
140 virtual const Init *convertValue( const BitInit *BI) { return (const Init*)BI; }
141 virtual const Init *convertValue( const BitsInit *BI);
142 virtual const Init *convertValue( const IntInit *II);
143 virtual const Init *convertValue(const StringInit *SI) { return 0; }
144 virtual const Init *convertValue( const ListInit *LI) { return 0; }
145 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
146 virtual const Init *convertValue(const VarBitInit *VB) { return (const Init*)VB; }
147 virtual const Init *convertValue( const DefInit *DI) { return 0; }
148 virtual const Init *convertValue( const DagInit *DI) { return 0; }
149 virtual const Init *convertValue( const UnOpInit *UI) { return RecTy::convertValue(UI);}
150 virtual const Init *convertValue( const BinOpInit *UI) { return RecTy::convertValue(UI);}
151 virtual const Init *convertValue( const TernOpInit *UI) { return RecTy::convertValue(UI);}
152 virtual const Init *convertValue( const TypedInit *TI);
153 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
154 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
156 std::string getAsString() const { return "bit"; }
158 bool typeIsConvertibleTo(const RecTy *RHS) const {
159 return RHS->baseClassOf(this);
161 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
162 virtual bool baseClassOf(const BitsRecTy *RHS) const;
163 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
164 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
165 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
166 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
167 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
168 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
173 // BitsRecTy - 'bits<n>' - Represent a fixed number of bits
174 /// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
176 class BitsRecTy : public RecTy {
178 explicit BitsRecTy(unsigned Sz) : Size(Sz) {}
180 static BitsRecTy *get(unsigned Sz);
182 unsigned getNumBits() const { return Size; }
184 virtual const Init *convertValue( const UnsetInit *UI);
185 virtual const Init *convertValue( const BitInit *UI);
186 virtual const Init *convertValue( const BitsInit *BI);
187 virtual const Init *convertValue( const IntInit *II);
188 virtual const Init *convertValue(const StringInit *SI) { return 0; }
189 virtual const Init *convertValue( const ListInit *LI) { return 0; }
190 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
191 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
192 virtual const Init *convertValue( const DefInit *DI) { return 0; }
193 virtual const Init *convertValue( const DagInit *DI) { return 0; }
194 virtual const Init *convertValue( const UnOpInit *UI) { return RecTy::convertValue(UI);}
195 virtual const Init *convertValue( const BinOpInit *UI) { return RecTy::convertValue(UI);}
196 virtual const Init *convertValue( const TernOpInit *UI) { return RecTy::convertValue(UI);}
197 virtual const Init *convertValue( const TypedInit *TI);
198 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
199 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
201 std::string getAsString() const;
203 bool typeIsConvertibleTo(const RecTy *RHS) const {
204 return RHS->baseClassOf(this);
206 virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
207 virtual bool baseClassOf(const BitsRecTy *RHS) const {
208 return RHS->Size == Size;
210 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
211 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
212 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
213 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
214 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
215 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
220 /// IntRecTy - 'int' - Represent an integer value of no particular size
222 class IntRecTy : public RecTy {
223 static IntRecTy Shared;
226 static IntRecTy *get() { return &Shared; }
228 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
229 virtual const Init *convertValue( const BitInit *BI);
230 virtual const Init *convertValue( const BitsInit *BI);
231 virtual const Init *convertValue( const IntInit *II) { return (const Init*)II; }
232 virtual const Init *convertValue(const StringInit *SI) { return 0; }
233 virtual const Init *convertValue( const ListInit *LI) { return 0; }
234 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
235 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
236 virtual const Init *convertValue( const DefInit *DI) { return 0; }
237 virtual const Init *convertValue( const DagInit *DI) { return 0; }
238 virtual const Init *convertValue( const UnOpInit *UI) { return RecTy::convertValue(UI);}
239 virtual const Init *convertValue( const BinOpInit *UI) { return RecTy::convertValue(UI);}
240 virtual const Init *convertValue( const TernOpInit *UI) { return RecTy::convertValue(UI);}
241 virtual const Init *convertValue( const TypedInit *TI);
242 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
243 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
245 std::string getAsString() const { return "int"; }
247 bool typeIsConvertibleTo(const RecTy *RHS) const {
248 return RHS->baseClassOf(this);
251 virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
252 virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
253 virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
254 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
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; }
262 /// StringRecTy - 'string' - Represent an string value
264 class StringRecTy : public RecTy {
265 static StringRecTy Shared;
268 static StringRecTy *get() { return &Shared; }
270 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
271 virtual const Init *convertValue( const BitInit *BI) { return 0; }
272 virtual const Init *convertValue( const BitsInit *BI) { return 0; }
273 virtual const Init *convertValue( const IntInit *II) { return 0; }
274 virtual const Init *convertValue(const StringInit *SI) { return (const Init*)SI; }
275 virtual const Init *convertValue( const ListInit *LI) { return 0; }
276 virtual const Init *convertValue( const UnOpInit *BO);
277 virtual const Init *convertValue( const BinOpInit *BO);
278 virtual const Init *convertValue( const TernOpInit *BO) { return RecTy::convertValue(BO);}
280 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
281 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
282 virtual const Init *convertValue( const DefInit *DI) { return 0; }
283 virtual const Init *convertValue( const DagInit *DI) { return 0; }
284 virtual const Init *convertValue( const TypedInit *TI);
285 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
286 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
288 std::string getAsString() const { return "string"; }
290 bool typeIsConvertibleTo(const RecTy *RHS) const {
291 return RHS->baseClassOf(this);
294 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
295 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
296 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
297 virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
298 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
299 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
300 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
301 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
304 // ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
305 // the specified type.
306 /// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must
307 /// be of the specified type.
309 class ListRecTy : public RecTy {
311 explicit ListRecTy(RecTy *T) : Ty(T) {}
312 friend ListRecTy *RecTy::getListTy();
314 static ListRecTy *get(RecTy *T) { return T->getListTy(); }
315 RecTy *getElementType() const { return Ty; }
317 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
318 virtual const Init *convertValue( const BitInit *BI) { return 0; }
319 virtual const Init *convertValue( const BitsInit *BI) { return 0; }
320 virtual const Init *convertValue( const IntInit *II) { return 0; }
321 virtual const Init *convertValue(const StringInit *SI) { return 0; }
322 virtual const Init *convertValue( const ListInit *LI);
323 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
324 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
325 virtual const Init *convertValue( const DefInit *DI) { return 0; }
326 virtual const Init *convertValue( const DagInit *DI) { return 0; }
327 virtual const Init *convertValue( const UnOpInit *UI) { return RecTy::convertValue(UI);}
328 virtual const Init *convertValue( const BinOpInit *UI) { return RecTy::convertValue(UI);}
329 virtual const Init *convertValue( const TernOpInit *UI) { return RecTy::convertValue(UI);}
330 virtual const Init *convertValue( const TypedInit *TI);
331 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
332 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
334 std::string getAsString() const;
336 bool typeIsConvertibleTo(const RecTy *RHS) const {
337 return RHS->baseClassOf(this);
340 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
341 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
342 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
343 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
344 virtual bool baseClassOf(const ListRecTy *RHS) const {
345 return RHS->getElementType()->typeIsConvertibleTo(Ty);
347 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
348 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
349 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
352 /// CodeRecTy - 'code' - Represent an code fragment, function or method.
354 class CodeRecTy : public RecTy {
355 static CodeRecTy Shared;
358 static CodeRecTy *get() { return &Shared; }
360 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
361 virtual const Init *convertValue( const BitInit *BI) { return 0; }
362 virtual const Init *convertValue( const BitsInit *BI) { return 0; }
363 virtual const Init *convertValue( const IntInit *II) { return 0; }
364 virtual const Init *convertValue(const StringInit *SI) { return 0; }
365 virtual const Init *convertValue( const ListInit *LI) { return 0; }
366 virtual const Init *convertValue( const CodeInit *CI) { return (const Init*)CI; }
367 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
368 virtual const Init *convertValue( const DefInit *DI) { return 0; }
369 virtual const Init *convertValue( const DagInit *DI) { return 0; }
370 virtual const Init *convertValue( const UnOpInit *UI) { return RecTy::convertValue(UI);}
371 virtual const Init *convertValue( const BinOpInit *UI) { return RecTy::convertValue(UI);}
372 virtual const Init *convertValue( const TernOpInit *UI) { return RecTy::convertValue(UI);}
373 virtual const Init *convertValue( const TypedInit *TI);
374 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
375 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
377 std::string getAsString() const { return "code"; }
379 bool typeIsConvertibleTo(const RecTy *RHS) const {
380 return RHS->baseClassOf(this);
382 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
383 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
384 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
385 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
386 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
387 virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; }
388 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
389 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
392 /// DagRecTy - 'dag' - Represent a dag fragment
394 class DagRecTy : public RecTy {
395 static DagRecTy Shared;
398 static DagRecTy *get() { return &Shared; }
400 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
401 virtual const Init *convertValue( const BitInit *BI) { return 0; }
402 virtual const Init *convertValue( const BitsInit *BI) { return 0; }
403 virtual const Init *convertValue( const IntInit *II) { return 0; }
404 virtual const Init *convertValue(const StringInit *SI) { return 0; }
405 virtual const Init *convertValue( const ListInit *LI) { return 0; }
406 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
407 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
408 virtual const Init *convertValue( const DefInit *DI) { return 0; }
409 virtual const Init *convertValue( const UnOpInit *BO);
410 virtual const Init *convertValue( const BinOpInit *BO);
411 virtual const Init *convertValue( const TernOpInit *BO) { return RecTy::convertValue(BO);}
412 virtual const Init *convertValue( const DagInit *CI) { return (const Init*)CI; }
413 virtual const Init *convertValue( const TypedInit *TI);
414 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
415 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
417 std::string getAsString() const { return "dag"; }
419 bool typeIsConvertibleTo(const RecTy *RHS) const {
420 return RHS->baseClassOf(this);
423 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
424 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
425 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
426 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
427 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
428 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
429 virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
430 virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
434 /// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
437 class RecordRecTy : public RecTy {
439 explicit RecordRecTy(Record *R) : Rec(R) {}
442 static RecordRecTy *get(Record *R);
444 Record *getRecord() const { return Rec; }
446 virtual const Init *convertValue( const UnsetInit *UI) { return (const Init*)UI; }
447 virtual const Init *convertValue( const BitInit *BI) { return 0; }
448 virtual const Init *convertValue( const BitsInit *BI) { return 0; }
449 virtual const Init *convertValue( const IntInit *II) { return 0; }
450 virtual const Init *convertValue(const StringInit *SI) { return 0; }
451 virtual const Init *convertValue( const ListInit *LI) { return 0; }
452 virtual const Init *convertValue( const CodeInit *CI) { return 0; }
453 virtual const Init *convertValue(const VarBitInit *VB) { return 0; }
454 virtual const Init *convertValue( const UnOpInit *UI) { return RecTy::convertValue(UI);}
455 virtual const Init *convertValue( const BinOpInit *UI) { return RecTy::convertValue(UI);}
456 virtual const Init *convertValue( const TernOpInit *UI) { return RecTy::convertValue(UI);}
457 virtual const Init *convertValue( const DefInit *DI);
458 virtual const Init *convertValue( const DagInit *DI) { return 0; }
459 virtual const Init *convertValue( const TypedInit *VI);
460 virtual const Init *convertValue( const VarInit *VI) { return RecTy::convertValue(VI);}
461 virtual const Init *convertValue( const FieldInit *FI) { return RecTy::convertValue(FI);}
463 std::string getAsString() const;
465 bool typeIsConvertibleTo(const RecTy *RHS) const {
466 return RHS->baseClassOf(this);
468 virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
469 virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
470 virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
471 virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
472 virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
473 virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
474 virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
475 virtual bool baseClassOf(const RecordRecTy *RHS) const;
478 /// resolveTypes - Find a common type that T1 and T2 convert to.
479 /// Return 0 if no such type exists.
481 RecTy *resolveTypes(RecTy *T1, RecTy *T2);
483 //===----------------------------------------------------------------------===//
484 // Initializer Classes
485 //===----------------------------------------------------------------------===//
491 /// isComplete - This virtual method should be overridden by values that may
492 /// not be completely specified yet.
493 virtual bool isComplete() const { return true; }
495 /// print - Print out this value.
496 void print(raw_ostream &OS) const { OS << getAsString(); }
498 /// getAsString - Convert this value to a string form.
499 virtual std::string getAsString() const = 0;
501 /// dump - Debugging method that may be called through a debugger, just
502 /// invokes print on stderr.
505 /// convertInitializerTo - This virtual function is a simple call-back
506 /// function that should be overridden to call the appropriate
507 /// RecTy::convertValue method.
509 virtual const Init *convertInitializerTo(RecTy *Ty) const = 0;
511 /// convertInitializerBitRange - This method is used to implement the bitrange
512 /// selection operator. Given an initializer, it selects the specified bits
513 /// out, returning them as a new init of bits type. If it is not legal to use
514 /// the bit subscript operator on this initializer, return null.
517 convertInitializerBitRange(const std::vector<unsigned> &Bits) const {
521 /// convertInitListSlice - This method is used to implement the list slice
522 /// selection operator. Given an initializer, it selects the specified list
523 /// elements, returning them as a new init of list type. If it is not legal
524 /// to take a slice of this, return null.
527 convertInitListSlice(const std::vector<unsigned> &Elements) const {
531 /// getFieldType - This method is used to implement the FieldInit class.
532 /// Implementors of this method should return the type of the named field if
533 /// they are of record type.
535 virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
537 /// getFieldInit - This method complements getFieldType to return the
538 /// initializer for the specified field. If getFieldType returns non-null
539 /// this method should return non-null, otherwise it returns null.
541 virtual const Init *getFieldInit(Record &R, const RecordVal *RV,
542 const std::string &FieldName) const {
546 /// resolveReferences - This method is used by classes that refer to other
547 /// variables which may not be defined at the time the expression is formed.
548 /// If a value is set for the variable later, this method will be called on
549 /// users of the value to allow the value to propagate out.
551 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const {
556 inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
557 I.print(OS); return OS;
560 /// TypedInit - This is the common super-class of types that have a specific,
563 class TypedInit : public Init {
566 explicit TypedInit(RecTy *T) : Ty(T) {}
568 RecTy *getType() const { return Ty; }
571 convertInitializerBitRange(const std::vector<unsigned> &Bits) const;
573 convertInitListSlice(const std::vector<unsigned> &Elements) const;
575 /// getFieldType - This method is used to implement the FieldInit class.
576 /// Implementors of this method should return the type of the named field if
577 /// they are of record type.
579 virtual RecTy *getFieldType(const std::string &FieldName) const;
581 /// resolveBitReference - This method is used to implement
582 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
583 /// simply return the resolved value, otherwise we return null.
585 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
586 unsigned Bit) const = 0;
588 /// resolveListElementReference - This method is used to implement
589 /// VarListElementInit::resolveReferences. If the list element is resolvable
590 /// now, we return the resolved value, otherwise we return null.
591 virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV,
592 unsigned Elt) const = 0;
596 /// UnsetInit - ? - Represents an uninitialized value
598 class UnsetInit : public Init {
600 virtual const Init *convertInitializerTo(RecTy *Ty) const {
601 return Ty->convertValue(this);
604 virtual bool isComplete() const { return false; }
605 virtual std::string getAsString() const { return "?"; }
609 /// BitInit - true/false - Represent a concrete initializer for a bit.
611 class BitInit : public Init {
614 explicit BitInit(bool V) : Value(V) {}
616 bool getValue() const { return Value; }
618 virtual const Init *convertInitializerTo(RecTy *Ty) const {
619 return Ty->convertValue(this);
622 virtual std::string getAsString() const { return Value ? "1" : "0"; }
625 /// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
626 /// It contains a vector of bits, whose size is determined by the type.
628 class BitsInit : public Init {
629 std::vector<const Init*> Bits;
631 explicit BitsInit(unsigned Size) : Bits(Size) {}
632 BitsInit(ArrayRef<const Init *> Range) : Bits(Range.begin(), Range.end()) {}
634 unsigned getNumBits() const { return Bits.size(); }
636 const Init *getBit(unsigned Bit) const {
637 assert(Bit < Bits.size() && "Bit index out of range!");
641 virtual const Init *convertInitializerTo(RecTy *Ty) const {
642 return Ty->convertValue(this);
645 convertInitializerBitRange(const std::vector<unsigned> &Bits) const;
647 virtual bool isComplete() const {
648 for (unsigned i = 0; i != getNumBits(); ++i)
649 if (!getBit(i)->isComplete()) return false;
652 bool allInComplete() const {
653 for (unsigned i = 0; i != getNumBits(); ++i)
654 if (getBit(i)->isComplete()) return false;
657 virtual std::string getAsString() const;
659 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
663 /// IntInit - 7 - Represent an initalization by a literal integer value.
665 class IntInit : public TypedInit {
668 explicit IntInit(int64_t V) : TypedInit(IntRecTy::get()), Value(V) {}
670 int64_t getValue() const { return Value; }
672 virtual const Init *convertInitializerTo(RecTy *Ty) const {
673 return Ty->convertValue(this);
676 convertInitializerBitRange(const std::vector<unsigned> &Bits) const;
678 virtual std::string getAsString() const;
680 /// resolveBitReference - This method is used to implement
681 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
682 /// simply return the resolved value, otherwise we return null.
684 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
685 unsigned Bit) const {
686 assert(0 && "Illegal bit reference off int");
690 /// resolveListElementReference - This method is used to implement
691 /// VarListElementInit::resolveReferences. If the list element is resolvable
692 /// now, we return the resolved value, otherwise we return null.
693 virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV,
694 unsigned Elt) const {
695 assert(0 && "Illegal element reference off int");
701 /// StringInit - "foo" - Represent an initialization by a string value.
703 class StringInit : public TypedInit {
706 explicit StringInit(const std::string &V)
707 : TypedInit(StringRecTy::get()), Value(V) {}
709 const std::string &getValue() const { return Value; }
711 virtual const Init *convertInitializerTo(RecTy *Ty) const {
712 return Ty->convertValue(this);
715 virtual std::string getAsString() const { return "\"" + Value + "\""; }
717 /// resolveBitReference - This method is used to implement
718 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
719 /// simply return the resolved value, otherwise we return null.
721 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
722 unsigned Bit) const {
723 assert(0 && "Illegal bit reference off string");
727 /// resolveListElementReference - This method is used to implement
728 /// VarListElementInit::resolveReferences. If the list element is resolvable
729 /// now, we return the resolved value, otherwise we return null.
730 virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV,
731 unsigned Elt) const {
732 assert(0 && "Illegal element reference off string");
737 /// CodeInit - "[{...}]" - Represent a code fragment.
739 class CodeInit : public Init {
742 explicit CodeInit(const std::string &V) : Value(V) {}
744 const std::string &getValue() const { return Value; }
746 virtual const Init *convertInitializerTo(RecTy *Ty) const {
747 return Ty->convertValue(this);
750 virtual std::string getAsString() const { return "[{" + Value + "}]"; }
753 /// ListInit - [AL, AH, CL] - Represent a list of defs
755 class ListInit : public TypedInit {
756 std::vector<const Init*> Values;
758 typedef std::vector<const Init*>::const_iterator const_iterator;
760 explicit ListInit(std::vector<const Init*> &Vs, RecTy *EltTy)
761 : TypedInit(ListRecTy::get(EltTy)) {
764 explicit ListInit(ArrayRef<const Init *> Range, RecTy *EltTy)
765 : TypedInit(ListRecTy::get(EltTy)), Values(Range.begin(), Range.end()) {}
767 unsigned getSize() const { return Values.size(); }
768 const Init *getElement(unsigned i) const {
769 assert(i < Values.size() && "List element index out of range!");
773 Record *getElementAsRecord(unsigned i) const;
775 const Init *convertInitListSlice(const std::vector<unsigned> &Elements) const;
777 virtual const Init *convertInitializerTo(RecTy *Ty) const {
778 return Ty->convertValue(this);
781 /// resolveReferences - This method is used by classes that refer to other
782 /// variables which may not be defined at the time they expression is formed.
783 /// If a value is set for the variable later, this method will be called on
784 /// users of the value to allow the value to propagate out.
786 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
788 virtual std::string getAsString() const;
790 ArrayRef<const Init*> getValues() const { return Values; }
792 inline const_iterator begin() const { return Values.begin(); }
793 inline const_iterator end () const { return Values.end(); }
795 inline size_t size () const { return Values.size(); }
796 inline bool empty() const { return Values.empty(); }
798 /// resolveBitReference - This method is used to implement
799 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
800 /// simply return the resolved value, otherwise we return null.
802 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
803 unsigned Bit) const {
804 assert(0 && "Illegal bit reference off list");
808 /// resolveListElementReference - This method is used to implement
809 /// VarListElementInit::resolveReferences. If the list element is resolvable
810 /// now, we return the resolved value, otherwise we return null.
811 virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV,
816 /// OpInit - Base class for operators
818 class OpInit : public TypedInit {
820 OpInit(RecTy *Type) : TypedInit(Type) {}
822 // Clone - Clone this operator, replacing arguments with the new list
823 virtual const OpInit *clone(std::vector<const Init *> &Operands) const = 0;
825 virtual int getNumOperands() const = 0;
826 virtual const Init *getOperand(int i) const = 0;
828 // Fold - If possible, fold this to a simpler init. Return this if not
830 virtual const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const = 0;
832 virtual const Init *convertInitializerTo(RecTy *Ty) const {
833 return Ty->convertValue(this);
836 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
838 virtual const Init *resolveListElementReference(Record &R,
844 /// UnOpInit - !op (X) - Transform an init.
846 class UnOpInit : public OpInit {
848 enum UnaryOp { CAST, HEAD, TAIL, EMPTY };
853 UnOpInit(UnaryOp opc, const Init *lhs, RecTy *Type) :
854 OpInit(Type), Opc(opc), LHS(lhs) {
857 // Clone - Clone this operator, replacing arguments with the new list
858 virtual const OpInit *clone(std::vector<const Init *> &Operands) const {
859 assert(Operands.size() == 1 &&
860 "Wrong number of operands for unary operation");
861 return new UnOpInit(getOpcode(), *Operands.begin(), getType());
864 int getNumOperands() const { return 1; }
865 const Init *getOperand(int i) const {
866 assert(i == 0 && "Invalid operand id for unary operator");
870 UnaryOp getOpcode() const { return Opc; }
871 const Init *getOperand() const { return LHS; }
873 // Fold - If possible, fold this to a simpler init. Return this if not
875 const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const;
877 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
879 virtual std::string getAsString() const;
882 /// BinOpInit - !op (X, Y) - Combine two inits.
884 class BinOpInit : public OpInit {
886 enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, EQ };
889 const Init *LHS, *RHS;
891 BinOpInit(BinaryOp opc, const Init *lhs, const Init *rhs, RecTy *Type) :
892 OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {
895 // Clone - Clone this operator, replacing arguments with the new list
896 virtual const OpInit *clone(std::vector<const Init *> &Operands) const {
897 assert(Operands.size() == 2 &&
898 "Wrong number of operands for binary operation");
899 return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType());
902 int getNumOperands() const { return 2; }
903 const Init *getOperand(int i) const {
904 assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
912 BinaryOp getOpcode() const { return Opc; }
913 const Init *getLHS() const { return LHS; }
914 const Init *getRHS() const { return RHS; }
916 // Fold - If possible, fold this to a simpler init. Return this if not
918 const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const;
920 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
922 virtual std::string getAsString() const;
925 /// TernOpInit - !op (X, Y, Z) - Combine two inits.
927 class TernOpInit : public OpInit {
929 enum TernaryOp { SUBST, FOREACH, IF };
932 const Init *LHS, *MHS, *RHS;
934 TernOpInit(TernaryOp opc, const Init *lhs, const Init *mhs, const Init *rhs,
936 OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {
939 // Clone - Clone this operator, replacing arguments with the new list
940 virtual const OpInit *clone(std::vector<const Init *> &Operands) const {
941 assert(Operands.size() == 3 &&
942 "Wrong number of operands for ternary operation");
943 return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2],
947 int getNumOperands() const { return 3; }
948 const Init *getOperand(int i) const {
949 assert((i == 0 || i == 1 || i == 2) &&
950 "Invalid operand id for ternary operator");
960 TernaryOp getOpcode() const { return Opc; }
961 const Init *getLHS() const { return LHS; }
962 const Init *getMHS() const { return MHS; }
963 const Init *getRHS() const { return RHS; }
965 // Fold - If possible, fold this to a simpler init. Return this if not
967 const Init *Fold(Record *CurRec, MultiClass *CurMultiClass) const;
969 virtual bool isComplete() const { return false; }
971 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
973 virtual std::string getAsString() const;
977 /// VarInit - 'Opcode' - Represent a reference to an entire variable object.
979 class VarInit : public TypedInit {
982 explicit VarInit(const std::string &VN, RecTy *T)
983 : TypedInit(T), VarName(VN) {}
985 virtual const Init *convertInitializerTo(RecTy *Ty) const {
986 return Ty->convertValue(this);
989 const std::string &getName() const { return VarName; }
991 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
993 virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV,
996 virtual RecTy *getFieldType(const std::string &FieldName) const;
997 virtual const Init *getFieldInit(Record &R, const RecordVal *RV,
998 const std::string &FieldName) const;
1000 /// resolveReferences - This method is used by classes that refer to other
1001 /// variables which may not be defined at the time they expression is formed.
1002 /// If a value is set for the variable later, this method will be called on
1003 /// users of the value to allow the value to propagate out.
1005 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
1007 virtual std::string getAsString() const { return VarName; }
1011 /// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
1013 class VarBitInit : public Init {
1014 const TypedInit *TI;
1017 VarBitInit(const TypedInit *T, unsigned B) : TI(T), Bit(B) {
1018 assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
1019 ((BitsRecTy*)T->getType())->getNumBits() > B &&
1020 "Illegal VarBitInit expression!");
1023 virtual const Init *convertInitializerTo(RecTy *Ty) const {
1024 return Ty->convertValue(this);
1027 const TypedInit *getVariable() const { return TI; }
1028 unsigned getBitNum() const { return Bit; }
1030 virtual std::string getAsString() const;
1031 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
1034 /// VarListElementInit - List[4] - Represent access to one element of a var or
1036 class VarListElementInit : public TypedInit {
1037 const TypedInit *TI;
1040 VarListElementInit(const TypedInit *T, unsigned E)
1041 : TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
1043 assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
1044 "Illegal VarBitInit expression!");
1047 virtual const Init *convertInitializerTo(RecTy *Ty) const {
1048 return Ty->convertValue(this);
1051 const TypedInit *getVariable() const { return TI; }
1052 unsigned getElementNum() const { return Element; }
1054 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
1055 unsigned Bit) const;
1057 /// resolveListElementReference - This method is used to implement
1058 /// VarListElementInit::resolveReferences. If the list element is resolvable
1059 /// now, we return the resolved value, otherwise we return null.
1060 virtual const Init *resolveListElementReference(Record &R,
1061 const RecordVal *RV,
1062 unsigned Elt) const;
1064 virtual std::string getAsString() const;
1065 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
1068 /// DefInit - AL - Represent a reference to a 'def' in the description
1070 class DefInit : public TypedInit {
1072 DefInit(Record *D, RecordRecTy *T) : TypedInit(T), Def(D) {}
1073 friend class Record;
1075 static DefInit *get(Record*);
1077 virtual const Init *convertInitializerTo(RecTy *Ty) const {
1078 return Ty->convertValue(this);
1081 Record *getDef() const { return Def; }
1083 //virtual const Init *
1084 //convertInitializerBitRange(const std::vector<unsigned> &Bits);
1086 virtual RecTy *getFieldType(const std::string &FieldName) const;
1087 virtual const Init *getFieldInit(Record &R, const RecordVal *RV,
1088 const std::string &FieldName) const;
1090 virtual std::string getAsString() const;
1092 /// resolveBitReference - This method is used to implement
1093 /// VarBitInit::resolveReferences. If the bit is able to be resolved, we
1094 /// simply return the resolved value, otherwise we return null.
1096 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
1097 unsigned Bit) const {
1098 assert(0 && "Illegal bit reference off def");
1102 /// resolveListElementReference - This method is used to implement
1103 /// VarListElementInit::resolveReferences. If the list element is resolvable
1104 /// now, we return the resolved value, otherwise we return null.
1105 virtual const Init *resolveListElementReference(Record &R, const RecordVal *RV,
1106 unsigned Elt) const {
1107 assert(0 && "Illegal element reference off def");
1113 /// FieldInit - X.Y - Represent a reference to a subfield of a variable
1115 class FieldInit : public TypedInit {
1116 const Init *Rec; // Record we are referring to
1117 std::string FieldName; // Field we are accessing
1119 FieldInit(const Init *R, const std::string &FN)
1120 : TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
1121 assert(getType() && "FieldInit with non-record type!");
1124 virtual const Init *convertInitializerTo(RecTy *Ty) const {
1125 return Ty->convertValue(this);
1128 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
1129 unsigned Bit) const;
1130 virtual const Init *resolveListElementReference(Record &R,
1131 const RecordVal *RV,
1132 unsigned Elt) const;
1134 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
1136 virtual std::string getAsString() const {
1137 return Rec->getAsString() + "." + FieldName;
1141 /// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required
1142 /// to have at least one value then a (possibly empty) list of arguments. Each
1143 /// argument can have a name associated with it.
1145 class DagInit : public TypedInit {
1147 std::string ValName;
1148 std::vector<const Init*> Args;
1149 std::vector<std::string> ArgNames;
1151 DagInit(const Init *V, std::string VN,
1152 const std::vector<std::pair<const Init*, std::string> > &args)
1153 : TypedInit(DagRecTy::get()), Val(V), ValName(VN) {
1154 Args.reserve(args.size());
1155 ArgNames.reserve(args.size());
1156 for (unsigned i = 0, e = args.size(); i != e; ++i) {
1157 Args.push_back(args[i].first);
1158 ArgNames.push_back(args[i].second);
1161 DagInit(const Init *V, std::string VN, const std::vector<const Init*> &args,
1162 const std::vector<std::string> &argNames)
1163 : TypedInit(DagRecTy::get()), Val(V), ValName(VN), Args(args),
1164 ArgNames(argNames) { }
1166 virtual const Init *convertInitializerTo(RecTy *Ty) const {
1167 return Ty->convertValue(this);
1170 const Init *getOperator() const { return Val; }
1172 const std::string &getName() const { return ValName; }
1174 unsigned getNumArgs() const { return Args.size(); }
1175 const Init *getArg(unsigned Num) const {
1176 assert(Num < Args.size() && "Arg number out of range!");
1179 const std::string &getArgName(unsigned Num) const {
1180 assert(Num < ArgNames.size() && "Arg number out of range!");
1181 return ArgNames[Num];
1184 virtual const Init *resolveReferences(Record &R, const RecordVal *RV) const;
1186 virtual std::string getAsString() const;
1188 typedef std::vector<const Init*>::const_iterator const_arg_iterator;
1189 typedef std::vector<std::string>::const_iterator const_name_iterator;
1191 inline const_arg_iterator arg_begin() const { return Args.begin(); }
1192 inline const_arg_iterator arg_end () const { return Args.end(); }
1194 inline size_t arg_size () const { return Args.size(); }
1195 inline bool arg_empty() const { return Args.empty(); }
1197 inline const_name_iterator name_begin() const { return ArgNames.begin(); }
1198 inline const_name_iterator name_end () const { return ArgNames.end(); }
1200 inline size_t name_size () const { return ArgNames.size(); }
1201 inline bool name_empty() const { return ArgNames.empty(); }
1203 virtual const Init *resolveBitReference(Record &R, const RecordVal *RV,
1204 unsigned Bit) const {
1205 assert(0 && "Illegal bit reference off dag");
1209 virtual const Init *resolveListElementReference(Record &R,
1210 const RecordVal *RV,
1211 unsigned Elt) const {
1212 assert(0 && "Illegal element reference off dag");
1217 //===----------------------------------------------------------------------===//
1218 // High-Level Classes
1219 //===----------------------------------------------------------------------===//
1227 RecordVal(const std::string &N, RecTy *T, unsigned P);
1229 const std::string &getName() const { return Name; }
1231 unsigned getPrefix() const { return Prefix; }
1232 RecTy *getType() const { return Ty; }
1233 const Init *getValue() const { return Value; }
1235 bool setValue(const Init *V) {
1237 Value = V->convertInitializerTo(Ty);
1245 void print(raw_ostream &OS, bool PrintSem = true) const;
1248 inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
1249 RV.print(OS << " ");
1254 static unsigned LastID;
1256 // Unique record ID.
1260 std::vector<std::string> TemplateArgs;
1261 std::vector<RecordVal> Values;
1262 std::vector<Record*> SuperClasses;
1264 // Tracks Record instances. Not owned by Record.
1265 RecordKeeper &TrackedRecords;
1271 // Constructs a record.
1272 explicit Record(const std::string &N, SMLoc loc, RecordKeeper &records) :
1273 ID(LastID++), Name(N), Loc(loc), TrackedRecords(records), TheInit(0) {}
1277 static unsigned getNewUID() { return LastID++; }
1280 unsigned getID() const { return ID; }
1282 const std::string &getName() const { return Name; }
1283 void setName(const std::string &Name); // Also updates RecordKeeper.
1285 SMLoc getLoc() const { return Loc; }
1287 /// get the corresponding DefInit.
1288 DefInit *getDefInit();
1290 const std::vector<std::string> &getTemplateArgs() const {
1291 return TemplateArgs;
1293 const std::vector<RecordVal> &getValues() const { return Values; }
1294 const std::vector<Record*> &getSuperClasses() const { return SuperClasses; }
1296 bool isTemplateArg(StringRef Name) const {
1297 for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
1298 if (TemplateArgs[i] == Name) return true;
1302 const RecordVal *getValue(StringRef Name) const {
1303 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1304 if (Values[i].getName() == Name) return &Values[i];
1307 RecordVal *getValue(StringRef Name) {
1308 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1309 if (Values[i].getName() == Name) return &Values[i];
1313 void addTemplateArg(StringRef Name) {
1314 assert(!isTemplateArg(Name) && "Template arg already defined!");
1315 TemplateArgs.push_back(Name);
1318 void addValue(const RecordVal &RV) {
1319 assert(getValue(RV.getName()) == 0 && "Value already added!");
1320 Values.push_back(RV);
1323 void removeValue(StringRef Name) {
1324 for (unsigned i = 0, e = Values.size(); i != e; ++i)
1325 if (Values[i].getName() == Name) {
1326 Values.erase(Values.begin()+i);
1329 assert(0 && "Cannot remove an entry that does not exist!");
1332 bool isSubClassOf(const Record *R) const {
1333 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
1334 if (SuperClasses[i] == R)
1339 bool isSubClassOf(StringRef Name) const {
1340 for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
1341 if (SuperClasses[i]->getName() == Name)
1346 void addSuperClass(Record *R) {
1347 assert(!isSubClassOf(R) && "Already subclassing record!");
1348 SuperClasses.push_back(R);
1351 /// resolveReferences - If there are any field references that refer to fields
1352 /// that have been filled in, we can propagate the values now.
1354 void resolveReferences() { resolveReferencesTo(0); }
1356 /// resolveReferencesTo - If anything in this record refers to RV, replace the
1357 /// reference to RV with the RHS of RV. If RV is null, we resolve all
1358 /// possible references.
1359 void resolveReferencesTo(const RecordVal *RV);
1361 RecordKeeper &getRecords() const {
1362 return TrackedRecords;
1367 //===--------------------------------------------------------------------===//
1368 // High-level methods useful to tablegen back-ends
1371 /// getValueInit - Return the initializer for a value with the specified name,
1372 /// or throw an exception if the field does not exist.
1374 const Init *getValueInit(StringRef FieldName) const;
1376 /// getValueAsString - This method looks up the specified field and returns
1377 /// its value as a string, throwing an exception if the field does not exist
1378 /// or if the value is not a string.
1380 std::string getValueAsString(StringRef FieldName) const;
1382 /// getValueAsBitsInit - This method looks up the specified field and returns
1383 /// its value as a BitsInit, throwing an exception if the field does not exist
1384 /// or if the value is not the right type.
1386 const BitsInit *getValueAsBitsInit(StringRef FieldName) const;
1388 /// getValueAsListInit - This method looks up the specified field and returns
1389 /// its value as a ListInit, throwing an exception if the field does not exist
1390 /// or if the value is not the right type.
1392 const ListInit *getValueAsListInit(StringRef FieldName) const;
1394 /// getValueAsListOfDefs - This method looks up the specified field and
1395 /// returns its value as a vector of records, throwing an exception if the
1396 /// field does not exist or if the value is not the right type.
1398 std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
1400 /// getValueAsListOfInts - This method looks up the specified field and
1401 /// returns its value as a vector of integers, throwing an exception if the
1402 /// field does not exist or if the value is not the right type.
1404 std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
1406 /// getValueAsListOfStrings - This method looks up the specified field and
1407 /// returns its value as a vector of strings, throwing an exception if the
1408 /// field does not exist or if the value is not the right type.
1410 std::vector<std::string> getValueAsListOfStrings(StringRef FieldName) const;
1412 /// getValueAsDef - This method looks up the specified field and returns its
1413 /// value as a Record, throwing an exception if the field does not exist or if
1414 /// the value is not the right type.
1416 Record *getValueAsDef(StringRef FieldName) const;
1418 /// getValueAsBit - This method looks up the specified field and returns its
1419 /// value as a bit, throwing an exception if the field does not exist or if
1420 /// the value is not the right type.
1422 bool getValueAsBit(StringRef FieldName) const;
1424 /// getValueAsInt - This method looks up the specified field and returns its
1425 /// value as an int64_t, throwing an exception if the field does not exist or
1426 /// if the value is not the right type.
1428 int64_t getValueAsInt(StringRef FieldName) const;
1430 /// getValueAsDag - This method looks up the specified field and returns its
1431 /// value as an Dag, throwing an exception if the field does not exist or if
1432 /// the value is not the right type.
1434 const DagInit *getValueAsDag(StringRef FieldName) const;
1436 /// getValueAsCode - This method looks up the specified field and returns
1437 /// its value as the string data in a CodeInit, throwing an exception if the
1438 /// field does not exist or if the value is not a code object.
1440 std::string getValueAsCode(StringRef FieldName) const;
1443 raw_ostream &operator<<(raw_ostream &OS, const Record &R);
1446 Record Rec; // Placeholder for template args and Name.
1447 typedef std::vector<Record*> RecordVector;
1448 RecordVector DefPrototypes;
1452 MultiClass(const std::string &Name, SMLoc Loc, RecordKeeper &Records) :
1453 Rec(Name, Loc, Records) {}
1456 class RecordKeeper {
1457 std::map<std::string, Record*> Classes, Defs;
1460 for (std::map<std::string, Record*>::iterator I = Classes.begin(),
1461 E = Classes.end(); I != E; ++I)
1463 for (std::map<std::string, Record*>::iterator I = Defs.begin(),
1464 E = Defs.end(); I != E; ++I)
1468 const std::map<std::string, Record*> &getClasses() const { return Classes; }
1469 const std::map<std::string, Record*> &getDefs() const { return Defs; }
1471 Record *getClass(const std::string &Name) const {
1472 std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
1473 return I == Classes.end() ? 0 : I->second;
1475 Record *getDef(const std::string &Name) const {
1476 std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
1477 return I == Defs.end() ? 0 : I->second;
1479 void addClass(Record *R) {
1480 assert(getClass(R->getName()) == 0 && "Class already exists!");
1481 Classes.insert(std::make_pair(R->getName(), R));
1483 void addDef(Record *R) {
1484 assert(getDef(R->getName()) == 0 && "Def already exists!");
1485 Defs.insert(std::make_pair(R->getName(), R));
1488 /// removeClass - Remove, but do not delete, the specified record.
1490 void removeClass(const std::string &Name) {
1491 assert(Classes.count(Name) && "Class does not exist!");
1492 Classes.erase(Name);
1494 /// removeDef - Remove, but do not delete, the specified record.
1496 void removeDef(const std::string &Name) {
1497 assert(Defs.count(Name) && "Def does not exist!");
1501 //===--------------------------------------------------------------------===//
1502 // High-level helper methods, useful for tablegen backends...
1504 /// getAllDerivedDefinitions - This method returns all concrete definitions
1505 /// that derive from the specified class name. If a class with the specified
1506 /// name does not exist, an exception is thrown.
1507 std::vector<Record*>
1508 getAllDerivedDefinitions(const std::string &ClassName) const;
1513 /// LessRecord - Sorting predicate to sort record pointers by name.
1516 bool operator()(const Record *Rec1, const Record *Rec2) const {
1517 return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
1521 /// LessRecordFieldName - Sorting predicate to sort record pointers by their
1524 struct LessRecordFieldName {
1525 bool operator()(const Record *Rec1, const Record *Rec2) const {
1526 return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
1530 raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
1532 } // End llvm namespace