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