2016-11-02 07:47:30 +08:00
|
|
|
//===-- RISCVAsmBackend.cpp - RISCV Assembler Backend ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "MCTargetDesc/RISCVMCTargetDesc.h"
|
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
|
|
|
#include "llvm/MC/MCAssembler.h"
|
|
|
|
#include "llvm/MC/MCDirectives.h"
|
|
|
|
#include "llvm/MC/MCELFObjectWriter.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2016-11-02 07:47:30 +08:00
|
|
|
#include "llvm/MC/MCFixupKindInfo.h"
|
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class RISCVAsmBackend : public MCAsmBackend {
|
|
|
|
uint8_t OSABI;
|
|
|
|
bool Is64Bit;
|
|
|
|
|
|
|
|
public:
|
|
|
|
RISCVAsmBackend(uint8_t OSABI, bool Is64Bit)
|
|
|
|
: MCAsmBackend(), OSABI(OSABI), Is64Bit(Is64Bit) {}
|
|
|
|
~RISCVAsmBackend() override {}
|
|
|
|
|
2017-06-24 06:52:36 +08:00
|
|
|
void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
|
|
|
const MCValue &Target, MutableArrayRef<char> Data,
|
2017-07-12 07:18:25 +08:00
|
|
|
uint64_t Value, bool IsResolved) const override;
|
2016-11-02 07:47:30 +08:00
|
|
|
|
|
|
|
MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override;
|
|
|
|
|
|
|
|
bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
|
|
|
|
const MCRelaxableFragment *DF,
|
|
|
|
const MCAsmLayout &Layout) const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumFixupKinds() const override { return 1; }
|
|
|
|
|
|
|
|
bool mayNeedRelaxation(const MCInst &Inst) const override { return false; }
|
|
|
|
|
|
|
|
void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
|
|
|
|
MCInst &Res) const override {
|
|
|
|
|
2017-08-20 14:57:27 +08:00
|
|
|
report_fatal_error("RISCVAsmBackend::relaxInstruction() unimplemented");
|
2016-11-02 07:47:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool RISCVAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
|
|
|
|
// Once support for the compressed instruction set is added, we will be able
|
|
|
|
// to conditionally support 16-bit NOPs
|
|
|
|
if ((Count % 4) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// The canonical nop on RISC-V is addi x0, x0, 0
|
|
|
|
for (uint64_t i = 0; i < Count; i += 4)
|
|
|
|
OW->write32(0x13);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-24 06:52:36 +08:00
|
|
|
void RISCVAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,
|
|
|
|
const MCValue &Target,
|
2017-06-22 07:06:53 +08:00
|
|
|
MutableArrayRef<char> Data, uint64_t Value,
|
2017-07-12 07:18:25 +08:00
|
|
|
bool IsResolved) const {
|
2016-11-02 07:47:30 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCObjectWriter *
|
|
|
|
RISCVAsmBackend::createObjectWriter(raw_pwrite_stream &OS) const {
|
|
|
|
return createRISCVELFObjectWriter(OS, OSABI, Is64Bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
MCAsmBackend *llvm::createRISCVAsmBackend(const Target &T,
|
|
|
|
const MCRegisterInfo &MRI,
|
|
|
|
const Triple &TT, StringRef CPU,
|
|
|
|
const MCTargetOptions &Options) {
|
|
|
|
uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
|
|
|
|
return new RISCVAsmBackend(OSABI, TT.isArch64Bit());
|
|
|
|
}
|