#include "llvm/DerivedTypes.h"
#include "llvm/SymbolTable.h"
+#include "llvm/Constants.h"
#include "Support/StringExtras.h"
#include "Support/STLExtras.h"
#include <iostream>
//
bool Type::isLosslesslyConvertableTo(const Type *Ty) const {
if (this == Ty) return true;
- if ((!isPrimitiveType() && !isPointerType()) ||
- (!Ty->isPointerType() && !Ty->isPrimitiveType())) return false;
+ if ((!isPrimitiveType() && !isa<PointerType>(this)) ||
+ (!isa<PointerType>(Ty) && !Ty->isPrimitiveType())) return false;
if (getPrimitiveID() == Ty->getPrimitiveID())
return true; // Handles identity cast, and cast of differing pointer types
}
}
+// getPrimitiveSize - Return the basic size of this type if it is a primative
+// type. These are fixed by LLVM and are not target dependant. This will
+// return zero if the type does not have a size or is not a primitive type.
+//
+unsigned Type::getPrimitiveSize() const {
+ switch (getPrimitiveID()) {
+#define HANDLE_PRIM_TYPE(TY,SIZE) case TY##TyID: return SIZE;
+#include "llvm/Type.def"
+ default: return 0;
+ }
+}
+
bool StructType::indexValid(const Value *V) const {
if (!isa<Constant>(V)) return false;
// These classes are used to implement specialized behavior for each different
// type.
//
-class SignedIntType : public Type {
- int Size;
-public:
- SignedIntType(const string &Name, PrimitiveID id, int size) : Type(Name, id) {
- Size = size;
- }
+struct SignedIntType : public Type {
+ SignedIntType(const string &Name, PrimitiveID id) : Type(Name, id) {}
// isSigned - Return whether a numeric type is signed.
virtual bool isSigned() const { return 1; }
- // isIntegral - Equivalent to isSigned() || isUnsigned, but with only a single
+ // isInteger - Equivalent to isSigned() || isUnsigned, but with only a single
// virtual function invocation.
//
- virtual bool isIntegral() const { return 1; }
+ virtual bool isInteger() const { return 1; }
};
-class UnsignedIntType : public Type {
- uint64_t Size;
-public:
- UnsignedIntType(const string &N, PrimitiveID id, int size) : Type(N, id) {
- Size = size;
- }
+struct UnsignedIntType : public Type {
+ UnsignedIntType(const string &N, PrimitiveID id) : Type(N, id) {}
// isUnsigned - Return whether a numeric type is signed.
virtual bool isUnsigned() const { return 1; }
- // isIntegral - Equivalent to isSigned() || isUnsigned, but with only a single
+ // isInteger - Equivalent to isSigned() || isUnsigned, but with only a single
// virtual function invocation.
//
- virtual bool isIntegral() const { return 1; }
+ virtual bool isInteger() const { return 1; }
};
static struct TypeType : public Type {
Type *Type::VoidTy = new Type("void" , VoidTyID),
*Type::BoolTy = new Type("bool" , BoolTyID),
- *Type::SByteTy = new SignedIntType("sbyte" , SByteTyID, 1),
- *Type::UByteTy = new UnsignedIntType("ubyte" , UByteTyID, 1),
- *Type::ShortTy = new SignedIntType("short" , ShortTyID, 2),
- *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID, 2),
- *Type::IntTy = new SignedIntType("int" , IntTyID, 4),
- *Type::UIntTy = new UnsignedIntType("uint" , UIntTyID, 4),
- *Type::LongTy = new SignedIntType("long" , LongTyID, 8),
- *Type::ULongTy = new UnsignedIntType("ulong" , ULongTyID, 8),
+ *Type::SByteTy = new SignedIntType("sbyte" , SByteTyID),
+ *Type::UByteTy = new UnsignedIntType("ubyte" , UByteTyID),
+ *Type::ShortTy = new SignedIntType("short" , ShortTyID),
+ *Type::UShortTy = new UnsignedIntType("ushort", UShortTyID),
+ *Type::IntTy = new SignedIntType("int" , IntTyID),
+ *Type::UIntTy = new UnsignedIntType("uint" , UIntTyID),
+ *Type::LongTy = new SignedIntType("long" , LongTyID),
+ *Type::ULongTy = new UnsignedIntType("ulong" , ULongTyID),
*Type::FloatTy = new Type("float" , FloatTyID),
*Type::DoubleTy = new Type("double", DoubleTyID),
*Type::TypeTy = &TheTypeType,
~TypeMap() { print("ON EXIT"); }
inline TypeClass *get(const ValType &V) {
- map<ValType, PATypeHandle<TypeClass> >::iterator I = Map.find(V);
+ typename map<ValType, PATypeHandle<TypeClass> >::iterator I = Map.find(V);
// TODO: FIXME: When Types are not CONST.
return (I != Map.end()) ? (TypeClass*)I->second.get() : 0;
}
// structurally equivalent to the specified type.
//
inline const TypeClass *containsEquivalent(const TypeClass *Ty) {
- for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
+ for (typename MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
if (I->second.get() != Ty && TypesEqual(Ty, I->second.get()))
return (TypeClass*)I->second.get(); // FIXME TODO when types not const
return 0;
<< OldTy->getDescription() << " replacement == " << (void*)NewTy
<< ", " << NewTy->getDescription() << endl;
#endif
- for (MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
+ for (typename MapTy::iterator I = Map.begin(), E = Map.end(); I != E; ++I)
if (I->second == OldTy) {
// Check to see if the type just became concrete. If so, remove self
// from user list.
}
void remove(const ValType &OldVal) {
- MapTy::iterator I = Map.find(OldVal);
+ typename MapTy::iterator I = Map.find(OldVal);
assert(I != Map.end() && "TypeMap::remove, element not found!");
Map.erase(I);
}