aboutsummaryrefslogtreecommitdiffstats
path: root/support
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-12-03 06:00:33 +0000
committerChris Lattner <sabre@nondot.org>2002-12-03 06:00:33 +0000
commitb1ed0fc6308885c5887ed0474e8a4fbf63a39b45 (patch)
tree61d3617705aad26853dbdcc1d4a726811f1c6bb9 /support
parent4767a0c1b65caa7caa26104e34868685e103e8fa (diff)
downloadexternal_llvm-b1ed0fc6308885c5887ed0474e8a4fbf63a39b45.zip
external_llvm-b1ed0fc6308885c5887ed0474e8a4fbf63a39b45.tar.gz
external_llvm-b1ed0fc6308885c5887ed0474e8a4fbf63a39b45.tar.bz2
Continue implementing field initializers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4879 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'support')
-rw-r--r--support/tools/TableGen/Record.cpp70
-rw-r--r--support/tools/TableGen/Record.h12
2 files changed, 52 insertions, 30 deletions
diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp
index 8f6d430..5931cb8 100644
--- a/support/tools/TableGen/Record.cpp
+++ b/support/tools/TableGen/Record.cpp
@@ -82,25 +82,6 @@ Init *BitsRecTy::convertValue(TypedInit *VI) {
return 0;
}
-#if 0
-Init *BitsRecTy::convertValue(FieldInit *VI) {
- if (BitsRecTy *BRT = dynamic_cast<BitsRecTy*>(VI->getType()))
- if (BRT->Size == Size) {
- BitsInit *Ret = new BitsInit(Size);
- for (unsigned i = 0; i != Size; ++i)
- Ret->setBit(i, new VarBitInit(VI, i));
- return Ret;
- }
- if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
- BitsInit *Ret = new BitsInit(1);
- Ret->setBit(0, VI);
- return Ret;
- }
- return 0;
-}
-#endif
-
-
Init *IntRecTy::convertValue(BitsInit *BI) {
int Result = 0;
for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
@@ -168,8 +149,8 @@ Init *BitsInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
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) {
@@ -282,13 +263,6 @@ Init *VarInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
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;
@@ -306,16 +280,43 @@ Init *VarInit::resolveBitReference(Record &R, unsigned Bit) {
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();
}
@@ -337,7 +338,16 @@ Init *FieldInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
}
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;
}
diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h
index e736f80..8c55140 100644
--- a/support/tools/TableGen/Record.h
+++ b/support/tools/TableGen/Record.h
@@ -180,6 +180,14 @@ struct Init {
///
virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
+ /// getFieldInit - This method complements getFieldType to return the
+ /// initializer for the specified field. If getFieldType returns non-null
+ /// this method should return non-null, otherwise it returns null.
+ ///
+ virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
+ return 0;
+ }
+
/// resolveReferences - This method is used by classes that refer to other
/// variables which may not be defined at the time they expression is formed.
/// If a value is set for the variable later, this method will be called on
@@ -352,6 +360,7 @@ public:
virtual Init *resolveBitReference(Record &R, unsigned Bit);
virtual RecTy *getFieldType(const std::string &FieldName) const;
+ virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
virtual void print(std::ostream &OS) const { OS << VarName; }
};
@@ -397,6 +406,9 @@ public:
Record *getDef() const { return Def; }
//virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
+
+ virtual RecTy *getFieldType(const std::string &FieldName) const;
+ virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
virtual void print(std::ostream &OS) const;
};