mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-13 01:15:32 +00:00
Move EmitInstruction to MCObjectStreamer so that ELF and MachO can share it.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@117925 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9729d2e998
commit
f89671d994
@ -33,6 +33,9 @@ class MCObjectStreamer : public MCStreamer {
|
|||||||
MCAssembler *Assembler;
|
MCAssembler *Assembler;
|
||||||
MCSectionData *CurSectionData;
|
MCSectionData *CurSectionData;
|
||||||
|
|
||||||
|
virtual void EmitInstToFragment(const MCInst &Inst) = 0;
|
||||||
|
virtual void EmitInstToData(const MCInst &Inst) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
MCObjectStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
||||||
raw_ostream &_OS, MCCodeEmitter *_Emitter,
|
raw_ostream &_OS, MCCodeEmitter *_Emitter,
|
||||||
@ -59,6 +62,7 @@ public:
|
|||||||
|
|
||||||
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
|
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
|
||||||
virtual void SwitchSection(const MCSection *Section);
|
virtual void SwitchSection(const MCSection *Section);
|
||||||
|
virtual void EmitInstruction(const MCInst &Inst);
|
||||||
virtual void Finish();
|
virtual void Finish();
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
@ -36,8 +36,6 @@ using namespace llvm;
|
|||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class MCELFStreamer : public MCObjectStreamer {
|
class MCELFStreamer : public MCObjectStreamer {
|
||||||
void EmitInstToFragment(const MCInst &Inst);
|
|
||||||
void EmitInstToData(const MCInst &Inst);
|
|
||||||
public:
|
public:
|
||||||
MCELFStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
MCELFStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
||||||
raw_ostream &OS, MCCodeEmitter *Emitter)
|
raw_ostream &OS, MCCodeEmitter *Emitter)
|
||||||
@ -109,10 +107,12 @@ public:
|
|||||||
DEBUG(dbgs() << "FIXME: MCELFStreamer:EmitDwarfFileDirective not implemented\n");
|
DEBUG(dbgs() << "FIXME: MCELFStreamer:EmitDwarfFileDirective not implemented\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EmitInstruction(const MCInst &Inst);
|
|
||||||
virtual void Finish();
|
virtual void Finish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void EmitInstToFragment(const MCInst &Inst);
|
||||||
|
virtual void EmitInstToData(const MCInst &Inst);
|
||||||
|
|
||||||
struct LocalCommon {
|
struct LocalCommon {
|
||||||
MCSymbolData *SD;
|
MCSymbolData *SD;
|
||||||
uint64_t Size;
|
uint64_t Size;
|
||||||
@ -510,35 +510,6 @@ void MCELFStreamer::EmitInstToData(const MCInst &Inst) {
|
|||||||
DF->getContents().append(Code.begin(), Code.end());
|
DF->getContents().append(Code.begin(), Code.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCELFStreamer::EmitInstruction(const MCInst &Inst) {
|
|
||||||
// Scan for values.
|
|
||||||
for (unsigned i = 0; i != Inst.getNumOperands(); ++i)
|
|
||||||
if (Inst.getOperand(i).isExpr())
|
|
||||||
AddValueSymbols(Inst.getOperand(i).getExpr());
|
|
||||||
|
|
||||||
getCurrentSectionData()->setHasInstructions(true);
|
|
||||||
|
|
||||||
// If this instruction doesn't need relaxation, just emit it as data.
|
|
||||||
if (!getAssembler().getBackend().MayNeedRelaxation(Inst)) {
|
|
||||||
EmitInstToData(Inst);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, if we are relaxing everything, relax the instruction as much as
|
|
||||||
// possible and emit it as data.
|
|
||||||
if (getAssembler().getRelaxAll()) {
|
|
||||||
MCInst Relaxed;
|
|
||||||
getAssembler().getBackend().RelaxInstruction(Inst, Relaxed);
|
|
||||||
while (getAssembler().getBackend().MayNeedRelaxation(Relaxed))
|
|
||||||
getAssembler().getBackend().RelaxInstruction(Relaxed, Relaxed);
|
|
||||||
EmitInstToData(Relaxed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise emit to a separate fragment.
|
|
||||||
EmitInstToFragment(Inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MCELFStreamer::Finish() {
|
void MCELFStreamer::Finish() {
|
||||||
for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
|
for (std::vector<LocalCommon>::const_iterator i = LocalCommons.begin(),
|
||||||
e = LocalCommons.end();
|
e = LocalCommons.end();
|
||||||
|
@ -31,8 +31,8 @@ namespace {
|
|||||||
|
|
||||||
class MCMachOStreamer : public MCObjectStreamer {
|
class MCMachOStreamer : public MCObjectStreamer {
|
||||||
private:
|
private:
|
||||||
void EmitInstToFragment(const MCInst &Inst);
|
virtual void EmitInstToFragment(const MCInst &Inst);
|
||||||
void EmitInstToData(const MCInst &Inst);
|
virtual void EmitInstToData(const MCInst &Inst);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
MCMachOStreamer(MCContext &Context, TargetAsmBackend &TAB,
|
||||||
@ -98,8 +98,6 @@ public:
|
|||||||
//report_fatal_error("unsupported directive: '.file'");
|
//report_fatal_error("unsupported directive: '.file'");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void EmitInstruction(const MCInst &Inst);
|
|
||||||
|
|
||||||
virtual void Finish();
|
virtual void Finish();
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
@ -406,39 +404,6 @@ void MCMachOStreamer::EmitInstToData(const MCInst &Inst) {
|
|||||||
DF->getContents().append(Code.begin(), Code.end());
|
DF->getContents().append(Code.begin(), Code.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCMachOStreamer::EmitInstruction(const MCInst &Inst) {
|
|
||||||
// Scan for values.
|
|
||||||
for (unsigned i = Inst.getNumOperands(); i--; )
|
|
||||||
if (Inst.getOperand(i).isExpr())
|
|
||||||
AddValueSymbols(Inst.getOperand(i).getExpr());
|
|
||||||
|
|
||||||
getCurrentSectionData()->setHasInstructions(true);
|
|
||||||
|
|
||||||
// Now that a machine instruction has been assembled into this section, make
|
|
||||||
// a line entry for any .loc directive that has been seen.
|
|
||||||
MCLineEntry::Make(this, getCurrentSection());
|
|
||||||
|
|
||||||
// If this instruction doesn't need relaxation, just emit it as data.
|
|
||||||
if (!getAssembler().getBackend().MayNeedRelaxation(Inst)) {
|
|
||||||
EmitInstToData(Inst);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, if we are relaxing everything, relax the instruction as much as
|
|
||||||
// possible and emit it as data.
|
|
||||||
if (getAssembler().getRelaxAll()) {
|
|
||||||
MCInst Relaxed;
|
|
||||||
getAssembler().getBackend().RelaxInstruction(Inst, Relaxed);
|
|
||||||
while (getAssembler().getBackend().MayNeedRelaxation(Relaxed))
|
|
||||||
getAssembler().getBackend().RelaxInstruction(Relaxed, Relaxed);
|
|
||||||
EmitInstToData(Relaxed);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise emit to a separate fragment.
|
|
||||||
EmitInstToFragment(Inst);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MCMachOStreamer::Finish() {
|
void MCMachOStreamer::Finish() {
|
||||||
// Dump out the dwarf file & directory tables and line tables.
|
// Dump out the dwarf file & directory tables and line tables.
|
||||||
if (getContext().hasDwarfFiles()) {
|
if (getContext().hasDwarfFiles()) {
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/MC/MCAssembler.h"
|
#include "llvm/MC/MCAssembler.h"
|
||||||
#include "llvm/MC/MCCodeEmitter.h"
|
#include "llvm/MC/MCCodeEmitter.h"
|
||||||
|
#include "llvm/MC/MCDwarf.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/Target/TargetAsmBackend.h"
|
#include "llvm/Target/TargetAsmBackend.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -90,6 +91,39 @@ void MCObjectStreamer::SwitchSection(const MCSection *Section) {
|
|||||||
CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
|
CurSectionData = &getAssembler().getOrCreateSectionData(*Section);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MCObjectStreamer::EmitInstruction(const MCInst &Inst) {
|
||||||
|
// Scan for values.
|
||||||
|
for (unsigned i = Inst.getNumOperands(); i--; )
|
||||||
|
if (Inst.getOperand(i).isExpr())
|
||||||
|
AddValueSymbols(Inst.getOperand(i).getExpr());
|
||||||
|
|
||||||
|
getCurrentSectionData()->setHasInstructions(true);
|
||||||
|
|
||||||
|
// Now that a machine instruction has been assembled into this section, make
|
||||||
|
// a line entry for any .loc directive that has been seen.
|
||||||
|
MCLineEntry::Make(this, getCurrentSection());
|
||||||
|
|
||||||
|
// If this instruction doesn't need relaxation, just emit it as data.
|
||||||
|
if (!getAssembler().getBackend().MayNeedRelaxation(Inst)) {
|
||||||
|
EmitInstToData(Inst);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, if we are relaxing everything, relax the instruction as much as
|
||||||
|
// possible and emit it as data.
|
||||||
|
if (getAssembler().getRelaxAll()) {
|
||||||
|
MCInst Relaxed;
|
||||||
|
getAssembler().getBackend().RelaxInstruction(Inst, Relaxed);
|
||||||
|
while (getAssembler().getBackend().MayNeedRelaxation(Relaxed))
|
||||||
|
getAssembler().getBackend().RelaxInstruction(Relaxed, Relaxed);
|
||||||
|
EmitInstToData(Relaxed);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise emit to a separate fragment.
|
||||||
|
EmitInstToFragment(Inst);
|
||||||
|
}
|
||||||
|
|
||||||
void MCObjectStreamer::Finish() {
|
void MCObjectStreamer::Finish() {
|
||||||
getAssembler().Finish();
|
getAssembler().Finish();
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,13 @@ public:
|
|||||||
virtual void Finish();
|
virtual void Finish();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
virtual void EmitInstToFragment(const MCInst &Inst) {
|
||||||
|
llvm_unreachable("Not used by WinCOFF.");
|
||||||
|
}
|
||||||
|
virtual void EmitInstToData(const MCInst &Inst) {
|
||||||
|
llvm_unreachable("Not used by WinCOFF.");
|
||||||
|
}
|
||||||
|
|
||||||
void SetSection(StringRef Section,
|
void SetSection(StringRef Section,
|
||||||
unsigned Characteristics,
|
unsigned Characteristics,
|
||||||
SectionKind Kind) {
|
SectionKind Kind) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user