blob: 2a8ddaa42c74cb57f405e95ef9d95b35d25f46f1 [file] [log] [blame]
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001//===- Record.cpp - Record implementation ---------------------------------===//
Misha Brukman650ba8e2005-04-22 00:00:37 +00002//
John Criswelld3032032003-10-20 20:20:30 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner8adcd9f2007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman650ba8e2005-04-22 00:00:37 +00007//
John Criswelld3032032003-10-20 20:20:30 +00008//===----------------------------------------------------------------------===//
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00009//
Chris Lattner51ffbf12006-03-31 21:53:49 +000010// Implement the tablegen record classes.
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "Record.h"
Misha Brukman46cee7d2004-09-30 18:27:39 +000015#include "llvm/Support/DataTypes.h"
Bill Wendling9bfb1e12006-12-07 22:21:48 +000016#include "llvm/Support/Streams.h"
Chris Lattner8b9ecda2007-11-20 22:25:16 +000017#include "llvm/ADT/StringExtras.h"
Duraid Madina14492af2005-12-26 05:08:55 +000018#include <ios>
19
Chris Lattner68478662004-08-01 03:55:39 +000020using namespace llvm;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000021
22//===----------------------------------------------------------------------===//
23// Type implementations
24//===----------------------------------------------------------------------===//
25
Bill Wendling9bfb1e12006-12-07 22:21:48 +000026void RecTy::dump() const { print(*cerr.stream()); }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000027
28Init *BitRecTy::convertValue(BitsInit *BI) {
29 if (BI->getNumBits() != 1) return 0; // Only accept if just one bit!
30 return BI->getBit(0);
31}
32
33bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
34 return RHS->getNumBits() == 1;
35}
36
37Init *BitRecTy::convertValue(IntInit *II) {
Dan Gohmanca0546f2008-10-17 01:33:43 +000038 int64_t Val = II->getValue();
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000039 if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
Misha Brukman650ba8e2005-04-22 00:00:37 +000040
41 return new BitInit(Val != 0);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000042}
43
44Init *BitRecTy::convertValue(TypedInit *VI) {
45 if (dynamic_cast<BitRecTy*>(VI->getType()))
46 return VI; // Accept variable if it is already of bit type!
47 return 0;
48}
49
Chris Lattner8b9ecda2007-11-20 22:25:16 +000050std::string BitsRecTy::getAsString() const {
51 return "bits<" + utostr(Size) + ">";
52}
53
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000054Init *BitsRecTy::convertValue(UnsetInit *UI) {
55 BitsInit *Ret = new BitsInit(Size);
56
57 for (unsigned i = 0; i != Size; ++i)
58 Ret->setBit(i, new UnsetInit());
59 return Ret;
60}
61
62Init *BitsRecTy::convertValue(BitInit *UI) {
63 if (Size != 1) return 0; // Can only convert single bit...
64 BitsInit *Ret = new BitsInit(1);
65 Ret->setBit(0, UI);
66 return Ret;
67}
68
69// convertValue from Int initializer to bits type: Split the integer up into the
70// appropriate bits...
71//
72Init *BitsRecTy::convertValue(IntInit *II) {
Misha Brukman6752fb52004-06-21 18:01:47 +000073 int64_t Value = II->getValue();
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000074 // Make sure this bitfield is large enough to hold the integer value...
75 if (Value >= 0) {
Misha Brukman6752fb52004-06-21 18:01:47 +000076 if (Value & ~((1LL << Size)-1))
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000077 return 0;
78 } else {
Jeff Cohen0add83e2006-02-18 03:20:33 +000079 if ((Value >> Size) != -1 || ((Value & (1LL << (Size-1))) == 0))
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000080 return 0;
81 }
82
83 BitsInit *Ret = new BitsInit(Size);
84 for (unsigned i = 0; i != Size; ++i)
Jeff Cohen0add83e2006-02-18 03:20:33 +000085 Ret->setBit(i, new BitInit(Value & (1LL << i)));
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000086
87 return Ret;
88}
89
90Init *BitsRecTy::convertValue(BitsInit *BI) {
91 // If the number of bits is right, return it. Otherwise we need to expand or
92 // truncate...
93 if (BI->getNumBits() == Size) return BI;
94 return 0;
95}
96
97Init *BitsRecTy::convertValue(TypedInit *VI) {
98 if (BitsRecTy *BRT = dynamic_cast<BitsRecTy*>(VI->getType()))
99 if (BRT->Size == Size) {
100 BitsInit *Ret = new BitsInit(Size);
101 for (unsigned i = 0; i != Size; ++i)
Jeff Cohen88e7b722005-04-22 04:13:13 +0000102 Ret->setBit(i, new VarBitInit(VI, i));
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000103 return Ret;
104 }
105 if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
106 BitsInit *Ret = new BitsInit(1);
107 Ret->setBit(0, VI);
108 return Ret;
109 }
Misha Brukman650ba8e2005-04-22 00:00:37 +0000110
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000111 return 0;
112}
113
114Init *IntRecTy::convertValue(BitInit *BI) {
115 return new IntInit(BI->getValue());
116}
117
118Init *IntRecTy::convertValue(BitsInit *BI) {
Dan Gohmanca0546f2008-10-17 01:33:43 +0000119 int64_t Result = 0;
Misha Brukman650ba8e2005-04-22 00:00:37 +0000120 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000121 if (BitInit *Bit = dynamic_cast<BitInit*>(BI->getBit(i))) {
122 Result |= Bit->getValue() << i;
123 } else {
124 return 0;
125 }
126 return new IntInit(Result);
127}
128
129Init *IntRecTy::convertValue(TypedInit *TI) {
130 if (TI->getType()->typeIsConvertibleTo(this))
131 return TI; // Accept variable if already of the right type!
132 return 0;
133}
134
David Greenee8f3b272009-05-14 21:22:49 +0000135Init *StringRecTy::convertValue(UnOpInit *BO) {
136 if (BO->getOpcode() == UnOpInit::CAST) {
137 Init *L = BO->getOperand()->convertInitializerTo(this);
138 if (L == 0) return 0;
139 if (L != BO->getOperand())
140 return new UnOpInit(UnOpInit::CAST, L, new StringRecTy);
141 return BO;
142 }
David Greene5d0c0512009-05-14 20:54:48 +0000143
David Greenee8f3b272009-05-14 21:22:49 +0000144 return convertValue((TypedInit*)BO);
145}
David Greene5d0c0512009-05-14 20:54:48 +0000146
Chris Lattner51ffbf12006-03-31 21:53:49 +0000147Init *StringRecTy::convertValue(BinOpInit *BO) {
148 if (BO->getOpcode() == BinOpInit::STRCONCAT) {
149 Init *L = BO->getLHS()->convertInitializerTo(this);
150 Init *R = BO->getRHS()->convertInitializerTo(this);
151 if (L == 0 || R == 0) return 0;
152 if (L != BO->getLHS() || R != BO->getRHS())
David Greene196ac3c2009-04-23 21:25:15 +0000153 return new BinOpInit(BinOpInit::STRCONCAT, L, R, new StringRecTy);
Chris Lattner51ffbf12006-03-31 21:53:49 +0000154 return BO;
155 }
David Greene196ac3c2009-04-23 21:25:15 +0000156 if (BO->getOpcode() == BinOpInit::NAMECONCAT) {
157 if (BO->getType()->getAsString() == getAsString()) {
158 Init *L = BO->getLHS()->convertInitializerTo(this);
159 Init *R = BO->getRHS()->convertInitializerTo(this);
160 if (L == 0 || R == 0) return 0;
161 if (L != BO->getLHS() || R != BO->getRHS())
162 return new BinOpInit(BinOpInit::NAMECONCAT, L, R, new StringRecTy);
163 return BO;
164 }
165 }
166
167 return convertValue((TypedInit*)BO);
Chris Lattner51ffbf12006-03-31 21:53:49 +0000168}
169
170
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000171Init *StringRecTy::convertValue(TypedInit *TI) {
172 if (dynamic_cast<StringRecTy*>(TI->getType()))
173 return TI; // Accept variable if already of the right type!
174 return 0;
175}
176
Chris Lattner8b9ecda2007-11-20 22:25:16 +0000177std::string ListRecTy::getAsString() const {
178 return "list<" + Ty->getAsString() + ">";
179}
180
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000181Init *ListRecTy::convertValue(ListInit *LI) {
182 std::vector<Init*> Elements;
183
184 // Verify that all of the elements of the list are subclasses of the
185 // appropriate class!
186 for (unsigned i = 0, e = LI->getSize(); i != e; ++i)
187 if (Init *CI = LI->getElement(i)->convertInitializerTo(Ty))
188 Elements.push_back(CI);
189 else
190 return 0;
191
192 return new ListInit(Elements);
193}
194
195Init *ListRecTy::convertValue(TypedInit *TI) {
196 // Ensure that TI is compatible with our class.
197 if (ListRecTy *LRT = dynamic_cast<ListRecTy*>(TI->getType()))
198 if (LRT->getElementType()->typeIsConvertibleTo(getElementType()))
199 return TI;
200 return 0;
201}
202
203Init *CodeRecTy::convertValue(TypedInit *TI) {
204 if (TI->getType()->typeIsConvertibleTo(this))
205 return TI;
206 return 0;
207}
208
209Init *DagRecTy::convertValue(TypedInit *TI) {
210 if (TI->getType()->typeIsConvertibleTo(this))
211 return TI;
212 return 0;
213}
214
David Greenee8f3b272009-05-14 21:22:49 +0000215Init *DagRecTy::convertValue(UnOpInit *BO) {
216 if (BO->getOpcode() == UnOpInit::CAST) {
217 Init *L = BO->getOperand()->convertInitializerTo(this);
218 if (L == 0) return 0;
219 if (L != BO->getOperand())
220 return new UnOpInit(UnOpInit::CAST, L, new DagRecTy);
221 return BO;
222 }
223 return 0;
224}
David Greene5d0c0512009-05-14 20:54:48 +0000225
Evan Chenga32dee22007-05-15 01:23:24 +0000226Init *DagRecTy::convertValue(BinOpInit *BO) {
227 if (BO->getOpcode() == BinOpInit::CONCAT) {
228 Init *L = BO->getLHS()->convertInitializerTo(this);
229 Init *R = BO->getRHS()->convertInitializerTo(this);
230 if (L == 0 || R == 0) return 0;
231 if (L != BO->getLHS() || R != BO->getRHS())
David Greene196ac3c2009-04-23 21:25:15 +0000232 return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
Evan Chenga32dee22007-05-15 01:23:24 +0000233 return BO;
234 }
David Greene196ac3c2009-04-23 21:25:15 +0000235 if (BO->getOpcode() == BinOpInit::NAMECONCAT) {
236 if (BO->getType()->getAsString() == getAsString()) {
237 Init *L = BO->getLHS()->convertInitializerTo(this);
238 Init *R = BO->getRHS()->convertInitializerTo(this);
239 if (L == 0 || R == 0) return 0;
240 if (L != BO->getLHS() || R != BO->getRHS())
241 return new BinOpInit(BinOpInit::CONCAT, L, R, new DagRecTy);
242 return BO;
243 }
244 }
Evan Chenga32dee22007-05-15 01:23:24 +0000245 return 0;
246}
247
Chris Lattner8b9ecda2007-11-20 22:25:16 +0000248std::string RecordRecTy::getAsString() const {
249 return Rec->getName();
250}
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000251
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000252Init *RecordRecTy::convertValue(DefInit *DI) {
253 // Ensure that DI is a subclass of Rec.
254 if (!DI->getDef()->isSubClassOf(Rec))
255 return 0;
256 return DI;
257}
258
259Init *RecordRecTy::convertValue(TypedInit *TI) {
260 // Ensure that TI is compatible with Rec.
261 if (RecordRecTy *RRT = dynamic_cast<RecordRecTy*>(TI->getType()))
262 if (RRT->getRecord()->isSubClassOf(getRecord()) ||
263 RRT->getRecord() == getRecord())
264 return TI;
265 return 0;
266}
267
268bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const {
269 return Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec);
270}
271
272
273//===----------------------------------------------------------------------===//
274// Initializer implementations
275//===----------------------------------------------------------------------===//
276
Bill Wendling9bfb1e12006-12-07 22:21:48 +0000277void Init::dump() const { return print(*cerr.stream()); }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000278
279Init *BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
280 BitsInit *BI = new BitsInit(Bits.size());
281 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
282 if (Bits[i] >= getNumBits()) {
283 delete BI;
284 return 0;
285 }
286 BI->setBit(i, getBit(Bits[i]));
287 }
288 return BI;
289}
290
Chris Lattner695506c2007-11-22 21:05:25 +0000291std::string BitsInit::getAsString() const {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000292 //if (!printInHex(OS)) return;
293 //if (!printAsVariable(OS)) return;
294 //if (!printAsUnset(OS)) return;
295
Chris Lattner695506c2007-11-22 21:05:25 +0000296 std::string Result = "{ ";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000297 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
Chris Lattner695506c2007-11-22 21:05:25 +0000298 if (i) Result += ", ";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000299 if (Init *Bit = getBit(e-i-1))
Chris Lattner695506c2007-11-22 21:05:25 +0000300 Result += Bit->getAsString();
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000301 else
Chris Lattner695506c2007-11-22 21:05:25 +0000302 Result += "*";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000303 }
Chris Lattner695506c2007-11-22 21:05:25 +0000304 return Result + " }";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000305}
306
307bool BitsInit::printInHex(std::ostream &OS) const {
308 // First, attempt to convert the value into an integer value...
Dan Gohmanca0546f2008-10-17 01:33:43 +0000309 int64_t Result = 0;
Misha Brukman650ba8e2005-04-22 00:00:37 +0000310 for (unsigned i = 0, e = getNumBits(); i != e; ++i)
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000311 if (BitInit *Bit = dynamic_cast<BitInit*>(getBit(i))) {
312 Result |= Bit->getValue() << i;
313 } else {
314 return true;
315 }
316
317 OS << "0x" << std::hex << Result << std::dec;
318 return false;
319}
320
321bool BitsInit::printAsVariable(std::ostream &OS) const {
322 // Get the variable that we may be set equal to...
323 assert(getNumBits() != 0);
324 VarBitInit *FirstBit = dynamic_cast<VarBitInit*>(getBit(0));
325 if (FirstBit == 0) return true;
326 TypedInit *Var = FirstBit->getVariable();
327
328 // Check to make sure the types are compatible.
329 BitsRecTy *Ty = dynamic_cast<BitsRecTy*>(FirstBit->getVariable()->getType());
330 if (Ty == 0) return true;
331 if (Ty->getNumBits() != getNumBits()) return true; // Incompatible types!
332
333 // Check to make sure all bits are referring to the right bits in the variable
334 for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
335 VarBitInit *Bit = dynamic_cast<VarBitInit*>(getBit(i));
336 if (Bit == 0 || Bit->getVariable() != Var || Bit->getBitNum() != i)
337 return true;
338 }
339
340 Var->print(OS);
341 return false;
342}
343
344bool BitsInit::printAsUnset(std::ostream &OS) const {
Misha Brukman650ba8e2005-04-22 00:00:37 +0000345 for (unsigned i = 0, e = getNumBits(); i != e; ++i)
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000346 if (!dynamic_cast<UnsetInit*>(getBit(i)))
347 return true;
348 OS << "?";
349 return false;
350}
351
352// resolveReferences - If there are any field references that refer to fields
353// that have been filled in, we can propagate the values now.
354//
Chris Lattneref943742005-04-19 03:36:21 +0000355Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000356 bool Changed = false;
357 BitsInit *New = new BitsInit(getNumBits());
358
359 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
360 Init *B;
361 Init *CurBit = getBit(i);
362
363 do {
364 B = CurBit;
Chris Lattneref943742005-04-19 03:36:21 +0000365 CurBit = CurBit->resolveReferences(R, RV);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000366 Changed |= B != CurBit;
367 } while (B != CurBit);
368 New->setBit(i, CurBit);
369 }
370
371 if (Changed)
372 return New;
373 delete New;
374 return this;
375}
376
Chris Lattner695506c2007-11-22 21:05:25 +0000377std::string IntInit::getAsString() const {
378 return itostr(Value);
379}
380
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000381Init *IntInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
382 BitsInit *BI = new BitsInit(Bits.size());
383
384 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
Dan Gohmanca0546f2008-10-17 01:33:43 +0000385 if (Bits[i] >= 64) {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000386 delete BI;
387 return 0;
388 }
Dan Gohmanca0546f2008-10-17 01:33:43 +0000389 BI->setBit(i, new BitInit(Value & (INT64_C(1) << Bits[i])));
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000390 }
391 return BI;
392}
393
Chris Lattner8bf9e062004-07-26 23:21:34 +0000394Init *ListInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
395 std::vector<Init*> Vals;
396 for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
397 if (Elements[i] >= getSize())
398 return 0;
399 Vals.push_back(getElement(Elements[i]));
400 }
401 return new ListInit(Vals);
402}
403
Chris Lattnercbebe462007-02-27 22:08:27 +0000404Record *ListInit::getElementAsRecord(unsigned i) const {
405 assert(i < Values.size() && "List element index out of range!");
406 DefInit *DI = dynamic_cast<DefInit*>(Values[i]);
407 if (DI == 0) throw "Expected record in list!";
408 return DI->getDef();
409}
410
Chris Lattneref943742005-04-19 03:36:21 +0000411Init *ListInit::resolveReferences(Record &R, const RecordVal *RV) {
Chris Lattner577fc3f2004-07-27 01:01:21 +0000412 std::vector<Init*> Resolved;
413 Resolved.reserve(getSize());
414 bool Changed = false;
415
416 for (unsigned i = 0, e = getSize(); i != e; ++i) {
417 Init *E;
418 Init *CurElt = getElement(i);
419
420 do {
421 E = CurElt;
Chris Lattneref943742005-04-19 03:36:21 +0000422 CurElt = CurElt->resolveReferences(R, RV);
Chris Lattner577fc3f2004-07-27 01:01:21 +0000423 Changed |= E != CurElt;
424 } while (E != CurElt);
425 Resolved.push_back(E);
426 }
427
428 if (Changed)
429 return new ListInit(Resolved);
430 return this;
431}
432
Chris Lattner695506c2007-11-22 21:05:25 +0000433std::string ListInit::getAsString() const {
434 std::string Result = "[";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000435 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
Chris Lattner695506c2007-11-22 21:05:25 +0000436 if (i) Result += ", ";
437 Result += Values[i]->getAsString();
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000438 }
Chris Lattner695506c2007-11-22 21:05:25 +0000439 return Result + "]";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000440}
441
David Greene5d0c0512009-05-14 20:54:48 +0000442Init *OpInit::resolveBitReference(Record &R, const RecordVal *IRV,
443 unsigned Bit) {
444 Init *Folded = Fold(&R, 0);
445
446 if (Folded != this) {
447 TypedInit *Typed = dynamic_cast<TypedInit *>(Folded);
448 if (Typed) {
449 return Typed->resolveBitReference(R, IRV, Bit);
450 }
451 }
452
453 return 0;
454}
455
456Init *OpInit::resolveListElementReference(Record &R, const RecordVal *IRV,
457 unsigned Elt) {
458 Init *Folded = Fold(&R, 0);
459
460 if (Folded != this) {
461 TypedInit *Typed = dynamic_cast<TypedInit *>(Folded);
462 if (Typed) {
463 return Typed->resolveListElementReference(R, IRV, Elt);
464 }
465 }
466
467 return 0;
468}
469
David Greenee8f3b272009-05-14 21:22:49 +0000470Init *UnOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
471 switch (getOpcode()) {
472 default: assert(0 && "Unknown unop");
473 case CAST: {
474 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
475 if (LHSs) {
476 std::string Name = LHSs->getValue();
David Greene5d0c0512009-05-14 20:54:48 +0000477
David Greenee8f3b272009-05-14 21:22:49 +0000478 // From TGParser::ParseIDValue
479 if (CurRec) {
480 if (const RecordVal *RV = CurRec->getValue(Name)) {
481 if (RV->getType() != getType()) {
482 throw "type mismatch in nameconcat";
483 }
484 return new VarInit(Name, RV->getType());
485 }
David Greene5d0c0512009-05-14 20:54:48 +0000486
David Greenee8f3b272009-05-14 21:22:49 +0000487 std::string TemplateArgName = CurRec->getName()+":"+Name;
488 if (CurRec->isTemplateArg(TemplateArgName)) {
489 const RecordVal *RV = CurRec->getValue(TemplateArgName);
490 assert(RV && "Template arg doesn't exist??");
David Greene5d0c0512009-05-14 20:54:48 +0000491
David Greenee8f3b272009-05-14 21:22:49 +0000492 if (RV->getType() != getType()) {
493 throw "type mismatch in nameconcat";
494 }
David Greene5d0c0512009-05-14 20:54:48 +0000495
David Greenee8f3b272009-05-14 21:22:49 +0000496 return new VarInit(TemplateArgName, RV->getType());
497 }
498 }
David Greene5d0c0512009-05-14 20:54:48 +0000499
David Greenee8f3b272009-05-14 21:22:49 +0000500 if (CurMultiClass) {
501 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
502 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
503 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
504 assert(RV && "Template arg doesn't exist??");
David Greene5d0c0512009-05-14 20:54:48 +0000505
David Greenee8f3b272009-05-14 21:22:49 +0000506 if (RV->getType() != getType()) {
507 throw "type mismatch in nameconcat";
508 }
David Greene5d0c0512009-05-14 20:54:48 +0000509
David Greenee8f3b272009-05-14 21:22:49 +0000510 return new VarInit(MCName, RV->getType());
511 }
512 }
David Greene5d0c0512009-05-14 20:54:48 +0000513
David Greenee8f3b272009-05-14 21:22:49 +0000514 if (Record *D = Records.getDef(Name))
515 return new DefInit(D);
David Greene5d0c0512009-05-14 20:54:48 +0000516
David Greenee8f3b272009-05-14 21:22:49 +0000517 cerr << "Variable not defined: '" + Name + "'\n";
518 assert(0 && "Variable not found");
519 return 0;
520 }
521 break;
522 }
523 }
524 return this;
525}
David Greene5d0c0512009-05-14 20:54:48 +0000526
David Greenee8f3b272009-05-14 21:22:49 +0000527Init *UnOpInit::resolveReferences(Record &R, const RecordVal *RV) {
528 Init *lhs = LHS->resolveReferences(R, RV);
David Greene5d0c0512009-05-14 20:54:48 +0000529
David Greenee8f3b272009-05-14 21:22:49 +0000530 if (LHS != lhs)
531 return (new UnOpInit(getOpcode(), lhs, getType()))->Fold(&R, 0);
532 return Fold(&R, 0);
533}
David Greene5d0c0512009-05-14 20:54:48 +0000534
David Greenee8f3b272009-05-14 21:22:49 +0000535std::string UnOpInit::getAsString() const {
536 std::string Result;
537 switch (Opc) {
538 case CAST: Result = "!cast<" + getType()->getAsString() + ">"; break;
539 }
540 return Result + "(" + LHS->getAsString() + ")";
541}
David Greene5d0c0512009-05-14 20:54:48 +0000542
David Greenea9c6c5d2009-04-22 20:18:10 +0000543Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
Chris Lattner51ffbf12006-03-31 21:53:49 +0000544 switch (getOpcode()) {
545 default: assert(0 && "Unknown binop");
Evan Chenga32dee22007-05-15 01:23:24 +0000546 case CONCAT: {
547 DagInit *LHSs = dynamic_cast<DagInit*>(LHS);
548 DagInit *RHSs = dynamic_cast<DagInit*>(RHS);
549 if (LHSs && RHSs) {
550 DefInit *LOp = dynamic_cast<DefInit*>(LHSs->getOperator());
551 DefInit *ROp = dynamic_cast<DefInit*>(RHSs->getOperator());
Evan Cheng94b5a802007-07-19 01:14:50 +0000552 if (LOp->getDef() != ROp->getDef()) {
553 bool LIsOps =
554 LOp->getDef()->getName() == "outs" ||
555 LOp->getDef()->getName() != "ins" ||
556 LOp->getDef()->getName() != "defs";
557 bool RIsOps =
558 ROp->getDef()->getName() == "outs" ||
559 ROp->getDef()->getName() != "ins" ||
560 ROp->getDef()->getName() != "defs";
561 if (!LIsOps || !RIsOps)
562 throw "Concated Dag operators do not match!";
563 }
Evan Chenga32dee22007-05-15 01:23:24 +0000564 std::vector<Init*> Args;
565 std::vector<std::string> ArgNames;
566 for (unsigned i = 0, e = LHSs->getNumArgs(); i != e; ++i) {
567 Args.push_back(LHSs->getArg(i));
568 ArgNames.push_back(LHSs->getArgName(i));
569 }
570 for (unsigned i = 0, e = RHSs->getNumArgs(); i != e; ++i) {
571 Args.push_back(RHSs->getArg(i));
572 ArgNames.push_back(RHSs->getArgName(i));
573 }
Nate Begemandbe3f772009-03-19 05:21:56 +0000574 return new DagInit(LHSs->getOperator(), "", Args, ArgNames);
Evan Chenga32dee22007-05-15 01:23:24 +0000575 }
576 break;
577 }
Chris Lattner51ffbf12006-03-31 21:53:49 +0000578 case STRCONCAT: {
579 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
580 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
581 if (LHSs && RHSs)
582 return new StringInit(LHSs->getValue() + RHSs->getValue());
583 break;
584 }
David Greenea9c6c5d2009-04-22 20:18:10 +0000585 case NAMECONCAT: {
586 StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
587 StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
588 if (LHSs && RHSs) {
589 std::string Name(LHSs->getValue() + RHSs->getValue());
590
591 // From TGParser::ParseIDValue
592 if (CurRec) {
David Greene196ac3c2009-04-23 21:25:15 +0000593 if (const RecordVal *RV = CurRec->getValue(Name)) {
594 if (RV->getType() != getType()) {
595 throw "type mismatch in nameconcat";
596 }
David Greenea9c6c5d2009-04-22 20:18:10 +0000597 return new VarInit(Name, RV->getType());
David Greene196ac3c2009-04-23 21:25:15 +0000598 }
599
David Greenea9c6c5d2009-04-22 20:18:10 +0000600 std::string TemplateArgName = CurRec->getName()+":"+Name;
601 if (CurRec->isTemplateArg(TemplateArgName)) {
602 const RecordVal *RV = CurRec->getValue(TemplateArgName);
603 assert(RV && "Template arg doesn't exist??");
David Greene196ac3c2009-04-23 21:25:15 +0000604
605 if (RV->getType() != getType()) {
606 throw "type mismatch in nameconcat";
607 }
608
David Greenea9c6c5d2009-04-22 20:18:10 +0000609 return new VarInit(TemplateArgName, RV->getType());
610 }
611 }
612
613 if (CurMultiClass) {
614 std::string MCName = CurMultiClass->Rec.getName()+"::"+Name;
615 if (CurMultiClass->Rec.isTemplateArg(MCName)) {
616 const RecordVal *RV = CurMultiClass->Rec.getValue(MCName);
617 assert(RV && "Template arg doesn't exist??");
David Greene196ac3c2009-04-23 21:25:15 +0000618
619 if (RV->getType() != getType()) {
620 throw "type mismatch in nameconcat";
621 }
622
David Greenea9c6c5d2009-04-22 20:18:10 +0000623 return new VarInit(MCName, RV->getType());
624 }
625 }
626
627 if (Record *D = Records.getDef(Name))
628 return new DefInit(D);
629
630 cerr << "Variable not defined: '" + Name + "'\n";
631 assert(0 && "Variable not found");
632 return 0;
633 }
634 break;
635 }
Chris Lattner51ffbf12006-03-31 21:53:49 +0000636 case SHL:
637 case SRA:
638 case SRL: {
639 IntInit *LHSi = dynamic_cast<IntInit*>(LHS);
640 IntInit *RHSi = dynamic_cast<IntInit*>(RHS);
641 if (LHSi && RHSi) {
Dan Gohmanca0546f2008-10-17 01:33:43 +0000642 int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue();
643 int64_t Result;
Chris Lattner51ffbf12006-03-31 21:53:49 +0000644 switch (getOpcode()) {
645 default: assert(0 && "Bad opcode!");
646 case SHL: Result = LHSv << RHSv; break;
647 case SRA: Result = LHSv >> RHSv; break;
Dan Gohmanca0546f2008-10-17 01:33:43 +0000648 case SRL: Result = (uint64_t)LHSv >> (uint64_t)RHSv; break;
Chris Lattner51ffbf12006-03-31 21:53:49 +0000649 }
650 return new IntInit(Result);
651 }
652 break;
653 }
654 }
655 return this;
656}
657
658Init *BinOpInit::resolveReferences(Record &R, const RecordVal *RV) {
659 Init *lhs = LHS->resolveReferences(R, RV);
660 Init *rhs = RHS->resolveReferences(R, RV);
661
662 if (LHS != lhs || RHS != rhs)
David Greene196ac3c2009-04-23 21:25:15 +0000663 return (new BinOpInit(getOpcode(), lhs, rhs, getType()))->Fold(&R, 0);
David Greenea9c6c5d2009-04-22 20:18:10 +0000664 return Fold(&R, 0);
Chris Lattner51ffbf12006-03-31 21:53:49 +0000665}
666
Chris Lattner695506c2007-11-22 21:05:25 +0000667std::string BinOpInit::getAsString() const {
668 std::string Result;
Chris Lattner51ffbf12006-03-31 21:53:49 +0000669 switch (Opc) {
Chris Lattner695506c2007-11-22 21:05:25 +0000670 case CONCAT: Result = "!con"; break;
671 case SHL: Result = "!shl"; break;
672 case SRA: Result = "!sra"; break;
673 case SRL: Result = "!srl"; break;
674 case STRCONCAT: Result = "!strconcat"; break;
David Greene196ac3c2009-04-23 21:25:15 +0000675 case NAMECONCAT:
676 Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
Chris Lattner51ffbf12006-03-31 21:53:49 +0000677 }
Chris Lattner695506c2007-11-22 21:05:25 +0000678 return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
Chris Lattner51ffbf12006-03-31 21:53:49 +0000679}
680
David Greene5d0c0512009-05-14 20:54:48 +0000681// Init *TernOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
682// switch (getOpcode()) {
683// default: assert(0 && "Unknown binop");
684// case SUBST: {
685// DefInit *LHSd = dynamic_cast<DefInit*>(LHS);
686// VarInit *LHSv = dynamic_cast<VarInit*>(LHS);
687// StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
David Greene196ac3c2009-04-23 21:25:15 +0000688
David Greene5d0c0512009-05-14 20:54:48 +0000689// DefInit *MHSd = dynamic_cast<DefInit*>(MHS);
690// VarInit *MHSv = dynamic_cast<VarInit*>(MHS);
691// StringInit *MHSs = dynamic_cast<StringInit*>(MHS);
692
693// DagInit *RHSd = dynamic_cast<DagInit*>(RHS);
694// ListInit *RHSl = dynamic_cast<ListInit*>(RHS);
695
696// DagRecTy *DagType = dynamic_cast<DagRecTy*>(getType());
697// ListRecTy *ListType = dynamic_cast<ListRecTy*>(getType());
698
699// if ((DagType && RHSd || ListType && RHSl)
700// && (LHSd && MHSd || LHSv && MHSv || LHSs && MHSs)) {
701// if (RHSd) {
702// Init *Val = RHSd->getOperator();
703// if (Val->getAsString() == LHS->getAsString()) {
704// Val = MHS;
705// }
706// std::vector<std::pair<Init *, std::string> > args;
707// for (int i = 0; i < RHSd->getNumArgs(); ++i) {
708// Init *Arg;
709// std::string ArgName;
710// Arg = RHSd->getArg(i);
711// ArgName = RHSd->getArgName(i);
712// if (Arg->getAsString() == LHS->getAsString()) {
713// Arg = MHS;
714// }
715// if (ArgName == LHS->getAsString()) {
716// ArgName = MHS->getAsString();
717// }
718// args.push_back(std::make_pair(Arg, ArgName));
719// }
720
721// return new DagInit(Val, args);
722// }
723// if (RHSl) {
724// std::vector<Init *> NewList(RHSl->begin(), RHSl->end());
725
726// for (ListInit::iterator i = NewList.begin(),
727// iend = NewList.end();
728// i != iend;
729// ++i) {
730// if ((*i)->getAsString() == LHS->getAsString()) {
731// *i = MHS;
732// }
733// }
734// return new ListInit(NewList);
735// }
736// }
737// break;
738// }
739
740// case FOREACH: {
741// DagInit *MHSd = dynamic_cast<DagInit*>(MHS);
742// ListInit *MHSl = dynamic_cast<ListInit*>(MHS);
743
744// DagRecTy *DagType = dynamic_cast<DagRecTy*>(getType());
745// ListRecTy *ListType = dynamic_cast<ListRecTy*>(getType());
746
747// OpInit *RHSo = dynamic_cast<OpInit*>(RHS);
748
749// if (!RHSo) {
750// cerr << "!foreach requires an operator\n";
751// assert(0 && "No operator for !foreach");
752// }
753
754// TypedInit *LHSt = dynamic_cast<TypedInit*>(LHS);
755
756// if (!LHSt) {
757// cerr << "!foreach requires typed variable\n";
758// assert(0 && "No typed variable for !foreach");
759// }
760
761// if (MHSd && DagType || MHSl && ListType) {
762// std::vector<Init *> NewOperands;
763// if (MHSd) {
764// Init *Val = MHSd->getOperator();
765// TypedInit *TVal = dynamic_cast<TypedInit*>(Val);
766
767// if (TVal && TVal->getType()->typeIsConvertibleTo(LHSt->getType())) {
768
769// // First, replace the foreach variable with the DAG leaf
770// for (int i = 0; i < RHSo->getNumOperands(); ++i) {
771// if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
772// NewOperands.push_back(Val);
773// }
774// else {
775// NewOperands.push_back(RHSo->getOperand(i));
776// }
777// }
778
779// // Now run the operator and use its result as the new leaf
780// OpInit *NewOp = RHSo->clone(NewOperands);
781// Val = NewOp->Fold(CurRec, CurMultiClass);
782// if (Val != NewOp) {
783// delete NewOp;
784// }
785// }
786
787// std::vector<std::pair<Init *, std::string> > args;
788// for (int i = 0; i < MHSd->getNumArgs(); ++i) {
789// Init *Arg;
790// std::string ArgName;
791// Arg = MHSd->getArg(i);
792// ArgName = MHSd->getArgName(i);
793
794// TypedInit *TArg = dynamic_cast<TypedInit*>(Arg);
795
796// if (TArg && TArg->getType()->typeIsConvertibleTo(LHSt->getType())) {
797// NewOperands.clear();
798
799// // First, replace the foreach variable with the DAG leaf
800// for (int i = 0; i < RHSo->getNumOperands(); ++i) {
801// if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
802// NewOperands.push_back(Arg);
803// }
804// else {
805// NewOperands.push_back(RHSo->getOperand(i));
806// }
807// }
808
809// // Now run the operator and use its result as the new leaf
810// OpInit *NewOp = RHSo->clone(NewOperands);
811// Arg = NewOp->Fold(CurRec, CurMultiClass);
812// if (Arg != NewOp) {
813// delete NewOp;
814// }
815// }
816
817// if (LHSt->getType()->getAsString() == "string") {
818// NewOperands.clear();
819
820// // First, replace the foreach variable with the DAG leaf
821// for (int i = 0; i < RHSo->getNumOperands(); ++i) {
822// if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
823// NewOperands.push_back(new StringInit(ArgName));
824// }
825// else {
826// NewOperands.push_back(RHSo->getOperand(i));
827// }
828// }
829
830// // Now run the operator and use its result as the new leaf
831// OpInit *NewOp = RHSo->clone(NewOperands);
832// Init *ArgNameInit = NewOp->Fold(CurRec, CurMultiClass);
833// StringInit *SArgNameInit = dynamic_cast<StringInit*>(ArgNameInit);
834// if (SArgNameInit) {
835// ArgName = SArgNameInit->getValue();
836// }
837// if (ArgNameInit != NewOp) {
838// delete NewOp;
839// }
840// delete ArgNameInit;
841// }
842
843// args.push_back(std::make_pair(Arg, ArgName));
844// }
845
846// return new DagInit(Val, args);
847// }
848// if (MHSl) {
849// std::vector<Init *> NewList(MHSl->begin(), MHSl->end());
850
851// for (ListInit::iterator li = NewList.begin(),
852// liend = NewList.end();
853// li != liend;
854// ++li) {
855// Init *Item = *li;
856// TypedInit *TItem = dynamic_cast<TypedInit*>(Item);
857// if (TItem && TItem->getType()->typeIsConvertibleTo(LHSt->getType())) {
858// // First, replace the foreach variable with the list item
859// for (int i = 0; i < RHSo->getNumOperands(); ++i) {
860// if (LHS->getAsString() == RHSo->getOperand(i)->getAsString()) {
861// NewOperands.push_back(Item);
862// }
863// else {
864// NewOperands.push_back(RHSo->getOperand(i));
865// }
866// }
867
868// // Now run the operator and use its result as the new list item
869// OpInit *NewOp = RHSo->clone(NewOperands);
870// *li = NewOp->Fold(CurRec, CurMultiClass);
871// if (*li != NewOp) {
872// delete NewOp;
873// }
874// }
875// }
876
877// return new ListInit(NewList);
878// }
879// }
880// break;
881// }
882// }
883
884// return this;
885// }
886
887// Init *TernOpInit::resolveReferences(Record &R, const RecordVal *RV) {
888// Init *lhs = LHS->resolveReferences(R, RV);
889// Init *mhs = MHS->resolveReferences(R, RV);
890// Init *rhs = RHS->resolveReferences(R, RV);
David Greene196ac3c2009-04-23 21:25:15 +0000891
David Greene5d0c0512009-05-14 20:54:48 +0000892// if (LHS != lhs || MHS != mhs || RHS != rhs)
893// return (new TernOpInit(getOpcode(), lhs, mhs, rhs, getType()))->Fold(&R, 0);
894// return Fold(&R, 0);
895// }
David Greene196ac3c2009-04-23 21:25:15 +0000896
David Greene5d0c0512009-05-14 20:54:48 +0000897// std::string TernOpInit::getAsString() const {
898// std::string Result;
899// switch (Opc) {
900// case SUBST: Result = "!subst"; break;
901// case FOREACH: Result = "!foreach"; break;
902// }
903// return Result + "(" + LHS->getAsString() + ", " + MHS->getAsString() + ", "
904// + RHS->getAsString() + ")";
905// }
David Greene196ac3c2009-04-23 21:25:15 +0000906
Chris Lattner577fc3f2004-07-27 01:01:21 +0000907Init *TypedInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000908 BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType());
909 if (T == 0) return 0; // Cannot subscript a non-bits variable...
910 unsigned NumBits = T->getNumBits();
911
912 BitsInit *BI = new BitsInit(Bits.size());
913 for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
914 if (Bits[i] >= NumBits) {
915 delete BI;
916 return 0;
917 }
918 BI->setBit(i, new VarBitInit(this, Bits[i]));
919 }
920 return BI;
921}
922
Chris Lattner577fc3f2004-07-27 01:01:21 +0000923Init *TypedInit::convertInitListSlice(const std::vector<unsigned> &Elements) {
924 ListRecTy *T = dynamic_cast<ListRecTy*>(getType());
925 if (T == 0) return 0; // Cannot subscript a non-list variable...
926
927 if (Elements.size() == 1)
928 return new VarListElementInit(this, Elements[0]);
929
930 std::vector<Init*> ListInits;
931 ListInits.reserve(Elements.size());
932 for (unsigned i = 0, e = Elements.size(); i != e; ++i)
933 ListInits.push_back(new VarListElementInit(this, Elements[i]));
934 return new ListInit(ListInits);
935}
936
937
Chris Lattneref943742005-04-19 03:36:21 +0000938Init *VarInit::resolveBitReference(Record &R, const RecordVal *IRV,
939 unsigned Bit) {
940 if (R.isTemplateArg(getName())) return 0;
941 if (IRV && IRV->getName() != getName()) return 0;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000942
943 RecordVal *RV = R.getValue(getName());
944 assert(RV && "Reference to a non-existant variable?");
945 assert(dynamic_cast<BitsInit*>(RV->getValue()));
946 BitsInit *BI = (BitsInit*)RV->getValue();
Misha Brukman650ba8e2005-04-22 00:00:37 +0000947
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000948 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
949 Init *B = BI->getBit(Bit);
950
951 if (!dynamic_cast<UnsetInit*>(B)) // If the bit is not set...
952 return B; // Replace the VarBitInit with it.
Chris Lattner577fc3f2004-07-27 01:01:21 +0000953 return 0;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000954}
955
Chris Lattneref943742005-04-19 03:36:21 +0000956Init *VarInit::resolveListElementReference(Record &R, const RecordVal *IRV,
957 unsigned Elt) {
958 if (R.isTemplateArg(getName())) return 0;
959 if (IRV && IRV->getName() != getName()) return 0;
Chris Lattner577fc3f2004-07-27 01:01:21 +0000960
961 RecordVal *RV = R.getValue(getName());
962 assert(RV && "Reference to a non-existant variable?");
963 ListInit *LI = dynamic_cast<ListInit*>(RV->getValue());
David Greene9d3febe2009-05-14 20:38:52 +0000964 if (!LI) {
965 VarInit *VI = dynamic_cast<VarInit*>(RV->getValue());
966 assert(VI && "Invalid list element!");
967 return new VarListElementInit(VI, Elt);
968 }
969
Chris Lattner577fc3f2004-07-27 01:01:21 +0000970 if (Elt >= LI->getSize())
971 return 0; // Out of range reference.
972 Init *E = LI->getElement(Elt);
973 if (!dynamic_cast<UnsetInit*>(E)) // If the element is set
974 return E; // Replace the VarListElementInit with it.
975 return 0;
976}
977
978
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000979RecTy *VarInit::getFieldType(const std::string &FieldName) const {
980 if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
981 if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
982 return RV->getType();
983 return 0;
984}
985
986Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
Reid Spencer2a826862006-11-02 20:46:16 +0000987 if (dynamic_cast<RecordRecTy*>(getType()))
Chris Lattnerd959ab92004-02-28 16:31:53 +0000988 if (const RecordVal *RV = R.getValue(VarName)) {
989 Init *TheInit = RV->getValue();
990 assert(TheInit != this && "Infinite loop detected!");
991 if (Init *I = TheInit->getFieldInit(R, FieldName))
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000992 return I;
993 else
994 return 0;
Chris Lattnerd959ab92004-02-28 16:31:53 +0000995 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000996 return 0;
997}
998
999/// resolveReferences - This method is used by classes that refer to other
1000/// variables which may not be defined at the time they expression is formed.
1001/// If a value is set for the variable later, this method will be called on
1002/// users of the value to allow the value to propagate out.
1003///
Chris Lattneref943742005-04-19 03:36:21 +00001004Init *VarInit::resolveReferences(Record &R, const RecordVal *RV) {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001005 if (RecordVal *Val = R.getValue(VarName))
Chris Lattneref943742005-04-19 03:36:21 +00001006 if (RV == Val || (RV == 0 && !dynamic_cast<UnsetInit*>(Val->getValue())))
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001007 return Val->getValue();
1008 return this;
1009}
Misha Brukman650ba8e2005-04-22 00:00:37 +00001010
Chris Lattner695506c2007-11-22 21:05:25 +00001011std::string VarBitInit::getAsString() const {
1012 return TI->getAsString() + "{" + utostr(Bit) + "}";
1013}
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001014
Chris Lattneref943742005-04-19 03:36:21 +00001015Init *VarBitInit::resolveReferences(Record &R, const RecordVal *RV) {
1016 if (Init *I = getVariable()->resolveBitReference(R, RV, getBitNum()))
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001017 return I;
1018 return this;
1019}
1020
Chris Lattner695506c2007-11-22 21:05:25 +00001021std::string VarListElementInit::getAsString() const {
1022 return TI->getAsString() + "[" + utostr(Element) + "]";
1023}
1024
Chris Lattneref943742005-04-19 03:36:21 +00001025Init *VarListElementInit::resolveReferences(Record &R, const RecordVal *RV) {
1026 if (Init *I = getVariable()->resolveListElementReference(R, RV,
1027 getElementNum()))
Chris Lattner577fc3f2004-07-27 01:01:21 +00001028 return I;
1029 return this;
1030}
1031
Chris Lattneref943742005-04-19 03:36:21 +00001032Init *VarListElementInit::resolveBitReference(Record &R, const RecordVal *RV,
1033 unsigned Bit) {
Chris Lattner577fc3f2004-07-27 01:01:21 +00001034 // FIXME: This should be implemented, to support references like:
1035 // bit B = AA[0]{1};
1036 return 0;
1037}
1038
Chris Lattneref943742005-04-19 03:36:21 +00001039Init *VarListElementInit::
1040resolveListElementReference(Record &R, const RecordVal *RV, unsigned Elt) {
Chris Lattner577fc3f2004-07-27 01:01:21 +00001041 // FIXME: This should be implemented, to support references like:
1042 // int B = AA[0][1];
1043 return 0;
1044}
1045
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001046RecTy *DefInit::getFieldType(const std::string &FieldName) const {
1047 if (const RecordVal *RV = Def->getValue(FieldName))
1048 return RV->getType();
1049 return 0;
1050}
1051
1052Init *DefInit::getFieldInit(Record &R, const std::string &FieldName) const {
1053 return Def->getValue(FieldName)->getValue();
1054}
1055
1056
Chris Lattner695506c2007-11-22 21:05:25 +00001057std::string DefInit::getAsString() const {
1058 return Def->getName();
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001059}
1060
Chris Lattneref943742005-04-19 03:36:21 +00001061Init *FieldInit::resolveBitReference(Record &R, const RecordVal *RV,
1062 unsigned Bit) {
Chris Lattner577fc3f2004-07-27 01:01:21 +00001063 if (Init *BitsVal = Rec->getFieldInit(R, FieldName))
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001064 if (BitsInit *BI = dynamic_cast<BitsInit*>(BitsVal)) {
1065 assert(Bit < BI->getNumBits() && "Bit reference out of range!");
1066 Init *B = BI->getBit(Bit);
Misha Brukman650ba8e2005-04-22 00:00:37 +00001067
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001068 if (dynamic_cast<BitInit*>(B)) // If the bit is set...
1069 return B; // Replace the VarBitInit with it.
1070 }
Chris Lattner577fc3f2004-07-27 01:01:21 +00001071 return 0;
1072}
1073
Chris Lattneref943742005-04-19 03:36:21 +00001074Init *FieldInit::resolveListElementReference(Record &R, const RecordVal *RV,
1075 unsigned Elt) {
Chris Lattner577fc3f2004-07-27 01:01:21 +00001076 if (Init *ListVal = Rec->getFieldInit(R, FieldName))
1077 if (ListInit *LI = dynamic_cast<ListInit*>(ListVal)) {
1078 if (Elt >= LI->getSize()) return 0;
1079 Init *E = LI->getElement(Elt);
1080
1081 if (!dynamic_cast<UnsetInit*>(E)) // If the bit is set...
1082 return E; // Replace the VarListElementInit with it.
1083 }
1084 return 0;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001085}
1086
Chris Lattneref943742005-04-19 03:36:21 +00001087Init *FieldInit::resolveReferences(Record &R, const RecordVal *RV) {
1088 Init *NewRec = RV ? Rec->resolveReferences(R, RV) : Rec;
1089
1090 Init *BitsVal = NewRec->getFieldInit(R, FieldName);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001091 if (BitsVal) {
Chris Lattneref943742005-04-19 03:36:21 +00001092 Init *BVR = BitsVal->resolveReferences(R, RV);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001093 return BVR->isComplete() ? BVR : this;
1094 }
Chris Lattneref943742005-04-19 03:36:21 +00001095
1096 if (NewRec != Rec) {
Chris Lattneref943742005-04-19 03:36:21 +00001097 return new FieldInit(NewRec, FieldName);
1098 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001099 return this;
1100}
1101
Chris Lattner0d3ef402006-01-31 06:02:35 +00001102Init *DagInit::resolveReferences(Record &R, const RecordVal *RV) {
1103 std::vector<Init*> NewArgs;
1104 for (unsigned i = 0, e = Args.size(); i != e; ++i)
1105 NewArgs.push_back(Args[i]->resolveReferences(R, RV));
1106
Chris Lattnerb59cf3c2006-03-30 22:50:40 +00001107 Init *Op = Val->resolveReferences(R, RV);
1108
1109 if (Args != NewArgs || Op != Val)
Nate Begemandbe3f772009-03-19 05:21:56 +00001110 return new DagInit(Op, "", NewArgs, ArgNames);
Chris Lattner0d3ef402006-01-31 06:02:35 +00001111
1112 return this;
1113}
1114
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001115
Chris Lattner695506c2007-11-22 21:05:25 +00001116std::string DagInit::getAsString() const {
1117 std::string Result = "(" + Val->getAsString();
Nate Begemandbe3f772009-03-19 05:21:56 +00001118 if (!ValName.empty())
1119 Result += ":" + ValName;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001120 if (Args.size()) {
Chris Lattner695506c2007-11-22 21:05:25 +00001121 Result += " " + Args[0]->getAsString();
1122 if (!ArgNames[0].empty()) Result += ":$" + ArgNames[0];
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001123 for (unsigned i = 1, e = Args.size(); i != e; ++i) {
Chris Lattner695506c2007-11-22 21:05:25 +00001124 Result += ", " + Args[i]->getAsString();
1125 if (!ArgNames[i].empty()) Result += ":$" + ArgNames[i];
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001126 }
1127 }
Chris Lattner695506c2007-11-22 21:05:25 +00001128 return Result + ")";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001129}
1130
1131
1132//===----------------------------------------------------------------------===//
1133// Other implementations
1134//===----------------------------------------------------------------------===//
1135
1136RecordVal::RecordVal(const std::string &N, RecTy *T, unsigned P)
1137 : Name(N), Ty(T), Prefix(P) {
1138 Value = Ty->convertValue(new UnsetInit());
1139 assert(Value && "Cannot create unset value for current type!");
1140}
1141
Bill Wendling9bfb1e12006-12-07 22:21:48 +00001142void RecordVal::dump() const { cerr << *this; }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001143
1144void RecordVal::print(std::ostream &OS, bool PrintSem) const {
1145 if (getPrefix()) OS << "field ";
1146 OS << *getType() << " " << getName();
Chris Lattneref943742005-04-19 03:36:21 +00001147
1148 if (getValue())
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001149 OS << " = " << *getValue();
Chris Lattneref943742005-04-19 03:36:21 +00001150
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001151 if (PrintSem) OS << ";\n";
1152}
1153
Chris Lattnerac284252005-08-19 17:58:11 +00001154void Record::setName(const std::string &Name) {
1155 if (Records.getDef(getName()) == this) {
1156 Records.removeDef(getName());
1157 this->Name = Name;
1158 Records.addDef(this);
1159 } else {
1160 Records.removeClass(getName());
1161 this->Name = Name;
1162 Records.addClass(this);
1163 }
1164}
1165
Chris Lattneref943742005-04-19 03:36:21 +00001166/// resolveReferencesTo - If anything in this record refers to RV, replace the
1167/// reference to RV with the RHS of RV. If RV is null, we resolve all possible
1168/// references.
1169void Record::resolveReferencesTo(const RecordVal *RV) {
1170 for (unsigned i = 0, e = Values.size(); i != e; ++i) {
1171 if (Init *V = Values[i].getValue())
1172 Values[i].setValue(V->resolveReferences(*this, RV));
1173 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001174}
1175
Chris Lattneref943742005-04-19 03:36:21 +00001176
Bill Wendling9bfb1e12006-12-07 22:21:48 +00001177void Record::dump() const { cerr << *this; }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001178
Chris Lattner68478662004-08-01 03:55:39 +00001179std::ostream &llvm::operator<<(std::ostream &OS, const Record &R) {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001180 OS << R.getName();
1181
1182 const std::vector<std::string> &TArgs = R.getTemplateArgs();
1183 if (!TArgs.empty()) {
1184 OS << "<";
1185 for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
1186 if (i) OS << ", ";
1187 const RecordVal *RV = R.getValue(TArgs[i]);
1188 assert(RV && "Template argument record not found??");
1189 RV->print(OS, false);
1190 }
1191 OS << ">";
1192 }
1193
1194 OS << " {";
1195 const std::vector<Record*> &SC = R.getSuperClasses();
1196 if (!SC.empty()) {
1197 OS << "\t//";
1198 for (unsigned i = 0, e = SC.size(); i != e; ++i)
1199 OS << " " << SC[i]->getName();
1200 }
1201 OS << "\n";
1202
1203 const std::vector<RecordVal> &Vals = R.getValues();
1204 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1205 if (Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1206 OS << Vals[i];
1207 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
1208 if (!Vals[i].getPrefix() && !R.isTemplateArg(Vals[i].getName()))
1209 OS << Vals[i];
1210
1211 return OS << "}\n";
1212}
1213
1214/// getValueInit - Return the initializer for a value with the specified name,
1215/// or throw an exception if the field does not exist.
1216///
1217Init *Record::getValueInit(const std::string &FieldName) const {
1218 const RecordVal *R = getValue(FieldName);
1219 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001220 throw "Record `" + getName() + "' does not have a field named `" +
1221 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001222 return R->getValue();
1223}
1224
1225
1226/// getValueAsString - This method looks up the specified field and returns its
1227/// value as a string, throwing an exception if the field does not exist or if
1228/// the value is not a string.
1229///
1230std::string Record::getValueAsString(const std::string &FieldName) const {
1231 const RecordVal *R = getValue(FieldName);
1232 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001233 throw "Record `" + getName() + "' does not have a field named `" +
1234 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001235
1236 if (const StringInit *SI = dynamic_cast<const StringInit*>(R->getValue()))
1237 return SI->getValue();
Misha Brukman41f9f292004-10-08 14:59:05 +00001238 throw "Record `" + getName() + "', field `" + FieldName +
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001239 "' does not have a string initializer!";
1240}
1241
1242/// getValueAsBitsInit - This method looks up the specified field and returns
1243/// its value as a BitsInit, throwing an exception if the field does not exist
1244/// or if the value is not the right type.
1245///
1246BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
1247 const RecordVal *R = getValue(FieldName);
1248 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001249 throw "Record `" + getName() + "' does not have a field named `" +
1250 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001251
1252 if (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue()))
1253 return BI;
Misha Brukman41f9f292004-10-08 14:59:05 +00001254 throw "Record `" + getName() + "', field `" + FieldName +
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001255 "' does not have a BitsInit initializer!";
1256}
1257
1258/// getValueAsListInit - This method looks up the specified field and returns
1259/// its value as a ListInit, throwing an exception if the field does not exist
1260/// or if the value is not the right type.
1261///
1262ListInit *Record::getValueAsListInit(const std::string &FieldName) const {
1263 const RecordVal *R = getValue(FieldName);
1264 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001265 throw "Record `" + getName() + "' does not have a field named `" +
1266 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001267
1268 if (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
1269 return LI;
Misha Brukman41f9f292004-10-08 14:59:05 +00001270 throw "Record `" + getName() + "', field `" + FieldName +
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001271 "' does not have a list initializer!";
1272}
1273
Chris Lattner7ad0bed2005-10-28 22:49:02 +00001274/// getValueAsListOfDefs - This method looks up the specified field and returns
Jim Laskeyb04feb62005-10-28 21:46:31 +00001275/// its value as a vector of records, throwing an exception if the field does
1276/// not exist or if the value is not the right type.
1277///
Chris Lattner7ad0bed2005-10-28 22:49:02 +00001278std::vector<Record*>
1279Record::getValueAsListOfDefs(const std::string &FieldName) const {
Jim Laskeyb04feb62005-10-28 21:46:31 +00001280 ListInit *List = getValueAsListInit(FieldName);
1281 std::vector<Record*> Defs;
1282 for (unsigned i = 0; i < List->getSize(); i++) {
1283 if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
1284 Defs.push_back(DI->getDef());
1285 } else {
1286 throw "Record `" + getName() + "', field `" + FieldName +
1287 "' list is not entirely DefInit!";
1288 }
1289 }
1290 return Defs;
1291}
1292
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001293/// getValueAsInt - This method looks up the specified field and returns its
Dan Gohmanca0546f2008-10-17 01:33:43 +00001294/// value as an int64_t, throwing an exception if the field does not exist or if
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001295/// the value is not the right type.
1296///
Dan Gohmanca0546f2008-10-17 01:33:43 +00001297int64_t Record::getValueAsInt(const std::string &FieldName) const {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001298 const RecordVal *R = getValue(FieldName);
1299 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001300 throw "Record `" + getName() + "' does not have a field named `" +
1301 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001302
1303 if (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
1304 return II->getValue();
Misha Brukman41f9f292004-10-08 14:59:05 +00001305 throw "Record `" + getName() + "', field `" + FieldName +
Nate Begemanf621b332005-11-30 18:37:14 +00001306 "' does not have an int initializer!";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001307}
1308
Anton Korobeynikova468a112007-11-11 11:19:37 +00001309/// getValueAsListOfInts - This method looks up the specified field and returns
1310/// its value as a vector of integers, throwing an exception if the field does
1311/// not exist or if the value is not the right type.
1312///
Dan Gohmanca0546f2008-10-17 01:33:43 +00001313std::vector<int64_t>
Anton Korobeynikova468a112007-11-11 11:19:37 +00001314Record::getValueAsListOfInts(const std::string &FieldName) const {
1315 ListInit *List = getValueAsListInit(FieldName);
Dan Gohmanca0546f2008-10-17 01:33:43 +00001316 std::vector<int64_t> Ints;
Anton Korobeynikova468a112007-11-11 11:19:37 +00001317 for (unsigned i = 0; i < List->getSize(); i++) {
1318 if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
1319 Ints.push_back(II->getValue());
1320 } else {
1321 throw "Record `" + getName() + "', field `" + FieldName +
1322 "' does not have a list of ints initializer!";
1323 }
1324 }
1325 return Ints;
1326}
1327
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001328/// getValueAsDef - This method looks up the specified field and returns its
1329/// value as a Record, throwing an exception if the field does not exist or if
1330/// the value is not the right type.
1331///
1332Record *Record::getValueAsDef(const std::string &FieldName) const {
1333 const RecordVal *R = getValue(FieldName);
1334 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001335 throw "Record `" + getName() + "' does not have a field named `" +
1336 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001337
1338 if (DefInit *DI = dynamic_cast<DefInit*>(R->getValue()))
1339 return DI->getDef();
Misha Brukman41f9f292004-10-08 14:59:05 +00001340 throw "Record `" + getName() + "', field `" + FieldName +
Nate Begemanf621b332005-11-30 18:37:14 +00001341 "' does not have a def initializer!";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001342}
1343
1344/// getValueAsBit - This method looks up the specified field and returns its
1345/// value as a bit, throwing an exception if the field does not exist or if
1346/// the value is not the right type.
1347///
1348bool Record::getValueAsBit(const std::string &FieldName) const {
1349 const RecordVal *R = getValue(FieldName);
1350 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001351 throw "Record `" + getName() + "' does not have a field named `" +
1352 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001353
1354 if (BitInit *BI = dynamic_cast<BitInit*>(R->getValue()))
1355 return BI->getValue();
Misha Brukman41f9f292004-10-08 14:59:05 +00001356 throw "Record `" + getName() + "', field `" + FieldName +
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001357 "' does not have a bit initializer!";
1358}
1359
1360/// getValueAsDag - This method looks up the specified field and returns its
1361/// value as an Dag, throwing an exception if the field does not exist or if
1362/// the value is not the right type.
1363///
1364DagInit *Record::getValueAsDag(const std::string &FieldName) const {
1365 const RecordVal *R = getValue(FieldName);
1366 if (R == 0 || R->getValue() == 0)
Misha Brukman41f9f292004-10-08 14:59:05 +00001367 throw "Record `" + getName() + "' does not have a field named `" +
1368 FieldName + "'!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001369
1370 if (DagInit *DI = dynamic_cast<DagInit*>(R->getValue()))
1371 return DI;
Misha Brukman41f9f292004-10-08 14:59:05 +00001372 throw "Record `" + getName() + "', field `" + FieldName +
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001373 "' does not have a dag initializer!";
1374}
1375
Chris Lattnerae939eb2005-09-13 21:44:28 +00001376std::string Record::getValueAsCode(const std::string &FieldName) const {
1377 const RecordVal *R = getValue(FieldName);
1378 if (R == 0 || R->getValue() == 0)
1379 throw "Record `" + getName() + "' does not have a field named `" +
1380 FieldName + "'!\n";
1381
1382 if (const CodeInit *CI = dynamic_cast<const CodeInit*>(R->getValue()))
1383 return CI->getValue();
1384 throw "Record `" + getName() + "', field `" + FieldName +
1385 "' does not have a code initializer!";
1386}
1387
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001388
David Greene7049e792009-04-24 16:55:41 +00001389void MultiClass::dump() const {
1390 cerr << "Record:\n";
1391 Rec.dump();
1392
1393 cerr << "Defs:\n";
1394 for (RecordVector::const_iterator r = DefPrototypes.begin(),
1395 rend = DefPrototypes.end();
1396 r != rend;
1397 ++r) {
1398 (*r)->dump();
1399 }
1400}
1401
1402
Bill Wendling9bfb1e12006-12-07 22:21:48 +00001403void RecordKeeper::dump() const { cerr << *this; }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001404
Chris Lattner68478662004-08-01 03:55:39 +00001405std::ostream &llvm::operator<<(std::ostream &OS, const RecordKeeper &RK) {
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001406 OS << "------------- Classes -----------------\n";
1407 const std::map<std::string, Record*> &Classes = RK.getClasses();
1408 for (std::map<std::string, Record*>::const_iterator I = Classes.begin(),
Jeff Cohen88e7b722005-04-22 04:13:13 +00001409 E = Classes.end(); I != E; ++I)
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001410 OS << "class " << *I->second;
Misha Brukman650ba8e2005-04-22 00:00:37 +00001411
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001412 OS << "------------- Defs -----------------\n";
1413 const std::map<std::string, Record*> &Defs = RK.getDefs();
1414 for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
Jeff Cohen88e7b722005-04-22 04:13:13 +00001415 E = Defs.end(); I != E; ++I)
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001416 OS << "def " << *I->second;
1417 return OS;
1418}
1419
1420
1421/// getAllDerivedDefinitions - This method returns all concrete definitions
1422/// that derive from the specified class name. If a class with the specified
1423/// name does not exist, an error is printed and true is returned.
1424std::vector<Record*>
1425RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName) const {
1426 Record *Class = Records.getClass(ClassName);
1427 if (!Class)
Misha Brukman41f9f292004-10-08 14:59:05 +00001428 throw "ERROR: Couldn't find the `" + ClassName + "' class!\n";
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001429
1430 std::vector<Record*> Defs;
1431 for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(),
1432 E = getDefs().end(); I != E; ++I)
1433 if (I->second->isSubClassOf(Class))
1434 Defs.push_back(I->second);
1435
1436 return Defs;
1437}
Brian Gaeke960707c2003-11-11 22:41:34 +00001438