diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-03 19:21:54 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-01-03 19:21:54 +0000 |
commit | 58873566b3718a6b2730e7d726491398766a39a4 (patch) | |
tree | 95885e037ec4064b92202d0a8d15fb4d803b4c8a /llvm/lib/IR/DataLayout.cpp | |
parent | e891c5f2648c85a31c57c2cc63f76a5b95da86d3 (diff) | |
download | llvm-58873566b3718a6b2730e7d726491398766a39a4.zip llvm-58873566b3718a6b2730e7d726491398766a39a4.tar.gz llvm-58873566b3718a6b2730e7d726491398766a39a4.tar.bz2 |
Make the llvm mangler depend only on DataLayout.
Before this patch any program that wanted to know the final symbol name of a
GlobalValue had to link with Target.
This patch implements a compromise solution where the mangler uses DataLayout.
This way, any tool that already links with Target (llc, clang) gets the exact
behavior as before and new IR files can be mangled without linking with Target.
With this patch the mangler is constructed with just a DataLayout and DataLayout
is extended to include the information the Mangler needs.
llvm-svn: 198438
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r-- | llvm/lib/IR/DataLayout.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp index 0b52f1e..ee2b4bc 100644 --- a/llvm/lib/IR/DataLayout.cpp +++ b/llvm/lib/IR/DataLayout.cpp @@ -19,6 +19,7 @@ #include "llvm/IR/DataLayout.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Triple.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Module.h" @@ -152,6 +153,15 @@ DataLayout::InvalidPointerElem = { 0U, 0U, 0U, ~0U }; // DataLayout Class Implementation //===----------------------------------------------------------------------===// +const char *DataLayout::getManglingComponent(const Triple &T) { + if (T.isOSBinFormatMachO()) + return "-m:o"; + if (T.isOSBinFormatELF() || T.isArch64Bit()) + return "-m:e"; + assert(T.isOSBinFormatCOFF()); + return "-m:c"; +} + static const LayoutAlignElem DefaultAlignments[] = { { INTEGER_ALIGN, 1, 1, 1 }, // i1 { INTEGER_ALIGN, 8, 1, 1 }, // i8 @@ -173,6 +183,7 @@ void DataLayout::init(StringRef Desc) { LayoutMap = 0; LittleEndian = false; StackNaturalAlign = 0; + ManglingMode = MM_None; // Default alignments for (int I = 0, N = array_lengthof(DefaultAlignments); I < N; ++I) { @@ -305,6 +316,26 @@ void DataLayout::parseSpecifier(StringRef Desc) { StackNaturalAlign = inBytes(getInt(Tok)); break; } + case 'm': + assert(Tok.empty()); + assert(Rest.size() == 1); + switch(Rest[0]) { + default: + llvm_unreachable("Unknown mangling in datalayout string"); + case 'e': + ManglingMode = MM_ELF; + break; + case 'o': + ManglingMode = MM_MachO; + break; + case 'm': + ManglingMode = MM_Mips; + break; + case 'c': + ManglingMode = MM_COFF; + break; + } + break; default: llvm_unreachable("Unknown specifier in datalayout string"); break; @@ -481,6 +512,24 @@ std::string DataLayout::getStringRepresentation() const { raw_string_ostream OS(Result); OS << (LittleEndian ? "e" : "E"); + + switch (ManglingMode) { + case MM_None: + break; + case MM_ELF: + OS << "-m:e"; + break; + case MM_MachO: + OS << "-m:o"; + break; + case MM_COFF: + OS << "-m:c"; + break; + case MM_Mips: + OS << "-m:m"; + break; + } + SmallVector<unsigned, 8> addrSpaces; // Lets get all of the known address spaces and sort them // into increasing order so that we can emit the string |