//===-- X86AsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly --------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file contains a printer that converts from our internal representation
// of machine-dependent LLVM code to AT&T format assembly
// language. This printer is the output mechanism used by `llc'.
//
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "asm-printer"
#include "X86AsmPrinter.h"
#include "X86ATTInstPrinter.h"
#include "X86IntelInstPrinter.h"
#include "X86MCInstLower.h"
#include "X86.h"
#include "X86COFF.h"
#include "X86COFFMachineModuleInfo.h"
#include "X86MachineFunctionInfo.h"
#include "X86TargetMachine.h"
#include "llvm/CallingConv.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/Type.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Mangler.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
using namespace llvm;
STATISTIC(EmittedInsts, "Number of machine instrs printed");
//===----------------------------------------------------------------------===//
// Primitive Helper Functions.
//===----------------------------------------------------------------------===//
void X86AsmPrinter::printMCInst(const MCInst *MI) {
if (MAI->getAssemblerDialect() == 0)
X86ATTInstPrinter(O, *MAI).printInstruction(MI);
else
X86IntelInstPrinter(O, *MAI).printInstruction(MI);
}
void X86AsmPrinter::PrintPICBaseSymbol() const {
// FIXME: Gross const cast hack.
X86AsmPrinter *AP = const_cast<X86AsmPrinter*>(this);
X86MCInstLower(OutContext, 0, *AP).GetPICBaseSymbol()->print(O, MAI);
}
void X86AsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
unsigned FnAlign = MF.getAlignment();
const Function *F = MF.getFunction();
if (Subtarget->isTargetCygMing()) {
X86COFFMachineModuleInfo &COFFMMI =
MMI->getObjFileInfo<X86COFFMachineModuleInfo>();
COFFMMI.DecorateCygMingName(CurrentFnName, F, *TM.getTargetData());
CurrentFnSym = OutContext.GetOrCreateSymbol(StringRef(CurrentFnName));
}
OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
EmitAlignment(FnAlign, F);
switch (F->getLinkage()) {
default: llvm_unreachable("Unknown linkage type!");
case Function::InternalLinkage: // Symbols default to internal.
case Function::PrivateLinkage:
break;
case Function::DLLExportLinkage:
case Function::ExternalLinkage:
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
break;
case Function::LinkerPrivateLinkage:
case Function::LinkOnceAnyLinkage:
case Function::LinkOnceODRLinkage:
case Function::WeakAnyLinkage:
case Function::WeakODRLinkage:
if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << '\n';
O << MAI->getWeakDefDirective();
CurrentFnSym->print(O, MAI);
O << '\n';
} else if (Subtarget->isTargetCygMing()) {
O << "\t.globl\t";
CurrentFnSym->print(O, MAI);
O << "\n\t.linkonce discard\n";
} else {
O << "\t.weak\t";
CurrentFnSym->print(O, MAI);
O << '\n';
}
break;
}
printVisibility(CurrentFnSym, F->getVisibility());
if (Subtarget->isTargetELF()) {
O << "\t.type\t";
CurrentFnSym->print(O, MAI);
O << ",@function\n";
} else if (Subtarget->isTargetCygMing()) {
O << "\t.def\t ";
CurrentFnSym->print(O, MAI);
O << ";\t.scl\t" <<
(F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
<< ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT