mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-26 14:16:12 +00:00
Simplify TableGen type-compatibility checks.
Patch by Elior Malul! llvm-svn: 171684
This commit is contained in:
parent
30bd563e01
commit
5e72630505
@ -128,16 +128,8 @@ public: // These methods should only be called from subclasses of Init
|
||||
return convertValue((TypedInit*)FI);
|
||||
}
|
||||
|
||||
public: // These methods should only be called by subclasses of RecTy.
|
||||
// baseClassOf - These virtual methods should be overloaded to return true iff
|
||||
// all values of type 'RHS' can be converted to the 'this' type.
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
public:
|
||||
virtual bool baseClassOf(const RecTy*) const;
|
||||
};
|
||||
|
||||
inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
|
||||
@ -179,14 +171,7 @@ public:
|
||||
virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const;
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
|
||||
virtual bool baseClassOf(const RecTy*) const;
|
||||
};
|
||||
|
||||
|
||||
@ -226,16 +211,7 @@ public:
|
||||
virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return Size == 1; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const {
|
||||
return RHS->Size == Size;
|
||||
}
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
|
||||
virtual bool baseClassOf(const RecTy*) const;
|
||||
};
|
||||
|
||||
|
||||
@ -273,14 +249,7 @@ public:
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
|
||||
virtual bool baseClassOf(const RecTy*) const;
|
||||
};
|
||||
|
||||
/// StringRecTy - 'string' - Represent an string value
|
||||
@ -317,14 +286,6 @@ public:
|
||||
virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
};
|
||||
|
||||
// ListRecTy - 'list<Ty>' - Represent a list of values, all of which must be of
|
||||
@ -366,15 +327,7 @@ public:
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const {
|
||||
return RHS->getElementType()->typeIsConvertibleTo(Ty);
|
||||
}
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecTy*) const;
|
||||
};
|
||||
|
||||
/// DagRecTy - 'dag' - Represent a dag fragment
|
||||
@ -410,14 +363,6 @@ public:
|
||||
virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return true; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const { return false; }
|
||||
};
|
||||
|
||||
|
||||
@ -458,13 +403,7 @@ public:
|
||||
virtual bool typeIsConvertibleTo(const RecTy *RHS) const {
|
||||
return RHS->baseClassOf(this);
|
||||
}
|
||||
virtual bool baseClassOf(const BitRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const BitsRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const IntRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const StringRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const ListRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const DagRecTy *RHS) const { return false; }
|
||||
virtual bool baseClassOf(const RecordRecTy *RHS) const;
|
||||
virtual bool baseClassOf(const RecTy*) const;
|
||||
};
|
||||
|
||||
/// resolveTypes - Find a common type that T1 and T2 convert to.
|
||||
|
@ -95,15 +95,16 @@ ListRecTy *RecTy::getListTy() {
|
||||
return ListTy;
|
||||
}
|
||||
|
||||
bool RecTy::baseClassOf(const RecTy *RHS) const{
|
||||
assert (RHS && "NULL pointer");
|
||||
return Kind == RHS->getRecTyKind();
|
||||
}
|
||||
|
||||
Init *BitRecTy::convertValue(BitsInit *BI) {
|
||||
if (BI->getNumBits() != 1) return 0; // Only accept if just one bit!
|
||||
return BI->getBit(0);
|
||||
}
|
||||
|
||||
bool BitRecTy::baseClassOf(const BitsRecTy *RHS) const {
|
||||
return RHS->getNumBits() == 1;
|
||||
}
|
||||
|
||||
Init *BitRecTy::convertValue(IntInit *II) {
|
||||
int64_t Val = II->getValue();
|
||||
if (Val != 0 && Val != 1) return 0; // Only accept 0 or 1 for a bit!
|
||||
@ -118,6 +119,14 @@ Init *BitRecTy::convertValue(TypedInit *VI) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool BitRecTy::baseClassOf(const RecTy *RHS) const{
|
||||
if(RecTy::baseClassOf(RHS) || getRecTyKind() == IntRecTyKind)
|
||||
return true;
|
||||
if(const BitsRecTy *BitsTy = dyn_cast<BitsRecTy>(RHS))
|
||||
return BitsTy->getNumBits() == 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
BitsRecTy *BitsRecTy::get(unsigned Sz) {
|
||||
static std::vector<BitsRecTy*> Shared;
|
||||
if (Sz >= Shared.size())
|
||||
@ -193,6 +202,13 @@ Init *BitsRecTy::convertValue(TypedInit *VI) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool BitsRecTy::baseClassOf(const RecTy *RHS) const{
|
||||
if (RecTy::baseClassOf(RHS)) //argument and the receiver are the same type
|
||||
return cast<BitsRecTy>(RHS)->Size == Size;
|
||||
RecTyKind kind = RHS->getRecTyKind();
|
||||
return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
|
||||
}
|
||||
|
||||
Init *IntRecTy::convertValue(BitInit *BI) {
|
||||
return IntInit::get(BI->getValue());
|
||||
}
|
||||
@ -214,6 +230,11 @@ Init *IntRecTy::convertValue(TypedInit *TI) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool IntRecTy::baseClassOf(const RecTy *RHS) const{
|
||||
RecTyKind kind = RHS->getRecTyKind();
|
||||
return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
|
||||
}
|
||||
|
||||
Init *StringRecTy::convertValue(UnOpInit *BO) {
|
||||
if (BO->getOpcode() == UnOpInit::CAST) {
|
||||
Init *L = BO->getOperand()->convertInitializerTo(this);
|
||||
@ -275,6 +296,12 @@ Init *ListRecTy::convertValue(TypedInit *TI) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ListRecTy::baseClassOf(const RecTy *RHS) const{
|
||||
if(const ListRecTy* ListTy = dyn_cast<ListRecTy>(RHS))
|
||||
return ListTy->getElementType()->typeIsConvertibleTo(Ty);
|
||||
return false;
|
||||
}
|
||||
|
||||
Init *DagRecTy::convertValue(TypedInit *TI) {
|
||||
if (TI->getType()->typeIsConvertibleTo(this))
|
||||
return TI;
|
||||
@ -328,13 +355,17 @@ Init *RecordRecTy::convertValue(TypedInit *TI) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RecordRecTy::baseClassOf(const RecordRecTy *RHS) const {
|
||||
if (Rec == RHS->getRecord() || RHS->getRecord()->isSubClassOf(Rec))
|
||||
bool RecordRecTy::baseClassOf(const RecTy *RHS) const{
|
||||
const RecordRecTy *RTy = dyn_cast<RecordRecTy>(RHS);
|
||||
if (!RTy)
|
||||
return false;
|
||||
|
||||
if (Rec == RTy->getRecord() || RTy->getRecord()->isSubClassOf(Rec))
|
||||
return true;
|
||||
|
||||
const std::vector<Record*> &SC = Rec->getSuperClasses();
|
||||
for (unsigned i = 0, e = SC.size(); i != e; ++i)
|
||||
if (RHS->getRecord()->isSubClassOf(SC[i]))
|
||||
if (RTy->getRecord()->isSubClassOf(SC[i]))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user