From 8e0f67dcec577760e3bdc36f0377c6f43e1894d8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 3 Jan 2014 19:21:54 +0000 Subject: 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@198438 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/IR/DataLayout.h | 53 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'include/llvm/IR/DataLayout.h') diff --git a/include/llvm/IR/DataLayout.h b/include/llvm/IR/DataLayout.h index a1776fbf9b..520d4ede18 100644 --- a/include/llvm/IR/DataLayout.h +++ b/include/llvm/IR/DataLayout.h @@ -34,6 +34,7 @@ class Type; class IntegerType; class StructType; class StructLayout; +class Triple; class GlobalVariable; class LLVMContext; template @@ -99,6 +100,15 @@ private: bool LittleEndian; ///< Defaults to false unsigned StackNaturalAlign; ///< Stack natural alignment + enum ManglingModeT { + MM_None, + MM_ELF, + MM_MachO, + MM_COFF, + MM_Mips + }; + ManglingModeT ManglingMode; + SmallVector LegalIntWidths; ///< Legal Integers. /// Alignments - Where the primitive type alignment data is stored. @@ -174,6 +184,7 @@ public: ImmutablePass(ID), LittleEndian(DL.isLittleEndian()), StackNaturalAlign(DL.StackNaturalAlign), + ManglingMode(DL.ManglingMode), LegalIntWidths(DL.LegalIntWidths), Alignments(DL.Alignments), Pointers(DL.Pointers), @@ -222,6 +233,48 @@ public: return (StackNaturalAlign != 0) && (Align > StackNaturalAlign); } + bool hasMicrosoftFastStdCallMangling() const { + return ManglingMode == MM_COFF; + } + + bool hasLinkerPrivateGlobalPrefix() const { + return ManglingMode == MM_MachO; + } + + const char *getLinkerPrivateGlobalPrefix() const { + if (ManglingMode == MM_MachO) + return "l"; + return getPrivateGlobalPrefix(); + } + + char getGlobalPrefix() const { + switch (ManglingMode) { + case MM_None: + case MM_ELF: + case MM_Mips: + return '\0'; + case MM_MachO: + case MM_COFF: + return '_'; + } + } + + const char *getPrivateGlobalPrefix() const { + switch (ManglingMode) { + case MM_None: + return ""; + case MM_ELF: + return ".L"; + case MM_Mips: + return "$"; + case MM_MachO: + case MM_COFF: + return "L"; + } + } + + static const char *getManglingComponent(const Triple &T); + /// fitsInLegalInteger - This function returns true if the specified type fits /// in a native integer type supported by the CPU. For example, if the CPU /// only supports i32 as a native integer type, then i27 fits in a legal -- cgit v1.2.3