aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Type.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-06 16:14:39 +0000
committerChris Lattner <sabre@nondot.org>2002-05-06 16:14:39 +0000
commitd44023ecb7a699e52f119bec0eb86830989ff35a (patch)
treea81696b9133933b15ade6b709cd31a683b5fd65d /lib/VMCore/Type.cpp
parent3f5b877dd4e1bd19915bf0de041dd5e199ef4062 (diff)
downloadexternal_llvm-d44023ecb7a699e52f119bec0eb86830989ff35a.zip
external_llvm-d44023ecb7a699e52f119bec0eb86830989ff35a.tar.gz
external_llvm-d44023ecb7a699e52f119bec0eb86830989ff35a.tar.bz2
Implement getPrimitiveSize()
don't use isPointerType() git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2485 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Type.cpp')
-rw-r--r--lib/VMCore/Type.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp
index 3ea928e..d193a38 100644
--- a/lib/VMCore/Type.cpp
+++ b/lib/VMCore/Type.cpp
@@ -87,8 +87,8 @@ const Type *Type::getPrimitiveType(PrimitiveID IDNumber) {
//
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
@@ -110,6 +110,18 @@ bool Type::isLosslesslyConvertableTo(const Type *Ty) const {
}
}
+// 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;