[WIP] Add quantifier to polymorphic types
This commit is contained in:
39
type.cpp
39
type.cpp
@@ -707,6 +707,11 @@ PolyType::GetVariability() const {
|
|||||||
return variability;
|
return variability;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
PolyType::GetQuant() const {
|
||||||
|
return quant;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
PolyType::IsFloatType() const {
|
PolyType::IsFloatType() const {
|
||||||
@@ -749,7 +754,7 @@ PolyType::GetAsConstType() const {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (asOtherConstType == NULL) {
|
if (asOtherConstType == NULL) {
|
||||||
asOtherConstType = new PolyType(restriction, variability, true);
|
asOtherConstType = new PolyType(restriction, variability, true, quant);
|
||||||
asOtherConstType->asOtherConstType = this;
|
asOtherConstType->asOtherConstType = this;
|
||||||
}
|
}
|
||||||
return asOtherConstType;
|
return asOtherConstType;
|
||||||
@@ -762,7 +767,7 @@ PolyType::GetAsNonConstType() const {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (asOtherConstType == NULL) {
|
if (asOtherConstType == NULL) {
|
||||||
asOtherConstType = new PolyType(restriction, variability, false);
|
asOtherConstType = new PolyType(restriction, variability, false, quant);
|
||||||
asOtherConstType->asOtherConstType = this;
|
asOtherConstType->asOtherConstType = this;
|
||||||
}
|
}
|
||||||
return asOtherConstType;
|
return asOtherConstType;
|
||||||
@@ -781,7 +786,8 @@ PolyType::GetAsVaryingType() const {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (asVaryingType == NULL) {
|
if (asVaryingType == NULL) {
|
||||||
asVaryingType = new PolyType(restriction, Variability::Varying, isConst);
|
asVaryingType = new PolyType(restriction, Variability::Varying,
|
||||||
|
isConst, quant);
|
||||||
if (variability == Variability::Uniform)
|
if (variability == Variability::Uniform)
|
||||||
asVaryingType->asUniformType = this;
|
asVaryingType->asUniformType = this;
|
||||||
}
|
}
|
||||||
@@ -795,7 +801,8 @@ PolyType::GetAsUniformType() const {
|
|||||||
return this;
|
return this;
|
||||||
|
|
||||||
if (asUniformType == NULL) {
|
if (asUniformType == NULL) {
|
||||||
asUniformType = new PolyType(restriction, Variability::Uniform, isConst);
|
asUniformType = new PolyType(restriction, Variability::Uniform,
|
||||||
|
isConst, quant);
|
||||||
if (variability == Variability::Varying)
|
if (variability == Variability::Varying)
|
||||||
asUniformType->asVaryingType = this;
|
asUniformType->asVaryingType = this;
|
||||||
}
|
}
|
||||||
@@ -807,7 +814,7 @@ const PolyType *
|
|||||||
PolyType::GetAsUnboundVariabilityType() const {
|
PolyType::GetAsUnboundVariabilityType() const {
|
||||||
if (variability == Variability::Unbound)
|
if (variability == Variability::Unbound)
|
||||||
return this;
|
return this;
|
||||||
return new PolyType(restriction, Variability::Unbound, isConst);
|
return new PolyType(restriction, Variability::Unbound, isConst, quant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -816,7 +823,7 @@ PolyType::GetAsSOAType(int width) const {
|
|||||||
if (variability == Variability(Variability::SOA, width))
|
if (variability == Variability(Variability::SOA, width))
|
||||||
return this;
|
return this;
|
||||||
return new PolyType(restriction, Variability(Variability::SOA, width),
|
return new PolyType(restriction, Variability(Variability::SOA, width),
|
||||||
isConst);
|
isConst, quant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -825,12 +832,12 @@ PolyType::ResolveUnboundVariability(Variability v) const {
|
|||||||
Assert(v != Variability::Unbound);
|
Assert(v != Variability::Unbound);
|
||||||
if (variability != Variability::Unbound)
|
if (variability != Variability::Unbound)
|
||||||
return this;
|
return this;
|
||||||
return new PolyType(restriction, v, isConst);
|
return new PolyType(restriction, v, isConst, quant);
|
||||||
}
|
}
|
||||||
|
|
||||||
const PolyType *
|
const PolyType *
|
||||||
PolyType::Quantify(int quant) const {
|
PolyType::Quantify(int q) const {
|
||||||
return new PolyType(restriction, variability, isConst, quant);
|
return new PolyType(restriction, variability, isConst, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
@@ -847,6 +854,12 @@ PolyType::GetString() const {
|
|||||||
case TYPE_NUMBER: ret += "number"; break;
|
case TYPE_NUMBER: ret += "number"; break;
|
||||||
default: FATAL("Logic error in PolyType::GetString()");
|
default: FATAL("Logic error in PolyType::GetString()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (quant >= 0) {
|
||||||
|
ret += "$";
|
||||||
|
ret += std::to_string(quant);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3912,6 +3925,14 @@ lCheckTypeEquality(const Type *a, const Type *b, bool ignoreConst) {
|
|||||||
(ata->GetVariability() == atb->GetVariability()));
|
(ata->GetVariability() == atb->GetVariability()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PolyType *pyta = CastType<PolyType>(a);
|
||||||
|
const PolyType *pytb = CastType<PolyType>(b);
|
||||||
|
if (pyta != NULL && pytb != NULL) {
|
||||||
|
return ((pyta->restriction == pytb->restriction) &&
|
||||||
|
(pyta->GetVariability() == pytb->GetVariability()) &&
|
||||||
|
(pyta->GetQuant() == pytb->GetQuant()));
|
||||||
|
}
|
||||||
|
|
||||||
// For all of the other types, we need to see if we have the same two
|
// For all of the other types, we need to see if we have the same two
|
||||||
// general types. If so, then we dig into the details of the type and
|
// general types. If so, then we dig into the details of the type and
|
||||||
// see if all of the relevant bits are equal...
|
// see if all of the relevant bits are equal...
|
||||||
|
|||||||
9
type.h
9
type.h
@@ -368,6 +368,7 @@ private:
|
|||||||
class PolyType : public Type {
|
class PolyType : public Type {
|
||||||
public:
|
public:
|
||||||
Variability GetVariability() const;
|
Variability GetVariability() const;
|
||||||
|
int GetQuant() const;
|
||||||
|
|
||||||
bool IsBoolType() const;
|
bool IsBoolType() const;
|
||||||
bool IsFloatType() const;
|
bool IsFloatType() const;
|
||||||
@@ -1064,6 +1065,14 @@ CastType(const Type *type) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <> inline const PolyType *
|
||||||
|
CastType(const Type *type) {
|
||||||
|
if (type != NULL && type->typeId == POLY_TYPE)
|
||||||
|
return (const PolyType *)type;
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
template <> inline const EnumType *
|
template <> inline const EnumType *
|
||||||
CastType(const Type *type) {
|
CastType(const Type *type) {
|
||||||
if (type != NULL && type->typeId == ENUM_TYPE)
|
if (type != NULL && type->typeId == ENUM_TYPE)
|
||||||
|
|||||||
Reference in New Issue
Block a user