diff options
author | Chris Lattner <sabre@nondot.org> | 2002-12-02 17:44:35 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2002-12-02 17:44:35 +0000 |
commit | db1b766fe63d22627b80346fcbf0ee95a69f791d (patch) | |
tree | dc99000972980f272aece324c4a7f09bca5810c4 /support/tools/TableGen | |
parent | 7331ab9d56cb7007b1f5c92c90cd0d18a0af1fe3 (diff) | |
download | external_llvm-db1b766fe63d22627b80346fcbf0ee95a69f791d.zip external_llvm-db1b766fe63d22627b80346fcbf0ee95a69f791d.tar.gz external_llvm-db1b766fe63d22627b80346fcbf0ee95a69f791d.tar.bz2 |
Continued support for field initializer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4854 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'support/tools/TableGen')
-rw-r--r-- | support/tools/TableGen/Record.cpp | 57 |
1 files changed, 46 insertions, 11 deletions
diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index d9cddf8..64711bf 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -82,6 +82,10 @@ Init *BitsRecTy::convertValue(VarInit *VI) { return 0; } +Init *BitsRecTy::convertValue(FieldInit *VI) { + return 0; +} + Init *IntRecTy::convertValue(BitsInit *BI) { int Result = 0; @@ -180,10 +184,10 @@ bool BitsInit::printAsVariable(std::ostream &OS) const { assert(getNumBits() != 0); VarBitInit *FirstBit = dynamic_cast<VarBitInit*>(getBit(0)); if (FirstBit == 0) return true; - VarInit *Var = FirstBit->getVariable(); + TypedInit *Var = FirstBit->getVariable(); // Check to make sure the types are compatible. - BitsRecTy *Ty = dynamic_cast<BitsRecTy*>(Var->getType()); + BitsRecTy *Ty = dynamic_cast<BitsRecTy*>(FirstBit->getVariable()->getType()); if (Ty == 0) return true; if (Ty->getNumBits() != getNumBits()) return true; // Incompatible types! @@ -194,7 +198,7 @@ bool BitsInit::printAsVariable(std::ostream &OS) const { return true; } - OS << Var->getName(); + Var->print(OS); return false; } @@ -249,7 +253,7 @@ void ListInit::print(std::ostream &OS) const { } Init *VarInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) { - BitsRecTy *T = dynamic_cast<BitsRecTy*>(Ty); + BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType()); if (T == 0) return 0; // Cannot subscript a non-bits variable... unsigned NumBits = T->getNumBits(); @@ -265,34 +269,65 @@ Init *VarInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) { } RecTy *VarInit::getFieldType(const std::string &FieldName) const { - if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(Ty)) + if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType())) if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName)) return RV->getType(); return 0; } - -Init *VarBitInit::resolveReferences(Record &R) { - if (R.isTemplateArg(getVariable()->getName())) +Init *VarInit::resolveBitReference(Record &R, unsigned Bit) { + if (R.isTemplateArg(getName())) return this; - RecordVal *RV = R.getValue(getVariable()->getName()); + RecordVal *RV = R.getValue(getName()); assert(RV && "Reference to a non-existant variable?"); assert(dynamic_cast<BitsInit*>(RV->getValue())); BitsInit *BI = (BitsInit*)RV->getValue(); - assert(getBitNum() < BI->getNumBits() && "Bit reference out of range!"); - Init *B = BI->getBit(getBitNum()); + assert(Bit < BI->getNumBits() && "Bit reference out of range!"); + Init *B = BI->getBit(Bit); if (!dynamic_cast<UnsetInit*>(B)) // If the bit is not set... return B; // Replace the VarBitInit with it. return this; } + + +Init *VarBitInit::resolveReferences(Record &R) { + Init *I = getVariable()->resolveBitReference(R, getBitNum()); + + if (I != getVariable()) + return I; + return this; +} + void DefInit::print(std::ostream &OS) const { OS << Def->getName(); } +Init *FieldInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) { + BitsRecTy *T = dynamic_cast<BitsRecTy*>(getType()); + if (T == 0) return 0; // Cannot subscript a non-bits field... + unsigned NumBits = T->getNumBits(); + + BitsInit *BI = new BitsInit(Bits.size()); + for (unsigned i = 0, e = Bits.size(); i != e; ++i) { + if (Bits[i] >= NumBits) { + delete BI; + return 0; + } + BI->setBit(i, new VarBitInit(this, Bits[i])); + } + return BI; +} + +Init *FieldInit::resolveBitReference(Record &R, unsigned Bit) { + // Can never be resolved yet. + return this; +} + + //===----------------------------------------------------------------------===// // Other implementations //===----------------------------------------------------------------------===// |