break coff symbol definition stuff out into proper MCStreamer callbacks,

patch by Nathan Jeffords!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103346 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-05-08 19:54:22 +00:00
parent 369252db2e
commit b54b9ddaaf
6 changed files with 81 additions and 23 deletions

View File

@ -27,7 +27,7 @@ namespace llvm {
class MCSection;
class MCSymbol;
class StringRef;
class TargetAsmBackend;
class TargetAsmBackend;
class Twine;
class raw_ostream;
class formatted_raw_ostream;
@ -138,7 +138,24 @@ class TargetAsmBackend;
/// @param DescValue - The value to set into the n_desc field.
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) = 0;
/// BeginCOFFSymbolDef - Start emitting COFF symbol definition
///
/// @param Symbol - The symbol to have its External & Type fields set.
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) = 0;
/// EmitCOFFSymbolStorageClass - Emit the storage class of the symbol.
///
/// @param StorageClass - The storage class the symbol should have.
virtual void EmitCOFFSymbolStorageClass(int StorageClass) = 0;
/// EmitCOFFSymbolType - Emit the type of the symbol.
///
/// @param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
virtual void EmitCOFFSymbolType(int Type) = 0;
/// EndCOFFSymbolDef - Marks the end of the symbol definition.
virtual void EndCOFFSymbolDef() = 0;
/// EmitELFSize - Emit an ELF .size directive.
///
/// This corresponds to an assembler statement such as:

View File

@ -109,7 +109,10 @@ public:
virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute);
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
virtual void EmitCOFFSymbolStorageClass(int StorageClass);
virtual void EmitCOFFSymbolType(int Type);
virtual void EndCOFFSymbolDef();
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value);
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment);
@ -293,6 +296,26 @@ void MCAsmStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {
EmitEOL();
}
void MCAsmStreamer::BeginCOFFSymbolDef(const MCSymbol *Symbol) {
OS << "\t.def\t " << *Symbol << ';';
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSymbolStorageClass (int StorageClass) {
OS << "\t.scl\t" << StorageClass << ';';
EmitEOL();
}
void MCAsmStreamer::EmitCOFFSymbolType (int Type) {
OS << "\t.type\t" << Type << ';';
EmitEOL();
}
void MCAsmStreamer::EndCOFFSymbolDef() {
OS << "\t.endef";
EmitEOL();
}
void MCAsmStreamer::EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
assert(MAI.hasDotTypeDotSizeDirective());
OS << "\t.size\t" << *Symbol << ", " << *Value << '\n';

View File

@ -96,6 +96,18 @@ public:
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment);
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {
assert(0 && "macho doesn't support this directive");
}
virtual void EmitCOFFSymbolStorageClass(int StorageClass) {
assert(0 && "macho doesn't support this directive");
}
virtual void EmitCOFFSymbolType(int Type) {
assert(0 && "macho doesn't support this directive");
}
virtual void EndCOFFSymbolDef() {
assert(0 && "macho doesn't support this directive");
}
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {
assert(0 && "macho doesn't support this directive");
}

View File

@ -42,6 +42,12 @@ namespace {
virtual void EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute){}
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol) {}
virtual void EmitCOFFSymbolStorageClass(int StorageClass) {}
virtual void EmitCOFFSymbolType(int Type) {}
virtual void EndCOFFSymbolDef() {}
virtual void EmitELFSize(MCSymbol *Symbol, const MCExpr *Value) {}
virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) {}

View File

@ -58,12 +58,11 @@ bool X86AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
SetupMachineFunction(MF);
if (Subtarget->isTargetCOFF()) {
const Function *F = MF.getFunction();
OutStreamer.EmitRawText("\t.def\t " + Twine(CurrentFnSym->getName()) +
";\t.scl\t" +
Twine(F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT) +
";\t.type\t" + Twine(COFF::DT_FCN << COFF::N_BTSHFT)
+ ";\t.endef");
bool Intrn = MF.getFunction()->hasInternalLinkage();
OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
OutStreamer.EmitCOFFSymbolStorageClass(Intrn ? COFF::C_STAT : COFF::C_EXT);
OutStreamer.EmitCOFFSymbolType(COFF::DT_FCN << COFF::N_BTSHFT);
OutStreamer.EndCOFFSymbolDef();
}
// Have common code print out the function header with linkage info etc.
@ -571,13 +570,14 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
MMI->getObjFileInfo<X86COFFMachineModuleInfo>();
// Emit type information for external functions
for (X86COFFMachineModuleInfo::stub_iterator I = COFFMMI.stub_begin(),
E = COFFMMI.stub_end(); I != E; ++I) {
OutStreamer.EmitRawText("\t.def\t " + Twine(I->getKeyData()) +
";\t.scl\t" + Twine(COFF::C_EXT) +
";\t.type\t" +
Twine(COFF::DT_FCN << COFF::N_BTSHFT) +
";\t.endef");
typedef X86COFFMachineModuleInfo::externals_iterator externals_iterator;
for (externals_iterator I = COFFMMI.externals_begin(),
E = COFFMMI.externals_end();
I != E; ++I) {
OutStreamer.BeginCOFFSymbolDef(CurrentFnSym);
OutStreamer.EmitCOFFSymbolStorageClass(COFF::C_EXT);
OutStreamer.EmitCOFFSymbolType(COFF::DT_FCN << COFF::N_BTSHFT);
OutStreamer.EndCOFFSymbolDef();
}
if (Subtarget->isTargetCygMing()) {

View File

@ -15,7 +15,7 @@
#define X86COFF_MACHINEMODULEINFO_H
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/DenseSet.h"
#include "X86MachineFunctionInfo.h"
namespace llvm {
@ -25,18 +25,18 @@ namespace llvm {
/// X86COFFMachineModuleInfo - This is a MachineModuleInfoImpl implementation
/// for X86 COFF targets.
class X86COFFMachineModuleInfo : public MachineModuleInfoImpl {
StringSet<> CygMingStubs;
DenseSet<MCSymbol const *> Externals;
public:
X86COFFMachineModuleInfo(const MachineModuleInfo &) {}
virtual ~X86COFFMachineModuleInfo();
void addExternalFunction(StringRef Name) {
CygMingStubs.insert(Name);
void addExternalFunction(MCSymbol* Symbol) {
Externals.insert(Symbol);
}
typedef StringSet<>::const_iterator stub_iterator;
stub_iterator stub_begin() const { return CygMingStubs.begin(); }
stub_iterator stub_end() const { return CygMingStubs.end(); }
typedef DenseSet<MCSymbol const *>::const_iterator externals_iterator;
externals_iterator externals_begin() const { return Externals.begin(); }
externals_iterator externals_end() const { return Externals.end(); }
};