Add a new constructor to TargetData that builds a TargetData from its
authorOwen Anderson <resistor@mac.com>
Fri, 12 May 2006 05:49:47 +0000 (05:49 +0000)
committerOwen Anderson <resistor@mac.com>
Fri, 12 May 2006 05:49:47 +0000 (05:49 +0000)
string representation.

This is part of PR 761.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28234 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetData.h
lib/Target/TargetData.cpp

index 1f031f2cc9130a4db759a3acf487c73ec0f45564..26821bd8a7b0f19460969eb2830249b32fdde9b6 100644 (file)
@@ -53,6 +53,13 @@ public:
              unsigned char IntAl   = 4, unsigned char ShortAl  = 2,
              unsigned char ByteAl  = 1, unsigned char BoolAl   = 1);
 
+  /// Constructs a TargetData from a string of the following format:
+  /// "E-p:64:64-d:64:64-f:32:32-l:64:64-i:32:32-s:16:16-b:8:8-B:8:8"
+  /// The above string is considered the default, and any values not specified
+  /// in the string will be assumed to be as above.
+  TargetData(const std::string &TargetName,
+             const std::string &TargetDescription);
+  
   // Copy constructor
   TargetData (const TargetData &TD) :
     ImmutablePass(),
index 63c5b6178a3f8803e52e8dddb376babc2bb4a029..be6ba605aef98a07c85fefc70f4f1abb9d30932e 100644 (file)
@@ -22,7 +22,9 @@
 #include "llvm/Constants.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/ADT/StringExtras.h"
 #include <algorithm>
+#include <cstdlib>
 using namespace llvm;
 
 // Handle the Pass registration stuff necessary to use TargetData's.
@@ -118,6 +120,69 @@ TargetData::TargetData(const std::string &TargetName,
   BoolAlignment    = BoolAl;
 }
 
+TargetData::TargetData(const std::string &TargetName,
+                       const std::string &TargetDescription) {
+  std::string temp = TargetDescription;
+  
+  LittleEndian = false;
+  PointerSize = 8;
+  PointerAlignment   = 8;
+  DoubleAlignment = 8;
+  FloatAlignment = 4;
+  LongAlignment   = 8;
+  IntAlignment   = 4;
+  ShortAlignment  = 2;
+  ByteAlignment  = 1;
+  BoolAlignment   = 1;
+  
+  while (temp.length() > 0) {
+    std::string token = getToken(temp, "-");
+    
+    switch(token[0]) {
+    case 'E':
+               LittleEndian = false;
+        break;
+    case 'e':
+               LittleEndian = true;
+       break;
+    case 'p':
+               PointerSize = atoi(getToken(token,":").c_str()) / 8;
+               PointerAlignment = atoi(getToken(token,":").c_str()) / 8;
+               break;
+    case 'd':
+               token = getToken(token,":"); //Ignore the size
+               DoubleAlignment = atoi(getToken(token,":").c_str()) / 8;
+        break;
+    case 'f':
+               token = getToken(token, ":"); //Ignore the size
+               FloatAlignment = atoi(getToken(token, ":").c_str()) / 8;
+       break;
+    case 'l':
+               token = getToken(token, ":"); //Ignore the size
+               LongAlignment = atoi(getToken(token, ":").c_str()) / 8;
+       break;
+    case 'i':
+               token = getToken(token, ":"); //Ignore the size
+               IntAlignment = atoi(getToken(token, ":").c_str()) / 8;
+       break;
+    case 's':
+               token = getToken(token, ":"); //Ignore the size
+               ShortAlignment = atoi(getToken(token, ":").c_str()) / 8;
+       break;
+    case 'b':
+               token = getToken(token, ":"); //Ignore the size
+               ByteAlignment = atoi(getToken(token, ":").c_str()) / 8;
+       break;
+    case 'B':
+               token = getToken(token, ":"); //Ignore the size
+               BoolAlignment = atoi(getToken(token, ":").c_str()) / 8;
+       break;
+    default:
+       break;
+    }
+  }
+}
+
 TargetData::TargetData(const std::string &ToolName, const Module *M) {
   LittleEndian     = M->getEndianness() != Module::BigEndian;
   PointerSize      = M->getPointerSize() != Module::Pointer64 ? 4 : 8;