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/Support/DataTypes.h"
16 #include "llvm/Support/Streams.h"
17 #include "llvm/ADT/StringExtras.h"
19 #include <sys/types.h>
24 //===----------------------------------------------------------------------===//
25 // Type implementations
26 //===----------------------------------------------------------------------===//
28 void RecTy::dump() const { print(*cerr.stream()); }
30 Init *BitRecTy::convertValue(BitsInit *BI) {
31 if (BI->getNumBits() != 1) return 0; // Only accept if just one bit!
35 bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
36 return RHS->getNumBits() == 1;
39 Init *BitRecTy::convertValue(IntInit *II) {
40 int64_t Val = II->getValue();
41 if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
43 return new BitInit(Val != 0);
46 Init *BitRecTy::convertValue(TypedInit *VI) {
47 if (dynamic_cast<BitRecTy*>(VI->getType()))
48 return VI; // Accept variable if it is already of bit type!
52 std::string BitsRecTy::getAsString() const {
53 return "bits<" + utostr(Size) + ">";
56 Init *BitsRecTy::convertValue(UnsetInit *UI) {
57 BitsInit *Ret = new BitsInit(Size);
59 for (unsigned i = 0; i != Size; ++i)
60 Ret->setBit(i, new UnsetInit());
64 Init *BitsRecTy::convertValue(BitInit *UI) {
65 if (Size != 1) return 0; // Can only convert single bit...
66 BitsInit *Ret = new BitsInit(1);
71 // convertValue from Int initializer to bits type: Split the integer up into the
72 // appropriate bits...
74 Init *BitsRecTy::convertValue(IntInit *II) {
75 int64_t Value = II->getValue();
76 // Make sure this bitfield is large enough to hold the integer value...
78 if (Value & ~((1LL << Size)-1))
81 if ((Value >> Size) != -1 || ((Value & (1LL << (Size-1))) == 0))
85 BitsInit *Ret = new BitsInit(Size);
86 for (unsigned i = 0; i != Size; ++i)
87 Ret->setBit(i, new BitInit(Value & (1LL << i)));
92 Init *BitsRecTy::convertValue(BitsInit *BI) {
93 // If the number of bits is right, return it. Otherwise we need to expand or
95 if (BI->getNumBits() == Size) return BI;
99 Init *BitsRecTy::convertValue(TypedInit *VI) {
100 if (BitsRecTy *BRT = dynamic_cast<BitsRecTy*>(VI->getType()))
101 if (BRT->Size == Size) {
102 BitsInit *Ret = new BitsInit(Size);
103 for (unsigned i = 0; i != Size; ++i)
104 Ret->setBit(i, new VarBitInit(VI, i));
107 if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
108 BitsInit *Ret = new BitsInit(1);
116 Init *IntRecTy::convertValue(BitInit *BI) {
117 return new IntInit(BI->getValue());
120 Init *IntRecTy::convertValue(BitsInit *BI) {
122 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
123 if (BitInit *Bit = dynamic_cast<BitInit*>(BI->getBit(i))) {
124 Result |= Bit->getValue() << i;
128 return new IntInit(Result);
131 Init *IntRecTy::convertValue(TypedInit *TI) {
132 if (TI->getType()->typeIsConvertibleTo(this))
133 return TI; // Accept variable if already of the right type!
137 Init *StringRecTy::convertValue(UnOpInit *BO) {
138 if (BO->getOpcode() == UnOpInit::CAST) {
139 Init *L = BO->getOperand()->convertInitializerTo(this);
140 if (L == 0) return 0;
141 if (L != BO->getOperand())
142 return new UnOpInit(UnOpInit::CAST, L, new StringRecTy);
146 return convertValue((TypedInit*)BO);
149 Init *StringRecTy::convertValue(BinOpInit *BO) {
150 if (BO->getOpcode() == BinOpInit::STRCONCAT) {
151 Init *L = BO->getLHS()->convertInitializerTo(this);
152 Init *R = BO->getRHS()->convertInitializerTo(this);
153 if (L == 0 || R == 0) return 0;
154 if (L != BO->getLHS() || R != BO->getRHS())
155 return new BinOpInit(BinOpInit::STRCONCAT, L, R, new StringRecTy);
158 if (BO->getOpcode() == BinOpInit::NAMECONCAT) {
159 if (BO->getType()->getAsString() == getAsString()) {
160 Init *L = BO->getLHS()->convertInitializerTo(this);
161 Init *R = BO->getRHS()->convertInitializerTo(this);
162 if (L == 0 || R == 0) return 0;
163 if (L != BO->getLHS() || R != BO->getRHS())
164 return new BinOpInit(BinOpInit::NAMECONCAT, L, R, new StringRecTy);
169 return convertValue((TypedInit*)BO);
173 Init *StringRecTy::convertValue(TypedInit *TI) {
174 if (dynamic_cast<StringRecTy*>(TI->getType()))
175 return TI; // Accept variable if already of the right type!
179 std::string ListRecTy::getAsString() const {
180 return "list<" + Ty->getAsString() + ">";
183 Init *ListRecTy::convertValue(ListInit *LI) {
184 std::vector<Init*> Elements;
186 // Verify that all of the elements of the list are subclasses of the
187 // appropriate class!
188 for (unsigned i = 0, e = LI->getSize(); i != e; ++i)
189 if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty))
190 Elements.push_back(CI);
194 ListRecTy *LType = dynamic_cast<ListRecTy*>(LI->getType());
199 return new ListInit(Elements, new ListRecTy(Ty));
202 Init *ListRecTy::convertValue(TypedInit *TI) {
203 // Ensure that TI is compatible with our class.
204 if (ListRecTy *LRT = dynamic_cast<ListRecTy*>(TI->getType()))
205 if (LRT->getElementType()->typeIsConvertibleTo(getElementType()))
210 Init *CodeRecTy::convertValue(TypedInit *TI) {
211 if (TI->getType()->typeIsConvertibleTo(this))
216 Init *DagRecTy::convertValue(TypedInit *TI) {
217 if (TI->getType()->typeIsConvertibleTo(this))
222 Init *DagRecTy::convertValue(UnOpInit *BO) {
223 if (BO->getOpcode() == UnOpInit::CAST) {
224 Init *L = BO->getOperand()->convertInitializerTo(this);
225 if (L == 0) return 0;
226 if (L != BO->getOperand())
227 return new UnOpInit(UnOpInit::CAST, L, new DagRecTy);
233 Init *DagRecTy::convertValue(BinOpInit *BO) {
234 if (BO->getOpcode() == BinOpInit::CONCAT) {
235 Init *L = BO->getLHS()->convertInitializerTo(this);
236 Init *R = BO->getRHS()->convertInitializerTo(this);
237 if (L == 0 || R == 0) return 0;
238 if (L != BO->getLHS() || R != BO->getRHS())
239 return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
242 if (BO->getOpcode() == BinOpInit::NAMECONCAT) {
243 if (BO->getType()->getAsString() == getAsString()) {
244 Init *L = BO->getLHS()->convertInitializerTo(this);
245 Init *R = BO->getRHS()->convertInitializerTo(this);
246 if (L == 0 || R == 0) return 0;
247 if (L != BO->getLHS() || R != BO->getRHS())
248 return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
255 std::string RecordRecTy::getAsString() const {
256 return Rec->getName();
259 Init *RecordRecTy::convertValue(DefInit *DI) {
260 // Ensure that DI is a subclass of Rec.
261 if (!DI->getDef()->isSubClassOf(Rec))
266 Init *RecordRecTy::convertValue(TypedInit *TI) {
267 // Ensure that TI is compatible with Rec.
268 if (RecordRecTy *RRT = dynamic_cast<RecordRecTy*>(TI->getType()))
269 if (RRT->getRecord()->isSubClassOf(getRecord()) ||
270 RRT->getRecord() == getRecord())
275 bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const {
276 return Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec);
280 /// resolveTypes - Find a common type that T1 and T2 convert to.
281 /// Return 0 if no such type exists.
283 RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
284 if (!T1->typeIsConvertibleTo(T2)) {
285 if (!T2->typeIsConvertibleTo(T1)) {
286 // If one is a Record type, check superclasses
287 RecordRecTy *RecTy1 = dynamic_cast<RecordRecTy*>(T1);
289 // See if T2 inherits from a type T1 also inherits from
290 const std::vector<Record *> &T1SuperClasses = RecTy1->getRecord()->getSuperClasses();
291 for(std::vector<Record *>::const_iterator i = T1SuperClasses.begin(),
292 iend = T1SuperClasses.end();
295 RecordRecTy *SuperRecTy1 = new RecordRecTy(*i);
296 RecTy *NewType1 = resolveTypes(SuperRecTy1, T2);
298 if (NewType1 != SuperRecTy1) {
305 RecordRecTy *RecTy2 = dynamic_cast<RecordRecTy*>(T2);
307 // See if T1 inherits from a type T2 also inherits from
308 const std::vector<Record *> &T2SuperClasses = RecTy2->getRecord()->getSuperClasses();
309 for(std::vector<Record *>::const_iterator i = T2SuperClasses.begin(),
310 iend = T2SuperClasses.end();
313 RecordRecTy *SuperRecTy2 = new RecordRecTy(*i);
314 RecTy *NewType2 = resolveTypes(T1, SuperRecTy2);
316 if (NewType2 != SuperRecTy2) {
331 //===----------------------------------------------------------------------===//
332 // Initializer implementations
333 //===----------------------------------------------------------------------===//
335 void Init::dump() const { return print(*cerr.stream()); }
337 Init *BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
338 BitsInit *BI = new BitsInit(Bits.size());
339 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
340 if (Bits[i] >= getNumBits()) {
344 BI->setBit(i, getBit(Bits[i]));
349 std::string BitsInit::getAsString() const {
350 //if (!printInHex(OS)) return;
351 //if (!printAsVariable(OS)) return;
352 //if (!printAsUnset(OS)) return;
354 std::string Result = "{ ";
355 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
356 if (i) Result += ", ";
357 if (Init *Bit = getBit(e-i-1))
358 Result += Bit->getAsString();
362 return Result + " }";
365 bool BitsInit::printInHex(std::ostream &OS) const {
366 // First, attempt to convert the value into an integer value...
368 for (unsigned i = 0, e = getNumBits(); i != e; ++i)
369 if (BitInit *Bit = dynamic_cast<BitInit*>(getBit(i))) {
370 Result |= Bit->getValue() << i;
375 OS << "0x" << std::hex << Result << std::dec;
379 bool BitsInit::printAsVariable(std::ostream &OS) const {
380 // Get the variable that we may be set equal to...
381 assert(getNumBits() != 0);
382 VarBitInit *FirstBit = dynamic_cast<VarBitInit*>(getBit(0));
383 if (FirstBit == 0) return true;
384 TypedInit *Var = FirstBit->getVariable();
386 // Check to make sure the types are compatible.
387 BitsRecTy *Ty = dynamic_cast<BitsRecTy*>(FirstBit->getVariable()->getType());
388 if (Ty == 0) return true;
389 if (Ty->getNumBits() != getNumBits()) return true; // Incompatible types!
391 // Check to make sure all bits are referring to the right bits in the variable
392 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
393 VarBitInit *Bit = dynamic_cast<VarBitInit*>(getBit(i));
394 if (Bit == 0 || Bit->getVariable() != Var || Bit->getBitNum() != i)
402 bool BitsInit::printAsUnset(std::ostream &OS) const {
403 for (unsigned i = 0, e = getNumBits(); i != e; ++i)
404 if (!dynamic_cast<UnsetInit*>(getBit(i)))
410 // resolveReferences - If there are any field references that refer to fields
411 // that have been filled in, we can propagate the values now.
413 Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) {
414 bool Changed = false;
415 BitsInit *New = new BitsInit(getNumBits());
417 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
419 Init *CurBit = getBit(i);
423 CurBit = CurBit->resolveReferences(R, RV);
424 Changed |= B != CurBit;
425 } while (B != CurBit);
426 New->setBit(i, CurBit);
435 std::string IntInit::getAsString() const {
436 return itostr(Value);
439 Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
440 BitsInit *BI = new BitsInit(Bits.size());
442 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
447 BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i])));
452 Init *ListInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
453 std::vector<Init*> Vals;
454 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
455 if (Elements[i] >= getSize())
457 Vals.push_back(getElement(Elements[i]));
459 return new ListInit(Vals, getType());
462 Record *ListInit::getElementAsRecord(unsigned i) const {
463 assert(i < Values.size() && "List element index out of range!");
464 DefInit *DI = dynamic_cast<DefInit*>(Values[i]);
465 if (DI == 0) throw "Expected record in list!";
469 Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) {
470 std::vector<Init*> Resolved;
471 Resolved.reserve(getSize());
472 bool Changed = false;
474 for (unsigned i = 0, e = getSize(); i != e; ++i) {
476 Init *CurElt = getElement(i);
480 CurElt = CurElt->resolveReferences(R, RV);
481 Changed |= E != CurElt;
482 } while (E != CurElt);
483 Resolved.push_back(E);
487 return new ListInit(Resolved, getType());
491 Init *ListInit::resolveListElementReference(Record &R, const RecordVal *IRV,
493 if (Elt >= getSize())
494 return 0; // Out of range reference.
495 Init *E = getElement(Elt);
496 if (!dynamic_cast<UnsetInit*>(E)) // If the element is set
497 return E; // Replace the VarListElementInit with it.
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 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
544 std::string Name = LHSs->getValue();
546 // From TGParser::ParseIDValue
548 if (const RecordVal *RV = CurRec->getValue(Name)) {
549 if (RV->getType() != getType()) {
550 throw "type mismatch in nameconcat";
552 return new VarInit(Name, RV->getType());
555 std::string TemplateArgName = CurRec->getName()+":"+Name;
556 if (CurRec->isTemplateArg(TemplateArgName)) {
557 const RecordVal *RV = CurRec->getValue(TemplateArgName);
558 assert(RV && "Template arg doesn't exist??");
560 if (RV->getType() != getType()) {
561 throw "type mismatch in nameconcat";
564 return new VarInit(TemplateArgName, RV->getType());
569 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
570 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
571 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
572 assert(RV && "Template arg doesn't exist??");
574 if (RV->getType() != getType()) {
575 throw "type mismatch in nameconcat";
578 return new VarInit(MCName, RV->getType());
582 if (Record *D = Records.getDef(Name))
583 return new DefInit(D);
585 cerr << "Variable not defined: '" + Name + "'\n";
586 assert(0 && "Variable not found");
592 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
594 if (LHSl->getSize() == 0) {
595 assert(0 && "Empty list in car");
598 return LHSl->getElement(0);
603 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
605 if (LHSl->getSize() == 0) {
606 assert(0 && "Empty list in cdr");
609 ListInit *Result = new ListInit(LHSl->begin()+1, LHSl->end(), LHSl->getType());
615 ListInit *LHSl = dynamic_cast<ListInit*>(LHS);
617 if (LHSl->getSize() == 0) {
618 return new IntInit(1);
621 return new IntInit(0);
624 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
626 if (LHSs->getValue().empty()) {
627 return new IntInit(1);
630 return new IntInit(0);
640 Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) {
641 Init *lhs = LHS->resolveReferences(R, RV);
644 return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
648 std::string UnOpInit::getAsString() const {
651 case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
652 case CAR: Result = "!car"; break;
653 case CDR: Result = "!cdr"; break;
654 case LNULL: Result = "!null"; break;
656 return Result + "(" + LHS->getAsString() + ")";
659 Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
660 switch (getOpcode()) {
661 default: assert(0 && "Unknown binop");
663 DagInit *LHSs = dynamic_cast<DagInit*>(LHS);
664 DagInit *RHSs = dynamic_cast<DagInit*>(RHS);
666 DefInit *LOp = dynamic_cast<DefInit*>(LHSs->getOperator());
667 DefInit *ROp = dynamic_cast<DefInit*>(RHSs->getOperator());
668 if (LOp->getDef() != ROp->getDef()) {
670 LOp->getDef()->getName() == "outs" ||
671 LOp->getDef()->getName() != "ins" ||
672 LOp->getDef()->getName() != "defs";
674 ROp->getDef()->getName() == "outs" ||
675 ROp->getDef()->getName() != "ins" ||
676 ROp->getDef()->getName() != "defs";
677 if (!LIsOps || !RIsOps)
678 throw "Concated Dag operators do not match!";
680 std::vector<Init*> Args;
681 std::vector<std::string> ArgNames;
682 for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
683 Args.push_back(LHSs->getArg(i));
684 ArgNames.push_back(LHSs->getArgName(i));
686 for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
687 Args.push_back(RHSs->getArg(i));
688 ArgNames.push_back(RHSs->getArgName(i));
690 return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
695 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
696 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
698 return new StringInit(LHSs->getValue() + RHSs->getValue());
702 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
703 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
705 std::string Name(LHSs->getValue() + RHSs->getValue());
707 // From TGParser::ParseIDValue
709 if (const RecordVal *RV = CurRec->getValue(Name)) {
710 if (RV->getType() != getType()) {
711 throw "type mismatch in nameconcat";
713 return new VarInit(Name, RV->getType());
716 std::string TemplateArgName = CurRec->getName()+":"+Name;
717 if (CurRec->isTemplateArg(TemplateArgName)) {
718 const RecordVal *RV = CurRec->getValue(TemplateArgName);
719 assert(RV && "Template arg doesn't exist??");
721 if (RV->getType() != getType()) {
722 throw "type mismatch in nameconcat";
725 return new VarInit(TemplateArgName, RV->getType());
730 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
731 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
732 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
733 assert(RV && "Template arg doesn't exist??");
735 if (RV->getType() != getType()) {
736 throw "type mismatch in nameconcat";
739 return new VarInit(MCName, RV->getType());
743 if (Record *D = Records.getDef(Name))
744 return new DefInit(D);
746 cerr << "Variable not defined in !nameconcat: '" + Name + "'\n";
747 assert(0 && "Variable not found in !nameconcat");
753 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
754 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
757 int err = regcomp (&compiled, LHSs->getValue().c_str(), REG_EXTENDED);
759 size_t length = regerror (err, &compiled, NULL, 0);
760 char *buffer = new char[length];
761 (void) regerror (err, &compiled, buffer, length);
762 std::string errmsg = buffer;
767 int result = regexec(&compiled, RHSs->getValue().c_str(), 0, NULL, 0);
768 if (result == REG_ESPACE) {
769 size_t length = regerror (err, &compiled, NULL, 0);
770 char *buffer = new char[length];
771 (void) regerror (err, &compiled, buffer, length);
772 std::string errmsg = buffer;
778 return new IntInit(result == 0);
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;
821 case REGMATCH: Result = "!regmatch"; break;
823 Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
825 return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
828 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
829 Record *CurRec, MultiClass *CurMultiClass);
831 static Init *EvaluateOperation(OpInit *RHSo, Init *LHS, Init *Arg,
832 RecTy *Type, Record *CurRec,
833 MultiClass *CurMultiClass) {
834 std::vector<Init *> NewOperands;
836 TypedInit *TArg = dynamic_cast<TypedInit*>(Arg);
838 // If this is a dag, recurse
839 if (TArg && TArg->getType()->getAsString() == "dag") {
840 Init *Result = ForeachHelper(LHS, Arg, RHSo, Type,
841 CurRec, CurMultiClass);
850 for (int i = 0; i < RHSo->getNumOperands(); ++i) {
851 OpInit *RHSoo = dynamic_cast<OpInit*>(RHSo->getOperand(i));
854 Init *Result = EvaluateOperation(RHSoo, LHS, Arg,
855 Type, CurRec, CurMultiClass);
857 NewOperands.push_back(Result);
860 NewOperands.push_back(Arg);
863 else if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
864 NewOperands.push_back(Arg);
867 NewOperands.push_back(RHSo->getOperand(i));
871 // Now run the operator and use its result as the new leaf
872 OpInit *NewOp = RHSo->clone(NewOperands);
873 Init *NewVal = NewOp->Fold(CurRec, CurMultiClass);
874 if (NewVal != NewOp) {
881 static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
882 Record *CurRec, MultiClass *CurMultiClass) {
883 DagInit *MHSd = dynamic_cast<DagInit*>(MHS);
884 ListInit *MHSl = dynamic_cast<ListInit*>(MHS);
886 DagRecTy *DagType = dynamic_cast<DagRecTy*>(Type);
887 ListRecTy *ListType = dynamic_cast<ListRecTy*>(Type);
889 OpInit *RHSo = dynamic_cast<OpInit*>(RHS);
892 cerr << "!foreach requires an operator\n";
893 assert(0 && "No operator for !foreach");
896 TypedInit *LHSt = dynamic_cast<TypedInit*>(LHS);
899 cerr << "!foreach requires typed variable\n";
900 assert(0 && "No typed variable for !foreach");
903 if ((MHSd && DagType) || (MHSl && ListType)) {
905 Init *Val = MHSd->getOperator();
906 Init *Result = EvaluateOperation(RHSo, LHS, Val,
907 Type, CurRec, CurMultiClass);
912 std::vector<std::pair<Init *, std::string> > args;
913 for (unsigned int i = 0; i < MHSd->getNumArgs(); ++i) {
916 Arg = MHSd->getArg(i);
917 ArgName = MHSd->getArgName(i);
920 Init *Result = EvaluateOperation(RHSo, LHS, Arg, Type,
921 CurRec, CurMultiClass);
926 // TODO: Process arg names
927 args.push_back(std::make_pair(Arg, ArgName));
930 return new DagInit(Val, "", args);
933 std::vector<Init *> NewOperands;
934 std::vector<Init *> NewList(MHSl->begin(), MHSl->end());
936 for (ListInit::iterator li = NewList.begin(),
937 liend = NewList.end();
942 for(int i = 0; i < RHSo->getNumOperands(); ++i) {
943 // First, replace the foreach variable with the list item
944 if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
945 NewOperands.push_back(Item);
948 NewOperands.push_back(RHSo->getOperand(i));
952 // Now run the operator and use its result as the new list item
953 OpInit *NewOp = RHSo->clone(NewOperands);
954 Init *NewItem = NewOp->Fold(CurRec, CurMultiClass);
955 if (NewItem != NewOp) {
960 return new ListInit(NewList, MHSl->getType());
966 Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
967 switch (getOpcode()) {
968 default: assert(0 && "Unknown binop");
970 DefInit *LHSd = dynamic_cast<DefInit*>(LHS);
971 VarInit *LHSv = dynamic_cast<VarInit*>(LHS);
972 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
974 DefInit *MHSd = dynamic_cast<DefInit*>(MHS);
975 VarInit *MHSv = dynamic_cast<VarInit*>(MHS);
976 StringInit *MHSs = dynamic_cast<StringInit*>(MHS);
978 DefInit *RHSd = dynamic_cast<DefInit*>(RHS);
979 VarInit *RHSv = dynamic_cast<VarInit*>(RHS);
980 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
982 if ((LHSd && MHSd && RHSd)
983 || (LHSv && MHSv && RHSv)
984 || (LHSs && MHSs && RHSs)) {
986 Record *Val = RHSd->getDef();
987 if (LHSd->getAsString() == RHSd->getAsString()) {
988 Val = MHSd->getDef();
990 return new DefInit(Val);
993 std::string Val = RHSv->getName();
994 if (LHSv->getAsString() == RHSv->getAsString()) {
995 Val = MHSv->getName();
997 return new VarInit(Val, getType());
1000 std::string Val = RHSs->getValue();
1002 std::string::size_type found;
1004 found = Val.find(LHSs->getValue());
1005 if (found != std::string::npos) {
1006 Val.replace(found, LHSs->getValue().size(), MHSs->getValue());
1008 } while (found != std::string::npos);
1010 return new StringInit(Val);
1017 Init *Result = ForeachHelper(LHS, MHS, RHS, getType(),
1018 CurRec, CurMultiClass);
1026 IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
1028 if (LHSi->getValue()) {
1042 Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) {
1043 Init *lhs = LHS->resolveReferences(R, RV);
1045 if (Opc == IF && lhs != LHS) {
1046 IntInit *Value = dynamic_cast<IntInit*>(lhs);
1049 if (Value->getValue()) {
1050 Init *mhs = MHS->resolveReferences(R, RV);
1051 return (new TernOpInit(getOpcode(), lhs, mhs, RHS, getType()))->Fold(&R, 0);
1054 Init *rhs = RHS->resolveReferences(R, RV);
1055 return (new TernOpInit(getOpcode(), lhs, MHS, rhs, getType()))->Fold(&R, 0);
1060 Init *mhs = MHS->resolveReferences(R, RV);
1061 Init *rhs = RHS->resolveReferences(R, RV);
1063 if (LHS != lhs || MHS != mhs || RHS != rhs)
1064 return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
1068 std::string TernOpInit::getAsString() const {
1071 case SUBST: Result = "!subst"; break;
1072 case FOREACH: Result = "!foreach"; break;
1073 case IF: Result = "!if"; break;
1075 return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", "
1076 + RHS->getAsString() + ")";
1079 Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
1080 BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType());
1081 if (T == 0) return 0; // Cannot subscript a non-bits variable...
1082 unsigned NumBits = T->getNumBits();
1084 BitsInit *BI = new BitsInit(Bits.size());
1085 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
1086 if (Bits[i] >= NumBits) {
1090 BI->setBit(i, new VarBitInit(this, Bits[i]));
1095 Init *TypedInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
1096 ListRecTy *T = dynamic_cast<ListRecTy*>(getType());
1097 if (T == 0) return 0; // Cannot subscript a non-list variable...
1099 if (Elements.size() == 1)
1100 return new VarListElementInit(this, Elements[0]);
1102 std::vector<Init*> ListInits;
1103 ListInits.reserve(Elements.size());
1104 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
1105 ListInits.push_back(new VarListElementInit(this, Elements[i]));
1106 return new ListInit(ListInits, T);
1110 Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV,
1112 if (R.isTemplateArg(getName())) return 0;
1113 if (IRV && IRV->getName() != getName()) return 0;
1115 RecordVal *RV = R.getValue(getName());
1116 assert(RV && "Reference to a non-existant variable?");
1117 assert(dynamic_cast<BitsInit*>(RV->getValue()));
1118 BitsInit *BI = (BitsInit*)RV->getValue();
1120 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1121 Init *B = BI->getBit(Bit);
1123 if (!dynamic_cast<UnsetInit*>(B)) // If the bit is not set...
1124 return B; // Replace the VarBitInit with it.
1128 Init *VarInit::resolveListElementReference(Record &R, const RecordVal *IRV,
1130 if (R.isTemplateArg(getName())) return 0;
1131 if (IRV && IRV->getName() != getName()) return 0;
1133 RecordVal *RV = R.getValue(getName());
1134 assert(RV && "Reference to a non-existant variable?");
1135 ListInit *LI = dynamic_cast<ListInit*>(RV->getValue());
1137 VarInit *VI = dynamic_cast<VarInit*>(RV->getValue());
1138 assert(VI && "Invalid list element!");
1139 return new VarListElementInit(VI, Elt);
1142 if (Elt >= LI->getSize())
1143 return 0; // Out of range reference.
1144 Init *E = LI->getElement(Elt);
1145 if (!dynamic_cast<UnsetInit*>(E)) // If the element is set
1146 return E; // Replace the VarListElementInit with it.
1151 RecTy *VarInit::getFieldType(const std::string &FieldName) const {
1152 if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
1153 if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
1154 return RV->getType();
1158 Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
1159 if (dynamic_cast<RecordRecTy*>(getType()))
1160 if (const RecordVal *RV = R.getValue(VarName)) {
1161 Init *TheInit = RV->getValue();
1162 assert(TheInit != this && "Infinite loop detected!");
1163 if (Init *I = TheInit->getFieldInit(R, FieldName))
1171 /// resolveReferences - This method is used by classes that refer to other
1172 /// variables which may not be defined at the time they expression is formed.
1173 /// If a value is set for the variable later, this method will be called on
1174 /// users of the value to allow the value to propagate out.
1176 Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) {
1177 if (RecordVal *Val = R.getValue(VarName))
1178 if (RV == Val || (RV == 0 && !dynamic_cast<UnsetInit*>(Val->getValue())))
1179 return Val->getValue();
1183 std::string VarBitInit::getAsString() const {
1184 return TI->getAsString() + "{" + utostr(Bit) + "}";
1187 Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) {
1188 if (Init *I = getVariable()->resolveBitReference(R, RV, getBitNum()))
1193 std::string VarListElementInit::getAsString() const {
1194 return TI->getAsString() + "[" + utostr(Element) + "]";
1197 Init *VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) {
1198 if (Init *I = getVariable()->resolveListElementReference(R, RV,
1204 Init *VarListElementInit::resolveBitReference(Record &R, const RecordVal *RV,
1206 // FIXME: This should be implemented, to support references like:
1207 // bit B = AA[0]{1};
1211 Init *VarListElementInit::
1212 resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) {
1213 // FIXME: This should be implemented, to support references like:
1214 // int B = AA[0][1];
1218 RecTy *DefInit::getFieldType(const std::string &FieldName) const {
1219 if (const RecordVal *RV = Def->getValue(FieldName))
1220 return RV->getType();
1224 Init *DefInit::getFieldInit(Record &R, const std::string &FieldName) const {
1225 return Def->getValue(FieldName)->getValue();
1229 std::string DefInit::getAsString() const {
1230 return Def->getName();
1233 Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
1235 if (Init *BitsVal = Rec->getFieldInit(R, FieldName))
1236 if (BitsInit *BI = dynamic_cast<BitsInit*>(BitsVal)) {
1237 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1238 Init *B = BI->getBit(Bit);
1240 if (dynamic_cast<BitInit*>(B)) // If the bit is set...
1241 return B; // Replace the VarBitInit with it.
1246 Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
1248 if (Init *ListVal = Rec->getFieldInit(R, FieldName))
1249 if (ListInit *LI = dynamic_cast<ListInit*>(ListVal)) {
1250 if (Elt >= LI->getSize()) return 0;
1251 Init *E = LI->getElement(Elt);
1253 if (!dynamic_cast<UnsetInit*>(E)) // If the bit is set...
1254 return E; // Replace the VarListElementInit with it.
1259 Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) {
1260 Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
1262 Init *BitsVal = NewRec->getFieldInit(R, FieldName);
1264 Init *BVR = BitsVal->resolveReferences(R, RV);
1265 return BVR->isComplete() ? BVR : this;
1268 if (NewRec != Rec) {
1269 return new FieldInit(NewRec, FieldName);
1274 Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
1275 std::vector<Init*> NewArgs;
1276 for (unsigned i = 0, e = Args.size(); i != e; ++i)
1277 NewArgs.push_back(Args[i]->resolveReferences(R, RV));
1279 Init *Op = Val->resolveReferences(R, RV);
1281 if (Args != NewArgs || Op != Val)
1282 return new DagInit(Op, "", NewArgs, ArgNames);
1288 std::string DagInit::getAsString() const {
1289 std::string Result = "(" + Val->getAsString();
1290 if (!ValName.empty())
1291 Result += ":" + ValName;
1293 Result += " " + Args[0]->getAsString();
1294 if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
1295 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
1296 Result += ", " + Args[i]->getAsString();
1297 if (!ArgNames[i].empty()) Result += ":$" + ArgNames[i];
1300 return Result + ")";
1304 //===----------------------------------------------------------------------===//
1305 // Other implementations
1306 //===----------------------------------------------------------------------===//
1308 RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P)
1309 : Name(N), Ty(T), Prefix(P) {
1310 Value = Ty->convertValue(new UnsetInit());
1311 assert(Value && "Cannot create unset value for current type!");
1314 void RecordVal::dump() const { cerr << *this; }
1316 void RecordVal::print(std::ostream &OS, bool PrintSem) const {
1317 if (getPrefix()) OS << "field ";
1318 OS << *getType() << " " << getName();
1321 OS << " = " << *getValue();
1323 if (PrintSem) OS << ";\n";
1326 void Record::setName(const std::string &Name) {
1327 if (Records.getDef(getName()) == this) {
1328 Records.removeDef(getName());
1330 Records.addDef(this);
1332 Records.removeClass(getName());
1334 Records.addClass(this);
1338 /// resolveReferencesTo - If anything in this record refers to RV, replace the
1339 /// reference to RV with the RHS of RV. If RV is null, we resolve all possible
1341 void Record::resolveReferencesTo(const RecordVal *RV) {
1342 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
1343 if (Init *V = Values[i].getValue())
1344 Values[i].setValue(V->resolveReferences(*this, RV));
1349 void Record::dump() const { cerr << *this; }
1351 std::ostream &llvm::operator<<(std::ostream &OS, const Record &R) {
1354 const std::vector<std::string> &TArgs = R.getTemplateArgs();
1355 if (!TArgs.empty()) {
1357 for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1359 const RecordVal *RV = R.getValue(TArgs[i]);
1360 assert(RV && "Template argument record not found??");
1361 RV->print(OS, false);
1367 const std::vector<Record*> &SC = R.getSuperClasses();
1370 for (unsigned i = 0, e = SC.size(); i != e; ++i)
1371 OS << " " << SC[i]->getName();
1375 const std::vector<RecordVal> &Vals = R.getValues();
1376 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1377 if (Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1379 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1380 if (!Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1386 /// getValueInit - Return the initializer for a value with the specified name,
1387 /// or throw an exception if the field does not exist.
1389 Init *Record::getValueInit(const std::string &FieldName) const {
1390 const RecordVal *R = getValue(FieldName);
1391 if (R == 0 || R->getValue() == 0)
1392 throw "Record `" + getName() + "' does not have a field named `" +
1394 return R->getValue();
1398 /// getValueAsString - This method looks up the specified field and returns its
1399 /// value as a string, throwing an exception if the field does not exist or if
1400 /// the value is not a string.
1402 std::string Record::getValueAsString(const std::string &FieldName) const {
1403 const RecordVal *R = getValue(FieldName);
1404 if (R == 0 || R->getValue() == 0)
1405 throw "Record `" + getName() + "' does not have a field named `" +
1408 if (const StringInit *SI = dynamic_cast<const StringInit*>(R->getValue()))
1409 return SI->getValue();
1410 throw "Record `" + getName() + "', field `" + FieldName +
1411 "' does not have a string initializer!";
1414 /// getValueAsBitsInit - This method looks up the specified field and returns
1415 /// its value as a BitsInit, throwing an exception if the field does not exist
1416 /// or if the value is not the right type.
1418 BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
1419 const RecordVal *R = getValue(FieldName);
1420 if (R == 0 || R->getValue() == 0)
1421 throw "Record `" + getName() + "' does not have a field named `" +
1424 if (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue()))
1426 throw "Record `" + getName() + "', field `" + FieldName +
1427 "' does not have a BitsInit initializer!";
1430 /// getValueAsListInit - This method looks up the specified field and returns
1431 /// its value as a ListInit, throwing an exception if the field does not exist
1432 /// or if the value is not the right type.
1434 ListInit *Record::getValueAsListInit(const std::string &FieldName) const {
1435 const RecordVal *R = getValue(FieldName);
1436 if (R == 0 || R->getValue() == 0)
1437 throw "Record `" + getName() + "' does not have a field named `" +
1440 if (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
1442 throw "Record `" + getName() + "', field `" + FieldName +
1443 "' does not have a list initializer!";
1446 /// getValueAsListOfDefs - This method looks up the specified field and returns
1447 /// its value as a vector of records, throwing an exception if the field does
1448 /// not exist or if the value is not the right type.
1450 std::vector<Record*>
1451 Record::getValueAsListOfDefs(const std::string &FieldName) const {
1452 ListInit *List = getValueAsListInit(FieldName);
1453 std::vector<Record*> Defs;
1454 for (unsigned i = 0; i < List->getSize(); i++) {
1455 if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
1456 Defs.push_back(DI->getDef());
1458 throw "Record `" + getName() + "', field `" + FieldName +
1459 "' list is not entirely DefInit!";
1465 /// getValueAsInt - This method looks up the specified field and returns its
1466 /// value as an int64_t, throwing an exception if the field does not exist or if
1467 /// the value is not the right type.
1469 int64_t Record::getValueAsInt(const std::string &FieldName) const {
1470 const RecordVal *R = getValue(FieldName);
1471 if (R == 0 || R->getValue() == 0)
1472 throw "Record `" + getName() + "' does not have a field named `" +
1475 if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
1476 return II->getValue();
1477 throw "Record `" + getName() + "', field `" + FieldName +
1478 "' does not have an int initializer!";
1481 /// getValueAsListOfInts - This method looks up the specified field and returns
1482 /// its value as a vector of integers, throwing an exception if the field does
1483 /// not exist or if the value is not the right type.
1485 std::vector<int64_t>
1486 Record::getValueAsListOfInts(const std::string &FieldName) const {
1487 ListInit *List = getValueAsListInit(FieldName);
1488 std::vector<int64_t> Ints;
1489 for (unsigned i = 0; i < List->getSize(); i++) {
1490 if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
1491 Ints.push_back(II->getValue());
1493 throw "Record `" + getName() + "', field `" + FieldName +
1494 "' does not have a list of ints initializer!";
1500 /// getValueAsDef - This method looks up the specified field and returns its
1501 /// value as a Record, throwing an exception if the field does not exist or if
1502 /// the value is not the right type.
1504 Record *Record::getValueAsDef(const std::string &FieldName) const {
1505 const RecordVal *R = getValue(FieldName);
1506 if (R == 0 || R->getValue() == 0)
1507 throw "Record `" + getName() + "' does not have a field named `" +
1510 if (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
1511 return DI->getDef();
1512 throw "Record `" + getName() + "', field `" + FieldName +
1513 "' does not have a def initializer!";
1516 /// getValueAsBit - This method looks up the specified field and returns its
1517 /// value as a bit, throwing an exception if the field does not exist or if
1518 /// the value is not the right type.
1520 bool Record::getValueAsBit(const std::string &FieldName) const {
1521 const RecordVal *R = getValue(FieldName);
1522 if (R == 0 || R->getValue() == 0)
1523 throw "Record `" + getName() + "' does not have a field named `" +
1526 if (BitInit *BI = dynamic_cast<BitInit*>(R->getValue()))
1527 return BI->getValue();
1528 throw "Record `" + getName() + "', field `" + FieldName +
1529 "' does not have a bit initializer!";
1532 /// getValueAsDag - This method looks up the specified field and returns its
1533 /// value as an Dag, throwing an exception if the field does not exist or if
1534 /// the value is not the right type.
1536 DagInit *Record::getValueAsDag(const std::string &FieldName) const {
1537 const RecordVal *R = getValue(FieldName);
1538 if (R == 0 || R->getValue() == 0)
1539 throw "Record `" + getName() + "' does not have a field named `" +
1542 if (DagInit *DI = dynamic_cast<DagInit*>(R->getValue()))
1544 throw "Record `" + getName() + "', field `" + FieldName +
1545 "' does not have a dag initializer!";
1548 std::string Record::getValueAsCode(const std::string &FieldName) const {
1549 const RecordVal *R = getValue(FieldName);
1550 if (R == 0 || R->getValue() == 0)
1551 throw "Record `" + getName() + "' does not have a field named `" +
1554 if (const CodeInit *CI = dynamic_cast<const CodeInit*>(R->getValue()))
1555 return CI->getValue();
1556 throw "Record `" + getName() + "', field `" + FieldName +
1557 "' does not have a code initializer!";
1561 void MultiClass::dump() const {
1562 cerr << "Record:\n";
1566 for (RecordVector::const_iterator r = DefPrototypes.begin(),
1567 rend = DefPrototypes.end();
1575 void RecordKeeper::dump() const { cerr << *this; }
1577 std::ostream &llvm::operator<<(std::ostream &OS, const RecordKeeper &RK) {
1578 OS << "------------- Classes -----------------\n";
1579 const std::map<std::string, Record*> &Classes = RK.getClasses();
1580 for (std::map<std::string, Record*>::const_iterator I = Classes.begin(),
1581 E = Classes.end(); I != E; ++I)
1582 OS << "class " << *I->second;
1584 OS << "------------- Defs -----------------\n";
1585 const std::map<std::string, Record*> &Defs = RK.getDefs();
1586 for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
1587 E = Defs.end(); I != E; ++I)
1588 OS << "def " << *I->second;
1593 /// getAllDerivedDefinitions - This method returns all concrete definitions
1594 /// that derive from the specified class name. If a class with the specified
1595 /// name does not exist, an error is printed and true is returned.
1596 std::vector<Record*>
1597 RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
1598 Record *Class = Records.getClass(ClassName);
1600 throw "ERROR: Couldn't find the `" + ClassName + "' class!\n";
1602 std::vector<Record*> Defs;
1603 for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(),
1604 E = getDefs().end(); I != E; ++I)
1605 if (I->second->isSubClassOf(Class))
1606 Defs.push_back(I->second);