Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 1 | //===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===// |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 081ce94 | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 10 | // This file contains a printer that converts from our internal representation |
| 11 | // of machine-dependent LLVM code to AT&T format assembly |
| 12 | // language. This printer is the output mechanism used by `llc'. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 16 | #define DEBUG_TYPE "asm-printer" |
| 17 | #include "X86AsmPrinter.h" |
| 18 | #include "X86ATTInstPrinter.h" |
| 19 | #include "X86IntelInstPrinter.h" |
| 20 | #include "X86MCInstLower.h" |
| 21 | #include "X86.h" |
| 22 | #include "X86COFF.h" |
| 23 | #include "X86COFFMachineModuleInfo.h" |
| 24 | #include "X86MachineFunctionInfo.h" |
| 25 | #include "X86TargetMachine.h" |
| 26 | #include "llvm/CallingConv.h" |
| 27 | #include "llvm/DerivedTypes.h" |
| 28 | #include "llvm/Module.h" |
| 29 | #include "llvm/Type.h" |
| 30 | #include "llvm/Assembly/Writer.h" |
| 31 | #include "llvm/MC/MCContext.h" |
| 32 | #include "llvm/MC/MCSectionMachO.h" |
| 33 | #include "llvm/MC/MCStreamer.h" |
| 34 | #include "llvm/MC/MCSymbol.h" |
| 35 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
| 36 | #include "llvm/CodeGen/MachineModuleInfoImpls.h" |
| 37 | #include "llvm/Support/ErrorHandling.h" |
| 38 | #include "llvm/Support/FormattedStream.h" |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 39 | #include "llvm/MC/MCAsmInfo.h" |
| 40 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 41 | #include "llvm/Target/TargetOptions.h" |
| 42 | #include "llvm/Target/TargetRegistry.h" |
| 43 | #include "llvm/ADT/SmallString.h" |
| 44 | #include "llvm/ADT/Statistic.h" |
| 45 | using namespace llvm; |
| 46 | |
| 47 | STATISTIC(EmittedInsts, "Number of machine instrs printed"); |
| 48 | |
| 49 | //===----------------------------------------------------------------------===// |
| 50 | // Primitive Helper Functions. |
| 51 | //===----------------------------------------------------------------------===// |
| 52 | |
| 53 | void X86AsmPrinter::printMCInst(const MCInst *MI) { |
| 54 | if (MAI->getAssemblerDialect() == 0) |
| 55 | X86ATTInstPrinter(O, *MAI).printInstruction(MI); |
| 56 | else |
| 57 | X86IntelInstPrinter(O, *MAI).printInstruction(MI); |
| 58 | } |
| 59 | |
| 60 | void X86AsmPrinter::PrintPICBaseSymbol() const { |
Chris Lattner | 541d890 | 2010-01-26 06:28:43 +0000 | [diff] [blame] | 61 | const TargetLowering *TLI = TM.getTargetLowering(); |
| 62 | O << *static_cast<const X86TargetLowering*>(TLI)->getPICBaseSymbol(MF, |
| 63 | OutContext); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void X86AsmPrinter::emitFunctionHeader(const MachineFunction &MF) { |
| 67 | unsigned FnAlign = MF.getAlignment(); |
| 68 | const Function *F = MF.getFunction(); |
| 69 | |
| 70 | if (Subtarget->isTargetCygMing()) { |
| 71 | X86COFFMachineModuleInfo &COFFMMI = |
| 72 | MMI->getObjFileInfo<X86COFFMachineModuleInfo>(); |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 73 | COFFMMI.DecorateCygMingName(CurrentFnSym, OutContext, F, |
| 74 | *TM.getTargetData()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM)); |
| 78 | EmitAlignment(FnAlign, F); |
| 79 | |
| 80 | switch (F->getLinkage()) { |
| 81 | default: llvm_unreachable("Unknown linkage type!"); |
| 82 | case Function::InternalLinkage: // Symbols default to internal. |
| 83 | case Function::PrivateLinkage: |
| 84 | break; |
| 85 | case Function::DLLExportLinkage: |
| 86 | case Function::ExternalLinkage: |
Chris Lattner | 2d7c814 | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 87 | OutStreamer.EmitSymbolAttribute(CurrentFnSym, MCSA_Global); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 88 | break; |
| 89 | case Function::LinkerPrivateLinkage: |
| 90 | case Function::LinkOnceAnyLinkage: |
| 91 | case Function::LinkOnceODRLinkage: |
| 92 | case Function::WeakAnyLinkage: |
| 93 | case Function::WeakODRLinkage: |
| 94 | if (Subtarget->isTargetDarwin()) { |
Chris Lattner | 2d7c814 | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 95 | OutStreamer.EmitSymbolAttribute(CurrentFnSym, MCSA_Global); |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 96 | O << MAI->getWeakDefDirective() << *CurrentFnSym << '\n'; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 97 | } else if (Subtarget->isTargetCygMing()) { |
Chris Lattner | 2d7c814 | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 98 | OutStreamer.EmitSymbolAttribute(CurrentFnSym, MCSA_Global); |
Chris Lattner | 59be4ea | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 99 | // FIXME: linkonce should be a section attribute, handled by COFF Section |
| 100 | // assignment. |
| 101 | // http://sourceware.org/binutils/docs-2.20/as/Linkonce.html#Linkonce |
Chris Lattner | b6ed586 | 2010-01-18 00:59:24 +0000 | [diff] [blame] | 102 | O << "\t.linkonce discard\n"; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 103 | } else { |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 104 | O << "\t.weak\t" << *CurrentFnSym << '\n'; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 105 | } |
| 106 | break; |
| 107 | } |
| 108 | |
Chris Lattner | 86ec971 | 2010-01-16 00:32:38 +0000 | [diff] [blame] | 109 | printVisibility(CurrentFnSym, F->getVisibility()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 110 | |
Chris Lattner | 59be4ea | 2010-01-25 18:58:59 +0000 | [diff] [blame] | 111 | if (MAI->hasDotTypeDotSizeDirective()) { |
Chris Lattner | 9f8ef90 | 2010-01-25 18:33:40 +0000 | [diff] [blame] | 112 | OutStreamer.EmitSymbolAttribute(CurrentFnSym, MCSA_ELF_TypeFunction); |
Chris Lattner | 86ec971 | 2010-01-16 00:32:38 +0000 | [diff] [blame] | 113 | } else if (Subtarget->isTargetCygMing()) { |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 114 | O << "\t.def\t " << *CurrentFnSym; |
Chris Lattner | 86ec971 | 2010-01-16 00:32:38 +0000 | [diff] [blame] | 115 | O << ";\t.scl\t" << |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 116 | (F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT) |
| 117 | << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT) |
| 118 | << ";\t.endef\n"; |
| 119 | } |
| 120 | |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 121 | O << *CurrentFnSym << ':'; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 122 | if (VerboseAsm) { |
| 123 | O.PadToColumn(MAI->getCommentColumn()); |
| 124 | O << MAI->getCommentString() << ' '; |
| 125 | WriteAsOperand(O, F, /*PrintType=*/false, F->getParent()); |
| 126 | } |
| 127 | O << '\n'; |
| 128 | |
| 129 | // Add some workaround for linkonce linkage on Cygwin\MinGW |
| 130 | if (Subtarget->isTargetCygMing() && |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 131 | (F->hasLinkOnceLinkage() || F->hasWeakLinkage())) |
| 132 | O << "Lllvm$workaround$fake$stub$" << *CurrentFnSym << ":\n"; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /// runOnMachineFunction - This uses the printMachineInstruction() |
| 136 | /// method to print assembly for each instruction. |
| 137 | /// |
| 138 | bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) { |
| 139 | const Function *F = MF.getFunction(); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 140 | CallingConv::ID CC = F->getCallingConv(); |
| 141 | |
| 142 | SetupMachineFunction(MF); |
| 143 | O << "\n\n"; |
| 144 | |
| 145 | if (Subtarget->isTargetCOFF()) { |
| 146 | X86COFFMachineModuleInfo &COFFMMI = |
| 147 | MMI->getObjFileInfo<X86COFFMachineModuleInfo>(); |
| 148 | |
| 149 | // Populate function information map. Don't want to populate |
| 150 | // non-stdcall or non-fastcall functions' information right now. |
| 151 | if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall) |
| 152 | COFFMMI.AddFunctionInfo(F, *MF.getInfo<X86MachineFunctionInfo>()); |
| 153 | } |
| 154 | |
| 155 | // Print out constants referenced by the function |
| 156 | EmitConstantPool(MF.getConstantPool()); |
| 157 | |
| 158 | // Print the 'header' of function |
| 159 | emitFunctionHeader(MF); |
| 160 | |
| 161 | // Emit pre-function debug and/or EH information. |
| 162 | if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling()) |
| 163 | DW->BeginFunction(&MF); |
| 164 | |
| 165 | // Print out code for the function. |
| 166 | bool hasAnyRealCode = false; |
| 167 | for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); |
| 168 | I != E; ++I) { |
| 169 | // Print a label for the basic block. |
Dan Gohman | 5fda434 | 2009-10-06 17:38:38 +0000 | [diff] [blame] | 170 | EmitBasicBlockStart(I); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 171 | for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end(); |
| 172 | II != IE; ++II) { |
| 173 | // Print the assembly for the instruction. |
| 174 | if (!II->isLabel()) |
| 175 | hasAnyRealCode = true; |
| 176 | printMachineInstruction(II); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | if (Subtarget->isTargetDarwin() && !hasAnyRealCode) { |
| 181 | // If the function is empty, then we need to emit *something*. Otherwise, |
| 182 | // the function's label might be associated with something that it wasn't |
| 183 | // meant to be associated with. We emit a noop in this situation. |
| 184 | // We are assuming inline asms are code. |
| 185 | O << "\tnop\n"; |
| 186 | } |
| 187 | |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 188 | if (MAI->hasDotTypeDotSizeDirective()) |
| 189 | O << "\t.size\t" << *CurrentFnSym << ", .-" << *CurrentFnSym << '\n'; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 190 | |
| 191 | // Emit post-function debug information. |
| 192 | if (MAI->doesSupportDebugInformation() || MAI->doesSupportExceptionHandling()) |
| 193 | DW->EndFunction(&MF); |
| 194 | |
| 195 | // Print out jump tables referenced by the function. |
Chris Lattner | 1f8c892 | 2010-01-25 22:41:33 +0000 | [diff] [blame] | 196 | EmitJumpTableInfo(MF); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 197 | |
| 198 | // We didn't modify anything. |
| 199 | return false; |
| 200 | } |
| 201 | |
| 202 | /// printSymbolOperand - Print a raw symbol reference operand. This handles |
| 203 | /// jump tables, constant pools, global address and external symbols, all of |
| 204 | /// which print to a label with various suffixes for relocation types etc. |
| 205 | void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) { |
| 206 | switch (MO.getType()) { |
| 207 | default: llvm_unreachable("unknown symbol type!"); |
| 208 | case MachineOperand::MO_JumpTableIndex: |
Chris Lattner | 242edfc | 2010-01-23 05:26:25 +0000 | [diff] [blame] | 209 | O << *GetJTISymbol(MO.getIndex()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 210 | break; |
| 211 | case MachineOperand::MO_ConstantPoolIndex: |
Chris Lattner | 242edfc | 2010-01-23 05:26:25 +0000 | [diff] [blame] | 212 | O << *GetCPISymbol(MO.getIndex()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 213 | printOffset(MO.getOffset()); |
| 214 | break; |
| 215 | case MachineOperand::MO_GlobalAddress: { |
| 216 | const GlobalValue *GV = MO.getGlobal(); |
| 217 | |
Chris Lattner | b6ed586 | 2010-01-18 00:59:24 +0000 | [diff] [blame] | 218 | MCSymbol *GVSym; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 219 | if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) |
Chris Lattner | a6f2a10 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 220 | GVSym = GetSymbolWithGlobalValueBase(GV, "$stub"); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 221 | else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || |
| 222 | MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE || |
| 223 | MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE) |
Chris Lattner | a6f2a10 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 224 | GVSym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 225 | else |
| 226 | GVSym = GetGlobalValueSymbol(GV); |
| 227 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 228 | if (Subtarget->isTargetCygMing()) { |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 229 | X86COFFMachineModuleInfo &COFFMMI = |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 230 | MMI->getObjFileInfo<X86COFFMachineModuleInfo>(); |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 231 | COFFMMI.DecorateCygMingName(GVSym, OutContext, GV, *TM.getTargetData()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Handle dllimport linkage. |
| 235 | if (MO.getTargetFlags() == X86II::MO_DLLIMPORT) |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 236 | GVSym = OutContext.GetOrCreateSymbol(Twine("__imp_") + GVSym->getName()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 237 | |
| 238 | if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || |
| 239 | MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) { |
Chris Lattner | a6f2a10 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 240 | MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 241 | |
| 242 | const MCSymbol *&StubSym = |
| 243 | MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym); |
Chris Lattner | 178a932 | 2010-01-16 01:00:27 +0000 | [diff] [blame] | 244 | if (StubSym == 0) |
| 245 | StubSym = GetGlobalValueSymbol(GV); |
| 246 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 247 | } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){ |
Chris Lattner | a6f2a10 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 248 | MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 249 | const MCSymbol *&StubSym = |
| 250 | MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym); |
Chris Lattner | 178a932 | 2010-01-16 01:00:27 +0000 | [diff] [blame] | 251 | if (StubSym == 0) |
| 252 | StubSym = GetGlobalValueSymbol(GV); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 253 | } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { |
Chris Lattner | a6f2a10 | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 254 | MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub"); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 255 | const MCSymbol *&StubSym = |
| 256 | MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); |
Chris Lattner | 178a932 | 2010-01-16 01:00:27 +0000 | [diff] [blame] | 257 | if (StubSym == 0) |
| 258 | StubSym = GetGlobalValueSymbol(GV); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // If the name begins with a dollar-sign, enclose it in parens. We do this |
| 262 | // to avoid having it look like an integer immediate to the assembler. |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 263 | if (GVSym->getName()[0] != '$') |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 264 | O << *GVSym; |
| 265 | else |
| 266 | O << '(' << *GVSym << ')'; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 267 | printOffset(MO.getOffset()); |
| 268 | break; |
| 269 | } |
| 270 | case MachineOperand::MO_ExternalSymbol: { |
Chris Lattner | f80743e | 2010-01-13 07:56:59 +0000 | [diff] [blame] | 271 | const MCSymbol *SymToPrint; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 272 | if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { |
Chris Lattner | 178a932 | 2010-01-16 01:00:27 +0000 | [diff] [blame] | 273 | SmallString<128> TempNameStr; |
| 274 | TempNameStr += StringRef(MO.getSymbolName()); |
| 275 | TempNameStr += StringRef("$stub"); |
| 276 | |
| 277 | const MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 278 | const MCSymbol *&StubSym = |
| 279 | MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); |
| 280 | if (StubSym == 0) { |
Chris Lattner | a38b287 | 2010-01-13 06:38:18 +0000 | [diff] [blame] | 281 | TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end()); |
| 282 | StubSym = OutContext.GetOrCreateSymbol(TempNameStr.str()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 283 | } |
Chris Lattner | f80743e | 2010-01-13 07:56:59 +0000 | [diff] [blame] | 284 | SymToPrint = StubSym; |
| 285 | } else { |
Chris Lattner | 178a932 | 2010-01-16 01:00:27 +0000 | [diff] [blame] | 286 | SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName()); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | // If the name begins with a dollar-sign, enclose it in parens. We do this |
| 290 | // to avoid having it look like an integer immediate to the assembler. |
Chris Lattner | f80743e | 2010-01-13 07:56:59 +0000 | [diff] [blame] | 291 | if (SymToPrint->getName()[0] != '$') |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 292 | O << *SymToPrint; |
| 293 | else |
| 294 | O << '(' << *SymToPrint << '('; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 295 | break; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | switch (MO.getTargetFlags()) { |
| 300 | default: |
| 301 | llvm_unreachable("Unknown target flag on GV operand"); |
| 302 | case X86II::MO_NO_FLAG: // No flag. |
| 303 | break; |
| 304 | case X86II::MO_DARWIN_NONLAZY: |
| 305 | case X86II::MO_DLLIMPORT: |
| 306 | case X86II::MO_DARWIN_STUB: |
| 307 | // These affect the name of the symbol, not any suffix. |
| 308 | break; |
| 309 | case X86II::MO_GOT_ABSOLUTE_ADDRESS: |
| 310 | O << " + [.-"; |
| 311 | PrintPICBaseSymbol(); |
| 312 | O << ']'; |
| 313 | break; |
| 314 | case X86II::MO_PIC_BASE_OFFSET: |
| 315 | case X86II::MO_DARWIN_NONLAZY_PIC_BASE: |
| 316 | case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: |
| 317 | O << '-'; |
| 318 | PrintPICBaseSymbol(); |
| 319 | break; |
| 320 | case X86II::MO_TLSGD: O << "@TLSGD"; break; |
| 321 | case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break; |
| 322 | case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break; |
| 323 | case X86II::MO_TPOFF: O << "@TPOFF"; break; |
| 324 | case X86II::MO_NTPOFF: O << "@NTPOFF"; break; |
| 325 | case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break; |
| 326 | case X86II::MO_GOT: O << "@GOT"; break; |
| 327 | case X86II::MO_GOTOFF: O << "@GOTOFF"; break; |
| 328 | case X86II::MO_PLT: O << "@PLT"; break; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /// print_pcrel_imm - This is used to print an immediate value that ends up |
| 333 | /// being encoded as a pc-relative value. These print slightly differently, for |
| 334 | /// example, a $ is not emitted. |
| 335 | void X86AsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) { |
| 336 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 337 | switch (MO.getType()) { |
| 338 | default: llvm_unreachable("Unknown pcrel immediate operand"); |
| 339 | case MachineOperand::MO_Immediate: |
| 340 | O << MO.getImm(); |
| 341 | return; |
| 342 | case MachineOperand::MO_MachineBasicBlock: |
Chris Lattner | 84d5ca9 | 2010-01-26 04:55:51 +0000 | [diff] [blame] | 343 | O << *MO.getMBB()->getSymbol(OutContext); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 344 | return; |
| 345 | case MachineOperand::MO_GlobalAddress: |
| 346 | case MachineOperand::MO_ExternalSymbol: |
| 347 | printSymbolOperand(MO); |
| 348 | return; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
| 353 | void X86AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo, |
Chris Lattner | b6ed586 | 2010-01-18 00:59:24 +0000 | [diff] [blame] | 354 | const char *Modifier) { |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 355 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 356 | switch (MO.getType()) { |
| 357 | default: llvm_unreachable("unknown operand type!"); |
| 358 | case MachineOperand::MO_Register: { |
| 359 | O << '%'; |
| 360 | unsigned Reg = MO.getReg(); |
| 361 | if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) { |
| 362 | EVT VT = (strcmp(Modifier+6,"64") == 0) ? |
| 363 | MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 : |
| 364 | ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8)); |
| 365 | Reg = getX86SubSuperRegister(Reg, VT); |
| 366 | } |
| 367 | O << X86ATTInstPrinter::getRegisterName(Reg); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | case MachineOperand::MO_Immediate: |
| 372 | O << '$' << MO.getImm(); |
| 373 | return; |
| 374 | |
| 375 | case MachineOperand::MO_JumpTableIndex: |
| 376 | case MachineOperand::MO_ConstantPoolIndex: |
| 377 | case MachineOperand::MO_GlobalAddress: |
| 378 | case MachineOperand::MO_ExternalSymbol: { |
| 379 | O << '$'; |
| 380 | printSymbolOperand(MO); |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | void X86AsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) { |
| 387 | unsigned char value = MI->getOperand(Op).getImm(); |
| 388 | assert(value <= 7 && "Invalid ssecc argument!"); |
| 389 | switch (value) { |
| 390 | case 0: O << "eq"; break; |
| 391 | case 1: O << "lt"; break; |
| 392 | case 2: O << "le"; break; |
| 393 | case 3: O << "unord"; break; |
| 394 | case 4: O << "neq"; break; |
| 395 | case 5: O << "nlt"; break; |
| 396 | case 6: O << "nle"; break; |
| 397 | case 7: O << "ord"; break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | void X86AsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op, |
| 402 | const char *Modifier) { |
| 403 | const MachineOperand &BaseReg = MI->getOperand(Op); |
| 404 | const MachineOperand &IndexReg = MI->getOperand(Op+2); |
| 405 | const MachineOperand &DispSpec = MI->getOperand(Op+3); |
| 406 | |
| 407 | // If we really don't want to print out (rip), don't. |
| 408 | bool HasBaseReg = BaseReg.getReg() != 0; |
| 409 | if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") && |
| 410 | BaseReg.getReg() == X86::RIP) |
| 411 | HasBaseReg = false; |
| 412 | |
| 413 | // HasParenPart - True if we will print out the () part of the mem ref. |
| 414 | bool HasParenPart = IndexReg.getReg() || HasBaseReg; |
| 415 | |
| 416 | if (DispSpec.isImm()) { |
| 417 | int DispVal = DispSpec.getImm(); |
| 418 | if (DispVal || !HasParenPart) |
| 419 | O << DispVal; |
| 420 | } else { |
| 421 | assert(DispSpec.isGlobal() || DispSpec.isCPI() || |
| 422 | DispSpec.isJTI() || DispSpec.isSymbol()); |
| 423 | printSymbolOperand(MI->getOperand(Op+3)); |
| 424 | } |
| 425 | |
| 426 | if (HasParenPart) { |
| 427 | assert(IndexReg.getReg() != X86::ESP && |
| 428 | "X86 doesn't allow scaling by ESP"); |
| 429 | |
| 430 | O << '('; |
| 431 | if (HasBaseReg) |
| 432 | printOperand(MI, Op, Modifier); |
| 433 | |
| 434 | if (IndexReg.getReg()) { |
| 435 | O << ','; |
| 436 | printOperand(MI, Op+2, Modifier); |
| 437 | unsigned ScaleVal = MI->getOperand(Op+1).getImm(); |
| 438 | if (ScaleVal != 1) |
| 439 | O << ',' << ScaleVal; |
| 440 | } |
| 441 | O << ')'; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | void X86AsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op, |
| 446 | const char *Modifier) { |
| 447 | assert(isMem(MI, Op) && "Invalid memory reference!"); |
| 448 | const MachineOperand &Segment = MI->getOperand(Op+4); |
| 449 | if (Segment.getReg()) { |
| 450 | printOperand(MI, Op+4, Modifier); |
| 451 | O << ':'; |
| 452 | } |
| 453 | printLeaMemReference(MI, Op, Modifier); |
| 454 | } |
| 455 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 456 | void X86AsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) { |
| 457 | PrintPICBaseSymbol(); |
| 458 | O << '\n'; |
| 459 | PrintPICBaseSymbol(); |
| 460 | O << ':'; |
| 461 | } |
| 462 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 463 | bool X86AsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode) { |
| 464 | unsigned Reg = MO.getReg(); |
| 465 | switch (Mode) { |
| 466 | default: return true; // Unknown mode. |
| 467 | case 'b': // Print QImode register |
| 468 | Reg = getX86SubSuperRegister(Reg, MVT::i8); |
| 469 | break; |
| 470 | case 'h': // Print QImode high register |
| 471 | Reg = getX86SubSuperRegister(Reg, MVT::i8, true); |
| 472 | break; |
| 473 | case 'w': // Print HImode register |
| 474 | Reg = getX86SubSuperRegister(Reg, MVT::i16); |
| 475 | break; |
| 476 | case 'k': // Print SImode register |
| 477 | Reg = getX86SubSuperRegister(Reg, MVT::i32); |
| 478 | break; |
| 479 | case 'q': // Print DImode register |
| 480 | Reg = getX86SubSuperRegister(Reg, MVT::i64); |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | O << '%' << X86ATTInstPrinter::getRegisterName(Reg); |
| 485 | return false; |
| 486 | } |
| 487 | |
| 488 | /// PrintAsmOperand - Print out an operand for an inline asm expression. |
| 489 | /// |
| 490 | bool X86AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 491 | unsigned AsmVariant, |
| 492 | const char *ExtraCode) { |
| 493 | // Does this asm operand have a single letter operand modifier? |
| 494 | if (ExtraCode && ExtraCode[0]) { |
| 495 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
| 496 | |
| 497 | const MachineOperand &MO = MI->getOperand(OpNo); |
| 498 | |
| 499 | switch (ExtraCode[0]) { |
| 500 | default: return true; // Unknown modifier. |
| 501 | case 'a': // This is an address. Currently only 'i' and 'r' are expected. |
| 502 | if (MO.isImm()) { |
| 503 | O << MO.getImm(); |
| 504 | return false; |
| 505 | } |
| 506 | if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) { |
| 507 | printSymbolOperand(MO); |
| 508 | return false; |
| 509 | } |
| 510 | if (MO.isReg()) { |
| 511 | O << '('; |
| 512 | printOperand(MI, OpNo); |
| 513 | O << ')'; |
| 514 | return false; |
| 515 | } |
| 516 | return true; |
| 517 | |
| 518 | case 'c': // Don't print "$" before a global var name or constant. |
| 519 | if (MO.isImm()) |
| 520 | O << MO.getImm(); |
| 521 | else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol()) |
| 522 | printSymbolOperand(MO); |
| 523 | else |
| 524 | printOperand(MI, OpNo); |
| 525 | return false; |
| 526 | |
| 527 | case 'A': // Print '*' before a register (it must be a register) |
| 528 | if (MO.isReg()) { |
| 529 | O << '*'; |
| 530 | printOperand(MI, OpNo); |
| 531 | return false; |
| 532 | } |
| 533 | return true; |
| 534 | |
| 535 | case 'b': // Print QImode register |
| 536 | case 'h': // Print QImode high register |
| 537 | case 'w': // Print HImode register |
| 538 | case 'k': // Print SImode register |
| 539 | case 'q': // Print DImode register |
| 540 | if (MO.isReg()) |
| 541 | return printAsmMRegister(MO, ExtraCode[0]); |
| 542 | printOperand(MI, OpNo); |
| 543 | return false; |
| 544 | |
| 545 | case 'P': // This is the operand of a call, treat specially. |
| 546 | print_pcrel_imm(MI, OpNo); |
| 547 | return false; |
| 548 | |
| 549 | case 'n': // Negate the immediate or print a '-' before the operand. |
| 550 | // Note: this is a temporary solution. It should be handled target |
| 551 | // independently as part of the 'MC' work. |
| 552 | if (MO.isImm()) { |
| 553 | O << -MO.getImm(); |
| 554 | return false; |
| 555 | } |
| 556 | O << '-'; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | printOperand(MI, OpNo); |
| 561 | return false; |
| 562 | } |
| 563 | |
| 564 | bool X86AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
| 565 | unsigned OpNo, unsigned AsmVariant, |
| 566 | const char *ExtraCode) { |
| 567 | if (ExtraCode && ExtraCode[0]) { |
| 568 | if (ExtraCode[1] != 0) return true; // Unknown modifier. |
| 569 | |
| 570 | switch (ExtraCode[0]) { |
| 571 | default: return true; // Unknown modifier. |
| 572 | case 'b': // Print QImode register |
| 573 | case 'h': // Print QImode high register |
| 574 | case 'w': // Print HImode register |
| 575 | case 'k': // Print SImode register |
| 576 | case 'q': // Print SImode register |
| 577 | // These only apply to registers, ignore on mem. |
| 578 | break; |
| 579 | case 'P': // Don't print @PLT, but do print as memory. |
| 580 | printMemReference(MI, OpNo, "no-rip"); |
| 581 | return false; |
| 582 | } |
| 583 | } |
| 584 | printMemReference(MI, OpNo); |
| 585 | return false; |
| 586 | } |
| 587 | |
| 588 | |
| 589 | |
| 590 | /// printMachineInstruction -- Print out a single X86 LLVM instruction MI in |
| 591 | /// AT&T syntax to the current output stream. |
| 592 | /// |
| 593 | void X86AsmPrinter::printMachineInstruction(const MachineInstr *MI) { |
| 594 | ++EmittedInsts; |
| 595 | |
Devang Patel | 5450fc1 | 2009-10-06 02:19:11 +0000 | [diff] [blame] | 596 | processDebugLoc(MI, true); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 597 | |
| 598 | printInstructionThroughMCStreamer(MI); |
| 599 | |
David Greene | ca9b04b | 2009-11-13 21:34:57 +0000 | [diff] [blame] | 600 | if (VerboseAsm) |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 601 | EmitComments(*MI); |
| 602 | O << '\n'; |
Devang Patel | 5450fc1 | 2009-10-06 02:19:11 +0000 | [diff] [blame] | 603 | |
| 604 | processDebugLoc(MI, false); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 605 | } |
| 606 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 607 | void X86AsmPrinter::EmitEndOfAsmFile(Module &M) { |
| 608 | if (Subtarget->isTargetDarwin()) { |
| 609 | // All darwin targets use mach-o. |
| 610 | TargetLoweringObjectFileMachO &TLOFMacho = |
| 611 | static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering()); |
| 612 | |
| 613 | MachineModuleInfoMachO &MMIMacho = |
| 614 | MMI->getObjFileInfo<MachineModuleInfoMachO>(); |
| 615 | |
| 616 | // Output stubs for dynamically-linked functions. |
| 617 | MachineModuleInfoMachO::SymbolListTy Stubs; |
| 618 | |
| 619 | Stubs = MMIMacho.GetFnStubList(); |
| 620 | if (!Stubs.empty()) { |
| 621 | const MCSection *TheSection = |
| 622 | TLOFMacho.getMachOSection("__IMPORT", "__jump_table", |
| 623 | MCSectionMachO::S_SYMBOL_STUBS | |
| 624 | MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE | |
| 625 | MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS, |
| 626 | 5, SectionKind::getMetadata()); |
| 627 | OutStreamer.SwitchSection(TheSection); |
| 628 | |
| 629 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 630 | O << *Stubs[i].first << ":\n"; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 631 | // Get the MCSymbol without the $stub suffix. |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 632 | O << "\t.indirect_symbol " << *Stubs[i].second; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 633 | O << "\n\thlt ; hlt ; hlt ; hlt ; hlt\n"; |
| 634 | } |
| 635 | O << '\n'; |
| 636 | |
| 637 | Stubs.clear(); |
| 638 | } |
| 639 | |
| 640 | // Output stubs for external and common global variables. |
| 641 | Stubs = MMIMacho.GetGVStubList(); |
| 642 | if (!Stubs.empty()) { |
| 643 | const MCSection *TheSection = |
| 644 | TLOFMacho.getMachOSection("__IMPORT", "__pointers", |
| 645 | MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS, |
| 646 | SectionKind::getMetadata()); |
| 647 | OutStreamer.SwitchSection(TheSection); |
| 648 | |
| 649 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 650 | O << *Stubs[i].first << ":\n\t.indirect_symbol " << *Stubs[i].second; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 651 | O << "\n\t.long\t0\n"; |
| 652 | } |
| 653 | Stubs.clear(); |
| 654 | } |
| 655 | |
| 656 | Stubs = MMIMacho.GetHiddenGVStubList(); |
| 657 | if (!Stubs.empty()) { |
| 658 | OutStreamer.SwitchSection(getObjFileLowering().getDataSection()); |
| 659 | EmitAlignment(2); |
| 660 | |
| 661 | for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 662 | O << *Stubs[i].first << ":\n" << MAI->getData32bitsDirective(); |
| 663 | O << *Stubs[i].second << '\n'; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 664 | } |
| 665 | Stubs.clear(); |
| 666 | } |
| 667 | |
| 668 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 669 | // contain code that falls through to other global symbols (e.g. the obvious |
| 670 | // implementation of multiple entry points). If this doesn't occur, the |
| 671 | // linker can safely perform dead code stripping. Since LLVM never |
| 672 | // generates code that does this, it is always safe to set. |
Chris Lattner | 2d7c814 | 2010-01-23 06:39:22 +0000 | [diff] [blame] | 673 | OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols); |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 674 | } |
| 675 | |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 676 | if (Subtarget->isTargetCOFF()) { |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 677 | X86COFFMachineModuleInfo &COFFMMI = |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 678 | MMI->getObjFileInfo<X86COFFMachineModuleInfo>(); |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 679 | |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 680 | // Emit type information for external functions |
| 681 | for (X86COFFMachineModuleInfo::stub_iterator I = COFFMMI.stub_begin(), |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 682 | E = COFFMMI.stub_end(); I != E; ++I) { |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 683 | O << "\t.def\t " << I->getKeyData() |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 684 | << ";\t.scl\t" << COFF::C_EXT |
| 685 | << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT) |
| 686 | << ";\t.endef\n"; |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 687 | } |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 688 | |
| 689 | if (Subtarget->isTargetCygMing()) { |
| 690 | // Necessary for dllexport support |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 691 | std::vector<const MCSymbol*> DLLExportedFns, DLLExportedGlobals; |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 692 | |
| 693 | TargetLoweringObjectFileCOFF &TLOFCOFF = |
| 694 | static_cast<TargetLoweringObjectFileCOFF&>(getObjFileLowering()); |
| 695 | |
| 696 | for (Module::const_iterator I = M.begin(), E = M.end(); I != E; ++I) |
| 697 | if (I->hasDLLExportLinkage()) { |
Chris Lattner | b6ed586 | 2010-01-18 00:59:24 +0000 | [diff] [blame] | 698 | MCSymbol *Sym = GetGlobalValueSymbol(I); |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 699 | COFFMMI.DecorateCygMingName(Sym, OutContext, I, *TM.getTargetData()); |
| 700 | DLLExportedFns.push_back(Sym); |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | for (Module::const_global_iterator I = M.global_begin(), |
| 704 | E = M.global_end(); I != E; ++I) |
Chris Lattner | c53c24c | 2010-01-16 00:51:39 +0000 | [diff] [blame] | 705 | if (I->hasDLLExportLinkage()) |
| 706 | DLLExportedGlobals.push_back(GetGlobalValueSymbol(I)); |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 707 | |
| 708 | // Output linker support code for dllexported globals on windows. |
| 709 | if (!DLLExportedGlobals.empty() || !DLLExportedFns.empty()) { |
| 710 | OutStreamer.SwitchSection(TLOFCOFF.getCOFFSection(".section .drectve", |
| 711 | true, |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 712 | SectionKind::getMetadata())); |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 713 | for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) |
| 714 | O << "\t.ascii \" -export:" << *DLLExportedGlobals[i] << ",data\"\n"; |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 715 | |
Chris Lattner | ce40984 | 2010-01-17 21:43:43 +0000 | [diff] [blame] | 716 | for (unsigned i = 0, e = DLLExportedFns.size(); i != e; ++i) |
| 717 | O << "\t.ascii \" -export:" << *DLLExportedFns[i] << "\"\n"; |
Anton Korobeynikov | d5fcb1d | 2009-10-15 22:36:18 +0000 | [diff] [blame] | 718 | } |
Chris Lattner | bf4b6a8 | 2009-09-20 07:41:30 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | |
| 724 | //===----------------------------------------------------------------------===// |
| 725 | // Target Registry Stuff |
| 726 | //===----------------------------------------------------------------------===// |
| 727 | |
| 728 | static MCInstPrinter *createX86MCInstPrinter(const Target &T, |
| 729 | unsigned SyntaxVariant, |
| 730 | const MCAsmInfo &MAI, |
| 731 | raw_ostream &O) { |
| 732 | if (SyntaxVariant == 0) |
| 733 | return new X86ATTInstPrinter(O, MAI); |
| 734 | if (SyntaxVariant == 1) |
| 735 | return new X86IntelInstPrinter(O, MAI); |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | // Force static initialization. |
| 740 | extern "C" void LLVMInitializeX86AsmPrinter() { |
| 741 | RegisterAsmPrinter<X86AsmPrinter> X(TheX86_32Target); |
| 742 | RegisterAsmPrinter<X86AsmPrinter> Y(TheX86_64Target); |
| 743 | |
| 744 | TargetRegistry::RegisterMCInstPrinter(TheX86_32Target,createX86MCInstPrinter); |
| 745 | TargetRegistry::RegisterMCInstPrinter(TheX86_64Target,createX86MCInstPrinter); |
| 746 | } |