2014-03-27 19:39:03 +08:00
|
|
|
//===-------- MipsELFStreamer.cpp - ELF Object Output ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MipsELFStreamer.h"
|
2017-02-04 07:39:33 +08:00
|
|
|
#include "MipsOptionRecord.h"
|
2014-11-06 00:35:20 +08:00
|
|
|
#include "MipsTargetStreamer.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2017-10-11 09:57:21 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2017-02-04 07:39:33 +08:00
|
|
|
#include "llvm/MC/MCAssembler.h"
|
2017-10-12 07:34:47 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2017-02-04 07:39:33 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2014-07-21 21:30:55 +08:00
|
|
|
#include "llvm/MC/MCInst.h"
|
2015-06-03 04:38:46 +08:00
|
|
|
#include "llvm/MC/MCSymbolELF.h"
|
2017-02-04 07:39:33 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
2014-11-06 00:35:20 +08:00
|
|
|
|
2014-09-04 05:04:12 +08:00
|
|
|
using namespace llvm;
|
2014-07-21 21:30:55 +08:00
|
|
|
|
2017-10-11 09:57:21 +08:00
|
|
|
MipsELFStreamer::MipsELFStreamer(MCContext &Context,
|
|
|
|
std::unique_ptr<MCAsmBackend> MAB,
|
2017-10-12 07:34:47 +08:00
|
|
|
raw_pwrite_stream &OS,
|
|
|
|
std::unique_ptr<MCCodeEmitter> Emitter)
|
|
|
|
: MCELFStreamer(Context, std::move(MAB), OS, std::move(Emitter)) {
|
2017-10-11 09:57:21 +08:00
|
|
|
RegInfoRecord = new MipsRegInfoRecord(this, Context);
|
|
|
|
MipsOptionRecords.push_back(
|
|
|
|
std::unique_ptr<MipsRegInfoRecord>(RegInfoRecord));
|
|
|
|
}
|
|
|
|
|
2014-07-21 21:30:55 +08:00
|
|
|
void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
|
2017-04-14 15:44:23 +08:00
|
|
|
const MCSubtargetInfo &STI, bool) {
|
2014-07-21 21:30:55 +08:00
|
|
|
MCELFStreamer::EmitInstruction(Inst, STI);
|
|
|
|
|
|
|
|
MCContext &Context = getContext();
|
|
|
|
const MCRegisterInfo *MCRegInfo = Context.getRegisterInfo();
|
|
|
|
|
|
|
|
for (unsigned OpIndex = 0; OpIndex < Inst.getNumOperands(); ++OpIndex) {
|
|
|
|
const MCOperand &Op = Inst.getOperand(OpIndex);
|
|
|
|
|
|
|
|
if (!Op.isReg())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned Reg = Op.getReg();
|
|
|
|
RegInfoRecord->SetPhysRegUsed(Reg, MCRegInfo);
|
|
|
|
}
|
2014-11-06 00:35:20 +08:00
|
|
|
|
2015-04-16 17:53:47 +08:00
|
|
|
createPendingLabelRelocs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsELFStreamer::createPendingLabelRelocs() {
|
|
|
|
MipsTargetELFStreamer *ELFTargetStreamer =
|
|
|
|
static_cast<MipsTargetELFStreamer *>(getTargetStreamer());
|
|
|
|
|
|
|
|
// FIXME: Also mark labels when in MIPS16 mode.
|
2014-11-06 00:35:20 +08:00
|
|
|
if (ELFTargetStreamer->isMicroMipsEnabled()) {
|
2015-06-03 04:38:46 +08:00
|
|
|
for (auto *L : Labels) {
|
|
|
|
auto *Label = cast<MCSymbolELF>(L);
|
2015-06-04 03:03:11 +08:00
|
|
|
getAssembler().registerSymbol(*Label);
|
2015-06-04 13:59:23 +08:00
|
|
|
Label->setOther(ELF::STO_MIPS_MICROMIPS);
|
2014-11-06 00:35:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Labels.clear();
|
|
|
|
}
|
|
|
|
|
2017-02-10 23:13:12 +08:00
|
|
|
void MipsELFStreamer::EmitLabel(MCSymbol *Symbol, SMLoc Loc) {
|
2014-11-06 00:35:20 +08:00
|
|
|
MCELFStreamer::EmitLabel(Symbol);
|
|
|
|
Labels.push_back(Symbol);
|
|
|
|
}
|
|
|
|
|
2015-05-22 03:20:38 +08:00
|
|
|
void MipsELFStreamer::SwitchSection(MCSection *Section,
|
2014-11-06 00:35:20 +08:00
|
|
|
const MCExpr *Subsection) {
|
|
|
|
MCELFStreamer::SwitchSection(Section, Subsection);
|
|
|
|
Labels.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsELFStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size,
|
2015-09-21 07:35:59 +08:00
|
|
|
SMLoc Loc) {
|
2014-11-06 00:35:20 +08:00
|
|
|
MCELFStreamer::EmitValueImpl(Value, Size, Loc);
|
|
|
|
Labels.clear();
|
2014-07-21 21:30:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsELFStreamer::EmitMipsOptionRecords() {
|
|
|
|
for (const auto &I : MipsOptionRecords)
|
|
|
|
I->EmitMipsOptionRecord();
|
|
|
|
}
|
2014-03-27 19:39:03 +08:00
|
|
|
|
2017-10-12 07:34:47 +08:00
|
|
|
MCELFStreamer *llvm::createMipsELFStreamer(
|
|
|
|
MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
|
|
|
|
raw_pwrite_stream &OS, std::unique_ptr<MCCodeEmitter> Emitter,
|
|
|
|
bool RelaxAll) {
|
|
|
|
return new MipsELFStreamer(Context, std::move(MAB), OS, std::move(Emitter));
|
2014-03-27 19:39:03 +08:00
|
|
|
}
|