Type.h revision b9b8959091517b47675f7126b40bd50bcfdbb384
1//===-- llvm/Type.h - Classes for handling data types ------------*- C++ -*--=// 2// 3// This file contains the declaration of the Type class. For more "Type" type 4// stuff, look in DerivedTypes.h and Opt/ConstantHandling.h 5// 6// Note that instances of the Type class are immutable: once they are created, 7// they are never changed. Also note that only one instance of a particular 8// type is ever created. Thus seeing if two types are equal is a matter of 9// doing a trivial pointer comparison. 10// 11// Types, once allocated, are never free'd. 12// 13//===----------------------------------------------------------------------===// 14 15#ifndef LLVM_TYPE_H 16#define LLVM_TYPE_H 17 18#include "llvm/Value.h" 19 20namespace opt { 21 class ConstRules; 22} 23class ConstPoolVal; 24 25class Type : public Value { 26public: 27 //===--------------------------------------------------------------------===// 28 // Definitions of all of the base types for the Type system. Based on this 29 // value, you can cast to a "DerivedType" subclass (see DerivedTypes.h) 30 // Note: If you add an element to this, you need to add an element to the 31 // Type::getPrimitiveType function, or else things will break! 32 // 33 enum PrimitiveID { 34 VoidTyID = 0 , BoolTyID, // 0, 1: Basics... 35 UByteTyID , SByteTyID, // 2, 3: 8 bit types... 36 UShortTyID , ShortTyID, // 4, 5: 16 bit types... 37 UIntTyID , IntTyID, // 6, 7: 32 bit types... 38 ULongTyID , LongTyID, // 8, 9: 64 bit types... 39 40 FloatTyID , DoubleTyID, // 10,11: Floating point types... 41 42 TypeTyID, // 12 : Type definitions 43 LabelTyID , LockTyID, // 13,14: Labels... mutexes... 44 45 // TODO: Kill FillerTyID. It just makes FirstDerivedTyID = 0x10 46 FillerTyID , // 15 : filler 47 48 // Derived types... see DerivedTypes.h file... 49 // Make sure FirstDerivedTyID stays up to date!!! 50 MethodTyID , ModuleTyID, // Methods... Modules... 51 ArrayTyID , PointerTyID, // Array... pointer... 52 StructTyID , PackedTyID, // Structure... SIMD 'packed' format... 53 //... 54 55 NumPrimitiveIDs, // Must remain as last defined ID 56 FirstDerivedTyID = MethodTyID, 57 }; 58 59private: 60 PrimitiveID ID; // The current base type of this type... 61 unsigned UID; // The unique ID number for this class 62 63 // ConstRulesImpl - See Opt/ConstantHandling.h for more info 64 mutable const opt::ConstRules *ConstRulesImpl; 65 66protected: 67 // ctor is protected, so only subclasses can create Type objects... 68 Type(const string &Name, PrimitiveID id); 69public: 70 virtual ~Type() {} 71 72 // isSigned - Return whether a numeric type is signed. 73 virtual bool isSigned() const { return 0; } 74 75 // isUnsigned - Return whether a numeric type is unsigned. This is not 76 // quite the complement of isSigned... nonnumeric types return false as they 77 // do with isSigned. 78 // 79 virtual bool isUnsigned() const { return 0; } 80 81 inline unsigned getUniqueID() const { return UID; } 82 inline PrimitiveID getPrimitiveID() const { return ID; } 83 84 // getPrimitiveType/getUniqueIDType - Return a type based on an identifier. 85 static const Type *getPrimitiveType(PrimitiveID IDNumber); 86 static const Type *getUniqueIDType(unsigned UID); 87 88 // Methods for dealing with constants uniformly. See Opt/ConstantHandling.h 89 // for more info on this... 90 // 91 inline const opt::ConstRules *getConstRules() const { return ConstRulesImpl; } 92 inline void setConstRules(const opt::ConstRules *R) const { ConstRulesImpl = R; } 93 94public: // These are the builtin types that are always available... 95 static const Type *VoidTy , *BoolTy; 96 static const Type *SByteTy, *UByteTy, 97 *ShortTy, *UShortTy, 98 *IntTy , *UIntTy, 99 *LongTy , *ULongTy; 100 static const Type *FloatTy, *DoubleTy; 101 102 static const Type *TypeTy , *LabelTy, *LockTy; 103 104 // Here are some useful little methods to query what type derived types are 105 // Note that all other types can just compare to see if this == Type::xxxTy; 106 // 107 inline bool isDerivedType() const { return ID >= FirstDerivedTyID; } 108 inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; } 109 110 inline bool isLabelType() const { return this == LabelTy; } 111 inline bool isMethodType() const { return ID == MethodTyID; } 112 inline bool isModuleType() const { return ID == ModuleTyID; } 113 inline bool isArrayType() const { return ID == ArrayTyID; } 114 inline bool isPointerType() const { return ID == PointerTyID; } 115 inline bool isStructType() const { return ID == StructTyID; } 116}; 117 118#endif 119