Init *BitRecTy::convertValue(IntInit *II) {
int Val = II->getValue();
if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
- delete II;
return new BitInit(Val != 0);
}
-Init *BitRecTy::convertValue(VarInit *VI) {
+Init *BitRecTy::convertValue(TypedInit *VI) {
if (dynamic_cast<BitRecTy*>(VI->getType()))
return VI; // Accept variable if it is already of bit type!
return 0;
//
Init *BitsRecTy::convertValue(IntInit *II) {
int Value = II->getValue();
- delete II;
BitsInit *Ret = new BitsInit(Size);
for (unsigned i = 0; i != Size; ++i)
return 0;
}
-Init *BitsRecTy::convertValue(VarInit *VI) {
+Init *BitsRecTy::convertValue(TypedInit *VI) {
if (BitsRecTy *BRT = dynamic_cast<BitsRecTy*>(VI->getType()))
if (BRT->Size == Size) {
BitsInit *Ret = new BitsInit(Size);
return 0;
}
-Init *BitsRecTy::convertValue(FieldInit *VI) {
- return 0;
-}
-
-
Init *IntRecTy::convertValue(BitsInit *BI) {
int Result = 0;
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
return new IntInit(Result);
}
-Init *IntRecTy::convertValue(VarInit *VI) {
- if (dynamic_cast<IntRecTy*>(VI->getType()))
- return VI; // Accept variable if already of the right type!
+Init *IntRecTy::convertValue(TypedInit *TI) {
+ if (dynamic_cast<IntRecTy*>(TI->getType()))
+ return TI; // Accept variable if already of the right type!
return 0;
}
-Init *StringRecTy::convertValue(VarInit *VI) {
- if (dynamic_cast<StringRecTy*>(VI->getType()))
- return VI; // Accept variable if already of the right type!
+Init *StringRecTy::convertValue(TypedInit *TI) {
+ if (dynamic_cast<StringRecTy*>(TI->getType()))
+ return TI; // Accept variable if already of the right type!
return 0;
}
void BitsInit::print(std::ostream &OS) const {
//if (!printInHex(OS)) return;
- if (!printAsVariable(OS)) return;
- if (!printAsUnset(OS)) return;
+ //if (!printAsVariable(OS)) return;
+ //if (!printAsUnset(OS)) return;
OS << "{ ";
for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
if (i) OS << ", ";
- getBit(e-i-1)->print(OS);
+ if (Init *Bit = getBit(e-i-1))
+ Bit->print(OS);
+ else
+ OS << "*";
}
OS << " }";
}
for (unsigned i = 0, e = Bits.size(); i != e; ++i) {
Init *B;
- New->setBit(i, getBit(i));
+ Init *CurBit = getBit(i);
+
do {
- B = New->getBit(i);
- New->setBit(i, B->resolveReferences(R));
- Changed |= B != New->getBit(i);
- } while (B != New->getBit(i));
+ B = CurBit;
+ CurBit = CurBit->resolveReferences(R);
+ Changed |= B != CurBit;
+ } while (B != CurBit);
+ New->setBit(i, CurBit);
}
if (Changed)
return BI;
}
-RecTy *VarInit::getFieldType(const std::string &FieldName) const {
- if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
- if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
- return RV->getType();
- return 0;
-}
-
Init *VarInit::resolveBitReference(Record &R, unsigned Bit) {
if (R.isTemplateArg(getName()))
return this;
return this;
}
+RecTy *VarInit::getFieldType(const std::string &FieldName) const {
+ if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
+ if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
+ return RV->getType();
+ return 0;
+}
+
+Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
+ if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
+ if (const RecordVal *RV = R.getValue(VarName))
+ if (Init *I = RV->getValue()->getFieldInit(R, FieldName))
+ return I;
+ else
+ return (Init*)this;
+ return 0;
+}
+
Init *VarBitInit::resolveReferences(Record &R) {
Init *I = getVariable()->resolveBitReference(R, getBitNum());
-
if (I != getVariable())
return I;
return this;
}
+RecTy *DefInit::getFieldType(const std::string &FieldName) const {
+ if (const RecordVal *RV = Def->getValue(FieldName))
+ return RV->getType();
+ return 0;
+}
+
+Init *DefInit::getFieldInit(Record &R, const std::string &FieldName) const {
+ return Def->getValue(FieldName)->getValue();
+}
+
+
void DefInit::print(std::ostream &OS) const {
OS << Def->getName();
}
}
Init *FieldInit::resolveBitReference(Record &R, unsigned Bit) {
- // Can never be resolved yet.
+ Init *BitsVal = Rec->getFieldInit(R, FieldName);
+ assert(BitsVal && "No initializer found!");
+
+ if (BitsInit *BI = dynamic_cast<BitsInit*>(BitsVal)) {
+ assert(Bit < BI->getNumBits() && "Bit reference out of range!");
+ Init *B = BI->getBit(Bit);
+
+ if (dynamic_cast<BitInit*>(B)) // If the bit is set...
+ return B; // Replace the VarBitInit with it.
+ }
return this;
}