61 lines · cpp
1//===-- RISCVMCAsmInfo.cpp - RISC-V Asm properties ------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8//9// This file contains the declarations of the RISCVMCAsmInfo properties.10//11//===----------------------------------------------------------------------===//12 13#include "RISCVMCAsmInfo.h"14#include "llvm/BinaryFormat/Dwarf.h"15#include "llvm/BinaryFormat/ELF.h"16#include "llvm/MC/MCExpr.h"17#include "llvm/MC/MCStreamer.h"18#include "llvm/TargetParser/Triple.h"19using namespace llvm;20 21void RISCVMCAsmInfo::anchor() {}22 23RISCVMCAsmInfo::RISCVMCAsmInfo(const Triple &TT) {24 IsLittleEndian = TT.isLittleEndian();25 CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;26 CommentString = "#";27 AlignmentIsInBytes = false;28 SupportsDebugInformation = true;29 ExceptionsType = ExceptionHandling::DwarfCFI;30 UseAtForSpecifier = false;31 Data16bitsDirective = "\t.half\t";32 Data32bitsDirective = "\t.word\t";33}34 35const MCExpr *RISCVMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,36 unsigned Encoding,37 MCStreamer &Streamer) const {38 if (!(Encoding & dwarf::DW_EH_PE_pcrel))39 return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);40 41 // The default symbol subtraction results in an ADD/SUB relocation pair.42 // Processing this relocation pair is problematic when linker relaxation is43 // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation44 // for the FDE initial location.45 MCContext &Ctx = Streamer.getContext();46 const MCExpr *ME = MCSymbolRefExpr::create(Sym, Ctx);47 assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding");48 return MCSpecifierExpr::create(ME, ELF::R_RISCV_32_PCREL, Ctx);49}50 51void RISCVMCAsmInfo::printSpecifierExpr(raw_ostream &OS,52 const MCSpecifierExpr &Expr) const {53 auto S = Expr.getSpecifier();54 bool HasSpecifier = S != 0 && S != ELF::R_RISCV_CALL_PLT;55 if (HasSpecifier)56 OS << '%' << RISCV::getSpecifierName(S) << '(';57 printExpr(OS, *Expr.getSubExpr());58 if (HasSpecifier)59 OS << ')';60}61