2013-11-18 23:55:27 +00:00
|
|
|
//===-- MipsTargetStreamer.cpp - Mips Target Streamer Methods -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides Mips specific target streamer methods.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-01-27 03:53:56 +00:00
|
|
|
#include "InstPrinter/MipsInstPrinter.h"
|
2013-11-18 23:55:27 +00:00
|
|
|
#include "MipsTargetStreamer.h"
|
2014-01-26 06:57:13 +00:00
|
|
|
#include "MipsMCTargetDesc.h"
|
2013-11-18 23:55:27 +00:00
|
|
|
#include "llvm/MC/MCELF.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2014-01-26 06:57:13 +00:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2013-11-18 23:55:27 +00:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-01-07 11:48:04 +00:00
|
|
|
#include "llvm/Support/ELF.h"
|
2013-11-18 23:55:27 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2014-01-06 23:27:31 +00:00
|
|
|
// Pin vtable to this file.
|
2013-11-18 23:55:27 +00:00
|
|
|
void MipsTargetStreamer::anchor() {}
|
|
|
|
|
2014-01-26 06:06:37 +00:00
|
|
|
MipsTargetStreamer::MipsTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
|
|
|
|
|
|
|
|
MipsTargetAsmStreamer::MipsTargetAsmStreamer(MCStreamer &S,
|
|
|
|
formatted_raw_ostream &OS)
|
|
|
|
: MipsTargetStreamer(S), OS(OS) {}
|
2013-11-19 20:53:28 +00:00
|
|
|
|
2014-01-14 04:25:13 +00:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMicroMips() {
|
|
|
|
OS << "\t.set\tmicromips\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMicroMips() {
|
|
|
|
OS << "\t.set\tnomicromips\n";
|
2013-11-19 20:53:28 +00:00
|
|
|
}
|
2014-01-14 04:25:13 +00:00
|
|
|
|
2014-01-14 18:57:12 +00:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips16() {
|
|
|
|
OS << "\t.set\tmips16\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMips16() {
|
|
|
|
OS << "\t.set\tnomips16\n";
|
|
|
|
}
|
|
|
|
|
2014-01-26 05:06:48 +00:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetReorder() {
|
|
|
|
OS << "\t.set\treorder\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoReorder() {
|
|
|
|
OS << "\t.set\tnoreorder\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMacro() {
|
|
|
|
OS << "\t.set\tmacro\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoMacro() {
|
|
|
|
OS << "\t.set\tnomacro\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetAt() {
|
|
|
|
OS << "\t.set\tat\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetNoAt() {
|
|
|
|
OS << "\t.set\tnoat\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveEnd(StringRef Name) {
|
|
|
|
OS << "\t.end\t" << Name << '\n';
|
|
|
|
}
|
|
|
|
|
2014-01-14 18:57:12 +00:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
|
|
|
|
OS << "\t.ent\t" << Symbol.getName() << '\n';
|
|
|
|
}
|
|
|
|
|
2014-01-06 23:27:31 +00:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveAbiCalls() { OS << "\t.abicalls\n"; }
|
|
|
|
void MipsTargetAsmStreamer::emitDirectiveOptionPic0() {
|
|
|
|
OS << "\t.option\tpic0\n";
|
|
|
|
}
|
|
|
|
|
2014-01-27 03:53:56 +00:00
|
|
|
void MipsTargetAsmStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
|
|
|
unsigned ReturnReg) {
|
|
|
|
OS << "\t.frame\t$"
|
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(StackReg)).lower() << ","
|
|
|
|
<< StackSize << ",$"
|
|
|
|
<< StringRef(MipsInstPrinter::getRegisterName(ReturnReg)).lower();
|
|
|
|
}
|
|
|
|
|
2014-01-06 23:27:31 +00:00
|
|
|
// This part is for ELF object output.
|
2014-01-26 06:57:13 +00:00
|
|
|
MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
|
|
|
|
const MCSubtargetInfo &STI)
|
|
|
|
: MipsTargetStreamer(S), MicroMipsEnabled(false) {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
uint64_t Features = STI.getFeatureBits();
|
|
|
|
Triple T(STI.getTargetTriple());
|
|
|
|
|
|
|
|
// Update e_header flags
|
|
|
|
unsigned EFlags = 0;
|
|
|
|
|
|
|
|
// Architecture
|
|
|
|
if (Features & Mips::FeatureMips64r2)
|
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_64R2;
|
|
|
|
else if (Features & Mips::FeatureMips64)
|
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_64;
|
|
|
|
else if (Features & Mips::FeatureMips32r2)
|
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_32R2;
|
|
|
|
else if (Features & Mips::FeatureMips32)
|
|
|
|
EFlags |= ELF::EF_MIPS_ARCH_32;
|
|
|
|
|
|
|
|
if (T.isArch64Bit()) {
|
|
|
|
EFlags |= ELF::EF_MIPS_ABI2;
|
|
|
|
} else {
|
|
|
|
if (Features & Mips::FeatureMips64r2 || Features & Mips::FeatureMips64)
|
|
|
|
EFlags |= ELF::EF_MIPS_32BITMODE;
|
|
|
|
|
|
|
|
// ABI
|
|
|
|
EFlags |= ELF::EF_MIPS_ABI_O32;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCA.setELFHeaderEFlags(EFlags);
|
|
|
|
}
|
2013-11-18 23:55:27 +00:00
|
|
|
|
2014-01-14 04:25:13 +00:00
|
|
|
void MipsTargetELFStreamer::emitLabel(MCSymbol *Symbol) {
|
2014-01-15 03:07:12 +00:00
|
|
|
if (!isMicroMipsEnabled())
|
|
|
|
return;
|
2014-01-14 04:25:13 +00:00
|
|
|
MCSymbolData &Data = getStreamer().getOrCreateSymbolData(Symbol);
|
2014-01-15 03:07:12 +00:00
|
|
|
uint8_t Type = MCELF::GetType(Data);
|
|
|
|
if (Type != ELF::STT_FUNC)
|
|
|
|
return;
|
|
|
|
|
2014-01-14 04:25:13 +00:00
|
|
|
// The "other" values are stored in the last 6 bits of the second byte
|
|
|
|
// The traditional defines for STO values assume the full byte and thus
|
|
|
|
// the shift to pack it.
|
2014-01-15 03:07:12 +00:00
|
|
|
MCELF::setOther(Data, ELF::STO_MIPS_MICROMIPS >> 2);
|
2014-01-14 04:25:13 +00:00
|
|
|
}
|
|
|
|
|
2013-11-18 23:55:27 +00:00
|
|
|
MCELFStreamer &MipsTargetELFStreamer::getStreamer() {
|
2014-01-26 06:06:37 +00:00
|
|
|
return static_cast<MCELFStreamer &>(Streamer);
|
2013-11-18 23:55:27 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 04:25:13 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
|
|
|
|
MicroMipsEnabled = true;
|
2014-01-26 06:57:13 +00:00
|
|
|
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_MICROMIPS;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
2014-01-14 04:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoMicroMips() {
|
|
|
|
MicroMipsEnabled = false;
|
2013-11-18 23:55:27 +00:00
|
|
|
}
|
2014-01-14 04:25:13 +00:00
|
|
|
|
2014-01-14 18:57:12 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMips16() {
|
2014-01-24 16:13:20 +00:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
2014-01-14 18:57:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoMips16() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
2014-01-26 05:06:48 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetReorder() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoReorder() {
|
2014-01-26 06:57:13 +00:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_NOREORDER;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
2014-01-26 05:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMacro() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoMacro() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetAt() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoAt() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
2014-01-14 18:57:12 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveEnt(const MCSymbol &Symbol) {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
2014-01-06 23:27:31 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveAbiCalls() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
2014-01-26 06:57:13 +00:00
|
|
|
Flags |= ELF::EF_MIPS_CPIC | ELF::EF_MIPS_PIC;
|
2014-01-06 23:27:31 +00:00
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags &= ~ELF::EF_MIPS_PIC;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
2014-01-27 03:53:56 +00:00
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitFrame(unsigned StackReg, unsigned StackSize,
|
|
|
|
unsigned ReturnReg) {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|