X86: refactor export directive generation

Create a helper function to generate the export directive.  This was previously
duplicated inline to handle export directives for variables and functions.  This
also enables the use of range-based iterators for the generation of the
directive rather than the traditional loops.  NFC.

llvm-svn: 207925
This commit is contained in:
Saleem Abdulrasool 2014-05-04 00:03:41 +00:00
parent cf63a79818
commit 75e68cbd12
2 changed files with 27 additions and 22 deletions

View File

@ -550,7 +550,27 @@ emitNonLazySymbolPointer(MCStreamer &OutStreamer, MCSymbol *StubLabel,
4 /*size*/);
}
void X86AsmPrinter::GenerateExportDirective(const MCSymbol *Sym, bool IsData) {
SmallString<128> Directive;
raw_svector_ostream OS(Directive);
if (Subtarget->isTargetKnownWindowsMSVC())
OS << " /EXPORT:";
else
OS << " -export:";
OS << Sym->getName();
if (IsData) {
if (Subtarget->isTargetKnownWindowsMSVC())
OS << ",DATA";
else
OS << ",data";
}
OS.flush();
OutStreamer.EmitBytes(Directive);
}
void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
if (Subtarget->isTargetMacho()) {
@ -682,28 +702,11 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
static_cast<const TargetLoweringObjectFileCOFF&>(getObjFileLowering());
OutStreamer.SwitchSection(TLOFCOFF.getDrectveSection());
SmallString<128> name;
for (unsigned i = 0, e = DLLExportedGlobals.size(); i != e; ++i) {
if (Subtarget->isTargetKnownWindowsMSVC())
name = " /EXPORT:";
else
name = " -export:";
name += DLLExportedGlobals[i]->getName();
if (Subtarget->isTargetKnownWindowsMSVC())
name += ",DATA";
else
name += ",data";
OutStreamer.EmitBytes(name);
}
for (unsigned i = 0, e = DLLExportedFns.size(); i != e; ++i) {
if (Subtarget->isTargetKnownWindowsMSVC())
name = " /EXPORT:";
else
name = " -export:";
name += DLLExportedFns[i]->getName();
OutStreamer.EmitBytes(name);
}
for (auto & Symbol : DLLExportedGlobals)
GenerateExportDirective(Symbol, /*IsData=*/true);
for (auto & Symbol : DLLExportedFns)
GenerateExportDirective(Symbol, /*IsData=*/false);
}
}

View File

@ -16,13 +16,15 @@
#include "llvm/Target/TargetMachine.h"
namespace llvm {
class MCStreamer;
class MCSymbol;
class LLVM_LIBRARY_VISIBILITY X86AsmPrinter : public AsmPrinter {
const X86Subtarget *Subtarget;
StackMaps SM;
void GenerateExportDirective(const MCSymbol *Sym, bool IsData);
public:
explicit X86AsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
: AsmPrinter(TM, Streamer), SM(*this) {