1 //===- Record.cpp - Record implementation ---------------------------------===//
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 // Implement the tablegen record classes.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/System/DataTypes.h"
16 #include "llvm/Support/Format.h"
17 #include "llvm/ADT/StringExtras.h"
21 //===----------------------------------------------------------------------===//
22 // Type implementations
23 //===----------------------------------------------------------------------===//
25 void RecTy::dump() const { print(errs()); }
27 Init *BitRecTy::convertValue(BitsInit *BI) {
28 if (BI->getNumBits() != 1) return 0; // Only accept if just one bit!
32 bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
33 return RHS->getNumBits() == 1;
36 Init *BitRecTy::convertValue(IntInit *II) {
37 int64_t Val = II->getValue();
38 if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
40 return new BitInit(Val != 0);
43 Init *BitRecTy::convertValue(TypedInit *VI) {
44 if (dynamic_cast<BitRecTy*>(VI->getType()))
45 return VI; // Accept variable if it is already of bit type!
49 std::string BitsRecTy::getAsString() const {
50 return "bits<" + utostr(Size) + ">";
53 Init *BitsRecTy::convertValue(UnsetInit *UI) {
54 BitsInit *Ret = new BitsInit(Size);
56 for (unsigned i = 0; i != Size; ++i)
57 Ret->setBit(i, new UnsetInit());
61 Init *BitsRecTy::convertValue(BitInit *UI) {
62 if (Size != 1) return 0; // Can only convert single bit...
63 BitsInit *Ret = new BitsInit(1);
68 // convertValue from Int initializer to bits type: Split the integer up into the
69 // appropriate bits...
71 Init *BitsRecTy::convertValue(IntInit *II) {
72 int64_t Value = II->getValue();
73 // Make sure this bitfield is large enough to hold the integer value...
75 if (Value & ~((1LL << Size)-1))
78 if ((Value >> Size) != -1 || ((Value & (1LL << (Size-1))) == 0))
82 BitsInit *Ret = new BitsInit(Size);
83 for (unsigned i = 0; i != Size; ++i)
84 Ret->setBit(i, new BitInit(Value & (1LL << i)));
89 Init *BitsRecTy::convertValue(BitsInit *BI) {
90 // If the number of bits is right, return it. Otherwise we need to expand or
92 if (BI->getNumBits() == Size) return BI;
96 Init *BitsRecTy::convertValue(TypedInit *VI) {
97 if (BitsRecTy *BRT = dynamic_cast<BitsRecTy*>(VI->getType()))
98 if (BRT->Size == Size) {
99 BitsInit *Ret = new BitsInit(Size);
100 for (unsigned i = 0; i != Size; ++i)
101 Ret->setBit(i, new VarBitInit(VI, i));
104 if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
105 BitsInit *Ret = new BitsInit(1);
113 Init *IntRecTy::convertValue(BitInit *BI) {
114 return new IntInit(BI->getValue());
117 Init *IntRecTy::convertValue(BitsInit *BI) {
119 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
120 if (BitInit *Bit = dynamic_cast<BitInit*>(BI->getBit(i))) {
121 Result |= Bit->getValue() << i;
125 return new IntInit(Result);
128 Init *IntRecTy::convertValue(TypedInit *TI) {
129 if (TI->getType()->typeIsConvertibleTo(this))
130 return TI; // Accept variable if already of the right type!
134 Init *StringRecTy::convertValue(UnOpInit *BO) {
135 if (BO->getOpcode() == UnOpInit::CAST) {
136 Init *L = BO->getOperand()->convertInitializerTo(this);
137 if (L == 0) return 0;
138 if (L != BO->getOperand())
139 return new UnOpInit(UnOpInit::CAST, L, new StringRecTy);
143 return convertValue((TypedInit*)BO);
146 Init *StringRecTy::convertValue(BinOpInit *BO) {
147 if (BO->getOpcode() == BinOpInit::STRCONCAT) {
148 Init *L = BO->getLHS()->convertInitializerTo(this);
149 Init *R = BO->getRHS()->convertInitializerTo(this);
150 if (L == 0 || R == 0) return 0;
151 if (L != BO->getLHS() || R != BO->getRHS())
152 return new BinOpInit(BinOpInit::STRCONCAT, L, R, new StringRecTy);
155 if (BO->getOpcode() == BinOpInit::NAMECONCAT) {
156 if (BO->getType()->getAsString() == getAsString()) {
157 Init *L = BO->getLHS()->convertInitializerTo(this);
158 Init *R = BO->getRHS()->convertInitializerTo(this);
159 if (L == 0 || R == 0) return 0;
160 if (L != BO->getLHS() || R != BO->getRHS())
161 return new BinOpInit(BinOpInit::NAMECONCAT, L, R, new StringRecTy);
166 return convertValue((TypedInit*)BO);
170 Init *StringRecTy::convertValue(TypedInit *TI) {
171 if (dynamic_cast<StringRecTy*>(TI->getType()))
172 return TI; // Accept variable if already of the right type!
176 std::string ListRecTy::getAsString() const {
177 return "list<" + Ty->getAsString() + ">";
180 Init *ListRecTy::convertValue(ListInit *LI) {
181 std::vector<Init*> Elements;
183 // Verify that all of the elements of the list are subclasses of the
184 // appropriate class!
185 for (unsigned i = 0, e = LI->getSize(); i != e; ++i)
186 if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty))
187 Elements.push_back(CI);
191 ListRecTy *LType = dynamic_cast<ListRecTy*>(LI->getType());
196 return new ListInit(Elements, new ListRecTy(Ty));
199 Init *ListRecTy::convertValue(TypedInit *TI) {
200 // Ensure that TI is compatible with our class.
201 if (ListRecTy *LRT = dynamic_cast<ListRecTy*>(TI->getType()))
202 if (LRT->getElementType()->typeIsConvertibleTo(getElementType()))
207 Init *CodeRecTy::convertValue(TypedInit *TI) {
208 if (TI->getType()->typeIsConvertibleTo(this))
213 Init *DagRecTy::convertValue(TypedInit *TI) {
214 if (TI->getType()->typeIsConvertibleTo(this))
219 Init *DagRecTy::convertValue(UnOpInit *BO) {
220 if (BO->getOpcode() == UnOpInit::CAST) {
221 Init *L = BO->getOperand()->convertInitializerTo(this);
222 if (L == 0) return 0;
223 if (L != BO->getOperand())
224 return new UnOpInit(UnOpInit::CAST, L, new DagRecTy);
230 Init *DagRecTy::convertValue(BinOpInit *BO) {
231 if (BO->getOpcode() == BinOpInit::CONCAT) {
232 Init *L = BO->getLHS()->convertInitializerTo(this);
233 Init *R = BO->getRHS()->convertInitializerTo(this);
234 if (L == 0 || R == 0) return 0;
235 if (L != BO->getLHS() || R != BO->getRHS())
236 return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
239 if (BO->getOpcode() == BinOpInit::NAMECONCAT) {
240 if (BO->getType()->getAsString() == getAsString()) {
241 Init *L = BO->getLHS()->convertInitializerTo(this);
242 Init *R = BO->getRHS()->convertInitializerTo(this);
243 if (L == 0 || R == 0) return 0;
244 if (L != BO->getLHS() || R != BO->getRHS())
245 return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
252 std::string RecordRecTy::getAsString() const {
253 return Rec->getName();
256 Init *RecordRecTy::convertValue(DefInit *DI) {
257 // Ensure that DI is a subclass of Rec.
258 if (!DI->getDef()->isSubClassOf(Rec))
263 Init *RecordRecTy::convertValue(TypedInit *TI) {
264 // Ensure that TI is compatible with Rec.
265 if (RecordRecTy *RRT = dynamic_cast<RecordRecTy*>(TI->getType()))
266 if (RRT->getRecord()->isSubClassOf(getRecord()) ||
267 RRT->getRecord() == getRecord())
272 bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const {
273 return Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec);
277 /// resolveTypes - Find a common type that T1 and T2 convert to.
278 /// Return 0 if no such type exists.
280 RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
281 if (!T1->typeIsConvertibleTo(T2)) {
282 if (!T2->typeIsConvertibleTo(T1)) {
283 // If one is a Record type, check superclasses
284 RecordRecTy *RecTy1 = dynamic_cast<RecordRecTy*>(T1);
286 // See if T2 inherits from a type T1 also inherits from
287 const std::vector<Record *> &T1SuperClasses = RecTy1->getRecord()->getSuperClasses();
288 for(std::vector<Record *>::const_iterator i = T1SuperClasses.begin(),
289 iend = T1SuperClasses.end();
292 RecordRecTy *SuperRecTy1 = new RecordRecTy(*i);
293 RecTy *NewType1 = resolveTypes(SuperRecTy1, T2);
295 if (NewType1 != SuperRecTy1) {
302 RecordRecTy *RecTy2 = dynamic_cast<RecordRecTy*>(T2);
304 // See if T1 inherits from a type T2 also inherits from
305 const std::vector<Record *> &T2SuperClasses = RecTy2->getRecord()->getSuperClasses();
306 for(std::vector<Record *>::const_iterator i = T2SuperClasses.begin(),
307 iend = T2SuperClasses.end();
310 RecordRecTy *SuperRecTy2 = new RecordRecTy(*i);
311 RecTy *NewType2 = resolveTypes(T1, SuperRecTy2);
313 if (NewType2 != SuperRecTy2) {
328 //===----------------------------------------------------------------------===//
329 // Initializer implementations
330 //===----------------------------------------------------------------------===//
332 void Init::dump() const { return print(errs()); }
334 Init *BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
335 BitsInit *BI = new BitsInit(Bits.size());
336 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
337 if (Bits[i] >= getNumBits()) {
341 BI->setBit(i, getBit(Bits[i]));
346 std::string BitsInit::getAsString() const {
347 //if (!printInHex(OS)) return;
348 //if (!printAsVariable(OS)) return;
349 //if (!printAsUnset(OS)) return;
351 std::string Result = "{ ";
352 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
353 if (i) Result += ", ";
354 if (Init *Bit = getBit(e-i-1))
355 Result += Bit->getAsString();
359 return Result + " }";
362 bool BitsInit::printInHex(raw_ostream &OS) const {
363 // First, attempt to convert the value into an integer value...
365 for (unsigned i = 0, e = getNumBits(); i != e; ++i)
366 if (BitInit *Bit = dynamic_cast<BitInit*>(getBit(i))) {
367 Result |= Bit->getValue() << i;
372 OS << format("0x%x", Result);
376 bool BitsInit::printAsVariable(raw_ostream &OS) const {
377 // Get the variable that we may be set equal to...
378 assert(getNumBits() != 0);
379 VarBitInit *FirstBit = dynamic_cast<VarBitInit*>(getBit(0));
380 if (FirstBit == 0) return true;
381 TypedInit *Var = FirstBit->getVariable();
383 // Check to make sure the types are compatible.
384 BitsRecTy *Ty = dynamic_cast<BitsRecTy*>(FirstBit->getVariable()->getType());
385 if (Ty == 0) return true;
386 if (Ty->getNumBits() != getNumBits()) return true; // Incompatible types!
388 // Check to make sure all bits are referring to the right bits in the variable
389 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
390 VarBitInit *Bit = dynamic_cast<VarBitInit*>(getBit(i));
391 if (Bit == 0 || Bit->getVariable() != Var || Bit->getBitNum() != i)
399 bool BitsInit::printAsUnset(raw_ostream &OS) const {
400 for (unsigned i = 0, e = getNumBits(); i != e; ++i)
401 if (!dynamic_cast<UnsetInit*>(getBit(i)))
407 // resolveReferences - If there are any field references that refer to fields
408 // that have been filled in, we can propagate the values now.
410 Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) {
411 bool Changed = false;
412 BitsInit *New = new BitsInit(getNumBits());
414 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
416 Init *CurBit = getBit(i);
420 CurBit = CurBit->resolveReferences(R, RV);
421 Changed |= B != CurBit;
422 } while (B != CurBit);
423 New->setBit(i, CurBit);
432 std::string IntInit::getAsString() const {
433 return itostr(Value);
436 Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
437 BitsInit *BI = new BitsInit(Bits.size());
439 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
444 BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i])));
449 Init *ListInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
450 std::vector<Init*> Vals;
451 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
452 if (Elements[i] >= getSize())
454 Vals.push_back(getElement(Elements[i]));
456 return new ListInit(Vals, getType());
459 Record *ListInit::getElementAsRecord(unsigned i) const {
460 assert(i < Values.size() && "List element index out of range!");
461 DefInit *DI = dynamic_cast<DefInit*>(Values[i]);
462 if (DI == 0) throw "Expected record in list!";
466 Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) {
467 std::vector<Init*> Resolved;
468 Resolved.reserve(getSize());
469 bool Changed = false;
471 for (unsigned i = 0, e = getSize(); i != e; ++i) {
473 Init *CurElt = getElement(i);
477 CurElt = CurElt->resolveReferences(R, RV);
478 Changed |= E != CurElt;
479 } while (E != CurElt);
480 Resolved.push_back(E);
484 return new ListInit(Resolved, getType());
488 Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV,
490 if (Elt >= getSize())
491 return 0; // Out of range reference.
492 Init *E = getElement(Elt);
493 // If the element is set to some value, or if we are resolving a reference
494 // to a specific variable and that variable is explicitly unset, then
495 // replace the VarListElementInit with it.
496 if (IRV || !dynamic_cast<UnsetInit*>(E))
501 std::string ListInit::getAsString() const {
502 std::string Result = "[";
503 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
504 if (i) Result += ", ";
505 Result += Values[i]->getAsString();
510 Init *OpInit::resolveBitReference(Record &R, const RecordVal *IRV,
512 Init *Folded = Fold(&R, 0);
514 if (Folded != this) {
515 TypedInit *Typed = dynamic_cast<TypedInit *>(Folded);
517 return Typed->resolveBitReference(R, IRV, Bit);
524 Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
526 Init *Folded = Fold(&R, 0);
528 if (Folded != this) {
529 TypedInit *Typed = dynamic_cast<TypedInit *>(Folded);
531 return Typed->resolveListElementReference(R, IRV, Elt);
538 Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
539 switch (getOpcode()) {
540 default: assert(0 && "Unknown unop");
542 if (getType()->getAsString() == "string") {
543 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
548 DefInit *LHSd = dynamic_cast<DefInit*>(LHS);
550 return new StringInit(LHSd->getDef()->getName());
554 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
556 std::string Name = LHSs->getValue();
558 // From TGParser::ParseIDValue
560 if (const RecordVal *RV = CurRec->getValue(Name)) {
561 if (RV->getType() != getType()) {
562 throw "type mismatch in nameconcat";
564 return new VarInit(Name, RV->getType());
567 std::string TemplateArgName = CurRec->getName()+":"+Name;
568 if (CurRec->isTemplateArg(TemplateArgName)) {
569 const RecordVal *RV = CurRec->getValue(TemplateArgName);
570 assert(RV && "Template arg doesn't exist??");
572 if (RV->getType() != getType()) {
573 throw "type mismatch in nameconcat";
576 return new VarInit(TemplateArgName, RV->getType());
581 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
582 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
583 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
584 assert(RV && "Template arg doesn't exist??");
586 if (RV->getType() != getType()) {
587 throw "type mismatch in nameconcat";
590 return new VarInit(MCName, RV->getType());
594 if (Record *D = Records.getDef(Name))
595 return new DefInit(D);
597 errs() << "Variable not defined: '" + Name + "'\n";
598 assert(0 && "Variable not found");
605 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
607 if (LHSl->getSize() == 0) {
608 assert(0 && "Empty list in car");
611 return LHSl->getElement(0);
616 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
618 if (LHSl->getSize() == 0) {
619 assert(0 && "Empty list in cdr");
622 ListInit *Result = new ListInit(LHSl->begin()+1, LHSl->end(), LHSl->getType());
628 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
630 if (LHSl->getSize() == 0) {
631 return new IntInit(1);
634 return new IntInit(0);
637 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
639 if (LHSs->getValue().empty()) {
640 return new IntInit(1);
643 return new IntInit(0);
653 Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) {
654 Init *lhs = LHS->resolveReferences(R, RV);
657 return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
661 std::string UnOpInit::getAsString() const {
664 case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
665 case CAR: Result = "!car"; break;
666 case CDR: Result = "!cdr"; break;
667 case LNULL: Result = "!null"; break;
669 return Result + "(" + LHS->getAsString() + ")";
672 RecTy *UnOpInit::getFieldType(const std::string &FieldName) const {
673 switch (getOpcode()) {
674 default: assert(0 && "Unknown unop");
676 RecordRecTy *RecordType = dynamic_cast<RecordRecTy *>(getType());
678 RecordVal *Field = RecordType->getRecord()->getValue(FieldName);
680 return Field->getType();
689 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
690 switch (getOpcode()) {
691 default: assert(0 && "Unknown binop");
693 DagInit *LHSs = dynamic_cast<DagInit*>(LHS);
694 DagInit *RHSs = dynamic_cast<DagInit*>(RHS);
696 DefInit *LOp = dynamic_cast<DefInit*>(LHSs->getOperator());
697 DefInit *ROp = dynamic_cast<DefInit*>(RHSs->getOperator());
698 if (LOp->getDef() != ROp->getDef()) {
700 LOp->getDef()->getName() == "outs" ||
701 LOp->getDef()->getName() != "ins" ||
702 LOp->getDef()->getName() != "defs";
704 ROp->getDef()->getName() == "outs" ||
705 ROp->getDef()->getName() != "ins" ||
706 ROp->getDef()->getName() != "defs";
707 if (!LIsOps || !RIsOps)
708 throw "Concated Dag operators do not match!";
710 std::vector<Init*> Args;
711 std::vector<std::string> ArgNames;
712 for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
713 Args.push_back(LHSs->getArg(i));
714 ArgNames.push_back(LHSs->getArgName(i));
716 for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
717 Args.push_back(RHSs->getArg(i));
718 ArgNames.push_back(RHSs->getArgName(i));
720 return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
725 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
726 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
728 return new StringInit(LHSs->getValue() + RHSs->getValue());
732 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
733 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
735 std::string Name(LHSs->getValue() + RHSs->getValue());
737 // From TGParser::ParseIDValue
739 if (const RecordVal *RV = CurRec->getValue(Name)) {
740 if (RV->getType() != getType()) {
741 throw "type mismatch in nameconcat";
743 return new VarInit(Name, RV->getType());
746 std::string TemplateArgName = CurRec->getName()+":"+Name;
747 if (CurRec->isTemplateArg(TemplateArgName)) {
748 const RecordVal *RV = CurRec->getValue(TemplateArgName);
749 assert(RV && "Template arg doesn't exist??");
751 if (RV->getType() != getType()) {
752 throw "type mismatch in nameconcat";
755 return new VarInit(TemplateArgName, RV->getType());
760 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
761 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
762 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
763 assert(RV && "Template arg doesn't exist??");
765 if (RV->getType() != getType()) {
766 throw "type mismatch in nameconcat";
769 return new VarInit(MCName, RV->getType());
773 if (Record *D = Records.getDef(Name))
774 return new DefInit(D);
776 errs() << "Variable not defined in !nameconcat: '" + Name + "'\n";
777 assert(0 && "Variable not found in !nameconcat");
785 IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
786 IntInit *RHSi = dynamic_cast<IntInit*>(RHS);
788 int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
790 switch (getOpcode()) {
791 default: assert(0 && "Bad opcode!");
792 case SHL: Result = LHSv << RHSv; break;
793 case SRA: Result = LHSv >> RHSv; break;
794 case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
796 return new IntInit(Result);
804 Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) {
805 Init *lhs = LHS->resolveReferences(R, RV);
806 Init *rhs = RHS->resolveReferences(R, RV);
808 if (LHS != lhs || RHS != rhs)
809 return (new BinOpInit(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0);
813 std::string BinOpInit::getAsString() const {
816 case CONCAT: Result = "!con"; break;
817 case SHL: Result = "!shl"; break;
818 case SRA: Result = "!sra"; break;
819 case SRL: Result = "!srl"; break;
820 case STRCONCAT: Result = "!strconcat"; break;
822 Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
824 return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
827 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
828 Record *CurRec, MultiClass *CurMultiClass);
830 static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
831 RecTy *Type, Record *CurRec,
832 MultiClass *CurMultiClass) {
833 std::vector<Init *> NewOperands;
835 TypedInit *TArg = dynamic_cast<TypedInit*>(Arg);
837 // If this is a dag, recurse
838 if (TArg && TArg->getType()->getAsString() == "dag") {
839 Init *Result = ForeachHelper(LHS, Arg, RHSo, Type,
840 CurRec, CurMultiClass);
849 for (int i = 0; i < RHSo->getNumOperands(); ++i) {
850 OpInit *RHSoo = dynamic_cast<OpInit*>(RHSo->getOperand(i));
853 Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
854 Type, CurRec, CurMultiClass);
856 NewOperands.push_back(Result);
859 NewOperands.push_back(Arg);
862 else if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
863 NewOperands.push_back(Arg);
866 NewOperands.push_back(RHSo->getOperand(i));
870 // Now run the operator and use its result as the new leaf
871 OpInit *NewOp = RHSo->clone(NewOperands);
872 Init *NewVal = NewOp->Fold(CurRec, CurMultiClass);
873 if (NewVal != NewOp) {
880 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
881 Record *CurRec, MultiClass *CurMultiClass) {
882 DagInit *MHSd = dynamic_cast<DagInit*>(MHS);
883 ListInit *MHSl = dynamic_cast<ListInit*>(MHS);
885 DagRecTy *DagType = dynamic_cast<DagRecTy*>(Type);
886 ListRecTy *ListType = dynamic_cast<ListRecTy*>(Type);
888 OpInit *RHSo = dynamic_cast<OpInit*>(RHS);
891 errs() << "!foreach requires an operator\n";
892 assert(0 && "No operator for !foreach");
895 TypedInit *LHSt = dynamic_cast<TypedInit*>(LHS);
898 errs() << "!foreach requires typed variable\n";
899 assert(0 && "No typed variable for !foreach");
902 if ((MHSd && DagType) || (MHSl && ListType)) {
904 Init *Val = MHSd->getOperator();
905 Init *Result = EvaluateOperation(RHSo, LHS, Val,
906 Type, CurRec, CurMultiClass);
911 std::vector<std::pair<Init *, std::string> > args;
912 for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
915 Arg = MHSd->getArg(i);
916 ArgName = MHSd->getArgName(i);
919 Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
920 CurRec, CurMultiClass);
925 // TODO: Process arg names
926 args.push_back(std::make_pair(Arg, ArgName));
929 return new DagInit(Val, "", args);
932 std::vector<Init *> NewOperands;
933 std::vector<Init *> NewList(MHSl->begin(), MHSl->end());
935 for (ListInit::iterator li = NewList.begin(),
936 liend = NewList.end();
941 for(int i = 0; i < RHSo->getNumOperands(); ++i) {
942 // First, replace the foreach variable with the list item
943 if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
944 NewOperands.push_back(Item);
947 NewOperands.push_back(RHSo->getOperand(i));
951 // Now run the operator and use its result as the new list item
952 OpInit *NewOp = RHSo->clone(NewOperands);
953 Init *NewItem = NewOp->Fold(CurRec, CurMultiClass);
954 if (NewItem != NewOp) {
959 return new ListInit(NewList, MHSl->getType());
965 Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
966 switch (getOpcode()) {
967 default: assert(0 && "Unknown binop");
969 DefInit *LHSd = dynamic_cast<DefInit*>(LHS);
970 VarInit *LHSv = dynamic_cast<VarInit*>(LHS);
971 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
973 DefInit *MHSd = dynamic_cast<DefInit*>(MHS);
974 VarInit *MHSv = dynamic_cast<VarInit*>(MHS);
975 StringInit *MHSs = dynamic_cast<StringInit*>(MHS);
977 DefInit *RHSd = dynamic_cast<DefInit*>(RHS);
978 VarInit *RHSv = dynamic_cast<VarInit*>(RHS);
979 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
981 if ((LHSd && MHSd && RHSd)
982 || (LHSv && MHSv && RHSv)
983 || (LHSs && MHSs && RHSs)) {
985 Record *Val = RHSd->getDef();
986 if (LHSd->getAsString() == RHSd->getAsString()) {
987 Val = MHSd->getDef();
989 return new DefInit(Val);
992 std::string Val = RHSv->getName();
993 if (LHSv->getAsString() == RHSv->getAsString()) {
994 Val = MHSv->getName();
996 return new VarInit(Val, getType());
999 std::string Val = RHSs->getValue();
1001 std::string::size_type found;
1003 found = Val.find(LHSs->getValue());
1004 if (found != std::string::npos) {
1005 Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
1007 } while (found != std::string::npos);
1009 return new StringInit(Val);
1016 Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
1017 CurRec, CurMultiClass);
1025 IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
1027 if (LHSi->getValue()) {
1041 Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) {
1042 Init *lhs = LHS->resolveReferences(R, RV);
1044 if (Opc == IF && lhs != LHS) {
1045 IntInit *Value = dynamic_cast<IntInit*>(lhs);
1048 if (Value->getValue()) {
1049 Init *mhs = MHS->resolveReferences(R, RV);
1050 return (new TernOpInit(getOpcode(), lhs, mhs, RHS, getType()))->Fold(&R, 0);
1053 Init *rhs = RHS->resolveReferences(R, RV);
1054 return (new TernOpInit(getOpcode(), lhs, MHS, rhs, getType()))->Fold(&R, 0);
1059 Init *mhs = MHS->resolveReferences(R, RV);
1060 Init *rhs = RHS->resolveReferences(R, RV);
1062 if (LHS != lhs || MHS != mhs || RHS != rhs)
1063 return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
1067 std::string TernOpInit::getAsString() const {
1070 case SUBST: Result = "!subst"; break;
1071 case FOREACH: Result = "!foreach"; break;
1072 case IF: Result = "!if"; break;
1074 return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", "
1075 + RHS->getAsString() + ")";
1078 Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
1079 BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType());
1080 if (T == 0) return 0; // Cannot subscript a non-bits variable...
1081 unsigned NumBits = T->getNumBits();
1083 BitsInit *BI = new BitsInit(Bits.size());
1084 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
1085 if (Bits[i] >= NumBits) {
1089 BI->setBit(i, new VarBitInit(this, Bits[i]));
1094 Init *TypedInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
1095 ListRecTy *T = dynamic_cast<ListRecTy*>(getType());
1096 if (T == 0) return 0; // Cannot subscript a non-list variable...
1098 if (Elements.size() == 1)
1099 return new VarListElementInit(this, Elements[0]);
1101 std::vector<Init*> ListInits;
1102 ListInits.reserve(Elements.size());
1103 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
1104 ListInits.push_back(new VarListElementInit(this, Elements[i]));
1105 return new ListInit(ListInits, T);
1109 Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV,
1111 if (R.isTemplateArg(getName())) return 0;
1112 if (IRV && IRV->getName() != getName()) return 0;
1114 RecordVal *RV = R.getValue(getName());
1115 assert(RV && "Reference to a non-existent variable?");
1116 assert(dynamic_cast<BitsInit*>(RV->getValue()));
1117 BitsInit *BI = (BitsInit*)RV->getValue();
1119 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1120 Init *B = BI->getBit(Bit);
1122 // If the bit is set to some value, or if we are resolving a reference to a
1123 // specific variable and that variable is explicitly unset, then replace the
1124 // VarBitInit with it.
1125 if (IRV || !dynamic_cast<UnsetInit*>(B))
1130 Init *VarInit::resolveListElementReference(Record &R, const RecordVal *IRV,
1132 if (R.isTemplateArg(getName())) return 0;
1133 if (IRV && IRV->getName() != getName()) return 0;
1135 RecordVal *RV = R.getValue(getName());
1136 assert(RV && "Reference to a non-existent variable?");
1137 ListInit *LI = dynamic_cast<ListInit*>(RV->getValue());
1139 VarInit *VI = dynamic_cast<VarInit*>(RV->getValue());
1140 assert(VI && "Invalid list element!");
1141 return new VarListElementInit(VI, Elt);
1144 if (Elt >= LI->getSize())
1145 return 0; // Out of range reference.
1146 Init *E = LI->getElement(Elt);
1147 // If the element is set to some value, or if we are resolving a reference
1148 // to a specific variable and that variable is explicitly unset, then
1149 // replace the VarListElementInit with it.
1150 if (IRV || !dynamic_cast<UnsetInit*>(E))
1156 RecTy *VarInit::getFieldType(const std::string &FieldName) const {
1157 if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
1158 if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
1159 return RV->getType();
1163 Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
1164 if (dynamic_cast<RecordRecTy*>(getType()))
1165 if (const RecordVal *RV = R.getValue(VarName)) {
1166 Init *TheInit = RV->getValue();
1167 assert(TheInit != this && "Infinite loop detected!");
1168 if (Init *I = TheInit->getFieldInit(R, FieldName))
1176 /// resolveReferences - This method is used by classes that refer to other
1177 /// variables which may not be defined at the time the expression is formed.
1178 /// If a value is set for the variable later, this method will be called on
1179 /// users of the value to allow the value to propagate out.
1181 Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) {
1182 if (RecordVal *Val = R.getValue(VarName))
1183 if (RV == Val || (RV == 0 && !dynamic_cast<UnsetInit*>(Val->getValue())))
1184 return Val->getValue();
1188 std::string VarBitInit::getAsString() const {
1189 return TI->getAsString() + "{" + utostr(Bit) + "}";
1192 Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) {
1193 if (Init *I = getVariable()->resolveBitReference(R, RV, getBitNum()))
1198 std::string VarListElementInit::getAsString() const {
1199 return TI->getAsString() + "[" + utostr(Element) + "]";
1202 Init *VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) {
1203 if (Init *I = getVariable()->resolveListElementReference(R, RV,
1209 Init *VarListElementInit::resolveBitReference(Record &R, const RecordVal *RV,
1211 // FIXME: This should be implemented, to support references like:
1212 // bit B = AA[0]{1};
1216 Init *VarListElementInit::
1217 resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) {
1218 // FIXME: This should be implemented, to support references like:
1219 // int B = AA[0][1];
1223 RecTy *DefInit::getFieldType(const std::string &FieldName) const {
1224 if (const RecordVal *RV = Def->getValue(FieldName))
1225 return RV->getType();
1229 Init *DefInit::getFieldInit(Record &R, const std::string &FieldName) const {
1230 return Def->getValue(FieldName)->getValue();
1234 std::string DefInit::getAsString() const {
1235 return Def->getName();
1238 Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
1240 if (Init *BitsVal = Rec->getFieldInit(R, FieldName))
1241 if (BitsInit *BI = dynamic_cast<BitsInit*>(BitsVal)) {
1242 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1243 Init *B = BI->getBit(Bit);
1245 if (dynamic_cast<BitInit*>(B)) // If the bit is set...
1246 return B; // Replace the VarBitInit with it.
1251 Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
1253 if (Init *ListVal = Rec->getFieldInit(R, FieldName))
1254 if (ListInit *LI = dynamic_cast<ListInit*>(ListVal)) {
1255 if (Elt >= LI->getSize()) return 0;
1256 Init *E = LI->getElement(Elt);
1258 // If the element is set to some value, or if we are resolving a
1259 // reference to a specific variable and that variable is explicitly
1260 // unset, then replace the VarListElementInit with it.
1261 if (RV || !dynamic_cast<UnsetInit*>(E))
1267 Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) {
1268 Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
1270 Init *BitsVal = NewRec->getFieldInit(R, FieldName);
1272 Init *BVR = BitsVal->resolveReferences(R, RV);
1273 return BVR->isComplete() ? BVR : this;
1276 if (NewRec != Rec) {
1277 return new FieldInit(NewRec, FieldName);
1282 Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
1283 std::vector<Init*> NewArgs;
1284 for (unsigned i = 0, e = Args.size(); i != e; ++i)
1285 NewArgs.push_back(Args[i]->resolveReferences(R, RV));
1287 Init *Op = Val->resolveReferences(R, RV);
1289 if (Args != NewArgs || Op != Val)
1290 return new DagInit(Op, "", NewArgs, ArgNames);
1296 std::string DagInit::getAsString() const {
1297 std::string Result = "(" + Val->getAsString();
1298 if (!ValName.empty())
1299 Result += ":" + ValName;
1301 Result += " " + Args[0]->getAsString();
1302 if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
1303 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
1304 Result += ", " + Args[i]->getAsString();
1305 if (!ArgNames[i].empty()) Result += ":$" + ArgNames[i];
1308 return Result + ")";
1312 //===----------------------------------------------------------------------===//
1313 // Other implementations
1314 //===----------------------------------------------------------------------===//
1316 RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P)
1317 : Name(N), Ty(T), Prefix(P) {
1318 Value = Ty->convertValue(new UnsetInit());
1319 assert(Value && "Cannot create unset value for current type!");
1322 void RecordVal::dump() const { errs() << *this; }
1324 void RecordVal::print(raw_ostream &OS, bool PrintSem) const {
1325 if (getPrefix()) OS << "field ";
1326 OS << *getType() << " " << getName();
1329 OS << " = " << *getValue();
1331 if (PrintSem) OS << ";\n";
1334 unsigned Record::LastID = 0;
1336 void Record::setName(const std::string &Name) {
1337 if (Records.getDef(getName()) == this) {
1338 Records.removeDef(getName());
1340 Records.addDef(this);
1342 Records.removeClass(getName());
1344 Records.addClass(this);
1348 /// resolveReferencesTo - If anything in this record refers to RV, replace the
1349 /// reference to RV with the RHS of RV. If RV is null, we resolve all possible
1351 void Record::resolveReferencesTo(const RecordVal *RV) {
1352 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
1353 if (Init *V = Values[i].getValue())
1354 Values[i].setValue(V->resolveReferences(*this, RV));
1359 void Record::dump() const { errs() << *this; }
1361 raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) {
1364 const std::vector<std::string> &TArgs = R.getTemplateArgs();
1365 if (!TArgs.empty()) {
1367 for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1369 const RecordVal *RV = R.getValue(TArgs[i]);
1370 assert(RV && "Template argument record not found??");
1371 RV->print(OS, false);
1377 const std::vector<Record*> &SC = R.getSuperClasses();
1380 for (unsigned i = 0, e = SC.size(); i != e; ++i)
1381 OS << " " << SC[i]->getName();
1385 const std::vector<RecordVal> &Vals = R.getValues();
1386 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1387 if (Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1389 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1390 if (!Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1396 /// getValueInit - Return the initializer for a value with the specified name,
1397 /// or throw an exception if the field does not exist.
1399 Init *Record::getValueInit(StringRef FieldName) const {
1400 const RecordVal *R = getValue(FieldName);
1401 if (R == 0 || R->getValue() == 0)
1402 throw "Record `" + getName() + "' does not have a field named `" +
1403 FieldName.str() + "'!\n";
1404 return R->getValue();
1408 /// getValueAsString - This method looks up the specified field and returns its
1409 /// value as a string, throwing an exception if the field does not exist or if
1410 /// the value is not a string.
1412 std::string Record::getValueAsString(StringRef FieldName) const {
1413 const RecordVal *R = getValue(FieldName);
1414 if (R == 0 || R->getValue() == 0)
1415 throw "Record `" + getName() + "' does not have a field named `" +
1416 FieldName.str() + "'!\n";
1418 if (const StringInit *SI = dynamic_cast<const StringInit*>(R->getValue()))
1419 return SI->getValue();
1420 throw "Record `" + getName() + "', field `" + FieldName.str() +
1421 "' does not have a string initializer!";
1424 /// getValueAsBitsInit - This method looks up the specified field and returns
1425 /// its value as a BitsInit, throwing an exception if the field does not exist
1426 /// or if the value is not the right type.
1428 BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const {
1429 const RecordVal *R = getValue(FieldName);
1430 if (R == 0 || R->getValue() == 0)
1431 throw "Record `" + getName() + "' does not have a field named `" +
1432 FieldName.str() + "'!\n";
1434 if (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue()))
1436 throw "Record `" + getName() + "', field `" + FieldName.str() +
1437 "' does not have a BitsInit initializer!";
1440 /// getValueAsListInit - This method looks up the specified field and returns
1441 /// its value as a ListInit, throwing an exception if the field does not exist
1442 /// or if the value is not the right type.
1444 ListInit *Record::getValueAsListInit(StringRef FieldName) const {
1445 const RecordVal *R = getValue(FieldName);
1446 if (R == 0 || R->getValue() == 0)
1447 throw "Record `" + getName() + "' does not have a field named `" +
1448 FieldName.str() + "'!\n";
1450 if (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
1452 throw "Record `" + getName() + "', field `" + FieldName.str() +
1453 "' does not have a list initializer!";
1456 /// getValueAsListOfDefs - This method looks up the specified field and returns
1457 /// its value as a vector of records, throwing an exception if the field does
1458 /// not exist or if the value is not the right type.
1460 std::vector<Record*>
1461 Record::getValueAsListOfDefs(StringRef FieldName) const {
1462 ListInit *List = getValueAsListInit(FieldName);
1463 std::vector<Record*> Defs;
1464 for (unsigned i = 0; i < List->getSize(); i++) {
1465 if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
1466 Defs.push_back(DI->getDef());
1468 throw "Record `" + getName() + "', field `" + FieldName.str() +
1469 "' list is not entirely DefInit!";
1475 /// getValueAsInt - This method looks up the specified field and returns its
1476 /// value as an int64_t, throwing an exception if the field does not exist or if
1477 /// the value is not the right type.
1479 int64_t Record::getValueAsInt(StringRef FieldName) const {
1480 const RecordVal *R = getValue(FieldName);
1481 if (R == 0 || R->getValue() == 0)
1482 throw "Record `" + getName() + "' does not have a field named `" +
1483 FieldName.str() + "'!\n";
1485 if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
1486 return II->getValue();
1487 throw "Record `" + getName() + "', field `" + FieldName.str() +
1488 "' does not have an int initializer!";
1491 /// getValueAsListOfInts - This method looks up the specified field and returns
1492 /// its value as a vector of integers, throwing an exception if the field does
1493 /// not exist or if the value is not the right type.
1495 std::vector<int64_t>
1496 Record::getValueAsListOfInts(StringRef FieldName) const {
1497 ListInit *List = getValueAsListInit(FieldName);
1498 std::vector<int64_t> Ints;
1499 for (unsigned i = 0; i < List->getSize(); i++) {
1500 if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
1501 Ints.push_back(II->getValue());
1503 throw "Record `" + getName() + "', field `" + FieldName.str() +
1504 "' does not have a list of ints initializer!";
1510 /// getValueAsDef - This method looks up the specified field and returns its
1511 /// value as a Record, throwing an exception if the field does not exist or if
1512 /// the value is not the right type.
1514 Record *Record::getValueAsDef(StringRef FieldName) const {
1515 const RecordVal *R = getValue(FieldName);
1516 if (R == 0 || R->getValue() == 0)
1517 throw "Record `" + getName() + "' does not have a field named `" +
1518 FieldName.str() + "'!\n";
1520 if (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
1521 return DI->getDef();
1522 throw "Record `" + getName() + "', field `" + FieldName.str() +
1523 "' does not have a def initializer!";
1526 /// getValueAsBit - This method looks up the specified field and returns its
1527 /// value as a bit, throwing an exception if the field does not exist or if
1528 /// the value is not the right type.
1530 bool Record::getValueAsBit(StringRef FieldName) const {
1531 const RecordVal *R = getValue(FieldName);
1532 if (R == 0 || R->getValue() == 0)
1533 throw "Record `" + getName() + "' does not have a field named `" +
1534 FieldName.str() + "'!\n";
1536 if (BitInit *BI = dynamic_cast<BitInit*>(R->getValue()))
1537 return BI->getValue();
1538 throw "Record `" + getName() + "', field `" + FieldName.str() +
1539 "' does not have a bit initializer!";
1542 /// getValueAsDag - This method looks up the specified field and returns its
1543 /// value as an Dag, throwing an exception if the field does not exist or if
1544 /// the value is not the right type.
1546 DagInit *Record::getValueAsDag(StringRef FieldName) const {
1547 const RecordVal *R = getValue(FieldName);
1548 if (R == 0 || R->getValue() == 0)
1549 throw "Record `" + getName() + "' does not have a field named `" +
1550 FieldName.str() + "'!\n";
1552 if (DagInit *DI = dynamic_cast<DagInit*>(R->getValue()))
1554 throw "Record `" + getName() + "', field `" + FieldName.str() +
1555 "' does not have a dag initializer!";
1558 std::string Record::getValueAsCode(StringRef FieldName) const {
1559 const RecordVal *R = getValue(FieldName);
1560 if (R == 0 || R->getValue() == 0)
1561 throw "Record `" + getName() + "' does not have a field named `" +
1562 FieldName.str() + "'!\n";
1564 if (const CodeInit *CI = dynamic_cast<const CodeInit*>(R->getValue()))
1565 return CI->getValue();
1566 throw "Record `" + getName() + "', field `" + FieldName.str() +
1567 "' does not have a code initializer!";
1571 void MultiClass::dump() const {
1572 errs() << "Record:\n";
1575 errs() << "Defs:\n";
1576 for (RecordVector::const_iterator r = DefPrototypes.begin(),
1577 rend = DefPrototypes.end();
1585 void RecordKeeper::dump() const { errs() << *this; }
1587 raw_ostream &llvm::operator<<(raw_ostream &OS, const RecordKeeper &RK) {
1588 OS << "------------- Classes -----------------\n";
1589 const std::map<std::string, Record*> &Classes = RK.getClasses();
1590 for (std::map<std::string, Record*>::const_iterator I = Classes.begin(),
1591 E = Classes.end(); I != E; ++I)
1592 OS << "class " << *I->second;
1594 OS << "------------- Defs -----------------\n";
1595 const std::map<std::string, Record*> &Defs = RK.getDefs();
1596 for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
1597 E = Defs.end(); I != E; ++I)
1598 OS << "def " << *I->second;
1603 /// getAllDerivedDefinitions - This method returns all concrete definitions
1604 /// that derive from the specified class name. If a class with the specified
1605 /// name does not exist, an error is printed and true is returned.
1606 std::vector<Record*>
1607 RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
1608 Record *Class = Records.getClass(ClassName);
1610 throw "ERROR: Couldn't find the `" + ClassName + "' class!\n";
1612 std::vector<Record*> Defs;
1613 for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(),
1614 E = getDefs().end(); I != E; ++I)
1615 if (I->second->isSubClassOf(Class))
1616 Defs.push_back(I->second);