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 if (Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec))
276 const std::vector<Record*> &SC = Rec->getSuperClasses();
277 for (unsigned i = 0, e = SC.size(); i != e; ++i)
278 if (RHS->getRecord()->isSubClassOf(SC[i]))
285 /// resolveTypes - Find a common type that T1 and T2 convert to.
286 /// Return 0 if no such type exists.
288 RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
289 if (!T1->typeIsConvertibleTo(T2)) {
290 if (!T2->typeIsConvertibleTo(T1)) {
291 // If one is a Record type, check superclasses
292 RecordRecTy *RecTy1 = dynamic_cast<RecordRecTy*>(T1);
294 // See if T2 inherits from a type T1 also inherits from
295 const std::vector<Record *> &T1SuperClasses =
296 RecTy1->getRecord()->getSuperClasses();
297 for(std::vector<Record *>::const_iterator i = T1SuperClasses.begin(),
298 iend = T1SuperClasses.end();
301 RecordRecTy *SuperRecTy1 = new RecordRecTy(*i);
302 RecTy *NewType1 = resolveTypes(SuperRecTy1, T2);
304 if (NewType1 != SuperRecTy1) {
311 RecordRecTy *RecTy2 = dynamic_cast<RecordRecTy*>(T2);
313 // See if T1 inherits from a type T2 also inherits from
314 const std::vector<Record *> &T2SuperClasses =
315 RecTy2->getRecord()->getSuperClasses();
316 for (std::vector<Record *>::const_iterator i = T2SuperClasses.begin(),
317 iend = T2SuperClasses.end();
320 RecordRecTy *SuperRecTy2 = new RecordRecTy(*i);
321 RecTy *NewType2 = resolveTypes(T1, SuperRecTy2);
323 if (NewType2 != SuperRecTy2) {
338 //===----------------------------------------------------------------------===//
339 // Initializer implementations
340 //===----------------------------------------------------------------------===//
342 void Init::dump() const { return print(errs()); }
344 Init *BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
345 BitsInit *BI = new BitsInit(Bits.size());
346 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
347 if (Bits[i] >= getNumBits()) {
351 BI->setBit(i, getBit(Bits[i]));
356 std::string BitsInit::getAsString() const {
357 std::string Result = "{ ";
358 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
359 if (i) Result += ", ";
360 if (Init *Bit = getBit(e-i-1))
361 Result += Bit->getAsString();
365 return Result + " }";
368 // resolveReferences - If there are any field references that refer to fields
369 // that have been filled in, we can propagate the values now.
371 Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) {
372 bool Changed = false;
373 BitsInit *New = new BitsInit(getNumBits());
375 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
377 Init *CurBit = getBit(i);
381 CurBit = CurBit->resolveReferences(R, RV);
382 Changed |= B != CurBit;
383 } while (B != CurBit);
384 New->setBit(i, CurBit);
393 std::string IntInit::getAsString() const {
394 return itostr(Value);
397 Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
398 BitsInit *BI = new BitsInit(Bits.size());
400 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
405 BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i])));
410 Init *ListInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
411 std::vector<Init*> Vals;
412 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
413 if (Elements[i] >= getSize())
415 Vals.push_back(getElement(Elements[i]));
417 return new ListInit(Vals, getType());
420 Record *ListInit::getElementAsRecord(unsigned i) const {
421 assert(i < Values.size() && "List element index out of range!");
422 DefInit *DI = dynamic_cast<DefInit*>(Values[i]);
423 if (DI == 0) throw "Expected record in list!";
427 Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) {
428 std::vector<Init*> Resolved;
429 Resolved.reserve(getSize());
430 bool Changed = false;
432 for (unsigned i = 0, e = getSize(); i != e; ++i) {
434 Init *CurElt = getElement(i);
438 CurElt = CurElt->resolveReferences(R, RV);
439 Changed |= E != CurElt;
440 } while (E != CurElt);
441 Resolved.push_back(E);
445 return new ListInit(Resolved, getType());
449 Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV,
451 if (Elt >= getSize())
452 return 0; // Out of range reference.
453 Init *E = getElement(Elt);
454 // If the element is set to some value, or if we are resolving a reference
455 // to a specific variable and that variable is explicitly unset, then
456 // replace the VarListElementInit with it.
457 if (IRV || !dynamic_cast<UnsetInit*>(E))
462 std::string ListInit::getAsString() const {
463 std::string Result = "[";
464 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
465 if (i) Result += ", ";
466 Result += Values[i]->getAsString();
471 Init *OpInit::resolveBitReference(Record &R, const RecordVal *IRV,
473 Init *Folded = Fold(&R, 0);
475 if (Folded != this) {
476 TypedInit *Typed = dynamic_cast<TypedInit *>(Folded);
478 return Typed->resolveBitReference(R, IRV, Bit);
485 Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
487 Init *Folded = Fold(&R, 0);
489 if (Folded != this) {
490 TypedInit *Typed = dynamic_cast<TypedInit *>(Folded);
492 return Typed->resolveListElementReference(R, IRV, Elt);
499 Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
500 switch (getOpcode()) {
501 default: assert(0 && "Unknown unop");
503 if (getType()->getAsString() == "string") {
504 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
509 DefInit *LHSd = dynamic_cast<DefInit*>(LHS);
511 return new StringInit(LHSd->getDef()->getName());
514 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
516 std::string Name = LHSs->getValue();
518 // From TGParser::ParseIDValue
520 if (const RecordVal *RV = CurRec->getValue(Name)) {
521 if (RV->getType() != getType()) {
522 throw "type mismatch in nameconcat";
524 return new VarInit(Name, RV->getType());
527 std::string TemplateArgName = CurRec->getName()+":"+Name;
528 if (CurRec->isTemplateArg(TemplateArgName)) {
529 const RecordVal *RV = CurRec->getValue(TemplateArgName);
530 assert(RV && "Template arg doesn't exist??");
532 if (RV->getType() != getType()) {
533 throw "type mismatch in nameconcat";
536 return new VarInit(TemplateArgName, RV->getType());
541 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
542 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
543 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
544 assert(RV && "Template arg doesn't exist??");
546 if (RV->getType() != getType()) {
547 throw "type mismatch in nameconcat";
550 return new VarInit(MCName, RV->getType());
554 if (Record *D = Records.getDef(Name))
555 return new DefInit(D);
557 errs() << "Variable not defined: '" + Name + "'\n";
558 assert(0 && "Variable not found");
565 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
567 if (LHSl->getSize() == 0) {
568 assert(0 && "Empty list in car");
571 return LHSl->getElement(0);
576 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
578 if (LHSl->getSize() == 0) {
579 assert(0 && "Empty list in cdr");
582 ListInit *Result = new ListInit(LHSl->begin()+1, LHSl->end(),
589 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
591 if (LHSl->getSize() == 0) {
592 return new IntInit(1);
594 return new IntInit(0);
597 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
599 if (LHSs->getValue().empty()) {
600 return new IntInit(1);
602 return new IntInit(0);
612 Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) {
613 Init *lhs = LHS->resolveReferences(R, RV);
616 return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
620 std::string UnOpInit::getAsString() const {
623 case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
624 case CAR: Result = "!car"; break;
625 case CDR: Result = "!cdr"; break;
626 case LNULL: Result = "!null"; break;
628 return Result + "(" + LHS->getAsString() + ")";
631 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
632 switch (getOpcode()) {
633 default: assert(0 && "Unknown binop");
635 DagInit *LHSs = dynamic_cast<DagInit*>(LHS);
636 DagInit *RHSs = dynamic_cast<DagInit*>(RHS);
638 DefInit *LOp = dynamic_cast<DefInit*>(LHSs->getOperator());
639 DefInit *ROp = dynamic_cast<DefInit*>(RHSs->getOperator());
640 if (LOp == 0 || ROp == 0 || LOp->getDef() != ROp->getDef())
641 throw "Concated Dag operators do not match!";
642 std::vector<Init*> Args;
643 std::vector<std::string> ArgNames;
644 for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
645 Args.push_back(LHSs->getArg(i));
646 ArgNames.push_back(LHSs->getArgName(i));
648 for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
649 Args.push_back(RHSs->getArg(i));
650 ArgNames.push_back(RHSs->getArgName(i));
652 return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
657 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
658 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
660 return new StringInit(LHSs->getValue() + RHSs->getValue());
664 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
665 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
667 std::string Name(LHSs->getValue() + RHSs->getValue());
669 // From TGParser::ParseIDValue
671 if (const RecordVal *RV = CurRec->getValue(Name)) {
672 if (RV->getType() != getType()) {
673 throw "type mismatch in nameconcat";
675 return new VarInit(Name, RV->getType());
678 std::string TemplateArgName = CurRec->getName()+":"+Name;
679 if (CurRec->isTemplateArg(TemplateArgName)) {
680 const RecordVal *RV = CurRec->getValue(TemplateArgName);
681 assert(RV && "Template arg doesn't exist??");
683 if (RV->getType() != getType()) {
684 throw "type mismatch in nameconcat";
687 return new VarInit(TemplateArgName, RV->getType());
692 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
693 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
694 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
695 assert(RV && "Template arg doesn't exist??");
697 if (RV->getType() != getType()) {
698 throw "type mismatch in nameconcat";
701 return new VarInit(MCName, RV->getType());
705 if (Record *D = Records.getDef(Name))
706 return new DefInit(D);
708 errs() << "Variable not defined in !nameconcat: '" + Name + "'\n";
709 assert(0 && "Variable not found in !nameconcat");
715 // try to fold eq comparison for 'bit' and 'int', otherwise fallback
716 // to string objects.
718 dynamic_cast<IntInit*>(LHS->convertInitializerTo(new IntRecTy()));
720 dynamic_cast<IntInit*>(RHS->convertInitializerTo(new IntRecTy()));
723 return new IntInit(L->getValue() == R->getValue());
725 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
726 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
728 // Make sure we've resolved
730 return new IntInit(LHSs->getValue() == RHSs->getValue());
737 IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
738 IntInit *RHSi = dynamic_cast<IntInit*>(RHS);
740 int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
742 switch (getOpcode()) {
743 default: assert(0 && "Bad opcode!");
744 case SHL: Result = LHSv << RHSv; break;
745 case SRA: Result = LHSv >> RHSv; break;
746 case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
748 return new IntInit(Result);
756 Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) {
757 Init *lhs = LHS->resolveReferences(R, RV);
758 Init *rhs = RHS->resolveReferences(R, RV);
760 if (LHS != lhs || RHS != rhs)
761 return (new BinOpInit(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0);
765 std::string BinOpInit::getAsString() const {
768 case CONCAT: Result = "!con"; break;
769 case SHL: Result = "!shl"; break;
770 case SRA: Result = "!sra"; break;
771 case SRL: Result = "!srl"; break;
772 case EQ: Result = "!eq"; break;
773 case STRCONCAT: Result = "!strconcat"; break;
775 Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
777 return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
780 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
781 Record *CurRec, MultiClass *CurMultiClass);
783 static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
784 RecTy *Type, Record *CurRec,
785 MultiClass *CurMultiClass) {
786 std::vector<Init *> NewOperands;
788 TypedInit *TArg = dynamic_cast<TypedInit*>(Arg);
790 // If this is a dag, recurse
791 if (TArg && TArg->getType()->getAsString() == "dag") {
792 Init *Result = ForeachHelper(LHS, Arg, RHSo, Type,
793 CurRec, CurMultiClass);
801 for (int i = 0; i < RHSo->getNumOperands(); ++i) {
802 OpInit *RHSoo = dynamic_cast<OpInit*>(RHSo->getOperand(i));
805 Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
806 Type, CurRec, CurMultiClass);
808 NewOperands.push_back(Result);
810 NewOperands.push_back(Arg);
812 } else if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
813 NewOperands.push_back(Arg);
815 NewOperands.push_back(RHSo->getOperand(i));
819 // Now run the operator and use its result as the new leaf
820 OpInit *NewOp = RHSo->clone(NewOperands);
821 Init *NewVal = NewOp->Fold(CurRec, CurMultiClass);
822 if (NewVal != NewOp) {
829 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
830 Record *CurRec, MultiClass *CurMultiClass) {
831 DagInit *MHSd = dynamic_cast<DagInit*>(MHS);
832 ListInit *MHSl = dynamic_cast<ListInit*>(MHS);
834 DagRecTy *DagType = dynamic_cast<DagRecTy*>(Type);
835 ListRecTy *ListType = dynamic_cast<ListRecTy*>(Type);
837 OpInit *RHSo = dynamic_cast<OpInit*>(RHS);
840 errs() << "!foreach requires an operator\n";
841 assert(0 && "No operator for !foreach");
844 TypedInit *LHSt = dynamic_cast<TypedInit*>(LHS);
847 errs() << "!foreach requires typed variable\n";
848 assert(0 && "No typed variable for !foreach");
851 if ((MHSd && DagType) || (MHSl && ListType)) {
853 Init *Val = MHSd->getOperator();
854 Init *Result = EvaluateOperation(RHSo, LHS, Val,
855 Type, CurRec, CurMultiClass);
860 std::vector<std::pair<Init *, std::string> > args;
861 for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
864 Arg = MHSd->getArg(i);
865 ArgName = MHSd->getArgName(i);
868 Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
869 CurRec, CurMultiClass);
874 // TODO: Process arg names
875 args.push_back(std::make_pair(Arg, ArgName));
878 return new DagInit(Val, "", args);
881 std::vector<Init *> NewOperands;
882 std::vector<Init *> NewList(MHSl->begin(), MHSl->end());
884 for (ListInit::iterator li = NewList.begin(),
885 liend = NewList.end();
890 for(int i = 0; i < RHSo->getNumOperands(); ++i) {
891 // First, replace the foreach variable with the list item
892 if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
893 NewOperands.push_back(Item);
895 NewOperands.push_back(RHSo->getOperand(i));
899 // Now run the operator and use its result as the new list item
900 OpInit *NewOp = RHSo->clone(NewOperands);
901 Init *NewItem = NewOp->Fold(CurRec, CurMultiClass);
902 if (NewItem != NewOp) {
907 return new ListInit(NewList, MHSl->getType());
913 Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
914 switch (getOpcode()) {
915 default: assert(0 && "Unknown binop");
917 DefInit *LHSd = dynamic_cast<DefInit*>(LHS);
918 VarInit *LHSv = dynamic_cast<VarInit*>(LHS);
919 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
921 DefInit *MHSd = dynamic_cast<DefInit*>(MHS);
922 VarInit *MHSv = dynamic_cast<VarInit*>(MHS);
923 StringInit *MHSs = dynamic_cast<StringInit*>(MHS);
925 DefInit *RHSd = dynamic_cast<DefInit*>(RHS);
926 VarInit *RHSv = dynamic_cast<VarInit*>(RHS);
927 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
929 if ((LHSd && MHSd && RHSd)
930 || (LHSv && MHSv && RHSv)
931 || (LHSs && MHSs && RHSs)) {
933 Record *Val = RHSd->getDef();
934 if (LHSd->getAsString() == RHSd->getAsString()) {
935 Val = MHSd->getDef();
937 return new DefInit(Val);
940 std::string Val = RHSv->getName();
941 if (LHSv->getAsString() == RHSv->getAsString()) {
942 Val = MHSv->getName();
944 return new VarInit(Val, getType());
947 std::string Val = RHSs->getValue();
949 std::string::size_type found;
950 std::string::size_type idx = 0;
952 found = Val.find(LHSs->getValue(), idx);
953 if (found != std::string::npos) {
954 Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
956 idx = found + MHSs->getValue().size();
957 } while (found != std::string::npos);
959 return new StringInit(Val);
966 Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
967 CurRec, CurMultiClass);
975 IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
976 if (Init *I = LHS->convertInitializerTo(new IntRecTy()))
977 LHSi = dynamic_cast<IntInit*>(I);
979 if (LHSi->getValue()) {
992 Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) {
993 Init *lhs = LHS->resolveReferences(R, RV);
995 if (Opc == IF && lhs != LHS) {
996 IntInit *Value = dynamic_cast<IntInit*>(lhs);
997 if (Init *I = lhs->convertInitializerTo(new IntRecTy()))
998 Value = dynamic_cast<IntInit*>(I);
1001 if (Value->getValue()) {
1002 Init *mhs = MHS->resolveReferences(R, RV);
1003 return (new TernOpInit(getOpcode(), lhs, mhs,
1004 RHS, getType()))->Fold(&R, 0);
1006 Init *rhs = RHS->resolveReferences(R, RV);
1007 return (new TernOpInit(getOpcode(), lhs, MHS,
1008 rhs, getType()))->Fold(&R, 0);
1013 Init *mhs = MHS->resolveReferences(R, RV);
1014 Init *rhs = RHS->resolveReferences(R, RV);
1016 if (LHS != lhs || MHS != mhs || RHS != rhs)
1017 return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
1021 std::string TernOpInit::getAsString() const {
1024 case SUBST: Result = "!subst"; break;
1025 case FOREACH: Result = "!foreach"; break;
1026 case IF: Result = "!if"; break;
1028 return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", "
1029 + RHS->getAsString() + ")";
1032 RecTy *TypedInit::getFieldType(const std::string &FieldName) const {
1033 RecordRecTy *RecordType = dynamic_cast<RecordRecTy *>(getType());
1035 RecordVal *Field = RecordType->getRecord()->getValue(FieldName);
1037 return Field->getType();
1043 Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
1044 BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType());
1045 if (T == 0) return 0; // Cannot subscript a non-bits variable...
1046 unsigned NumBits = T->getNumBits();
1048 BitsInit *BI = new BitsInit(Bits.size());
1049 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
1050 if (Bits[i] >= NumBits) {
1054 BI->setBit(i, new VarBitInit(this, Bits[i]));
1059 Init *TypedInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
1060 ListRecTy *T = dynamic_cast<ListRecTy*>(getType());
1061 if (T == 0) return 0; // Cannot subscript a non-list variable...
1063 if (Elements.size() == 1)
1064 return new VarListElementInit(this, Elements[0]);
1066 std::vector<Init*> ListInits;
1067 ListInits.reserve(Elements.size());
1068 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
1069 ListInits.push_back(new VarListElementInit(this, Elements[i]));
1070 return new ListInit(ListInits, T);
1074 Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV,
1076 if (R.isTemplateArg(getName())) return 0;
1077 if (IRV && IRV->getName() != getName()) return 0;
1079 RecordVal *RV = R.getValue(getName());
1080 assert(RV && "Reference to a non-existent variable?");
1081 assert(dynamic_cast<BitsInit*>(RV->getValue()));
1082 BitsInit *BI = (BitsInit*)RV->getValue();
1084 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1085 Init *B = BI->getBit(Bit);
1087 // If the bit is set to some value, or if we are resolving a reference to a
1088 // specific variable and that variable is explicitly unset, then replace the
1089 // VarBitInit with it.
1090 if (IRV || !dynamic_cast<UnsetInit*>(B))
1095 Init *VarInit::resolveListElementReference(Record &R, const RecordVal *IRV,
1097 if (R.isTemplateArg(getName())) return 0;
1098 if (IRV && IRV->getName() != getName()) return 0;
1100 RecordVal *RV = R.getValue(getName());
1101 assert(RV && "Reference to a non-existent variable?");
1102 ListInit *LI = dynamic_cast<ListInit*>(RV->getValue());
1104 VarInit *VI = dynamic_cast<VarInit*>(RV->getValue());
1105 assert(VI && "Invalid list element!");
1106 return new VarListElementInit(VI, Elt);
1109 if (Elt >= LI->getSize())
1110 return 0; // Out of range reference.
1111 Init *E = LI->getElement(Elt);
1112 // If the element is set to some value, or if we are resolving a reference
1113 // to a specific variable and that variable is explicitly unset, then
1114 // replace the VarListElementInit with it.
1115 if (IRV || !dynamic_cast<UnsetInit*>(E))
1121 RecTy *VarInit::getFieldType(const std::string &FieldName) const {
1122 if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
1123 if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
1124 return RV->getType();
1128 Init *VarInit::getFieldInit(Record &R, const RecordVal *RV,
1129 const std::string &FieldName) const {
1130 if (dynamic_cast<RecordRecTy*>(getType()))
1131 if (const RecordVal *Val = R.getValue(VarName)) {
1132 if (RV != Val && (RV || dynamic_cast<UnsetInit*>(Val->getValue())))
1134 Init *TheInit = Val->getValue();
1135 assert(TheInit != this && "Infinite loop detected!");
1136 if (Init *I = TheInit->getFieldInit(R, RV, FieldName))
1144 /// resolveReferences - This method is used by classes that refer to other
1145 /// variables which may not be defined at the time the expression is formed.
1146 /// If a value is set for the variable later, this method will be called on
1147 /// users of the value to allow the value to propagate out.
1149 Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) {
1150 if (RecordVal *Val = R.getValue(VarName))
1151 if (RV == Val || (RV == 0 && !dynamic_cast<UnsetInit*>(Val->getValue())))
1152 return Val->getValue();
1156 std::string VarBitInit::getAsString() const {
1157 return TI->getAsString() + "{" + utostr(Bit) + "}";
1160 Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) {
1161 if (Init *I = getVariable()->resolveBitReference(R, RV, getBitNum()))
1166 std::string VarListElementInit::getAsString() const {
1167 return TI->getAsString() + "[" + utostr(Element) + "]";
1170 Init *VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) {
1171 if (Init *I = getVariable()->resolveListElementReference(R, RV,
1177 Init *VarListElementInit::resolveBitReference(Record &R, const RecordVal *RV,
1179 // FIXME: This should be implemented, to support references like:
1180 // bit B = AA[0]{1};
1184 Init *VarListElementInit::
1185 resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) {
1186 // FIXME: This should be implemented, to support references like:
1187 // int B = AA[0][1];
1191 RecTy *DefInit::getFieldType(const std::string &FieldName) const {
1192 if (const RecordVal *RV = Def->getValue(FieldName))
1193 return RV->getType();
1197 Init *DefInit::getFieldInit(Record &R, const RecordVal *RV,
1198 const std::string &FieldName) const {
1199 return Def->getValue(FieldName)->getValue();
1203 std::string DefInit::getAsString() const {
1204 return Def->getName();
1207 Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
1209 if (Init *BitsVal = Rec->getFieldInit(R, RV, FieldName))
1210 if (BitsInit *BI = dynamic_cast<BitsInit*>(BitsVal)) {
1211 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1212 Init *B = BI->getBit(Bit);
1214 if (dynamic_cast<BitInit*>(B)) // If the bit is set...
1215 return B; // Replace the VarBitInit with it.
1220 Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
1222 if (Init *ListVal = Rec->getFieldInit(R, RV, FieldName))
1223 if (ListInit *LI = dynamic_cast<ListInit*>(ListVal)) {
1224 if (Elt >= LI->getSize()) return 0;
1225 Init *E = LI->getElement(Elt);
1227 // If the element is set to some value, or if we are resolving a
1228 // reference to a specific variable and that variable is explicitly
1229 // unset, then replace the VarListElementInit with it.
1230 if (RV || !dynamic_cast<UnsetInit*>(E))
1236 Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) {
1237 Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
1239 Init *BitsVal = NewRec->getFieldInit(R, RV, FieldName);
1241 Init *BVR = BitsVal->resolveReferences(R, RV);
1242 return BVR->isComplete() ? BVR : this;
1245 if (NewRec != Rec) {
1246 return new FieldInit(NewRec, FieldName);
1251 Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
1252 std::vector<Init*> NewArgs;
1253 for (unsigned i = 0, e = Args.size(); i != e; ++i)
1254 NewArgs.push_back(Args[i]->resolveReferences(R, RV));
1256 Init *Op = Val->resolveReferences(R, RV);
1258 if (Args != NewArgs || Op != Val)
1259 return new DagInit(Op, ValName, NewArgs, ArgNames);
1265 std::string DagInit::getAsString() const {
1266 std::string Result = "(" + Val->getAsString();
1267 if (!ValName.empty())
1268 Result += ":" + ValName;
1270 Result += " " + Args[0]->getAsString();
1271 if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
1272 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
1273 Result += ", " + Args[i]->getAsString();
1274 if (!ArgNames[i].empty()) Result += ":$" + ArgNames[i];
1277 return Result + ")";
1281 //===----------------------------------------------------------------------===//
1282 // Other implementations
1283 //===----------------------------------------------------------------------===//
1285 RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P)
1286 : Name(N), Ty(T), Prefix(P) {
1287 Value = Ty->convertValue(new UnsetInit());
1288 assert(Value && "Cannot create unset value for current type!");
1291 void RecordVal::dump() const { errs() << *this; }
1293 void RecordVal::print(raw_ostream &OS, bool PrintSem) const {
1294 if (getPrefix()) OS << "field ";
1295 OS << *getType() << " " << getName();
1298 OS << " = " << *getValue();
1300 if (PrintSem) OS << ";\n";
1303 unsigned Record::LastID = 0;
1305 void Record::setName(const std::string &Name) {
1306 if (Records.getDef(getName()) == this) {
1307 Records.removeDef(getName());
1309 Records.addDef(this);
1311 Records.removeClass(getName());
1313 Records.addClass(this);
1317 /// resolveReferencesTo - If anything in this record refers to RV, replace the
1318 /// reference to RV with the RHS of RV. If RV is null, we resolve all possible
1320 void Record::resolveReferencesTo(const RecordVal *RV) {
1321 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
1322 if (Init *V = Values[i].getValue())
1323 Values[i].setValue(V->resolveReferences(*this, RV));
1327 void Record::dump() const { errs() << *this; }
1329 raw_ostream &llvm::operator<<(raw_ostream &OS, const Record &R) {
1332 const std::vector<std::string> &TArgs = R.getTemplateArgs();
1333 if (!TArgs.empty()) {
1335 for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1337 const RecordVal *RV = R.getValue(TArgs[i]);
1338 assert(RV && "Template argument record not found??");
1339 RV->print(OS, false);
1345 const std::vector<Record*> &SC = R.getSuperClasses();
1348 for (unsigned i = 0, e = SC.size(); i != e; ++i)
1349 OS << " " << SC[i]->getName();
1353 const std::vector<RecordVal> &Vals = R.getValues();
1354 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1355 if (Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1357 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1358 if (!Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1364 /// getValueInit - Return the initializer for a value with the specified name,
1365 /// or throw an exception if the field does not exist.
1367 Init *Record::getValueInit(StringRef FieldName) const {
1368 const RecordVal *R = getValue(FieldName);
1369 if (R == 0 || R->getValue() == 0)
1370 throw "Record `" + getName() + "' does not have a field named `" +
1371 FieldName.str() + "'!\n";
1372 return R->getValue();
1376 /// getValueAsString - This method looks up the specified field and returns its
1377 /// value as a string, throwing an exception if the field does not exist or if
1378 /// the value is not a string.
1380 std::string Record::getValueAsString(StringRef FieldName) const {
1381 const RecordVal *R = getValue(FieldName);
1382 if (R == 0 || R->getValue() == 0)
1383 throw "Record `" + getName() + "' does not have a field named `" +
1384 FieldName.str() + "'!\n";
1386 if (const StringInit *SI = dynamic_cast<const StringInit*>(R->getValue()))
1387 return SI->getValue();
1388 throw "Record `" + getName() + "', field `" + FieldName.str() +
1389 "' does not have a string initializer!";
1392 /// getValueAsBitsInit - This method looks up the specified field and returns
1393 /// its value as a BitsInit, throwing an exception if the field does not exist
1394 /// or if the value is not the right type.
1396 BitsInit *Record::getValueAsBitsInit(StringRef FieldName) const {
1397 const RecordVal *R = getValue(FieldName);
1398 if (R == 0 || R->getValue() == 0)
1399 throw "Record `" + getName() + "' does not have a field named `" +
1400 FieldName.str() + "'!\n";
1402 if (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue()))
1404 throw "Record `" + getName() + "', field `" + FieldName.str() +
1405 "' does not have a BitsInit initializer!";
1408 /// getValueAsListInit - This method looks up the specified field and returns
1409 /// its value as a ListInit, throwing an exception if the field does not exist
1410 /// or if the value is not the right type.
1412 ListInit *Record::getValueAsListInit(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 (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
1420 throw "Record `" + getName() + "', field `" + FieldName.str() +
1421 "' does not have a list initializer!";
1424 /// getValueAsListOfDefs - This method looks up the specified field and returns
1425 /// its value as a vector of records, throwing an exception if the field does
1426 /// not exist or if the value is not the right type.
1428 std::vector<Record*>
1429 Record::getValueAsListOfDefs(StringRef FieldName) const {
1430 ListInit *List = getValueAsListInit(FieldName);
1431 std::vector<Record*> Defs;
1432 for (unsigned i = 0; i < List->getSize(); i++) {
1433 if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
1434 Defs.push_back(DI->getDef());
1436 throw "Record `" + getName() + "', field `" + FieldName.str() +
1437 "' list is not entirely DefInit!";
1443 /// getValueAsInt - This method looks up the specified field and returns its
1444 /// value as an int64_t, throwing an exception if the field does not exist or if
1445 /// the value is not the right type.
1447 int64_t Record::getValueAsInt(StringRef FieldName) const {
1448 const RecordVal *R = getValue(FieldName);
1449 if (R == 0 || R->getValue() == 0)
1450 throw "Record `" + getName() + "' does not have a field named `" +
1451 FieldName.str() + "'!\n";
1453 if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
1454 return II->getValue();
1455 throw "Record `" + getName() + "', field `" + FieldName.str() +
1456 "' does not have an int initializer!";
1459 /// getValueAsListOfInts - This method looks up the specified field and returns
1460 /// its value as a vector of integers, throwing an exception if the field does
1461 /// not exist or if the value is not the right type.
1463 std::vector<int64_t>
1464 Record::getValueAsListOfInts(StringRef FieldName) const {
1465 ListInit *List = getValueAsListInit(FieldName);
1466 std::vector<int64_t> Ints;
1467 for (unsigned i = 0; i < List->getSize(); i++) {
1468 if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
1469 Ints.push_back(II->getValue());
1471 throw "Record `" + getName() + "', field `" + FieldName.str() +
1472 "' does not have a list of ints initializer!";
1478 /// getValueAsDef - This method looks up the specified field and returns its
1479 /// value as a Record, throwing an exception if the field does not exist or if
1480 /// the value is not the right type.
1482 Record *Record::getValueAsDef(StringRef FieldName) const {
1483 const RecordVal *R = getValue(FieldName);
1484 if (R == 0 || R->getValue() == 0)
1485 throw "Record `" + getName() + "' does not have a field named `" +
1486 FieldName.str() + "'!\n";
1488 if (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
1489 return DI->getDef();
1490 throw "Record `" + getName() + "', field `" + FieldName.str() +
1491 "' does not have a def initializer!";
1494 /// getValueAsBit - This method looks up the specified field and returns its
1495 /// value as a bit, throwing an exception if the field does not exist or if
1496 /// the value is not the right type.
1498 bool Record::getValueAsBit(StringRef FieldName) const {
1499 const RecordVal *R = getValue(FieldName);
1500 if (R == 0 || R->getValue() == 0)
1501 throw "Record `" + getName() + "' does not have a field named `" +
1502 FieldName.str() + "'!\n";
1504 if (BitInit *BI = dynamic_cast<BitInit*>(R->getValue()))
1505 return BI->getValue();
1506 throw "Record `" + getName() + "', field `" + FieldName.str() +
1507 "' does not have a bit initializer!";
1510 /// getValueAsDag - This method looks up the specified field and returns its
1511 /// value as an Dag, throwing an exception if the field does not exist or if
1512 /// the value is not the right type.
1514 DagInit *Record::getValueAsDag(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 (DagInit *DI = dynamic_cast<DagInit*>(R->getValue()))
1522 throw "Record `" + getName() + "', field `" + FieldName.str() +
1523 "' does not have a dag initializer!";
1526 std::string Record::getValueAsCode(StringRef FieldName) const {
1527 const RecordVal *R = getValue(FieldName);
1528 if (R == 0 || R->getValue() == 0)
1529 throw "Record `" + getName() + "' does not have a field named `" +
1530 FieldName.str() + "'!\n";
1532 if (const CodeInit *CI = dynamic_cast<const CodeInit*>(R->getValue()))
1533 return CI->getValue();
1534 throw "Record `" + getName() + "', field `" + FieldName.str() +
1535 "' does not have a code initializer!";
1539 void MultiClass::dump() const {
1540 errs() << "Record:\n";
1543 errs() << "Defs:\n";
1544 for (RecordVector::const_iterator r = DefPrototypes.begin(),
1545 rend = DefPrototypes.end();
1553 void RecordKeeper::dump() const { errs() << *this; }
1555 raw_ostream &llvm::operator<<(raw_ostream &OS, const RecordKeeper &RK) {
1556 OS << "------------- Classes -----------------\n";
1557 const std::map<std::string, Record*> &Classes = RK.getClasses();
1558 for (std::map<std::string, Record*>::const_iterator I = Classes.begin(),
1559 E = Classes.end(); I != E; ++I)
1560 OS << "class " << *I->second;
1562 OS << "------------- Defs -----------------\n";
1563 const std::map<std::string, Record*> &Defs = RK.getDefs();
1564 for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
1565 E = Defs.end(); I != E; ++I)
1566 OS << "def " << *I->second;
1571 /// getAllDerivedDefinitions - This method returns all concrete definitions
1572 /// that derive from the specified class name. If a class with the specified
1573 /// name does not exist, an error is printed and true is returned.
1574 std::vector<Record*>
1575 RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
1576 Record *Class = Records.getClass(ClassName);
1578 throw "ERROR: Couldn't find the `" + ClassName + "' class!\n";
1580 std::vector<Record*> Defs;
1581 for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(),
1582 E = getDefs().end(); I != E; ++I)
1583 if (I->second->isSubClassOf(Class))
1584 Defs.push_back(I->second);