2005-07-02 06:44:09 +08:00
|
|
|
//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-22 07:38:14 +08:00
|
|
|
//
|
2003-10-21 03:43:21 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
2005-07-02 06:44:09 +08:00
|
|
|
// This file the shared super class printer that converts from our internal
|
|
|
|
// representation of machine-dependent LLVM code to Intel and AT&T format
|
|
|
|
// assembly language.
|
|
|
|
// This printer is the output mechanism used by `llc'.
|
2002-10-26 06:55:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-03-14 07:20:37 +08:00
|
|
|
#include "X86AsmPrinter.h"
|
2005-07-02 06:44:09 +08:00
|
|
|
#include "X86ATTAsmPrinter.h"
|
2007-01-17 00:41:57 +08:00
|
|
|
#include "X86COFF.h"
|
2005-07-02 06:44:09 +08:00
|
|
|
#include "X86IntelAsmPrinter.h"
|
2006-09-21 06:03:51 +08:00
|
|
|
#include "X86MachineFunctionInfo.h"
|
2005-11-22 06:39:40 +08:00
|
|
|
#include "X86Subtarget.h"
|
2006-09-21 06:03:51 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/CallingConv.h"
|
2005-12-13 12:53:51 +08:00
|
|
|
#include "llvm/Constants.h"
|
2003-08-12 04:06:16 +08:00
|
|
|
#include "llvm/Module.h"
|
2007-03-31 21:11:52 +08:00
|
|
|
#include "llvm/DerivedTypes.h"
|
2005-11-21 14:46:22 +08:00
|
|
|
#include "llvm/Type.h"
|
2003-08-12 04:06:16 +08:00
|
|
|
#include "llvm/Assembly/Writer.h"
|
2003-07-25 04:20:44 +08:00
|
|
|
#include "llvm/Support/Mangler.h"
|
2006-09-08 06:06:40 +08:00
|
|
|
#include "llvm/Target/TargetAsmInfo.h"
|
2007-01-17 18:33:08 +08:00
|
|
|
#include "llvm/Target/TargetOptions.h"
|
2004-02-14 14:00:36 +08:00
|
|
|
using namespace llvm;
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2007-04-18 01:21:52 +08:00
|
|
|
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
|
|
|
|
const TargetData *TD) {
|
|
|
|
X86MachineFunctionInfo Info;
|
2006-09-26 11:57:53 +08:00
|
|
|
uint64_t Size = 0;
|
2006-09-21 06:03:51 +08:00
|
|
|
|
|
|
|
switch (F->getCallingConv()) {
|
2006-09-26 11:57:53 +08:00
|
|
|
case CallingConv::X86_StdCall:
|
2006-09-21 06:03:51 +08:00
|
|
|
Info.setDecorationStyle(StdCall);
|
|
|
|
break;
|
2006-09-26 11:57:53 +08:00
|
|
|
case CallingConv::X86_FastCall:
|
2006-09-21 06:03:51 +08:00
|
|
|
Info.setDecorationStyle(FastCall);
|
|
|
|
break;
|
2006-09-26 11:57:53 +08:00
|
|
|
default:
|
2006-09-21 06:03:51 +08:00
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
2006-09-26 11:57:53 +08:00
|
|
|
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
|
|
|
|
AI != AE; ++AI)
|
2007-03-02 00:29:22 +08:00
|
|
|
// Size should be aligned to DWORD boundary
|
2007-11-05 08:04:43 +08:00
|
|
|
Size += ((TD->getABITypeSize(AI->getType()) + 3)/4)*4;
|
2006-10-15 04:53:35 +08:00
|
|
|
|
2006-09-21 06:03:51 +08:00
|
|
|
// We're not supporting tooooo huge arguments :)
|
2006-09-26 11:57:53 +08:00
|
|
|
Info.setBytesToPopOnReturn((unsigned int)Size);
|
2006-09-21 06:03:51 +08:00
|
|
|
return Info;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-26 11:57:53 +08:00
|
|
|
/// decorateName - Query FunctionInfoMap and use this information for various
|
|
|
|
/// name decoration.
|
|
|
|
void X86SharedAsmPrinter::decorateName(std::string &Name,
|
|
|
|
const GlobalValue *GV) {
|
|
|
|
const Function *F = dyn_cast<Function>(GV);
|
|
|
|
if (!F) return;
|
2006-09-21 06:03:51 +08:00
|
|
|
|
|
|
|
// We don't want to decorate non-stdcall or non-fastcall functions right now
|
2006-09-26 11:57:53 +08:00
|
|
|
unsigned CC = F->getCallingConv();
|
|
|
|
if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
|
2006-09-21 06:03:51 +08:00
|
|
|
return;
|
2007-01-28 21:31:35 +08:00
|
|
|
|
|
|
|
// Decorate names only when we're targeting Cygwin/Mingw32 targets
|
|
|
|
if (!Subtarget->isTargetCygMing())
|
|
|
|
return;
|
2006-09-21 06:03:51 +08:00
|
|
|
|
|
|
|
FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
|
|
|
|
|
2007-04-18 01:21:52 +08:00
|
|
|
const X86MachineFunctionInfo *Info;
|
2006-09-21 06:03:51 +08:00
|
|
|
if (info_item == FunctionInfoMap.end()) {
|
|
|
|
// Calculate apropriate function info and populate map
|
|
|
|
FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
|
|
|
|
Info = &FunctionInfoMap[F];
|
|
|
|
} else {
|
2006-09-26 11:57:53 +08:00
|
|
|
Info = &info_item->second;
|
2006-09-21 06:03:51 +08:00
|
|
|
}
|
2007-03-31 21:11:52 +08:00
|
|
|
|
|
|
|
const FunctionType *FT = F->getFunctionType();
|
2006-09-21 06:03:51 +08:00
|
|
|
switch (Info->getDecorationStyle()) {
|
2006-09-26 11:57:53 +08:00
|
|
|
case None:
|
2006-09-21 06:03:51 +08:00
|
|
|
break;
|
2006-09-26 11:57:53 +08:00
|
|
|
case StdCall:
|
2007-03-31 21:11:52 +08:00
|
|
|
// "Pure" variadic functions do not receive @0 suffix.
|
|
|
|
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
2007-11-27 21:23:08 +08:00
|
|
|
(FT->getNumParams() == 1 && F->isStructReturn()))
|
2006-09-21 06:03:51 +08:00
|
|
|
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
|
|
|
break;
|
2006-09-26 11:57:53 +08:00
|
|
|
case FastCall:
|
2007-03-31 21:11:52 +08:00
|
|
|
// "Pure" variadic functions do not receive @0 suffix.
|
|
|
|
if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
|
2007-11-27 21:23:08 +08:00
|
|
|
(FT->getNumParams() == 1 && F->isStructReturn()))
|
2006-09-21 06:03:51 +08:00
|
|
|
Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
|
2006-09-26 11:57:53 +08:00
|
|
|
|
2006-09-21 06:03:51 +08:00
|
|
|
if (Name[0] == '_') {
|
|
|
|
Name[0] = '@';
|
|
|
|
} else {
|
|
|
|
Name = '@' + Name;
|
|
|
|
}
|
|
|
|
break;
|
2006-09-26 11:57:53 +08:00
|
|
|
default:
|
2006-09-21 06:03:51 +08:00
|
|
|
assert(0 && "Unsupported DecorationStyle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-07 02:34:40 +08:00
|
|
|
/// doInitialization
|
2006-09-08 14:48:29 +08:00
|
|
|
bool X86SharedAsmPrinter::doInitialization(Module &M) {
|
2007-05-05 17:04:50 +08:00
|
|
|
if (TAI->doesSupportDebugInformation()) {
|
2006-03-07 10:23:26 +08:00
|
|
|
// Emit initial debug information.
|
2006-03-24 02:09:44 +08:00
|
|
|
DW.BeginModule(&M);
|
2006-03-07 10:23:26 +08:00
|
|
|
}
|
2006-03-07 10:02:57 +08:00
|
|
|
|
2007-07-26 03:33:14 +08:00
|
|
|
bool Result = AsmPrinter::doInitialization(M);
|
2007-06-22 08:54:56 +08:00
|
|
|
|
|
|
|
// Darwin wants symbols to be quoted if they have complex names.
|
|
|
|
if (Subtarget->isTargetDarwin())
|
|
|
|
Mang->setUseQuotes(true);
|
|
|
|
|
2007-07-26 03:33:14 +08:00
|
|
|
return Result;
|
2005-01-23 11:52:14 +08:00
|
|
|
}
|
|
|
|
|
2004-10-04 15:24:48 +08:00
|
|
|
bool X86SharedAsmPrinter::doFinalization(Module &M) {
|
2006-05-07 05:27:14 +08:00
|
|
|
// Note: this code is not shared by the Intel printer as it is too different
|
|
|
|
// from how MASM does things. When making changes here don't forget to look
|
|
|
|
// at X86IntelAsmPrinter::doFinalization().
|
2006-05-03 09:29:57 +08:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
2006-12-01 08:25:12 +08:00
|
|
|
|
2004-10-04 15:24:48 +08:00
|
|
|
// Print out module-level global variables here.
|
2006-02-07 16:38:37 +08:00
|
|
|
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ++I) {
|
2006-12-10 07:14:08 +08:00
|
|
|
if (!I->hasInitializer())
|
2006-12-01 08:25:12 +08:00
|
|
|
continue; // External global require no code
|
2005-11-22 06:48:18 +08:00
|
|
|
|
2005-12-13 14:32:50 +08:00
|
|
|
// Check to see if this is a special global used by LLVM, if so, emit it.
|
2007-01-30 16:04:53 +08:00
|
|
|
if (EmitSpecialLLVMGlobal(I)) {
|
|
|
|
if (Subtarget->isTargetDarwin() &&
|
|
|
|
TM.getRelocationModel() == Reloc::Static) {
|
|
|
|
if (I->getName() == "llvm.global_ctors")
|
|
|
|
O << ".reference .constructors_used\n";
|
|
|
|
else if (I->getName() == "llvm.global_dtors")
|
|
|
|
O << ".reference .destructors_used\n";
|
|
|
|
}
|
2005-12-13 14:32:50 +08:00
|
|
|
continue;
|
2007-01-30 16:04:53 +08:00
|
|
|
}
|
2005-12-13 12:53:51 +08:00
|
|
|
|
2005-11-22 06:48:18 +08:00
|
|
|
std::string name = Mang->getValueName(I);
|
|
|
|
Constant *C = I->getInitializer();
|
2007-03-08 09:07:07 +08:00
|
|
|
const Type *Type = C->getType();
|
2007-11-05 08:04:43 +08:00
|
|
|
unsigned Size = TD->getABITypeSize(Type);
|
2006-10-25 04:32:14 +08:00
|
|
|
unsigned Align = TD->getPreferredAlignmentLog(I);
|
2005-07-27 14:12:32 +08:00
|
|
|
|
2007-04-30 02:35:00 +08:00
|
|
|
if (I->hasHiddenVisibility()) {
|
2007-01-18 01:44:25 +08:00
|
|
|
if (const char *Directive = TAI->getHiddenDirective())
|
|
|
|
O << Directive << name << "\n";
|
2007-04-30 02:35:00 +08:00
|
|
|
} else if (I->hasProtectedVisibility()) {
|
|
|
|
if (const char *Directive = TAI->getProtectedDirective())
|
|
|
|
O << Directive << name << "\n";
|
|
|
|
}
|
|
|
|
|
2007-01-18 01:44:25 +08:00
|
|
|
if (Subtarget->isTargetELF())
|
2007-07-30 23:08:02 +08:00
|
|
|
O << "\t.type\t" << name << ",@object\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
|
2007-09-21 08:41:19 +08:00
|
|
|
if (C->isNullValue() && !I->hasSection()) {
|
2006-02-15 09:56:23 +08:00
|
|
|
if (I->hasExternalLinkage()) {
|
2007-01-18 01:44:25 +08:00
|
|
|
if (const char *Directive = TAI->getZeroFillDirective()) {
|
2006-02-23 10:43:52 +08:00
|
|
|
O << "\t.globl\t" << name << "\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
O << Directive << "__DATA__, __common, " << name << ", "
|
2007-01-18 10:30:19 +08:00
|
|
|
<< Size << ", " << Align << "\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-21 08:41:19 +08:00
|
|
|
if (!I->isThreadLocal() &&
|
2007-01-18 01:44:25 +08:00
|
|
|
(I->hasInternalLinkage() || I->hasWeakLinkage() ||
|
|
|
|
I->hasLinkOnceLinkage())) {
|
|
|
|
if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
|
2007-01-17 18:33:08 +08:00
|
|
|
if (!NoZerosInBSS && TAI->getBSSSection())
|
|
|
|
SwitchToDataSection(TAI->getBSSSection(), I);
|
|
|
|
else
|
|
|
|
SwitchToDataSection(TAI->getDataSection(), I);
|
2006-09-07 02:34:40 +08:00
|
|
|
if (TAI->getLCOMMDirective() != NULL) {
|
2006-02-15 09:56:23 +08:00
|
|
|
if (I->hasInternalLinkage()) {
|
2006-09-07 02:34:40 +08:00
|
|
|
O << TAI->getLCOMMDirective() << name << "," << Size;
|
2006-07-27 10:05:13 +08:00
|
|
|
if (Subtarget->isTargetDarwin())
|
2007-01-18 09:49:58 +08:00
|
|
|
O << "," << Align;
|
2006-02-15 09:56:23 +08:00
|
|
|
} else
|
2006-09-07 02:34:40 +08:00
|
|
|
O << TAI->getCOMMDirective() << name << "," << Size;
|
2006-02-15 09:56:23 +08:00
|
|
|
} else {
|
2007-01-03 19:43:14 +08:00
|
|
|
if (!Subtarget->isTargetCygMing()) {
|
2006-05-26 05:59:08 +08:00
|
|
|
if (I->hasInternalLinkage())
|
|
|
|
O << "\t.local\t" << name << "\n";
|
|
|
|
}
|
2006-09-07 02:34:40 +08:00
|
|
|
O << TAI->getCOMMDirective() << name << "," << Size;
|
|
|
|
if (TAI->getCOMMDirectiveTakesAlignment())
|
|
|
|
O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
|
2006-02-15 09:56:23 +08:00
|
|
|
}
|
2007-01-18 01:44:25 +08:00
|
|
|
O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
|
|
|
|
continue;
|
2006-02-07 16:38:37 +08:00
|
|
|
}
|
2007-01-18 01:44:25 +08:00
|
|
|
}
|
2006-10-31 09:26:55 +08:00
|
|
|
|
2007-01-18 01:44:25 +08:00
|
|
|
switch (I->getLinkage()) {
|
|
|
|
case GlobalValue::LinkOnceLinkage:
|
|
|
|
case GlobalValue::WeakLinkage:
|
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2007-10-05 23:58:41 +08:00
|
|
|
O << "\t.globl\t" << name << "\n"
|
2007-11-21 07:24:42 +08:00
|
|
|
<< TAI->getWeakDefDirective() << name << "\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
|
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
|
|
|
std::string SectionName(".section\t.data$linkonce." +
|
|
|
|
name +
|
|
|
|
",\"aw\"");
|
|
|
|
SwitchToDataSection(SectionName.c_str(), I);
|
2007-10-05 23:58:41 +08:00
|
|
|
O << "\t.globl\t" << name << "\n"
|
2007-01-18 01:44:25 +08:00
|
|
|
<< "\t.linkonce same_size\n";
|
|
|
|
} else {
|
|
|
|
std::string SectionName("\t.section\t.llvm.linkonce.d." +
|
|
|
|
name +
|
|
|
|
",\"aw\",@progbits");
|
|
|
|
SwitchToDataSection(SectionName.c_str(), I);
|
2007-07-30 23:08:02 +08:00
|
|
|
O << "\t.weak\t" << name << "\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GlobalValue::DLLExportLinkage:
|
|
|
|
DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
|
|
|
|
// FALL THROUGH
|
2007-08-14 02:42:37 +08:00
|
|
|
case GlobalValue::AppendingLinkage:
|
|
|
|
// FIXME: appending linkage variables should go into a section of
|
|
|
|
// their name or something. For now, just emit them as external.
|
2007-01-18 01:44:25 +08:00
|
|
|
case GlobalValue::ExternalLinkage:
|
|
|
|
// If external or appending, declare as a global symbol
|
2007-10-05 23:58:41 +08:00
|
|
|
O << "\t.globl\t" << name << "\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
// FALL THROUGH
|
|
|
|
case GlobalValue::InternalLinkage: {
|
|
|
|
if (I->isConstant()) {
|
|
|
|
const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
|
|
|
|
if (TAI->getCStringSection() && CVA && CVA->isCString()) {
|
|
|
|
SwitchToDataSection(TAI->getCStringSection(), I);
|
|
|
|
break;
|
2006-10-31 09:26:55 +08:00
|
|
|
}
|
2006-10-27 03:18:18 +08:00
|
|
|
}
|
2007-01-18 01:44:25 +08:00
|
|
|
// FIXME: special handling for ".ctors" & ".dtors" sections
|
|
|
|
if (I->hasSection() &&
|
|
|
|
(I->getSection() == ".ctors" ||
|
|
|
|
I->getSection() == ".dtors")) {
|
|
|
|
std::string SectionName = ".section " + I->getSection();
|
|
|
|
|
|
|
|
if (Subtarget->isTargetCygMing()) {
|
|
|
|
SectionName += ",\"aw\"";
|
|
|
|
} else {
|
|
|
|
assert(!Subtarget->isTargetDarwin());
|
|
|
|
SectionName += ",\"aw\",@progbits";
|
|
|
|
}
|
|
|
|
|
|
|
|
SwitchToDataSection(SectionName.c_str());
|
|
|
|
} else {
|
|
|
|
if (C->isNullValue() && !NoZerosInBSS && TAI->getBSSSection())
|
2007-04-21 05:38:10 +08:00
|
|
|
SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSBSSSection() :
|
|
|
|
TAI->getBSSSection(), I);
|
2007-03-08 09:07:07 +08:00
|
|
|
else if (!I->isConstant())
|
2007-04-21 05:38:10 +08:00
|
|
|
SwitchToDataSection(I->isThreadLocal() ? TAI->getTLSDataSection() :
|
|
|
|
TAI->getDataSection(), I);
|
|
|
|
else if (I->isThreadLocal())
|
|
|
|
SwitchToDataSection(TAI->getTLSDataSection());
|
2007-03-08 09:07:07 +08:00
|
|
|
else {
|
|
|
|
// Read-only data.
|
2007-03-08 16:31:54 +08:00
|
|
|
bool HasReloc = C->ContainsRelocations();
|
|
|
|
if (HasReloc &&
|
|
|
|
Subtarget->isTargetDarwin() &&
|
2007-03-08 09:07:07 +08:00
|
|
|
TM.getRelocationModel() != Reloc::Static)
|
|
|
|
SwitchToDataSection("\t.const_data\n");
|
2007-03-08 16:31:54 +08:00
|
|
|
else if (!HasReloc && Size == 4 &&
|
2007-03-08 09:07:07 +08:00
|
|
|
TAI->getFourByteConstantSection())
|
|
|
|
SwitchToDataSection(TAI->getFourByteConstantSection(), I);
|
2007-03-08 16:31:54 +08:00
|
|
|
else if (!HasReloc && Size == 8 &&
|
2007-03-08 09:07:07 +08:00
|
|
|
TAI->getEightByteConstantSection())
|
|
|
|
SwitchToDataSection(TAI->getEightByteConstantSection(), I);
|
2007-03-08 16:31:54 +08:00
|
|
|
else if (!HasReloc && Size == 16 &&
|
2007-03-08 09:07:07 +08:00
|
|
|
TAI->getSixteenByteConstantSection())
|
|
|
|
SwitchToDataSection(TAI->getSixteenByteConstantSection(), I);
|
|
|
|
else if (TAI->getReadOnlySection())
|
|
|
|
SwitchToDataSection(TAI->getReadOnlySection(), I);
|
|
|
|
else
|
|
|
|
SwitchToDataSection(TAI->getDataSection(), I);
|
|
|
|
}
|
2005-11-22 03:50:31 +08:00
|
|
|
}
|
2007-01-18 01:44:25 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
assert(0 && "Unknown linkage type!");
|
|
|
|
}
|
2005-11-22 03:50:31 +08:00
|
|
|
|
2007-01-18 01:44:25 +08:00
|
|
|
EmitAlignment(Align, I);
|
|
|
|
O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
|
|
|
|
<< "\n";
|
|
|
|
if (TAI->hasDotTypeDotSizeDirective())
|
2007-07-30 23:08:02 +08:00
|
|
|
O << "\t.size\t" << name << ", " << Size << "\n";
|
2007-01-18 01:44:25 +08:00
|
|
|
// If the initializer is a extern weak symbol, remember to emit the weak
|
|
|
|
// reference!
|
|
|
|
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
|
|
|
|
if (GV->hasExternalWeakLinkage())
|
|
|
|
ExtWeakSymbols.insert(GV);
|
2006-12-01 17:13:26 +08:00
|
|
|
|
2007-01-18 01:44:25 +08:00
|
|
|
EmitGlobalConstant(C);
|
2005-11-22 06:39:40 +08:00
|
|
|
}
|
|
|
|
|
2006-09-15 02:23:27 +08:00
|
|
|
// Output linker support code for dllexported globals
|
2007-10-04 03:26:29 +08:00
|
|
|
if (!DLLExportedGVs.empty()) {
|
2006-10-31 16:31:24 +08:00
|
|
|
SwitchToDataSection(".section .drectve");
|
2006-09-15 02:23:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (std::set<std::string>::iterator i = DLLExportedGVs.begin(),
|
|
|
|
e = DLLExportedGVs.end();
|
|
|
|
i != e; ++i) {
|
|
|
|
O << "\t.ascii \" -export:" << *i << ",data\"\n";
|
|
|
|
}
|
|
|
|
|
2007-10-04 03:26:29 +08:00
|
|
|
if (!DLLExportedFns.empty()) {
|
2006-10-31 16:31:24 +08:00
|
|
|
SwitchToDataSection(".section .drectve");
|
2006-09-15 02:23:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for (std::set<std::string>::iterator i = DLLExportedFns.begin(),
|
|
|
|
e = DLLExportedFns.end();
|
|
|
|
i != e; ++i) {
|
|
|
|
O << "\t.ascii \" -export:" << *i << "\"\n";
|
|
|
|
}
|
2006-12-01 08:25:12 +08:00
|
|
|
|
2006-07-27 10:05:13 +08:00
|
|
|
if (Subtarget->isTargetDarwin()) {
|
2006-10-31 16:31:24 +08:00
|
|
|
SwitchToDataSection("");
|
2005-07-12 09:37:28 +08:00
|
|
|
|
2005-07-08 08:23:26 +08:00
|
|
|
// Output stubs for dynamically-linked functions
|
|
|
|
unsigned j = 1;
|
|
|
|
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
2005-07-11 14:25:47 +08:00
|
|
|
i != e; ++i, ++j) {
|
2006-05-09 12:59:56 +08:00
|
|
|
SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs,"
|
|
|
|
"self_modifying_code+pure_instructions,5", 0);
|
2005-07-08 08:23:26 +08:00
|
|
|
O << "L" << *i << "$stub:\n";
|
|
|
|
O << "\t.indirect_symbol " << *i << "\n";
|
2006-02-07 16:38:37 +08:00
|
|
|
O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
|
2005-07-08 08:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
O << "\n";
|
2005-07-27 14:12:32 +08:00
|
|
|
|
2007-09-17 03:21:08 +08:00
|
|
|
if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) {
|
2007-09-11 16:27:17 +08:00
|
|
|
// Add the (possibly multiple) personalities to the set of global values.
|
|
|
|
const std::vector<Function *>& Personalities = MMI->getPersonalities();
|
|
|
|
|
|
|
|
for (std::vector<Function *>::const_iterator I = Personalities.begin(),
|
|
|
|
E = Personalities.end(); I != E; ++I)
|
|
|
|
if (*I) GVStubs.insert("_" + (*I)->getName());
|
|
|
|
}
|
|
|
|
|
2006-02-07 16:38:37 +08:00
|
|
|
// Output stubs for external and common global variables.
|
2007-10-04 03:26:29 +08:00
|
|
|
if (!GVStubs.empty())
|
2006-05-09 12:59:56 +08:00
|
|
|
SwitchToDataSection(
|
2006-10-31 16:31:24 +08:00
|
|
|
".section __IMPORT,__pointers,non_lazy_symbol_pointers");
|
2006-02-07 16:38:37 +08:00
|
|
|
for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
|
|
|
|
i != e; ++i) {
|
|
|
|
O << "L" << *i << "$non_lazy_ptr:\n";
|
|
|
|
O << "\t.indirect_symbol " << *i << "\n";
|
|
|
|
O << "\t.long\t0\n";
|
2005-07-08 08:23:26 +08:00
|
|
|
}
|
2004-10-04 15:24:48 +08:00
|
|
|
|
2006-10-31 06:32:30 +08:00
|
|
|
// Emit final debug information.
|
2006-03-24 02:09:44 +08:00
|
|
|
DW.EndModule();
|
2006-03-07 10:23:26 +08:00
|
|
|
|
|
|
|
// Funny Darwin hack: This flag tells the linker that no global symbols
|
|
|
|
// contain code that falls through to other global symbols (e.g. the obvious
|
|
|
|
// implementation of multiple entry points). If this doesn't occur, the
|
2006-03-24 02:09:44 +08:00
|
|
|
// linker can safely perform dead code stripping. Since LLVM never
|
|
|
|
// generates code that does this, it is always safe to set.
|
2006-03-07 10:23:26 +08:00
|
|
|
O << "\t.subsections_via_symbols\n";
|
2007-01-17 00:41:57 +08:00
|
|
|
} else if (Subtarget->isTargetCygMing()) {
|
|
|
|
// Emit type information for external functions
|
|
|
|
for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
|
|
|
|
i != e; ++i) {
|
|
|
|
O << "\t.def\t " << *i
|
|
|
|
<< ";\t.scl\t" << COFF::C_EXT
|
|
|
|
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
|
|
|
|
<< ";\t.endef\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit final debug information.
|
|
|
|
DW.EndModule();
|
|
|
|
} else if (Subtarget->isTargetELF()) {
|
2006-10-31 06:32:30 +08:00
|
|
|
// Emit final debug information.
|
|
|
|
DW.EndModule();
|
2006-03-07 10:23:26 +08:00
|
|
|
}
|
2006-03-07 10:02:57 +08:00
|
|
|
|
2007-07-26 03:33:14 +08:00
|
|
|
return AsmPrinter::doFinalization(M);
|
2004-10-04 15:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
|
|
|
|
/// for a MachineFunction to the given output stream, using the given target
|
|
|
|
/// machine description.
|
|
|
|
///
|
2006-03-14 07:20:37 +08:00
|
|
|
FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
|
2006-09-07 02:34:40 +08:00
|
|
|
X86TargetMachine &tm) {
|
2006-09-07 20:23:47 +08:00
|
|
|
const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>();
|
2006-09-07 02:34:40 +08:00
|
|
|
|
2006-09-07 20:23:47 +08:00
|
|
|
if (Subtarget->isFlavorIntel()) {
|
2006-09-08 06:06:40 +08:00
|
|
|
return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo());
|
2006-09-07 20:23:47 +08:00
|
|
|
} else {
|
2006-09-08 06:06:40 +08:00
|
|
|
return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo());
|
2004-10-04 15:24:48 +08:00
|
|
|
}
|
2003-06-20 03:32:32 +08:00
|
|
|
}
|