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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MipsTargetStreamer.h"
|
|
|
|
#include "llvm/MC/MCELF.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#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;
|
|
|
|
|
2013-11-19 20:53:28 +00:00
|
|
|
static cl::opt<bool> PrintHackDirectives("print-hack-directives",
|
|
|
|
cl::init(false), cl::Hidden);
|
|
|
|
|
2014-01-06 23:27:31 +00:00
|
|
|
// Pin vtable to this file.
|
2013-11-18 23:55:27 +00:00
|
|
|
void MipsTargetStreamer::anchor() {}
|
|
|
|
|
2013-11-19 20:53:28 +00:00
|
|
|
MipsTargetAsmStreamer::MipsTargetAsmStreamer(formatted_raw_ostream &OS)
|
|
|
|
: OS(OS) {}
|
|
|
|
|
|
|
|
void MipsTargetAsmStreamer::emitMipsHackELFFlags(unsigned Flags) {
|
|
|
|
if (!PrintHackDirectives)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OS << "\t.mips_hack_elf_flags 0x";
|
|
|
|
OS.write_hex(Flags);
|
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
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-22 23:08:42 +00:00
|
|
|
void MipsTargetAsmStreamer::emitDirectiveSetMips16(bool IsMips16) {
|
|
|
|
if (IsMips16)
|
|
|
|
OS << "\t.set\tmips16\n";
|
|
|
|
else
|
|
|
|
OS << "\t.set\tnomips16\n";
|
|
|
|
}
|
2014-01-06 23:27:31 +00:00
|
|
|
|
|
|
|
// This part is for ELF object output.
|
2014-01-15 03:27:26 +00:00
|
|
|
MipsTargetELFStreamer::MipsTargetELFStreamer() : MicroMipsEnabled(false) {}
|
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() {
|
|
|
|
return static_cast<MCELFStreamer &>(*Streamer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitMipsHackELFFlags(unsigned Flags) {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
|
|
|
|
2014-01-14 04:25:13 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMicroMips() {
|
|
|
|
MicroMipsEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetNoMips16() {
|
|
|
|
// FIXME: implement.
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
Flags |= ELF::EF_MIPS_CPIC;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
|
|
|
void MipsTargetELFStreamer::emitDirectiveOptionPic0() {
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags &= ~ELF::EF_MIPS_PIC;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|
2014-01-22 23:08:42 +00:00
|
|
|
void MipsTargetELFStreamer::emitDirectiveSetMips16(bool IsMips16) {
|
|
|
|
// Don't do anything for .set nomips16
|
|
|
|
if (!IsMips16)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
unsigned Flags = MCA.getELFHeaderEFlags();
|
|
|
|
Flags |= ELF::EF_MIPS_ARCH_ASE_M16;
|
|
|
|
MCA.setELFHeaderEFlags(Flags);
|
|
|
|
}
|