blob: 81ec50e345ea28b92371fb38bd8ab00abf23fd5c [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"
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +000031#include "llvm/Target/TargetOptions.h"
Chris Lattner300d0ed2004-02-14 06:00:36 +000032using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000033
Chris Lattnere87e1152006-09-26 03:57:53 +000034static X86FunctionInfo calculateFunctionInfo(const Function *F,
35 const TargetData *TD) {
Anton Korobeynikovf8248682006-09-20 22:03:51 +000036 X86FunctionInfo Info;
Chris Lattnere87e1152006-09-26 03:57:53 +000037 uint64_t Size = 0;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000038
39 switch (F->getCallingConv()) {
Chris Lattnere87e1152006-09-26 03:57:53 +000040 case CallingConv::X86_StdCall:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000041 Info.setDecorationStyle(StdCall);
42 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000043 case CallingConv::X86_FastCall:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000044 Info.setDecorationStyle(FastCall);
45 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000046 default:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000047 return Info;
48 }
49
Chris Lattnere87e1152006-09-26 03:57:53 +000050 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
51 AI != AE; ++AI)
Anton Korobeynikov9dd9abd2007-03-01 16:29:22 +000052 // Size should be aligned to DWORD boundary
53 Size += ((TD->getTypeSize(AI->getType()) + 3)/4)*4;
Anton Korobeynikov54b1cc62006-10-14 20:53:35 +000054
Anton Korobeynikovf8248682006-09-20 22:03:51 +000055 // We're not supporting tooooo huge arguments :)
Chris Lattnere87e1152006-09-26 03:57:53 +000056 Info.setBytesToPopOnReturn((unsigned int)Size);
Anton Korobeynikovf8248682006-09-20 22:03:51 +000057 return Info;
58}
59
60
Chris Lattnere87e1152006-09-26 03:57:53 +000061/// decorateName - Query FunctionInfoMap and use this information for various
62/// name decoration.
63void X86SharedAsmPrinter::decorateName(std::string &Name,
64 const GlobalValue *GV) {
65 const Function *F = dyn_cast<Function>(GV);
66 if (!F) return;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000067
68 // We don't want to decorate non-stdcall or non-fastcall functions right now
Chris Lattnere87e1152006-09-26 03:57:53 +000069 unsigned CC = F->getCallingConv();
70 if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
Anton Korobeynikovf8248682006-09-20 22:03:51 +000071 return;
Anton Korobeynikovb10308e2007-01-28 13:31:35 +000072
73 // Decorate names only when we're targeting Cygwin/Mingw32 targets
74 if (!Subtarget->isTargetCygMing())
75 return;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000076
77 FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
78
Chris Lattnere87e1152006-09-26 03:57:53 +000079 const X86FunctionInfo *Info;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000080 if (info_item == FunctionInfoMap.end()) {
81 // Calculate apropriate function info and populate map
82 FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
83 Info = &FunctionInfoMap[F];
84 } else {
Chris Lattnere87e1152006-09-26 03:57:53 +000085 Info = &info_item->second;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000086 }
87
88 switch (Info->getDecorationStyle()) {
Chris Lattnere87e1152006-09-26 03:57:53 +000089 case None:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000090 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000091 case StdCall:
92 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikovf8248682006-09-20 22:03:51 +000093 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Anton Korobeynikovf8248682006-09-20 22:03:51 +000094 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000095 case FastCall:
96 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikovf8248682006-09-20 22:03:51 +000097 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Chris Lattnere87e1152006-09-26 03:57:53 +000098
Anton Korobeynikovf8248682006-09-20 22:03:51 +000099 if (Name[0] == '_') {
100 Name[0] = '@';
101 } else {
102 Name = '@' + Name;
103 }
104 break;
Chris Lattnere87e1152006-09-26 03:57:53 +0000105 default:
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000106 assert(0 && "Unsupported DecorationStyle");
107 }
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000108}
109
Jim Laskey563321a2006-09-06 18:34:40 +0000110/// doInitialization
Evan Cheng25ab6902006-09-08 06:48:29 +0000111bool X86SharedAsmPrinter::doInitialization(Module &M) {
Anton Korobeynikov7f705592007-01-12 19:20:47 +0000112 if (Subtarget->isTargetELF() ||
113 Subtarget->isTargetCygMing() ||
114 Subtarget->isTargetDarwin()) {
Reid Spencer02b85112006-10-30 22:32:30 +0000115 // Emit initial debug information.
116 DW.BeginModule(&M);
Evan Chengd5948812006-03-07 02:23:26 +0000117 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000118
Reid Spencer5dc81f62005-01-23 03:52:14 +0000119 return AsmPrinter::doInitialization(M);
120}
121
Chris Lattnerac5701c2004-10-04 07:24:48 +0000122bool X86SharedAsmPrinter::doFinalization(Module &M) {
Jeff Cohend43b18d2006-05-06 21:27:14 +0000123 // Note: this code is not shared by the Intel printer as it is too different
124 // from how MASM does things. When making changes here don't forget to look
125 // at X86IntelAsmPrinter::doFinalization().
Owen Andersona69571c2006-05-03 01:29:57 +0000126 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000127
Chris Lattnerac5701c2004-10-04 07:24:48 +0000128 // Print out module-level global variables here.
Evan Cheng2338c5c2006-02-07 08:38:37 +0000129 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
130 I != E; ++I) {
Rafael Espindola3e69a7e2006-12-09 23:14:08 +0000131 if (!I->hasInitializer())
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000132 continue; // External global require no code
Chris Lattner9787c642005-11-21 22:48:18 +0000133
Chris Lattnerd1239b72005-12-13 06:32:50 +0000134 // Check to see if this is a special global used by LLVM, if so, emit it.
Evan Chengb267ca12007-01-30 08:04:53 +0000135 if (EmitSpecialLLVMGlobal(I)) {
136 if (Subtarget->isTargetDarwin() &&
137 TM.getRelocationModel() == Reloc::Static) {
138 if (I->getName() == "llvm.global_ctors")
139 O << ".reference .constructors_used\n";
140 else if (I->getName() == "llvm.global_dtors")
141 O << ".reference .destructors_used\n";
142 }
Chris Lattnerd1239b72005-12-13 06:32:50 +0000143 continue;
Evan Chengb267ca12007-01-30 08:04:53 +0000144 }
Chris Lattnera046e0d2005-12-13 04:53:51 +0000145
Chris Lattner9787c642005-11-21 22:48:18 +0000146 std::string name = Mang->getValueName(I);
147 Constant *C = I->getInitializer();
Evan Chengf0b5d562007-03-08 01:07:07 +0000148 const Type *Type = C->getType();
149 unsigned Size = TD->getTypeSize(Type);
Devang Patelf9c197e2006-10-24 20:32:14 +0000150 unsigned Align = TD->getPreferredAlignmentLog(I);
Jeff Cohen00b168892005-07-27 06:12:32 +0000151
Chris Lattner8e13e902007-01-17 17:44:25 +0000152 if (I->hasHiddenVisibility())
153 if (const char *Directive = TAI->getHiddenDirective())
154 O << Directive << name << "\n";
155 if (Subtarget->isTargetELF())
156 O << "\t.type " << name << ",@object\n";
157
158 if (C->isNullValue()) {
Evan Cheng17ef92e2006-02-15 01:56:23 +0000159 if (I->hasExternalLinkage()) {
Chris Lattner8e13e902007-01-17 17:44:25 +0000160 if (const char *Directive = TAI->getZeroFillDirective()) {
Evan Chenga0ea0532006-02-23 02:43:52 +0000161 O << "\t.globl\t" << name << "\n";
Chris Lattner8e13e902007-01-17 17:44:25 +0000162 O << Directive << "__DATA__, __common, " << name << ", "
Bill Wendling39e9c092007-01-18 02:30:19 +0000163 << Size << ", " << Align << "\n";
Chris Lattner8e13e902007-01-17 17:44:25 +0000164 continue;
165 }
166 }
167
168 if (!I->hasSection() &&
169 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
170 I->hasLinkOnceLinkage())) {
171 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Anton Korobeynikov5032e5a2007-01-17 10:33:08 +0000172 if (!NoZerosInBSS && TAI->getBSSSection())
173 SwitchToDataSection(TAI->getBSSSection(), I);
174 else
175 SwitchToDataSection(TAI->getDataSection(), I);
Jim Laskey563321a2006-09-06 18:34:40 +0000176 if (TAI->getLCOMMDirective() != NULL) {
Evan Cheng17ef92e2006-02-15 01:56:23 +0000177 if (I->hasInternalLinkage()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000178 O << TAI->getLCOMMDirective() << name << "," << Size;
Jim Laskeyea348582006-07-27 02:05:13 +0000179 if (Subtarget->isTargetDarwin())
Evan Cheng071b9d52007-01-18 01:49:58 +0000180 O << "," << Align;
Evan Cheng17ef92e2006-02-15 01:56:23 +0000181 } else
Jim Laskey563321a2006-09-06 18:34:40 +0000182 O << TAI->getCOMMDirective() << name << "," << Size;
Evan Cheng17ef92e2006-02-15 01:56:23 +0000183 } else {
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000184 if (!Subtarget->isTargetCygMing()) {
Evan Cheng932ad512006-05-25 21:59:08 +0000185 if (I->hasInternalLinkage())
186 O << "\t.local\t" << name << "\n";
187 }
Jim Laskey563321a2006-09-06 18:34:40 +0000188 O << TAI->getCOMMDirective() << name << "," << Size;
189 if (TAI->getCOMMDirectiveTakesAlignment())
190 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng17ef92e2006-02-15 01:56:23 +0000191 }
Chris Lattner8e13e902007-01-17 17:44:25 +0000192 O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
193 continue;
Chris Lattnerb12c9fa2005-07-11 06:25:47 +0000194 }
Chris Lattner9787c642005-11-21 22:48:18 +0000195 }
Chris Lattner8e13e902007-01-17 17:44:25 +0000196
197 switch (I->getLinkage()) {
198 case GlobalValue::LinkOnceLinkage:
199 case GlobalValue::WeakLinkage:
200 if (Subtarget->isTargetDarwin()) {
201 O << "\t.globl " << name << "\n"
202 << "\t.weak_definition " << name << "\n";
203 SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
204 } else if (Subtarget->isTargetCygMing()) {
205 std::string SectionName(".section\t.data$linkonce." +
206 name +
207 ",\"aw\"");
208 SwitchToDataSection(SectionName.c_str(), I);
209 O << "\t.globl " << name << "\n"
210 << "\t.linkonce same_size\n";
211 } else {
212 std::string SectionName("\t.section\t.llvm.linkonce.d." +
213 name +
214 ",\"aw\",@progbits");
215 SwitchToDataSection(SectionName.c_str(), I);
216 O << "\t.weak " << name << "\n";
217 }
218 break;
219 case GlobalValue::AppendingLinkage:
220 // FIXME: appending linkage variables should go into a section of
221 // their name or something. For now, just emit them as external.
222 case GlobalValue::DLLExportLinkage:
223 DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
224 // FALL THROUGH
225 case GlobalValue::ExternalLinkage:
226 // If external or appending, declare as a global symbol
227 O << "\t.globl " << name << "\n";
228 // FALL THROUGH
229 case GlobalValue::InternalLinkage: {
230 if (I->isConstant()) {
231 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
232 if (TAI->getCStringSection() && CVA && CVA->isCString()) {
233 SwitchToDataSection(TAI->getCStringSection(), I);
234 break;
235 }
236 }
237 // FIXME: special handling for ".ctors" & ".dtors" sections
238 if (I->hasSection() &&
239 (I->getSection() == ".ctors" ||
240 I->getSection() == ".dtors")) {
241 std::string SectionName = ".section " + I->getSection();
242
243 if (Subtarget->isTargetCygMing()) {
244 SectionName += ",\"aw\"";
245 } else {
246 assert(!Subtarget->isTargetDarwin());
247 SectionName += ",\"aw\",@progbits";
248 }
249
250 SwitchToDataSection(SectionName.c_str());
251 } else {
252 if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
253 SwitchToDataSection(TAI->getBSSSection(), I);
Evan Chengf0b5d562007-03-08 01:07:07 +0000254 else if (!I->isConstant())
Chris Lattner8e13e902007-01-17 17:44:25 +0000255 SwitchToDataSection(TAI->getDataSection(), I);
Evan Chengf0b5d562007-03-08 01:07:07 +0000256 else {
257 // Read-only data.
Evan Cheng032953d2007-03-08 08:31:54 +0000258 bool HasReloc = C->ContainsRelocations();
259 if (HasReloc &&
260 Subtarget->isTargetDarwin() &&
Evan Chengf0b5d562007-03-08 01:07:07 +0000261 TM.getRelocationModel() != Reloc::Static)
262 SwitchToDataSection("\t.const_data\n");
Evan Cheng032953d2007-03-08 08:31:54 +0000263 else if (!HasReloc && Size == 4 &&
Evan Chengf0b5d562007-03-08 01:07:07 +0000264 TAI->getFourByteConstantSection())
265 SwitchToDataSection(TAI->getFourByteConstantSection(), I);
Evan Cheng032953d2007-03-08 08:31:54 +0000266 else if (!HasReloc && Size == 8 &&
Evan Chengf0b5d562007-03-08 01:07:07 +0000267 TAI->getEightByteConstantSection())
268 SwitchToDataSection(TAI->getEightByteConstantSection(), I);
Evan Cheng032953d2007-03-08 08:31:54 +0000269 else if (!HasReloc && Size == 16 &&
Evan Chengf0b5d562007-03-08 01:07:07 +0000270 TAI->getSixteenByteConstantSection())
271 SwitchToDataSection(TAI->getSixteenByteConstantSection(), I);
272 else if (TAI->getReadOnlySection())
273 SwitchToDataSection(TAI->getReadOnlySection(), I);
274 else
275 SwitchToDataSection(TAI->getDataSection(), I);
276 }
Chris Lattner8e13e902007-01-17 17:44:25 +0000277 }
278
279 break;
280 }
281 default:
282 assert(0 && "Unknown linkage type!");
283 }
284
285 EmitAlignment(Align, I);
286 O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
287 << "\n";
288 if (TAI->hasDotTypeDotSizeDirective())
289 O << "\t.size " << name << ", " << Size << "\n";
290 // If the initializer is a extern weak symbol, remember to emit the weak
291 // reference!
292 if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
293 if (GV->hasExternalWeakLinkage())
294 ExtWeakSymbols.insert(GV);
295
296 EmitGlobalConstant(C);
297 O << '\n';
Chris Lattnera35a8e82005-11-21 22:39:40 +0000298 }
299
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000300 // Output linker support code for dllexported globals
301 if (DLLExportedGVs.begin() != DLLExportedGVs.end()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000302 SwitchToDataSection(".section .drectve");
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000303 }
304
305 for (std::set<std::string>::iterator i = DLLExportedGVs.begin(),
306 e = DLLExportedGVs.end();
307 i != e; ++i) {
308 O << "\t.ascii \" -export:" << *i << ",data\"\n";
309 }
310
311 if (DLLExportedFns.begin() != DLLExportedFns.end()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000312 SwitchToDataSection(".section .drectve");
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000313 }
314
315 for (std::set<std::string>::iterator i = DLLExportedFns.begin(),
316 e = DLLExportedFns.end();
317 i != e; ++i) {
318 O << "\t.ascii \" -export:" << *i << "\"\n";
319 }
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000320
Jim Laskeyea348582006-07-27 02:05:13 +0000321 if (Subtarget->isTargetDarwin()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000322 SwitchToDataSection("");
Nate Begeman73213f62005-07-12 01:37:28 +0000323
Nate Begeman72b286b2005-07-08 00:23:26 +0000324 // Output stubs for dynamically-linked functions
325 unsigned j = 1;
326 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
Chris Lattnerb12c9fa2005-07-11 06:25:47 +0000327 i != e; ++i, ++j) {
Chris Lattner4632d7a2006-05-09 04:59:56 +0000328 SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs,"
329 "self_modifying_code+pure_instructions,5", 0);
Nate Begeman72b286b2005-07-08 00:23:26 +0000330 O << "L" << *i << "$stub:\n";
331 O << "\t.indirect_symbol " << *i << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000332 O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
Nate Begeman72b286b2005-07-08 00:23:26 +0000333 }
334
335 O << "\n";
Jeff Cohen00b168892005-07-27 06:12:32 +0000336
Evan Cheng2338c5c2006-02-07 08:38:37 +0000337 // Output stubs for external and common global variables.
338 if (GVStubs.begin() != GVStubs.end())
Chris Lattner4632d7a2006-05-09 04:59:56 +0000339 SwitchToDataSection(
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000340 ".section __IMPORT,__pointers,non_lazy_symbol_pointers");
Evan Cheng2338c5c2006-02-07 08:38:37 +0000341 for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
342 i != e; ++i) {
343 O << "L" << *i << "$non_lazy_ptr:\n";
344 O << "\t.indirect_symbol " << *i << "\n";
345 O << "\t.long\t0\n";
Nate Begeman72b286b2005-07-08 00:23:26 +0000346 }
Chris Lattnerac5701c2004-10-04 07:24:48 +0000347
Reid Spencer02b85112006-10-30 22:32:30 +0000348 // Emit final debug information.
Jim Laskey99db0442006-03-23 18:09:44 +0000349 DW.EndModule();
Evan Chengd5948812006-03-07 02:23:26 +0000350
351 // Funny Darwin hack: This flag tells the linker that no global symbols
352 // contain code that falls through to other global symbols (e.g. the obvious
353 // implementation of multiple entry points). If this doesn't occur, the
Jim Laskey99db0442006-03-23 18:09:44 +0000354 // linker can safely perform dead code stripping. Since LLVM never
355 // generates code that does this, it is always safe to set.
Evan Chengd5948812006-03-07 02:23:26 +0000356 O << "\t.subsections_via_symbols\n";
Anton Korobeynikovd05ca652007-01-16 16:41:57 +0000357 } else if (Subtarget->isTargetCygMing()) {
358 // Emit type information for external functions
359 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
360 i != e; ++i) {
361 O << "\t.def\t " << *i
362 << ";\t.scl\t" << COFF::C_EXT
363 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
364 << ";\t.endef\n";
365 }
366
367 // Emit final debug information.
368 DW.EndModule();
369 } else if (Subtarget->isTargetELF()) {
Reid Spencer02b85112006-10-30 22:32:30 +0000370 // Emit final debug information.
371 DW.EndModule();
Evan Chengd5948812006-03-07 02:23:26 +0000372 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000373
Chris Lattnerac5701c2004-10-04 07:24:48 +0000374 AsmPrinter::doFinalization(M);
375 return false; // success
376}
377
Chris Lattnerac5701c2004-10-04 07:24:48 +0000378/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
379/// for a MachineFunction to the given output stream, using the given target
380/// machine description.
381///
Evan Chengc4c62572006-03-13 23:20:37 +0000382FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
Jim Laskey563321a2006-09-06 18:34:40 +0000383 X86TargetMachine &tm) {
Jim Laskey05a059d2006-09-07 12:23:47 +0000384 const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>();
Jim Laskey563321a2006-09-06 18:34:40 +0000385
Jim Laskey05a059d2006-09-07 12:23:47 +0000386 if (Subtarget->isFlavorIntel()) {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000387 return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo());
Jim Laskey05a059d2006-09-07 12:23:47 +0000388 } else {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000389 return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo());
Chris Lattnerac5701c2004-10-04 07:24:48 +0000390 }
Brian Gaeke9e474c42003-06-19 19:32:32 +0000391}