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/Support/SourceMgr.h"
19
#include "llvm/System/DataTypes.h"
20
#include "llvm/Support/raw_ostream.h"
54
class VarListElementInit;
61
//===----------------------------------------------------------------------===//
63
//===----------------------------------------------------------------------===//
68
virtual std::string getAsString() const = 0;
69
void print(raw_ostream &OS) const { OS << getAsString(); }
72
/// typeIsConvertibleTo - Return true if all values of 'this' type can be
73
/// converted to the specified type.
74
virtual bool typeIsConvertibleTo(const RecTy *RHS) const = 0;
76
public: // These methods should only be called from subclasses of Init
77
virtual Init *convertValue( UnsetInit *UI) { return 0; }
78
virtual Init *convertValue( BitInit *BI) { return 0; }
79
virtual Init *convertValue( BitsInit *BI) { return 0; }
80
virtual Init *convertValue( IntInit *II) { return 0; }
81
virtual Init *convertValue(StringInit *SI) { return 0; }
82
virtual Init *convertValue( ListInit *LI) { return 0; }
83
virtual Init *convertValue( UnOpInit *UI) {
84
return convertValue((TypedInit*)UI);
86
virtual Init *convertValue( BinOpInit *UI) {
87
return convertValue((TypedInit*)UI);
89
virtual Init *convertValue( TernOpInit *UI) {
90
return convertValue((TypedInit*)UI);
92
virtual Init *convertValue( CodeInit *CI) { return 0; }
93
virtual Init *convertValue(VarBitInit *VB) { return 0; }
94
virtual Init *convertValue( DefInit *DI) { return 0; }
95
virtual Init *convertValue( DagInit *DI) { return 0; }
96
virtual Init *convertValue( TypedInit *TI) { return 0; }
97
virtual Init *convertValue( VarInit *VI) {
98
return convertValue((TypedInit*)VI);
100
virtual Init *convertValue( FieldInit *FI) {
101
return convertValue((TypedInit*)FI);
104
public: // These methods should only be called by subclasses of RecTy.
105
// baseClassOf - These virtual methods should be overloaded to return true iff
106
// all values of type 'RHS' can be converted to the 'this' type.
107
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
108
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
109
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
110
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
111
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
112
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
113
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
114
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
117
inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
123
/// BitRecTy - 'bit' - Represent a single bit
125
class BitRecTy : public RecTy {
127
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
128
virtual Init *convertValue( BitInit *BI) { return (Init*)BI; }
129
virtual Init *convertValue( BitsInit *BI);
130
virtual Init *convertValue( IntInit *II);
131
virtual Init *convertValue(StringInit *SI) { return 0; }
132
virtual Init *convertValue( ListInit *LI) { return 0; }
133
virtual Init *convertValue( CodeInit *CI) { return 0; }
134
virtual Init *convertValue(VarBitInit *VB) { return (Init*)VB; }
135
virtual Init *convertValue( DefInit *DI) { return 0; }
136
virtual Init *convertValue( DagInit *DI) { return 0; }
137
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
138
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
139
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
140
virtual Init *convertValue( TypedInit *TI);
141
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
142
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
144
std::string getAsString() const { return "bit"; }
146
bool typeIsConvertibleTo(const RecTy *RHS) const {
147
return RHS->baseClassOf(this);
149
virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
150
virtual bool baseClassOf(const BitsRecTy *RHS) const;
151
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
152
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
153
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
154
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
155
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
156
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
161
// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
162
/// BitsRecTy - 'bits<n>' - Represent a fixed number of bits
164
class BitsRecTy : public RecTy {
167
explicit BitsRecTy(unsigned Sz) : Size(Sz) {}
169
unsigned getNumBits() const { return Size; }
171
virtual Init *convertValue( UnsetInit *UI);
172
virtual Init *convertValue( BitInit *UI);
173
virtual Init *convertValue( BitsInit *BI);
174
virtual Init *convertValue( IntInit *II);
175
virtual Init *convertValue(StringInit *SI) { return 0; }
176
virtual Init *convertValue( ListInit *LI) { return 0; }
177
virtual Init *convertValue( CodeInit *CI) { return 0; }
178
virtual Init *convertValue(VarBitInit *VB) { return 0; }
179
virtual Init *convertValue( DefInit *DI) { return 0; }
180
virtual Init *convertValue( DagInit *DI) { return 0; }
181
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
182
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
183
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
184
virtual Init *convertValue( TypedInit *TI);
185
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
186
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
188
std::string getAsString() const;
190
bool typeIsConvertibleTo(const RecTy *RHS) const {
191
return RHS->baseClassOf(this);
193
virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
194
virtual bool baseClassOf(const BitsRecTy *RHS) const {
195
return RHS->Size == Size;
197
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
198
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
199
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
200
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
201
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
202
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
207
/// IntRecTy - 'int' - Represent an integer value of no particular size
209
class IntRecTy : public RecTy {
211
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
212
virtual Init *convertValue( BitInit *BI);
213
virtual Init *convertValue( BitsInit *BI);
214
virtual Init *convertValue( IntInit *II) { return (Init*)II; }
215
virtual Init *convertValue(StringInit *SI) { return 0; }
216
virtual Init *convertValue( ListInit *LI) { return 0; }
217
virtual Init *convertValue( CodeInit *CI) { return 0; }
218
virtual Init *convertValue(VarBitInit *VB) { return 0; }
219
virtual Init *convertValue( DefInit *DI) { return 0; }
220
virtual Init *convertValue( DagInit *DI) { return 0; }
221
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
222
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
223
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
224
virtual Init *convertValue( TypedInit *TI);
225
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
226
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
228
std::string getAsString() const { return "int"; }
230
bool typeIsConvertibleTo(const RecTy *RHS) const {
231
return RHS->baseClassOf(this);
234
virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
235
virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
236
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
237
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
238
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
239
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
240
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
241
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
245
/// StringRecTy - 'string' - Represent an string value
247
class StringRecTy : public RecTy {
249
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
250
virtual Init *convertValue( BitInit *BI) { return 0; }
251
virtual Init *convertValue( BitsInit *BI) { return 0; }
252
virtual Init *convertValue( IntInit *II) { return 0; }
253
virtual Init *convertValue(StringInit *SI) { return (Init*)SI; }
254
virtual Init *convertValue( ListInit *LI) { return 0; }
255
virtual Init *convertValue( UnOpInit *BO);
256
virtual Init *convertValue( BinOpInit *BO);
257
virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
259
virtual Init *convertValue( CodeInit *CI) { return 0; }
260
virtual Init *convertValue(VarBitInit *VB) { return 0; }
261
virtual Init *convertValue( DefInit *DI) { return 0; }
262
virtual Init *convertValue( DagInit *DI) { return 0; }
263
virtual Init *convertValue( TypedInit *TI);
264
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
265
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
267
std::string getAsString() const { return "string"; }
269
bool typeIsConvertibleTo(const RecTy *RHS) const {
270
return RHS->baseClassOf(this);
273
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
274
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
275
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
276
virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
277
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
278
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
279
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
280
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
283
// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
284
// the specified type.
285
/// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must
286
/// be of the specified type.
288
class ListRecTy : public RecTy {
291
explicit ListRecTy(RecTy *T) : Ty(T) {}
293
RecTy *getElementType() const { return Ty; }
295
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
296
virtual Init *convertValue( BitInit *BI) { return 0; }
297
virtual Init *convertValue( BitsInit *BI) { return 0; }
298
virtual Init *convertValue( IntInit *II) { return 0; }
299
virtual Init *convertValue(StringInit *SI) { return 0; }
300
virtual Init *convertValue( ListInit *LI);
301
virtual Init *convertValue( CodeInit *CI) { return 0; }
302
virtual Init *convertValue(VarBitInit *VB) { return 0; }
303
virtual Init *convertValue( DefInit *DI) { return 0; }
304
virtual Init *convertValue( DagInit *DI) { return 0; }
305
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
306
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
307
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
308
virtual Init *convertValue( TypedInit *TI);
309
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
310
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
312
std::string getAsString() const;
314
bool typeIsConvertibleTo(const RecTy *RHS) const {
315
return RHS->baseClassOf(this);
318
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
319
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
320
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
321
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
322
virtual bool baseClassOf(const ListRecTy *RHS) const {
323
return RHS->getElementType()->typeIsConvertibleTo(Ty);
325
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
326
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
327
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
330
/// CodeRecTy - 'code' - Represent an code fragment, function or method.
332
class CodeRecTy : public RecTy {
334
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
335
virtual Init *convertValue( BitInit *BI) { return 0; }
336
virtual Init *convertValue( BitsInit *BI) { return 0; }
337
virtual Init *convertValue( IntInit *II) { return 0; }
338
virtual Init *convertValue(StringInit *SI) { return 0; }
339
virtual Init *convertValue( ListInit *LI) { return 0; }
340
virtual Init *convertValue( CodeInit *CI) { return (Init*)CI; }
341
virtual Init *convertValue(VarBitInit *VB) { return 0; }
342
virtual Init *convertValue( DefInit *DI) { return 0; }
343
virtual Init *convertValue( DagInit *DI) { return 0; }
344
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
345
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
346
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
347
virtual Init *convertValue( TypedInit *TI);
348
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
349
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
351
std::string getAsString() const { return "code"; }
353
bool typeIsConvertibleTo(const RecTy *RHS) const {
354
return RHS->baseClassOf(this);
356
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
357
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
358
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
359
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
360
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
361
virtual bool baseClassOf(const CodeRecTy *RHS) const { return true; }
362
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
363
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
366
/// DagRecTy - 'dag' - Represent a dag fragment
368
class DagRecTy : public RecTy {
370
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
371
virtual Init *convertValue( BitInit *BI) { return 0; }
372
virtual Init *convertValue( BitsInit *BI) { return 0; }
373
virtual Init *convertValue( IntInit *II) { return 0; }
374
virtual Init *convertValue(StringInit *SI) { return 0; }
375
virtual Init *convertValue( ListInit *LI) { return 0; }
376
virtual Init *convertValue( CodeInit *CI) { return 0; }
377
virtual Init *convertValue(VarBitInit *VB) { return 0; }
378
virtual Init *convertValue( DefInit *DI) { return 0; }
379
virtual Init *convertValue( UnOpInit *BO);
380
virtual Init *convertValue( BinOpInit *BO);
381
virtual Init *convertValue( TernOpInit *BO) { return RecTy::convertValue(BO);}
382
virtual Init *convertValue( DagInit *CI) { return (Init*)CI; }
383
virtual Init *convertValue( TypedInit *TI);
384
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
385
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
387
std::string getAsString() const { return "dag"; }
389
bool typeIsConvertibleTo(const RecTy *RHS) const {
390
return RHS->baseClassOf(this);
393
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
394
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
395
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
396
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
397
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
398
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
399
virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
400
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
404
/// RecordRecTy - '[classname]' - Represent an instance of a class, such as:
407
class RecordRecTy : public RecTy {
410
explicit RecordRecTy(Record *R) : Rec(R) {}
412
Record *getRecord() const { return Rec; }
414
virtual Init *convertValue( UnsetInit *UI) { return (Init*)UI; }
415
virtual Init *convertValue( BitInit *BI) { return 0; }
416
virtual Init *convertValue( BitsInit *BI) { return 0; }
417
virtual Init *convertValue( IntInit *II) { return 0; }
418
virtual Init *convertValue(StringInit *SI) { return 0; }
419
virtual Init *convertValue( ListInit *LI) { return 0; }
420
virtual Init *convertValue( CodeInit *CI) { return 0; }
421
virtual Init *convertValue(VarBitInit *VB) { return 0; }
422
virtual Init *convertValue( UnOpInit *UI) { return RecTy::convertValue(UI);}
423
virtual Init *convertValue( BinOpInit *UI) { return RecTy::convertValue(UI);}
424
virtual Init *convertValue( TernOpInit *UI) { return RecTy::convertValue(UI);}
425
virtual Init *convertValue( DefInit *DI);
426
virtual Init *convertValue( DagInit *DI) { return 0; }
427
virtual Init *convertValue( TypedInit *VI);
428
virtual Init *convertValue( VarInit *VI) { return RecTy::convertValue(VI);}
429
virtual Init *convertValue( FieldInit *FI) { return RecTy::convertValue(FI);}
431
std::string getAsString() const;
433
bool typeIsConvertibleTo(const RecTy *RHS) const {
434
return RHS->baseClassOf(this);
436
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
437
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
438
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
439
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
440
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
441
virtual bool baseClassOf(const CodeRecTy *RHS) const { return false; }
442
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
443
virtual bool baseClassOf(const RecordRecTy *RHS) const;
446
/// resolveTypes - Find a common type that T1 and T2 convert to.
447
/// Return 0 if no such type exists.
449
RecTy *resolveTypes(RecTy *T1, RecTy *T2);
451
//===----------------------------------------------------------------------===//
452
// Initializer Classes
453
//===----------------------------------------------------------------------===//
458
/// isComplete - This virtual method should be overridden by values that may
459
/// not be completely specified yet.
460
virtual bool isComplete() const { return true; }
462
/// print - Print out this value.
463
void print(raw_ostream &OS) const { OS << getAsString(); }
465
/// getAsString - Convert this value to a string form.
466
virtual std::string getAsString() const = 0;
468
/// dump - Debugging method that may be called through a debugger, just
469
/// invokes print on stderr.
472
/// convertInitializerTo - This virtual function is a simple call-back
473
/// function that should be overridden to call the appropriate
474
/// RecTy::convertValue method.
476
virtual Init *convertInitializerTo(RecTy *Ty) = 0;
478
/// convertInitializerBitRange - This method is used to implement the bitrange
479
/// selection operator. Given an initializer, it selects the specified bits
480
/// out, returning them as a new init of bits type. If it is not legal to use
481
/// the bit subscript operator on this initializer, return null.
483
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits) {
487
/// convertInitListSlice - This method is used to implement the list slice
488
/// selection operator. Given an initializer, it selects the specified list
489
/// elements, returning them as a new init of list type. If it is not legal
490
/// to take a slice of this, return null.
492
virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements) {
496
/// getFieldType - This method is used to implement the FieldInit class.
497
/// Implementors of this method should return the type of the named field if
498
/// they are of record type.
500
virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
502
/// getFieldInit - This method complements getFieldType to return the
503
/// initializer for the specified field. If getFieldType returns non-null
504
/// this method should return non-null, otherwise it returns null.
506
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
507
const std::string &FieldName) const {
511
/// resolveReferences - This method is used by classes that refer to other
512
/// variables which may not be defined at the time the expression is formed.
513
/// If a value is set for the variable later, this method will be called on
514
/// users of the value to allow the value to propagate out.
516
virtual Init *resolveReferences(Record &R, const RecordVal *RV) {
521
inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
522
I.print(OS); return OS;
525
/// TypedInit - This is the common super-class of types that have a specific,
528
class TypedInit : public Init {
531
explicit TypedInit(RecTy *T) : Ty(T) {}
533
RecTy *getType() const { return Ty; }
535
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
536
virtual Init *convertInitListSlice(const std::vector<unsigned> &Elements);
538
/// getFieldType - This method is used to implement the FieldInit class.
539
/// Implementors of this method should return the type of the named field if
540
/// they are of record type.
542
virtual RecTy *getFieldType(const std::string &FieldName) const;
544
/// resolveBitReference - This method is used to implement
545
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
546
/// simply return the resolved value, otherwise we return null.
548
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
551
/// resolveListElementReference - This method is used to implement
552
/// VarListElementInit::resolveReferences. If the list element is resolvable
553
/// now, we return the resolved value, otherwise we return null.
554
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
559
/// UnsetInit - ? - Represents an uninitialized value
561
class UnsetInit : public Init {
563
virtual Init *convertInitializerTo(RecTy *Ty) {
564
return Ty->convertValue(this);
567
virtual bool isComplete() const { return false; }
568
virtual std::string getAsString() const { return "?"; }
572
/// BitInit - true/false - Represent a concrete initializer for a bit.
574
class BitInit : public Init {
577
explicit BitInit(bool V) : Value(V) {}
579
bool getValue() const { return Value; }
581
virtual Init *convertInitializerTo(RecTy *Ty) {
582
return Ty->convertValue(this);
585
virtual std::string getAsString() const { return Value ? "1" : "0"; }
588
/// BitsInit - { a, b, c } - Represents an initializer for a BitsRecTy value.
589
/// It contains a vector of bits, whose size is determined by the type.
591
class BitsInit : public Init {
592
std::vector<Init*> Bits;
594
explicit BitsInit(unsigned Size) : Bits(Size) {}
596
unsigned getNumBits() const { return Bits.size(); }
598
Init *getBit(unsigned Bit) const {
599
assert(Bit < Bits.size() && "Bit index out of range!");
602
void setBit(unsigned Bit, Init *V) {
603
assert(Bit < Bits.size() && "Bit index out of range!");
604
assert(Bits[Bit] == 0 && "Bit already set!");
608
virtual Init *convertInitializerTo(RecTy *Ty) {
609
return Ty->convertValue(this);
611
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
613
virtual bool isComplete() const {
614
for (unsigned i = 0; i != getNumBits(); ++i)
615
if (!getBit(i)->isComplete()) return false;
618
bool allInComplete() const {
619
for (unsigned i = 0; i != getNumBits(); ++i)
620
if (getBit(i)->isComplete()) return false;
623
virtual std::string getAsString() const;
625
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
629
/// IntInit - 7 - Represent an initalization by a literal integer value.
631
class IntInit : public TypedInit {
634
explicit IntInit(int64_t V) : TypedInit(new IntRecTy), Value(V) {}
636
int64_t getValue() const { return Value; }
638
virtual Init *convertInitializerTo(RecTy *Ty) {
639
return Ty->convertValue(this);
641
virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
643
virtual std::string getAsString() const;
645
/// resolveBitReference - This method is used to implement
646
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
647
/// simply return the resolved value, otherwise we return null.
649
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
651
assert(0 && "Illegal bit reference off int");
655
/// resolveListElementReference - This method is used to implement
656
/// VarListElementInit::resolveReferences. If the list element is resolvable
657
/// now, we return the resolved value, otherwise we return null.
658
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
660
assert(0 && "Illegal element reference off int");
666
/// StringInit - "foo" - Represent an initialization by a string value.
668
class StringInit : public TypedInit {
671
explicit StringInit(const std::string &V)
672
: TypedInit(new StringRecTy), Value(V) {}
674
const std::string &getValue() const { return Value; }
676
virtual Init *convertInitializerTo(RecTy *Ty) {
677
return Ty->convertValue(this);
680
virtual std::string getAsString() const { return "\"" + Value + "\""; }
682
/// resolveBitReference - This method is used to implement
683
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
684
/// simply return the resolved value, otherwise we return null.
686
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
688
assert(0 && "Illegal bit reference off string");
692
/// resolveListElementReference - This method is used to implement
693
/// VarListElementInit::resolveReferences. If the list element is resolvable
694
/// now, we return the resolved value, otherwise we return null.
695
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
697
assert(0 && "Illegal element reference off string");
702
/// CodeInit - "[{...}]" - Represent a code fragment.
704
class CodeInit : public Init {
707
explicit CodeInit(const std::string &V) : Value(V) {}
709
const std::string getValue() const { return Value; }
711
virtual Init *convertInitializerTo(RecTy *Ty) {
712
return Ty->convertValue(this);
715
virtual std::string getAsString() const { return "[{" + Value + "}]"; }
718
/// ListInit - [AL, AH, CL] - Represent a list of defs
720
class ListInit : public TypedInit {
721
std::vector<Init*> Values;
723
typedef std::vector<Init*>::iterator iterator;
724
typedef std::vector<Init*>::const_iterator const_iterator;
726
explicit ListInit(std::vector<Init*> &Vs, RecTy *EltTy)
727
: TypedInit(new ListRecTy(EltTy)) {
730
explicit ListInit(iterator Start, iterator End, RecTy *EltTy)
731
: TypedInit(new ListRecTy(EltTy)), Values(Start, End) {}
733
unsigned getSize() const { return Values.size(); }
734
Init *getElement(unsigned i) const {
735
assert(i < Values.size() && "List element index out of range!");
739
Record *getElementAsRecord(unsigned i) const;
741
Init *convertInitListSlice(const std::vector<unsigned> &Elements);
743
virtual Init *convertInitializerTo(RecTy *Ty) {
744
return Ty->convertValue(this);
747
/// resolveReferences - This method is used by classes that refer to other
748
/// variables which may not be defined at the time they expression is formed.
749
/// If a value is set for the variable later, this method will be called on
750
/// users of the value to allow the value to propagate out.
752
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
754
virtual std::string getAsString() const;
756
inline iterator begin() { return Values.begin(); }
757
inline const_iterator begin() const { return Values.begin(); }
758
inline iterator end () { return Values.end(); }
759
inline const_iterator end () const { return Values.end(); }
761
inline size_t size () const { return Values.size(); }
762
inline bool empty() const { return Values.empty(); }
764
/// resolveBitReference - This method is used to implement
765
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
766
/// simply return the resolved value, otherwise we return null.
768
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
770
assert(0 && "Illegal bit reference off list");
774
/// resolveListElementReference - This method is used to implement
775
/// VarListElementInit::resolveReferences. If the list element is resolvable
776
/// now, we return the resolved value, otherwise we return null.
777
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
782
/// OpInit - Base class for operators
784
class OpInit : public TypedInit {
786
OpInit(RecTy *Type) : TypedInit(Type) {}
788
// Clone - Clone this operator, replacing arguments with the new list
789
virtual OpInit *clone(std::vector<Init *> &Operands) = 0;
791
virtual int getNumOperands() const = 0;
792
virtual Init *getOperand(int i) = 0;
794
// Fold - If possible, fold this to a simpler init. Return this if not
796
virtual Init *Fold(Record *CurRec, MultiClass *CurMultiClass) = 0;
798
virtual Init *convertInitializerTo(RecTy *Ty) {
799
return Ty->convertValue(this);
802
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
804
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
809
/// UnOpInit - !op (X) - Transform an init.
811
class UnOpInit : public OpInit {
813
enum UnaryOp { CAST, CAR, CDR, LNULL };
818
UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type) :
819
OpInit(Type), Opc(opc), LHS(lhs) {
822
// Clone - Clone this operator, replacing arguments with the new list
823
virtual OpInit *clone(std::vector<Init *> &Operands) {
824
assert(Operands.size() == 1 &&
825
"Wrong number of operands for unary operation");
826
return new UnOpInit(getOpcode(), *Operands.begin(), getType());
829
int getNumOperands() const { return 1; }
830
Init *getOperand(int i) {
831
assert(i == 0 && "Invalid operand id for unary operator");
835
UnaryOp getOpcode() const { return Opc; }
836
Init *getOperand() const { return LHS; }
838
// Fold - If possible, fold this to a simpler init. Return this if not
840
Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
842
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
844
virtual std::string getAsString() const;
847
/// BinOpInit - !op (X, Y) - Combine two inits.
849
class BinOpInit : public OpInit {
851
enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT, EQ };
856
BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
857
OpInit(Type), Opc(opc), LHS(lhs), RHS(rhs) {
860
// Clone - Clone this operator, replacing arguments with the new list
861
virtual OpInit *clone(std::vector<Init *> &Operands) {
862
assert(Operands.size() == 2 &&
863
"Wrong number of operands for binary operation");
864
return new BinOpInit(getOpcode(), Operands[0], Operands[1], getType());
867
int getNumOperands() const { return 2; }
868
Init *getOperand(int i) {
869
assert((i == 0 || i == 1) && "Invalid operand id for binary operator");
877
BinaryOp getOpcode() const { return Opc; }
878
Init *getLHS() const { return LHS; }
879
Init *getRHS() const { return RHS; }
881
// Fold - If possible, fold this to a simpler init. Return this if not
883
Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
885
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
887
virtual std::string getAsString() const;
890
/// TernOpInit - !op (X, Y, Z) - Combine two inits.
892
class TernOpInit : public OpInit {
894
enum TernaryOp { SUBST, FOREACH, IF };
897
Init *LHS, *MHS, *RHS;
899
TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, RecTy *Type) :
900
OpInit(Type), Opc(opc), LHS(lhs), MHS(mhs), RHS(rhs) {
903
// Clone - Clone this operator, replacing arguments with the new list
904
virtual OpInit *clone(std::vector<Init *> &Operands) {
905
assert(Operands.size() == 3 &&
906
"Wrong number of operands for ternary operation");
907
return new TernOpInit(getOpcode(), Operands[0], Operands[1], Operands[2],
911
int getNumOperands() const { return 3; }
912
Init *getOperand(int i) {
913
assert((i == 0 || i == 1 || i == 2) &&
914
"Invalid operand id for ternary operator");
924
TernaryOp getOpcode() const { return Opc; }
925
Init *getLHS() const { return LHS; }
926
Init *getMHS() const { return MHS; }
927
Init *getRHS() const { return RHS; }
929
// Fold - If possible, fold this to a simpler init. Return this if not
931
Init *Fold(Record *CurRec, MultiClass *CurMultiClass);
933
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
935
virtual std::string getAsString() const;
939
/// VarInit - 'Opcode' - Represent a reference to an entire variable object.
941
class VarInit : public TypedInit {
944
explicit VarInit(const std::string &VN, RecTy *T)
945
: TypedInit(T), VarName(VN) {}
947
virtual Init *convertInitializerTo(RecTy *Ty) {
948
return Ty->convertValue(this);
951
const std::string &getName() const { return VarName; }
953
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
955
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
958
virtual RecTy *getFieldType(const std::string &FieldName) const;
959
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
960
const std::string &FieldName) const;
962
/// resolveReferences - This method is used by classes that refer to other
963
/// variables which may not be defined at the time they expression is formed.
964
/// If a value is set for the variable later, this method will be called on
965
/// users of the value to allow the value to propagate out.
967
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
969
virtual std::string getAsString() const { return VarName; }
973
/// VarBitInit - Opcode{0} - Represent access to one bit of a variable or field.
975
class VarBitInit : public Init {
979
VarBitInit(TypedInit *T, unsigned B) : TI(T), Bit(B) {
980
assert(T->getType() && dynamic_cast<BitsRecTy*>(T->getType()) &&
981
((BitsRecTy*)T->getType())->getNumBits() > B &&
982
"Illegal VarBitInit expression!");
985
virtual Init *convertInitializerTo(RecTy *Ty) {
986
return Ty->convertValue(this);
989
TypedInit *getVariable() const { return TI; }
990
unsigned getBitNum() const { return Bit; }
992
virtual std::string getAsString() const;
993
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
996
/// VarListElementInit - List[4] - Represent access to one element of a var or
998
class VarListElementInit : public TypedInit {
1002
VarListElementInit(TypedInit *T, unsigned E)
1003
: TypedInit(dynamic_cast<ListRecTy*>(T->getType())->getElementType()),
1005
assert(T->getType() && dynamic_cast<ListRecTy*>(T->getType()) &&
1006
"Illegal VarBitInit expression!");
1009
virtual Init *convertInitializerTo(RecTy *Ty) {
1010
return Ty->convertValue(this);
1013
TypedInit *getVariable() const { return TI; }
1014
unsigned getElementNum() const { return Element; }
1016
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1019
/// resolveListElementReference - This method is used to implement
1020
/// VarListElementInit::resolveReferences. If the list element is resolvable
1021
/// now, we return the resolved value, otherwise we return null.
1022
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1025
virtual std::string getAsString() const;
1026
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
1029
/// DefInit - AL - Represent a reference to a 'def' in the description
1031
class DefInit : public TypedInit {
1034
explicit DefInit(Record *D) : TypedInit(new RecordRecTy(D)), Def(D) {}
1036
virtual Init *convertInitializerTo(RecTy *Ty) {
1037
return Ty->convertValue(this);
1040
Record *getDef() const { return Def; }
1042
//virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
1044
virtual RecTy *getFieldType(const std::string &FieldName) const;
1045
virtual Init *getFieldInit(Record &R, const RecordVal *RV,
1046
const std::string &FieldName) const;
1048
virtual std::string getAsString() const;
1050
/// resolveBitReference - This method is used to implement
1051
/// VarBitInit::resolveReferences. If the bit is able to be resolved, we
1052
/// simply return the resolved value, otherwise we return null.
1054
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1056
assert(0 && "Illegal bit reference off def");
1060
/// resolveListElementReference - This method is used to implement
1061
/// VarListElementInit::resolveReferences. If the list element is resolvable
1062
/// now, we return the resolved value, otherwise we return null.
1063
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1065
assert(0 && "Illegal element reference off def");
1071
/// FieldInit - X.Y - Represent a reference to a subfield of a variable
1073
class FieldInit : public TypedInit {
1074
Init *Rec; // Record we are referring to
1075
std::string FieldName; // Field we are accessing
1077
FieldInit(Init *R, const std::string &FN)
1078
: TypedInit(R->getFieldType(FN)), Rec(R), FieldName(FN) {
1079
assert(getType() && "FieldInit with non-record type!");
1082
virtual Init *convertInitializerTo(RecTy *Ty) {
1083
return Ty->convertValue(this);
1086
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1088
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1091
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
1093
virtual std::string getAsString() const {
1094
return Rec->getAsString() + "." + FieldName;
1098
/// DagInit - (v a, b) - Represent a DAG tree value. DAG inits are required
1099
/// to have at least one value then a (possibly empty) list of arguments. Each
1100
/// argument can have a name associated with it.
1102
class DagInit : public TypedInit {
1104
std::string ValName;
1105
std::vector<Init*> Args;
1106
std::vector<std::string> ArgNames;
1108
DagInit(Init *V, std::string VN,
1109
const std::vector<std::pair<Init*, std::string> > &args)
1110
: TypedInit(new DagRecTy), Val(V), ValName(VN) {
1111
Args.reserve(args.size());
1112
ArgNames.reserve(args.size());
1113
for (unsigned i = 0, e = args.size(); i != e; ++i) {
1114
Args.push_back(args[i].first);
1115
ArgNames.push_back(args[i].second);
1118
DagInit(Init *V, std::string VN, const std::vector<Init*> &args,
1119
const std::vector<std::string> &argNames)
1120
: TypedInit(new DagRecTy), Val(V), ValName(VN), Args(args),
1121
ArgNames(argNames) { }
1123
virtual Init *convertInitializerTo(RecTy *Ty) {
1124
return Ty->convertValue(this);
1127
Init *getOperator() const { return Val; }
1129
const std::string &getName() const { return ValName; }
1131
unsigned getNumArgs() const { return Args.size(); }
1132
Init *getArg(unsigned Num) const {
1133
assert(Num < Args.size() && "Arg number out of range!");
1136
const std::string &getArgName(unsigned Num) const {
1137
assert(Num < ArgNames.size() && "Arg number out of range!");
1138
return ArgNames[Num];
1141
void setArg(unsigned Num, Init *I) {
1142
assert(Num < Args.size() && "Arg number out of range!");
1146
virtual Init *resolveReferences(Record &R, const RecordVal *RV);
1148
virtual std::string getAsString() const;
1150
typedef std::vector<Init*>::iterator arg_iterator;
1151
typedef std::vector<Init*>::const_iterator const_arg_iterator;
1152
typedef std::vector<std::string>::iterator name_iterator;
1153
typedef std::vector<std::string>::const_iterator const_name_iterator;
1155
inline arg_iterator arg_begin() { return Args.begin(); }
1156
inline const_arg_iterator arg_begin() const { return Args.begin(); }
1157
inline arg_iterator arg_end () { return Args.end(); }
1158
inline const_arg_iterator arg_end () const { return Args.end(); }
1160
inline size_t arg_size () const { return Args.size(); }
1161
inline bool arg_empty() const { return Args.empty(); }
1163
inline name_iterator name_begin() { return ArgNames.begin(); }
1164
inline const_name_iterator name_begin() const { return ArgNames.begin(); }
1165
inline name_iterator name_end () { return ArgNames.end(); }
1166
inline const_name_iterator name_end () const { return ArgNames.end(); }
1168
inline size_t name_size () const { return ArgNames.size(); }
1169
inline bool name_empty() const { return ArgNames.empty(); }
1171
virtual Init *resolveBitReference(Record &R, const RecordVal *RV,
1173
assert(0 && "Illegal bit reference off dag");
1177
virtual Init *resolveListElementReference(Record &R, const RecordVal *RV,
1179
assert(0 && "Illegal element reference off dag");
1184
//===----------------------------------------------------------------------===//
1185
// High-Level Classes
1186
//===----------------------------------------------------------------------===//
1194
RecordVal(const std::string &N, RecTy *T, unsigned P);
1196
const std::string &getName() const { return Name; }
1198
unsigned getPrefix() const { return Prefix; }
1199
RecTy *getType() const { return Ty; }
1200
Init *getValue() const { return Value; }
1202
bool setValue(Init *V) {
1204
Value = V->convertInitializerTo(Ty);
1212
void print(raw_ostream &OS, bool PrintSem = true) const;
1215
inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) {
1216
RV.print(OS << " ");
1221
static unsigned LastID;
1223
// Unique record ID.
1227
std::vector<std::string> TemplateArgs;
1228
std::vector<RecordVal> Values;
1229
std::vector<Record*> SuperClasses;
1232
explicit Record(const std::string &N, SMLoc loc) :
1233
ID(LastID++), Name(N), Loc(loc) {}
1237
static unsigned getNewUID() { return LastID++; }
1240
unsigned getID() const { return ID; }
1242
const std::string &getName() const { return Name; }
1243
void setName(const std::string &Name); // Also updates RecordKeeper.
1245
SMLoc getLoc() const { return Loc; }
1247
const std::vector<std::string> &getTemplateArgs() const {
1248
return TemplateArgs;
1250
const std::vector<RecordVal> &getValues() const { return Values; }
1251
const std::vector<Record*> &getSuperClasses() const { return SuperClasses; }
1253
bool isTemplateArg(StringRef Name) const {
1254
for (unsigned i = 0, e = TemplateArgs.size(); i != e; ++i)
1255
if (TemplateArgs[i] == Name) return true;
1259
const RecordVal *getValue(StringRef Name) const {
1260
for (unsigned i = 0, e = Values.size(); i != e; ++i)
1261
if (Values[i].getName() == Name) return &Values[i];
1264
RecordVal *getValue(StringRef Name) {
1265
for (unsigned i = 0, e = Values.size(); i != e; ++i)
1266
if (Values[i].getName() == Name) return &Values[i];
1270
void addTemplateArg(StringRef Name) {
1271
assert(!isTemplateArg(Name) && "Template arg already defined!");
1272
TemplateArgs.push_back(Name);
1275
void addValue(const RecordVal &RV) {
1276
assert(getValue(RV.getName()) == 0 && "Value already added!");
1277
Values.push_back(RV);
1280
void removeValue(StringRef Name) {
1281
for (unsigned i = 0, e = Values.size(); i != e; ++i)
1282
if (Values[i].getName() == Name) {
1283
Values.erase(Values.begin()+i);
1286
assert(0 && "Cannot remove an entry that does not exist!");
1289
bool isSubClassOf(const Record *R) const {
1290
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
1291
if (SuperClasses[i] == R)
1296
bool isSubClassOf(StringRef Name) const {
1297
for (unsigned i = 0, e = SuperClasses.size(); i != e; ++i)
1298
if (SuperClasses[i]->getName() == Name)
1303
void addSuperClass(Record *R) {
1304
assert(!isSubClassOf(R) && "Already subclassing record!");
1305
SuperClasses.push_back(R);
1308
/// resolveReferences - If there are any field references that refer to fields
1309
/// that have been filled in, we can propagate the values now.
1311
void resolveReferences() { resolveReferencesTo(0); }
1313
/// resolveReferencesTo - If anything in this record refers to RV, replace the
1314
/// reference to RV with the RHS of RV. If RV is null, we resolve all
1315
/// possible references.
1316
void resolveReferencesTo(const RecordVal *RV);
1320
//===--------------------------------------------------------------------===//
1321
// High-level methods useful to tablegen back-ends
1324
/// getValueInit - Return the initializer for a value with the specified name,
1325
/// or throw an exception if the field does not exist.
1327
Init *getValueInit(StringRef FieldName) const;
1329
/// getValueAsString - This method looks up the specified field and returns
1330
/// its value as a string, throwing an exception if the field does not exist
1331
/// or if the value is not a string.
1333
std::string getValueAsString(StringRef FieldName) const;
1335
/// getValueAsBitsInit - This method looks up the specified field and returns
1336
/// its value as a BitsInit, throwing an exception if the field does not exist
1337
/// or if the value is not the right type.
1339
BitsInit *getValueAsBitsInit(StringRef FieldName) const;
1341
/// getValueAsListInit - This method looks up the specified field and returns
1342
/// its value as a ListInit, throwing an exception if the field does not exist
1343
/// or if the value is not the right type.
1345
ListInit *getValueAsListInit(StringRef FieldName) const;
1347
/// getValueAsListOfDefs - This method looks up the specified field and
1348
/// returns its value as a vector of records, throwing an exception if the
1349
/// field does not exist or if the value is not the right type.
1351
std::vector<Record*> getValueAsListOfDefs(StringRef FieldName) const;
1353
/// getValueAsListOfInts - This method looks up the specified field and returns
1354
/// its value as a vector of integers, throwing an exception if the field does
1355
/// not exist or if the value is not the right type.
1357
std::vector<int64_t> getValueAsListOfInts(StringRef FieldName) const;
1359
/// getValueAsDef - This method looks up the specified field and returns its
1360
/// value as a Record, throwing an exception if the field does not exist or if
1361
/// the value is not the right type.
1363
Record *getValueAsDef(StringRef FieldName) const;
1365
/// getValueAsBit - This method looks up the specified field and returns its
1366
/// value as a bit, throwing an exception if the field does not exist or if
1367
/// the value is not the right type.
1369
bool getValueAsBit(StringRef FieldName) const;
1371
/// getValueAsInt - This method looks up the specified field and returns its
1372
/// value as an int64_t, throwing an exception if the field does not exist or
1373
/// if the value is not the right type.
1375
int64_t getValueAsInt(StringRef FieldName) const;
1377
/// getValueAsDag - This method looks up the specified field and returns its
1378
/// value as an Dag, throwing an exception if the field does not exist or if
1379
/// the value is not the right type.
1381
DagInit *getValueAsDag(StringRef FieldName) const;
1383
/// getValueAsCode - This method looks up the specified field and returns
1384
/// its value as the string data in a CodeInit, throwing an exception if the
1385
/// field does not exist or if the value is not a code object.
1387
std::string getValueAsCode(StringRef FieldName) const;
1390
raw_ostream &operator<<(raw_ostream &OS, const Record &R);
1393
Record Rec; // Placeholder for template args and Name.
1394
typedef std::vector<Record*> RecordVector;
1395
RecordVector DefPrototypes;
1399
MultiClass(const std::string &Name, SMLoc Loc) : Rec(Name, Loc) {}
1402
class RecordKeeper {
1403
std::map<std::string, Record*> Classes, Defs;
1406
for (std::map<std::string, Record*>::iterator I = Classes.begin(),
1407
E = Classes.end(); I != E; ++I)
1409
for (std::map<std::string, Record*>::iterator I = Defs.begin(),
1410
E = Defs.end(); I != E; ++I)
1414
const std::map<std::string, Record*> &getClasses() const { return Classes; }
1415
const std::map<std::string, Record*> &getDefs() const { return Defs; }
1417
Record *getClass(const std::string &Name) const {
1418
std::map<std::string, Record*>::const_iterator I = Classes.find(Name);
1419
return I == Classes.end() ? 0 : I->second;
1421
Record *getDef(const std::string &Name) const {
1422
std::map<std::string, Record*>::const_iterator I = Defs.find(Name);
1423
return I == Defs.end() ? 0 : I->second;
1425
void addClass(Record *R) {
1426
assert(getClass(R->getName()) == 0 && "Class already exists!");
1427
Classes.insert(std::make_pair(R->getName(), R));
1429
void addDef(Record *R) {
1430
assert(getDef(R->getName()) == 0 && "Def already exists!");
1431
Defs.insert(std::make_pair(R->getName(), R));
1434
/// removeClass - Remove, but do not delete, the specified record.
1436
void removeClass(const std::string &Name) {
1437
assert(Classes.count(Name) && "Class does not exist!");
1438
Classes.erase(Name);
1440
/// removeDef - Remove, but do not delete, the specified record.
1442
void removeDef(const std::string &Name) {
1443
assert(Defs.count(Name) && "Def does not exist!");
1447
//===--------------------------------------------------------------------===//
1448
// High-level helper methods, useful for tablegen backends...
1450
/// getAllDerivedDefinitions - This method returns all concrete definitions
1451
/// that derive from the specified class name. If a class with the specified
1452
/// name does not exist, an exception is thrown.
1453
std::vector<Record*>
1454
getAllDerivedDefinitions(const std::string &ClassName) const;
1460
/// LessRecord - Sorting predicate to sort record pointers by name.
1463
bool operator()(const Record *Rec1, const Record *Rec2) const {
1464
return StringRef(Rec1->getName()).compare_numeric(Rec2->getName()) < 0;
1468
/// LessRecordFieldName - Sorting predicate to sort record pointers by their
1471
struct LessRecordFieldName {
1472
bool operator()(const Record *Rec1, const Record *Rec2) const {
1473
return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
1480
std::string Message;
1482
TGError(SMLoc loc, const std::string &message) : Loc(loc), Message(message) {}
1484
SMLoc getLoc() const { return Loc; }
1485
const std::string &getMessage() const { return Message; }
1489
raw_ostream &operator<<(raw_ostream &OS, const RecordKeeper &RK);
1491
extern RecordKeeper Records;
1493
void PrintError(SMLoc ErrorLoc, const std::string &Msg);
1495
} // End llvm namespace