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-exception
6//
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 is
43 // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation
44 // for the FDE initial location.
45 MCContext &Ctx = Streamer.getContext();
46 const MCExpr *ME = MCSymbolRefExpr::create(Symbol: Sym, Ctx);
47 assert(Encoding & dwarf::DW_EH_PE_sdata4 && "Unexpected encoding");
48 return MCSpecifierExpr::create(Expr: ME, S: 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 != RISCV::S_None && S != RISCV::S_CALL_PLT;
55 if (HasSpecifier)
56 OS << '%' << RISCV::getSpecifierName(Kind: S) << '(';
57 printExpr(OS, *Expr.getSubExpr());
58 if (HasSpecifier)
59 OS << ')';
60}
61
62RISCVMCAsmInfoDarwin::RISCVMCAsmInfoDarwin() {
63 CodePointerSize = 4;
64 PrivateGlobalPrefix = "L";
65 PrivateLabelPrefix = "L";
66 SeparatorString = "%%";
67 CommentString = ";";
68 AlignmentIsInBytes = false;
69 SupportsDebugInformation = true;
70 UseDataRegionDirectives = true;
71 ExceptionsType = ExceptionHandling::DwarfCFI;
72 Data16bitsDirective = "\t.half\t";
73 Data32bitsDirective = "\t.word\t";
74}
75
76void RISCVMCAsmInfoDarwin::printSpecifierExpr(
77 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
78 auto S = Expr.getSpecifier();
79 bool HasSpecifier = S != RISCV::S_None && S != RISCV::S_CALL_PLT;
80 if (HasSpecifier)
81 OS << '%' << RISCV::getSpecifierName(Kind: S) << '(';
82 printExpr(OS, *Expr.getSubExpr());
83 if (HasSpecifier)
84 OS << ')';
85}
86