From 7b651ce261483d9360c2ac6a4879806ef2826c31 Mon Sep 17 00:00:00 2001 From: Nadav Rotem Date: Thu, 9 Jan 2014 07:50:34 +0000 Subject: [PATCH] Revert r198819 - "Remove dead code." git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198854 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/Module.h | 14 +++++++++++++ lib/IR/Module.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index eb1812c09b4..fa7767a526c 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -142,6 +142,12 @@ public: /// The named metadata constant interators. typedef NamedMDListType::const_iterator const_named_metadata_iterator; + /// An enumeration for describing the endianess of the target machine. + enum Endianness { LittleEndian, BigEndian }; + + /// An enumeration for describing the size of a pointer on the target machine. + enum PointerSize { Pointer32, Pointer64 }; + /// This enumeration defines the supported behaviors of module flags. enum ModFlagBehavior { /// Emits an error if two values disagree, otherwise the resulting value is @@ -230,6 +236,14 @@ public: /// @returns a string containing the target triple. const std::string &getTargetTriple() const { return TargetTriple; } + /// Get the target endian information. + /// @returns Endianess - an enumeration for the endianess of the target + Endianness getEndianness() const; + + /// Get the target pointer size. + /// @returns PointerSize - an enumeration for the size of the target's pointer + PointerSize getPointerSize() const; + /// Get the global data context. /// @returns LLVMContext - a container for LLVM's global information LLVMContext &getContext() const { return Context; } diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 996c5b67a41..f938a92741a 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -60,6 +60,51 @@ Module::~Module() { delete static_cast *>(NamedMDSymTab); } +/// Target endian information. +Module::Endianness Module::getEndianness() const { + StringRef temp = DataLayout; + Module::Endianness ret = BigEndian; + + while (!temp.empty()) { + std::pair P = getToken(temp, "-"); + + StringRef token = P.first; + temp = P.second; + + if (token[0] == 'e') { + ret = LittleEndian; + } else if (token[0] == 'E') { + ret = BigEndian; + } + } + + return ret; +} + +/// Target Pointer Size information. +Module::PointerSize Module::getPointerSize() const { + StringRef temp = DataLayout; + Module::PointerSize ret = Pointer64; + + while (!temp.empty()) { + std::pair TmpP = getToken(temp, "-"); + temp = TmpP.second; + TmpP = getToken(TmpP.first, ":"); + StringRef token = TmpP.second, signalToken = TmpP.first; + + if (signalToken[0] == 'p') { + int size = 0; + getToken(token, ":").first.getAsInteger(10, size); + if (size == 32) + ret = Pointer32; + else if (size == 64) + ret = Pointer64; + } + } + + return ret; +} + /// getNamedValue - Return the first global value in the module with /// the specified name, of arbitrary type. This method returns null /// if a global with the specified name is not found. -- 2.34.1