1 //===-- llvm/Type.h - Classes for handling data types ------------*- C++ -*--=//
3 // This file contains the declaration of the Type class. For more "Type" type
4 // stuff, look in DerivedTypes.h and Opt/ConstantHandling.h
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.
11 // Types, once allocated, are never free'd.
13 //===----------------------------------------------------------------------===//
18 #include "llvm/Value.h"
23 class Type : public Value {
25 //===--------------------------------------------------------------------===//
26 // Definitions of all of the base types for the Type system. Based on this
27 // value, you can cast to a "DerivedType" subclass (see DerivedTypes.h)
28 // Note: If you add an element to this, you need to add an element to the
29 // Type::getPrimitiveType function, or else things will break!
32 VoidTyID = 0 , BoolTyID, // 0, 1: Basics...
33 UByteTyID , SByteTyID, // 2, 3: 8 bit types...
34 UShortTyID , ShortTyID, // 4, 5: 16 bit types...
35 UIntTyID , IntTyID, // 6, 7: 32 bit types...
36 ULongTyID , LongTyID, // 8, 9: 64 bit types...
38 FloatTyID , DoubleTyID, // 10,11: Floating point types...
40 TypeTyID, // 12 : Type definitions
41 LabelTyID , LockTyID, // 13,14: Labels... mutexes...
43 // TODO: Kill FillerTyID. It just makes FirstDerivedTyID = 0x10
44 FillerTyID , // 15 : filler
46 // Derived types... see DerivedTypes.h file...
47 // Make sure FirstDerivedTyID stays up to date!!!
48 MethodTyID , ModuleTyID, // Methods... Modules...
49 ArrayTyID , PointerTyID, // Array... pointer...
50 StructTyID , PackedTyID, // Structure... SIMD 'packed' format...
53 NumPrimitiveIDs, // Must remain as last defined ID
54 FirstDerivedTyID = MethodTyID,
58 PrimitiveID ID; // The current base type of this type...
59 unsigned UID; // The unique ID number for this class
61 // ConstRulesImpl - See Opt/ConstantHandling.h for more info
62 mutable const ConstRules *ConstRulesImpl;
65 // ctor is protected, so only subclasses can create Type objects...
66 Type(const string &Name, PrimitiveID id);
70 // isSigned - Return whether a numeric type is signed.
71 virtual bool isSigned() const { return 0; }
73 // isUnsigned - Return whether a numeric type is unsigned. This is not
74 // quite the complement of isSigned... nonnumeric types return false as they
77 virtual bool isUnsigned() const { return 0; }
79 inline unsigned getUniqueID() const { return UID; }
80 inline PrimitiveID getPrimitiveID() const { return ID; }
82 // getPrimitiveType/getUniqueIDType - Return a type based on an identifier.
83 static const Type *getPrimitiveType(PrimitiveID IDNumber);
84 static const Type *getUniqueIDType(unsigned UID);
86 // Methods for dealing with constants uniformly. See Opt/ConstantHandling.h
87 // for more info on this...
89 inline const ConstRules *getConstRules() const { return ConstRulesImpl; }
90 inline void setConstRules(const ConstRules *R) const { ConstRulesImpl = R; }
92 public: // These are the builtin types that are always available...
93 static const Type *VoidTy , *BoolTy;
94 static const Type *SByteTy, *UByteTy,
98 static const Type *FloatTy, *DoubleTy;
100 static const Type *TypeTy , *LabelTy, *LockTy;
102 // Here are some useful little methods to query what type derived types are
103 // Note that all other types can just compare to see if this == Type::xxxTy;
105 inline bool isDerivedType() const { return ID >= FirstDerivedTyID; }
106 inline bool isPrimitiveType() const { return ID < FirstDerivedTyID; }
108 inline bool isLabelType() const { return this == LabelTy; }
109 inline bool isMethodType() const { return ID == MethodTyID; }
110 inline bool isModuleType() const { return ID == ModuleTyID; }
111 inline bool isArrayType() const { return ID == ArrayTyID; }
112 inline bool isPointerType() const { return ID == PointerTyID; }
113 inline bool isStructType() const { return ID == StructTyID; }