diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-08-22 10:13:24 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-08-22 10:13:24 +0000 |
commit | ff3eafd39d2000e6b01140629c42937558301a88 (patch) | |
tree | 9c632367fee8dc16064e79521b3f390ae2f68779 /llvm/lib/MC/MCMachOStreamer.cpp | |
parent | db52f9c650218cdfb02a4d1166dc236faa5f46b6 (diff) | |
download | bcm5719-llvm-ff3eafd39d2000e6b01140629c42937558301a88.tar.gz bcm5719-llvm-ff3eafd39d2000e6b01140629c42937558301a88.zip |
llvm-mc/Mach-O: Sketch symbol table support.
- The only .s syntax this honors right now is emitting labels, and some parts
of the symbol table generation are wrong or faked.
- This is enough to get nm to report such symbols... incorrectly, but still.
Also, fixed byte emission to extend the previous fragment if possible.
llvm-svn: 79739
Diffstat (limited to 'llvm/lib/MC/MCMachOStreamer.cpp')
-rw-r--r-- | llvm/lib/MC/MCMachOStreamer.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 421faef6aa4..0b79944933b 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -26,6 +26,27 @@ class MCMachOStreamer : public MCStreamer { MCSectionData *CurSectionData; DenseMap<const MCSection*, MCSectionData*> SectionMap; + + DenseMap<const MCSymbol*, MCSymbolData*> SymbolMap; + +private: + MCFragment *getCurrentFragment() const { + assert(CurSectionData && "No current section!"); + + if (!CurSectionData->empty()) + return &CurSectionData->getFragmentList().back(); + + return 0; + } + + MCSymbolData &getSymbolData(MCSymbol &Symbol) { + MCSymbolData *&Entry = SymbolMap[&Symbol]; + + if (!Entry) + Entry = new MCSymbolData(Symbol, 0, 0, &Assembler); + + return *Entry; + } public: MCMachOStreamer(MCContext &Context, raw_ostream &_OS) @@ -92,10 +113,16 @@ void MCMachOStreamer::SwitchSection(const MCSection *Section) { void MCMachOStreamer::EmitLabel(MCSymbol *Symbol) { assert(Symbol->isUndefined() && "Cannot define a symbol twice!"); - assert(CurSection && "Cannot emit before setting section!"); - llvm_unreachable("FIXME: Not yet implemented!"); + MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment()); + if (!F) + F = new MCDataFragment(CurSectionData); + MCSymbolData &SD = getSymbolData(*Symbol); + assert(!SD.getFragment() && "Unexpected fragment on symbol data!"); + SD.setFragment(F); + SD.setOffset(F->getContents().size()); + Symbol->setSection(*CurSection); } @@ -138,7 +165,9 @@ void MCMachOStreamer::EmitZerofill(MCSection *Section, MCSymbol *Symbol, } void MCMachOStreamer::EmitBytes(const StringRef &Data) { - MCDataFragment *DF = new MCDataFragment(CurSectionData); + MCDataFragment *DF = dyn_cast_or_null<MCDataFragment>(getCurrentFragment()); + if (!DF) + DF = new MCDataFragment(CurSectionData); DF->getContents().append(Data.begin(), Data.end()); } @@ -154,7 +183,7 @@ void MCMachOStreamer::EmitValueToAlignment(unsigned ByteAlignment, new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit, CurSectionData); - // Update the maximum alignment on the current section if necessary + // Update the maximum alignment on the current section if necessary. if (ByteAlignment > CurSectionData->getAlignment()) CurSectionData->setAlignment(ByteAlignment); } |