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, const MCTargetOptions &Options)
24 : MCAsmInfoELF(Options) {
25 IsLittleEndian = TT.isLittleEndian();
26 CodePointerSize = CalleeSaveStackSlotSize = TT.isArch64Bit() ? 8 : 4;
27 CommentString = "#";
28 AlignmentIsInBytes = false;
29 SupportsDebugInformation = true;
30 ExceptionsType = ExceptionHandling::DwarfCFI;
31 Data16bitsDirective = "\t.half\t";
32 Data32bitsDirective = "\t.word\t";
33 // The default symbol subtraction results in an ADD/SUB relocation pair.
34 // Processing this relocation pair is problematic when linker relaxation is
35 // enabled, so we follow binutils in using the R_RISCV_32_PCREL relocation
36 // for the FDE initial location.
37 DwarfFDERelSymbolSpec = ELF::R_RISCV_32_PCREL;
38}
39
40void RISCVMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
41 const MCSpecifierExpr &Expr) const {
42 auto S = Expr.getSpecifier();
43 bool HasSpecifier = S != RISCV::S_None && S != RISCV::S_CALL_PLT;
44 if (HasSpecifier)
45 OS << '%' << RISCV::getSpecifierName(Kind: S) << '(';
46 printExpr(OS, *Expr.getSubExpr());
47 if (HasSpecifier)
48 OS << ')';
49}
50
51RISCVMCAsmInfoDarwin::RISCVMCAsmInfoDarwin(const MCTargetOptions &Options)
52 : MCAsmInfoDarwin(Options) {
53 CodePointerSize = 4;
54 InternalSymbolPrefix = "L";
55 SeparatorString = "%%";
56 CommentString = ";";
57 AlignmentIsInBytes = false;
58 SupportsDebugInformation = true;
59 UseDataRegionDirectives = true;
60 ExceptionsType = ExceptionHandling::DwarfCFI;
61 Data16bitsDirective = "\t.half\t";
62 Data32bitsDirective = "\t.word\t";
63}
64
65void RISCVMCAsmInfoDarwin::printSpecifierExpr(
66 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
67 auto S = Expr.getSpecifier();
68 bool HasSpecifier = S != RISCV::S_None && S != RISCV::S_CALL_PLT;
69 if (HasSpecifier)
70 OS << '%' << RISCV::getSpecifierName(Kind: S) << '(';
71 printExpr(OS, *Expr.getSubExpr());
72 if (HasSpecifier)
73 OS << ')';
74}
75