blob: 767ab23ce3bcec3b7af7c58306bd1c2e163591de [file] [log] [blame]
Chris Lattnerb36cbd02005-07-01 22:44:09 +00001//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
Misha Brukman0e0a7a452005-04-21 23:38:14 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman0e0a7a452005-04-21 23:38:14 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner72614082002-10-25 22:55:53 +00009//
Chris Lattnerb36cbd02005-07-01 22:44:09 +000010// This file the shared super class printer that converts from our internal
11// representation of machine-dependent LLVM code to Intel and AT&T format
12// assembly language.
13// This printer is the output mechanism used by `llc'.
Chris Lattner72614082002-10-25 22:55:53 +000014//
15//===----------------------------------------------------------------------===//
16
Evan Chengc4c62572006-03-13 23:20:37 +000017#include "X86AsmPrinter.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000018#include "X86ATTAsmPrinter.h"
Anton Korobeynikovd05ca652007-01-16 16:41:57 +000019#include "X86COFF.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000020#include "X86IntelAsmPrinter.h"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000021#include "X86MachineFunctionInfo.h"
Chris Lattnera35a8e82005-11-21 22:39:40 +000022#include "X86Subtarget.h"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000023#include "llvm/ADT/StringExtras.h"
24#include "llvm/CallingConv.h"
Chris Lattnera046e0d2005-12-13 04:53:51 +000025#include "llvm/Constants.h"
Chris Lattnerd59414f2003-08-11 20:06:16 +000026#include "llvm/Module.h"
Chris Lattnerc41cc832005-11-21 06:46:22 +000027#include "llvm/Type.h"
Chris Lattnerd59414f2003-08-11 20:06:16 +000028#include "llvm/Assembly/Writer.h"
Brian Gaeked9fb37a2003-07-24 20:20:44 +000029#include "llvm/Support/Mangler.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000030#include "llvm/Target/TargetAsmInfo.h"
Chris Lattner300d0ed2004-02-14 06:00:36 +000031using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000032
Chris Lattnere87e1152006-09-26 03:57:53 +000033static X86FunctionInfo calculateFunctionInfo(const Function *F,
34 const TargetData *TD) {
Anton Korobeynikovf8248682006-09-20 22:03:51 +000035 X86FunctionInfo Info;
Chris Lattnere87e1152006-09-26 03:57:53 +000036 uint64_t Size = 0;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000037
38 switch (F->getCallingConv()) {
Chris Lattnere87e1152006-09-26 03:57:53 +000039 case CallingConv::X86_StdCall:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000040 Info.setDecorationStyle(StdCall);
41 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000042 case CallingConv::X86_FastCall:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000043 Info.setDecorationStyle(FastCall);
44 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000045 default:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000046 return Info;
47 }
48
Chris Lattnere87e1152006-09-26 03:57:53 +000049 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
50 AI != AE; ++AI)
51 Size += TD->getTypeSize(AI->getType());
Anton Korobeynikovf8248682006-09-20 22:03:51 +000052
Anton Korobeynikov54b1cc62006-10-14 20:53:35 +000053 // Size should be aligned to DWORD boundary
54 Size = ((Size + 3)/4)*4;
55
Anton Korobeynikovf8248682006-09-20 22:03:51 +000056 // We're not supporting tooooo huge arguments :)
Chris Lattnere87e1152006-09-26 03:57:53 +000057 Info.setBytesToPopOnReturn((unsigned int)Size);
Anton Korobeynikovf8248682006-09-20 22:03:51 +000058 return Info;
59}
60
61
Chris Lattnere87e1152006-09-26 03:57:53 +000062/// decorateName - Query FunctionInfoMap and use this information for various
63/// name decoration.
64void X86SharedAsmPrinter::decorateName(std::string &Name,
65 const GlobalValue *GV) {
66 const Function *F = dyn_cast<Function>(GV);
67 if (!F) return;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000068
69 // We don't want to decorate non-stdcall or non-fastcall functions right now
Chris Lattnere87e1152006-09-26 03:57:53 +000070 unsigned CC = F->getCallingConv();
71 if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
Anton Korobeynikovf8248682006-09-20 22:03:51 +000072 return;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000073
74 FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
75
Chris Lattnere87e1152006-09-26 03:57:53 +000076 const X86FunctionInfo *Info;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000077 if (info_item == FunctionInfoMap.end()) {
78 // Calculate apropriate function info and populate map
79 FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
80 Info = &FunctionInfoMap[F];
81 } else {
Chris Lattnere87e1152006-09-26 03:57:53 +000082 Info = &info_item->second;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000083 }
84
85 switch (Info->getDecorationStyle()) {
Chris Lattnere87e1152006-09-26 03:57:53 +000086 case None:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000087 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000088 case StdCall:
89 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikovf8248682006-09-20 22:03:51 +000090 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Anton Korobeynikovf8248682006-09-20 22:03:51 +000091 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000092 case FastCall:
93 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikovf8248682006-09-20 22:03:51 +000094 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Chris Lattnere87e1152006-09-26 03:57:53 +000095
Anton Korobeynikovf8248682006-09-20 22:03:51 +000096 if (Name[0] == '_') {
97 Name[0] = '@';
98 } else {
99 Name = '@' + Name;
100 }
101 break;
Chris Lattnere87e1152006-09-26 03:57:53 +0000102 default:
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000103 assert(0 && "Unsupported DecorationStyle");
104 }
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000105}
106
Jim Laskey563321a2006-09-06 18:34:40 +0000107/// doInitialization
Evan Cheng25ab6902006-09-08 06:48:29 +0000108bool X86SharedAsmPrinter::doInitialization(Module &M) {
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000109 if (Subtarget->isTargetELF() ||
110 Subtarget->isTargetCygMing() ||
111 Subtarget->isTargetDarwin()) {
Reid Spencer02b85112006-10-30 22:32:30 +0000112 // Emit initial debug information.
113 DW.BeginModule(&M);
Evan Chengd5948812006-03-07 02:23:26 +0000114 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000115
Reid Spencer5dc81f62005-01-23 03:52:14 +0000116 return AsmPrinter::doInitialization(M);
117}
118
Chris Lattnerac5701c2004-10-04 07:24:48 +0000119bool X86SharedAsmPrinter::doFinalization(Module &M) {
Jeff Cohend43b18d2006-05-06 21:27:14 +0000120 // Note: this code is not shared by the Intel printer as it is too different
121 // from how MASM does things. When making changes here don't forget to look
122 // at X86IntelAsmPrinter::doFinalization().
Owen Andersona69571c2006-05-03 01:29:57 +0000123 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000124
Chris Lattnerac5701c2004-10-04 07:24:48 +0000125 // Print out module-level global variables here.
Evan Cheng2338c5c2006-02-07 08:38:37 +0000126 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
127 I != E; ++I) {
Rafael Espindola3e69a7e2006-12-09 23:14:08 +0000128 if (!I->hasInitializer())
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000129 continue; // External global require no code
Chris Lattner9787c642005-11-21 22:48:18 +0000130
Chris Lattnerd1239b72005-12-13 06:32:50 +0000131 // Check to see if this is a special global used by LLVM, if so, emit it.
Jim Laskey78098112006-03-07 22:00:35 +0000132 if (EmitSpecialLLVMGlobal(I))
Chris Lattnerd1239b72005-12-13 06:32:50 +0000133 continue;
Chris Lattnera046e0d2005-12-13 04:53:51 +0000134
Chris Lattner9787c642005-11-21 22:48:18 +0000135 std::string name = Mang->getValueName(I);
136 Constant *C = I->getInitializer();
Owen Andersona69571c2006-05-03 01:29:57 +0000137 unsigned Size = TD->getTypeSize(C->getType());
Devang Patelf9c197e2006-10-24 20:32:14 +0000138 unsigned Align = TD->getPreferredAlignmentLog(I);
Jeff Cohen00b168892005-07-27 06:12:32 +0000139
Evan Cheng2338c5c2006-02-07 08:38:37 +0000140 if (C->isNullValue() && /* FIXME: Verify correct */
Evan Cheng2e323aa2006-10-31 01:26:55 +0000141 !I->hasSection() &&
Evan Cheng2338c5c2006-02-07 08:38:37 +0000142 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
Evan Cheng17ef92e2006-02-15 01:56:23 +0000143 I->hasLinkOnceLinkage() ||
Jim Laskeyea348582006-07-27 02:05:13 +0000144 (Subtarget->isTargetDarwin() &&
Evan Cheng2e323aa2006-10-31 01:26:55 +0000145 I->hasExternalLinkage()))) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000146 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Evan Cheng17ef92e2006-02-15 01:56:23 +0000147 if (I->hasExternalLinkage()) {
Evan Chenga0ea0532006-02-23 02:43:52 +0000148 O << "\t.globl\t" << name << "\n";
Evan Cheng17ef92e2006-02-15 01:56:23 +0000149 O << "\t.zerofill __DATA__, __common, " << name << ", "
150 << Size << ", " << Align;
Evan Cheng2338c5c2006-02-07 08:38:37 +0000151 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000152 SwitchToDataSection(TAI->getDataSection(), I);
153 if (TAI->getLCOMMDirective() != NULL) {
Evan Cheng17ef92e2006-02-15 01:56:23 +0000154 if (I->hasInternalLinkage()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000155 O << TAI->getLCOMMDirective() << name << "," << Size;
Jim Laskeyea348582006-07-27 02:05:13 +0000156 if (Subtarget->isTargetDarwin())
Jim Laskey563321a2006-09-06 18:34:40 +0000157 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng17ef92e2006-02-15 01:56:23 +0000158 } else
Jim Laskey563321a2006-09-06 18:34:40 +0000159 O << TAI->getCOMMDirective() << name << "," << Size;
Evan Cheng17ef92e2006-02-15 01:56:23 +0000160 } else {
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000161 if (!Subtarget->isTargetCygMing()) {
Evan Cheng932ad512006-05-25 21:59:08 +0000162 if (I->hasInternalLinkage())
163 O << "\t.local\t" << name << "\n";
164 }
Jim Laskey563321a2006-09-06 18:34:40 +0000165 O << TAI->getCOMMDirective() << name << "," << Size;
166 if (TAI->getCOMMDirectiveTakesAlignment())
167 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng17ef92e2006-02-15 01:56:23 +0000168 }
Chris Lattnerb12c9fa2005-07-11 06:25:47 +0000169 }
Jim Laskey563321a2006-09-06 18:34:40 +0000170 O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000171 } else {
172 switch (I->getLinkage()) {
173 case GlobalValue::LinkOnceLinkage:
174 case GlobalValue::WeakLinkage:
Jim Laskeyea348582006-07-27 02:05:13 +0000175 if (Subtarget->isTargetDarwin()) {
Evan Cheng5ada3702006-02-07 23:32:58 +0000176 O << "\t.globl " << name << "\n"
177 << "\t.weak_definition " << name << "\n";
Evan Chengf8614db2006-06-04 07:24:07 +0000178 SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000179 } else if (Subtarget->isTargetCygMing()) {
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000180 std::string SectionName(".section\t.data$linkonce." +
181 name +
Evan Cheng2e323aa2006-10-31 01:26:55 +0000182 ",\"aw\"");
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000183 SwitchToDataSection(SectionName.c_str(), I);
184 O << "\t.globl " << name << "\n"
Anton Korobeynikovb1c88022006-10-18 09:12:29 +0000185 << "\t.linkonce same_size\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000186 } else {
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000187 std::string SectionName("\t.section\t.llvm.linkonce.d." +
188 name +
Evan Cheng2e323aa2006-10-31 01:26:55 +0000189 ",\"aw\",@progbits");
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000190 SwitchToDataSection(SectionName.c_str(), I);
191 O << "\t.weak " << name << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000192 }
193 break;
194 case GlobalValue::AppendingLinkage:
195 // FIXME: appending linkage variables should go into a section of
196 // their name or something. For now, just emit them as external.
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000197 case GlobalValue::DLLExportLinkage:
198 DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
199 // FALL THROUGH
Evan Cheng2338c5c2006-02-07 08:38:37 +0000200 case GlobalValue::ExternalLinkage:
201 // If external or appending, declare as a global symbol
202 O << "\t.globl " << name << "\n";
203 // FALL THROUGH
Evan Cheng8910c1c2006-10-26 19:18:18 +0000204 case GlobalValue::InternalLinkage: {
Evan Cheng71aae622006-10-28 05:56:06 +0000205 if (I->isConstant()) {
Evan Cheng8910c1c2006-10-26 19:18:18 +0000206 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
Evan Cheng71aae622006-10-28 05:56:06 +0000207 if (TAI->getCStringSection() && CVA && CVA->isCString()) {
Evan Cheng8910c1c2006-10-26 19:18:18 +0000208 SwitchToDataSection(TAI->getCStringSection(), I);
209 break;
210 }
211 }
Evan Cheng2e323aa2006-10-31 01:26:55 +0000212 // FIXME: special handling for ".ctors" & ".dtors" sections
213 if (I->hasSection() &&
214 (I->getSection() == ".ctors" ||
215 I->getSection() == ".dtors")) {
216 std::string SectionName = ".section " + I->getSection();
217
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000218 if (Subtarget->isTargetCygMing()) {
Evan Cheng2e323aa2006-10-31 01:26:55 +0000219 SectionName += ",\"aw\"";
220 } else {
221 assert(!Subtarget->isTargetDarwin());
222 SectionName += ",\"aw\",@progbits";
223 }
224
Anton Korobeynikovb52cf1f2006-10-31 06:11:06 +0000225 SwitchToDataSection(SectionName.c_str());
Evan Cheng2e323aa2006-10-31 01:26:55 +0000226 } else {
227 SwitchToDataSection(TAI->getDataSection(), I);
228 }
229
Evan Cheng2338c5c2006-02-07 08:38:37 +0000230 break;
Evan Cheng8910c1c2006-10-26 19:18:18 +0000231 }
Evan Cheng2338c5c2006-02-07 08:38:37 +0000232 default:
233 assert(0 && "Unknown linkage type!");
234 }
Chris Lattner9787c642005-11-21 22:48:18 +0000235
Evan Cheng2338c5c2006-02-07 08:38:37 +0000236 EmitAlignment(Align, I);
Jim Laskey563321a2006-09-06 18:34:40 +0000237 O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
Evan Cheng5ada3702006-02-07 23:32:58 +0000238 << "\n";
Jim Laskey563321a2006-09-06 18:34:40 +0000239 if (TAI->hasDotTypeDotSizeDirective())
Evan Cheng5ada3702006-02-07 23:32:58 +0000240 O << "\t.size " << name << ", " << Size << "\n";
Evan Cheng81cf60f2006-12-01 09:13:26 +0000241 // If the initializer is a extern weak symbol, remember to emit the weak
242 // reference!
243 if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
244 if (GV->hasExternalWeakLinkage())
Rafael Espindola15404d02006-12-18 03:37:18 +0000245 ExtWeakSymbols.insert(GV);
Evan Cheng81cf60f2006-12-01 09:13:26 +0000246
Evan Cheng2338c5c2006-02-07 08:38:37 +0000247 EmitGlobalConstant(C);
248 O << '\n';
Chris Lattner9787c642005-11-21 22:48:18 +0000249 }
Chris Lattner43bbc5c2007-01-14 06:29:53 +0000250 if (I->hasHiddenVisibility())
251 if (const char *Directive = TAI->getHiddenDirective())
252 O << Directive << name << "\n";
Anton Korobeynikovd05ca652007-01-16 16:41:57 +0000253
254 if (Subtarget->isTargetELF())
255 O << "\t.type " << name << ",@object\n";
Chris Lattnera35a8e82005-11-21 22:39:40 +0000256 }
257
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000258 // Output linker support code for dllexported globals
259 if (DLLExportedGVs.begin() != DLLExportedGVs.end()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000260 SwitchToDataSection(".section .drectve");
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000261 }
262
263 for (std::set<std::string>::iterator i = DLLExportedGVs.begin(),
264 e = DLLExportedGVs.end();
265 i != e; ++i) {
266 O << "\t.ascii \" -export:" << *i << ",data\"\n";
267 }
268
269 if (DLLExportedFns.begin() != DLLExportedFns.end()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000270 SwitchToDataSection(".section .drectve");
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000271 }
272
273 for (std::set<std::string>::iterator i = DLLExportedFns.begin(),
274 e = DLLExportedFns.end();
275 i != e; ++i) {
276 O << "\t.ascii \" -export:" << *i << "\"\n";
277 }
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000278
Jim Laskeyea348582006-07-27 02:05:13 +0000279 if (Subtarget->isTargetDarwin()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000280 SwitchToDataSection("");
Nate Begeman73213f62005-07-12 01:37:28 +0000281
Nate Begeman72b286b2005-07-08 00:23:26 +0000282 // Output stubs for dynamically-linked functions
283 unsigned j = 1;
284 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
Chris Lattnerb12c9fa2005-07-11 06:25:47 +0000285 i != e; ++i, ++j) {
Chris Lattner4632d7a2006-05-09 04:59:56 +0000286 SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs,"
287 "self_modifying_code+pure_instructions,5", 0);
Nate Begeman72b286b2005-07-08 00:23:26 +0000288 O << "L" << *i << "$stub:\n";
289 O << "\t.indirect_symbol " << *i << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000290 O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
Nate Begeman72b286b2005-07-08 00:23:26 +0000291 }
292
293 O << "\n";
Jeff Cohen00b168892005-07-27 06:12:32 +0000294
Evan Cheng2338c5c2006-02-07 08:38:37 +0000295 // Output stubs for external and common global variables.
296 if (GVStubs.begin() != GVStubs.end())
Chris Lattner4632d7a2006-05-09 04:59:56 +0000297 SwitchToDataSection(
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000298 ".section __IMPORT,__pointers,non_lazy_symbol_pointers");
Evan Cheng2338c5c2006-02-07 08:38:37 +0000299 for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
300 i != e; ++i) {
301 O << "L" << *i << "$non_lazy_ptr:\n";
302 O << "\t.indirect_symbol " << *i << "\n";
303 O << "\t.long\t0\n";
Nate Begeman72b286b2005-07-08 00:23:26 +0000304 }
Chris Lattnerac5701c2004-10-04 07:24:48 +0000305
Reid Spencer02b85112006-10-30 22:32:30 +0000306 // Emit final debug information.
Jim Laskey99db0442006-03-23 18:09:44 +0000307 DW.EndModule();
Evan Chengd5948812006-03-07 02:23:26 +0000308
309 // Funny Darwin hack: This flag tells the linker that no global symbols
310 // contain code that falls through to other global symbols (e.g. the obvious
311 // implementation of multiple entry points). If this doesn't occur, the
Jim Laskey99db0442006-03-23 18:09:44 +0000312 // linker can safely perform dead code stripping. Since LLVM never
313 // generates code that does this, it is always safe to set.
Evan Chengd5948812006-03-07 02:23:26 +0000314 O << "\t.subsections_via_symbols\n";
Anton Korobeynikovd05ca652007-01-16 16:41:57 +0000315 } else if (Subtarget->isTargetCygMing()) {
316 // Emit type information for external functions
317 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
318 i != e; ++i) {
319 O << "\t.def\t " << *i
320 << ";\t.scl\t" << COFF::C_EXT
321 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
322 << ";\t.endef\n";
323 }
324
325 // Emit final debug information.
326 DW.EndModule();
327 } else if (Subtarget->isTargetELF()) {
Reid Spencer02b85112006-10-30 22:32:30 +0000328 // Emit final debug information.
329 DW.EndModule();
Evan Chengd5948812006-03-07 02:23:26 +0000330 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000331
Chris Lattnerac5701c2004-10-04 07:24:48 +0000332 AsmPrinter::doFinalization(M);
333 return false; // success
334}
335
Chris Lattnerac5701c2004-10-04 07:24:48 +0000336/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
337/// for a MachineFunction to the given output stream, using the given target
338/// machine description.
339///
Evan Chengc4c62572006-03-13 23:20:37 +0000340FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
Jim Laskey563321a2006-09-06 18:34:40 +0000341 X86TargetMachine &tm) {
Jim Laskey05a059d2006-09-07 12:23:47 +0000342 const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>();
Jim Laskey563321a2006-09-06 18:34:40 +0000343
Jim Laskey05a059d2006-09-07 12:23:47 +0000344 if (Subtarget->isFlavorIntel()) {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000345 return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo());
Jim Laskey05a059d2006-09-07 12:23:47 +0000346 } else {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000347 return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo());
Chris Lattnerac5701c2004-10-04 07:24:48 +0000348 }
Brian Gaeke9e474c42003-06-19 19:32:32 +0000349}