From: Chris Lattner Date: Tue, 22 Apr 2003 18:02:04 +0000 (+0000) Subject: Add support for tracking whether a module is 64/32 bit and big/little endian X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=678c6a089da468bc20661922cf63deedef2d9b7a;p=oota-llvm.git Add support for tracking whether a module is 64/32 bit and big/little endian Also add a moduleID field which can be used for diagnostics git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5834 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 0bb23f9d409..bf7cf62be0c 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -50,16 +50,22 @@ public: typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; -private: - GlobalListType GlobalList; // The Global Variables - FunctionListType FunctionList; // The Functions - - GlobalValueRefMap *GVRefMap; + enum Endianness { LittleEndian, BigEndian }; + enum PointerSize { Pointer32, Pointer64 }; - SymbolTable *SymTab; - - // Accessor for the underlying GlobalValRefMap... only through the - // Constant class... +private: + GlobalListType GlobalList; // The Global Variables in the module + FunctionListType FunctionList; // The Functions in the module + GlobalValueRefMap *GVRefMap; // Keep track of GlobalValueRef's + SymbolTable *SymTab; // Symbol Table for the module + std::string ModuleID; // Human readable identifier for the module + + // These flags are probably not the right long-term way to handle this kind of + // target information, but it is sufficient for now. + Endianness Endian; // True if target is little endian + PointerSize PtrSize; // True if target has 32-bit pointers (false = 64-bit) + + // Accessor for the underlying GVRefMap... only through the Constant class... friend class Constant; friend class ConstantPointerRef; void mutateConstantPointerRef(GlobalValue *OldGV, GlobalValue *NewGV); @@ -67,9 +73,23 @@ private: void destroyConstantPointerRef(ConstantPointerRef *CPR); public: - Module(); + Module(const std::string &ModuleID); ~Module(); + const std::string &getModuleIdentifier() const { return ModuleID; } + + /// Target endian information... + bool isLittleEndian() const { return Endian == LittleEndian; } + bool isBigEndian() const { return Endian == BigEndian; } + Endianness getEndianness() const { return Endian; } + void setEndianness(Endianness E) { Endian = E; } + + /// Target Pointer Size information... + bool has32BitPointers() const { return PtrSize == Pointer32; } + bool has64BitPointers() const { return PtrSize == Pointer64; } + PointerSize getPointerSize() const { return PtrSize; } + void setPointerSize(PointerSize PS) { PtrSize = PS; } + /// getOrInsertFunction - Look up the specified function in the module symbol /// table. If it does not exist, add a prototype for the function and return /// it. diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp index e0a6fb271ce..fe9b828b2b9 100644 --- a/lib/VMCore/Module.cpp +++ b/lib/VMCore/Module.cpp @@ -52,7 +52,8 @@ struct GlobalValueRefMap { }; -Module::Module() { +Module::Module(const std::string &MID) + : ModuleID(MID), Endian(BigEndian), PtrSize(Pointer64) { FunctionList.setItemParent(this); FunctionList.setParent(this); GlobalList.setItemParent(this);