Add support for the new "target data" information in .ll files. This provides
authorOwen Anderson <resistor@mac.com>
Wed, 18 Oct 2006 02:21:12 +0000 (02:21 +0000)
committerOwen Anderson <resistor@mac.com>
Wed, 18 Oct 2006 02:21:12 +0000 (02:21 +0000)
a better encoding of the targets data layout, rather than trying to guess it
from the endianness and pointersize like before.

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

include/llvm/Module.h
lib/AsmParser/Lexer.l
lib/AsmParser/llvmAsmParser.y
lib/VMCore/AsmWriter.cpp

index 8e8f554abe3471701e23267fd23afd9f487f98cf..195c73d2f44a37ffd569a8bf97f196232db825ee 100644 (file)
@@ -116,6 +116,11 @@ public:
   /// @returns the module identifier as a string
   const std::string &getModuleIdentifier() const { return ModuleID; }
 
+  /// Get the data layout string for the module's target platform.  This encodes
+  /// the type sizes and alignments expected by this module.
+  /// @returns the data layout as a string
+  std::string getDataLayout() const { return DataLayout; }
+
   /// Get the target triple which is a string describing the target host.
   /// @returns a string containing the target triple.
   const std::string &getTargetTriple() const { return TargetTriple; }
@@ -139,6 +144,9 @@ public:
   /// Set the module identifier.
   void setModuleIdentifier(const std::string &ID) { ModuleID = ID; }
 
+  /// Set the data layout
+  void setDataLayout(std::string DL) { DataLayout = DL; }
+
   /// Set the target triple.
   void setTargetTriple(const std::string &T) { TargetTriple = T; }
 
index 635318c40ce12a30bc2ba64f36f036b2afd99ee6..af61a679fb13505986b652398afebdc1a0ba0644 100644 (file)
@@ -210,6 +210,7 @@ triple          { return TRIPLE; }
 deplibs         { return DEPLIBS; }
 endian          { return ENDIAN; }
 pointersize     { return POINTERSIZE; }
+data          { return DATA; }
 little          { return LITTLE; }
 big             { return BIG; }
 volatile        { return VOLATILE; }
index e57ca4ca5d41d0e775b922818c98e179715c4817..2842f27f1b8c475d5a71c8e6cc3d13a582e30067 100644 (file)
@@ -1068,6 +1068,7 @@ Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
 %token DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
 %token CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
 %token X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
+%token DATA
 %type <UIntVal> OptCallingConv
 
 // Basic Block Terminating Operators
@@ -1873,6 +1874,11 @@ TargetDefinition : ENDIAN '=' BigOrLittle {
     free($3);
     CHECK_FOR_ERROR
   };
+  | DATA '=' STRINGCONSTANT {
+    CurModule.CurrentModule->setDataLayout($3);
+    free($3);
+    CHECK_FOR_ERROR
+  };
 
 LibrariesDefinition : '[' LibList ']';
 
index 6b08266c312331fca83fb8bc4712afc12619ff7f..aedb2c4040ecf19a3c13a2fae89099785db4f7ad 100644 (file)
@@ -781,6 +781,9 @@ void AssemblyWriter::printModule(const Module *M) {
       M->getModuleIdentifier().find('\n') == std::string::npos)
     Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
 
+  if (!M->getDataLayout().empty())
+    Out << "target data = \"" << M->getDataLayout() << "\"\n";
+
   switch (M->getEndianness()) {
   case Module::LittleEndian: Out << "target endian = little\n"; break;
   case Module::BigEndian:    Out << "target endian = big\n";    break;