From 5fea9f0a93a626c4197b10dc5229bd2efadc8cc2 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 12 May 2006 07:01:44 +0000 Subject: [PATCH] Add a method to generate a string representation from a TargetData. This continues the work on PR 761. llvm-svn: 28239 --- llvm/include/llvm/Target/TargetData.h | 5 +++++ llvm/lib/Target/TargetData.cpp | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/llvm/include/llvm/Target/TargetData.h b/llvm/include/llvm/Target/TargetData.h index 26821bd8a7b0..428d05fdd5c1 100644 --- a/llvm/include/llvm/Target/TargetData.h +++ b/llvm/include/llvm/Target/TargetData.h @@ -94,6 +94,11 @@ public: unsigned char getPointerSize() const { return PointerSize; } unsigned char getPointerSizeInBits() const { return 8*PointerSize; } + /// getStringRepresentation - Return the string representation of the + /// TargetData. This representation is in the same format accepted by the + /// string constructor above. + std::string getStringRepresentation() const; + /// getTypeSize - Return the number of bytes necessary to hold the specified /// type. /// diff --git a/llvm/lib/Target/TargetData.cpp b/llvm/lib/Target/TargetData.cpp index 14ce6e89de7c..f7c0d7800b74 100644 --- a/llvm/lib/Target/TargetData.cpp +++ b/llvm/lib/Target/TargetData.cpp @@ -25,6 +25,7 @@ #include "llvm/ADT/StringExtras.h" #include #include +#include using namespace llvm; // Handle the Pass registration stuff necessary to use TargetData's. @@ -218,6 +219,26 @@ TargetData::~TargetData() { } } +std::string TargetData::getStringRepresentation() const { + std::stringstream repr; + + if (LittleEndian) + repr << "e"; + else + repr << "E"; + + repr << "-p:" << (PointerSize * 8) << ":" << (PointerAlignment * 8); + repr << "-d:64:" << (DoubleAlignment * 8); + repr << "-f:32:" << (FloatAlignment * 8); + repr << "-l:64:" << (LongAlignment * 8); + repr << "-i:32:" << (IntAlignment * 8); + repr << "-s:16:" << (ShortAlignment * 8); + repr << "-b:8:" << (ByteAlignment * 8); + repr << "-B:8:" << (BoolAlignment * 8); + + return repr.str(); +} + const StructLayout *TargetData::getStructLayout(const StructType *Ty) const { if (Layouts == 0) Layouts = new std::map,