1//===- SparcMCAsmInfo.cpp - Sparc 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 SparcMCAsmInfo properties.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SparcMCAsmInfo.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/MC/MCTargetOptions.h"
19#include "llvm/TargetParser/Triple.h"
20
21using namespace llvm;
22
23void SparcELFMCAsmInfo::anchor() {}
24
25SparcELFMCAsmInfo::SparcELFMCAsmInfo(const Triple &TheTriple,
26 const MCTargetOptions &Options)
27 : MCAsmInfoELF(Options) {
28 bool isV9 = (TheTriple.getArch() == Triple::sparcv9);
29 IsLittleEndian = (TheTriple.getArch() == Triple::sparcel);
30
31 if (isV9) {
32 CodePointerSize = CalleeSaveStackSlotSize = 8;
33 }
34
35 Data16bitsDirective = "\t.half\t";
36 Data32bitsDirective = "\t.word\t";
37 // .xword is only supported by V9.
38 Data64bitsDirective = (isV9) ? "\t.xword\t" : nullptr;
39 ZeroDirective = "\t.skip\t";
40 CommentString = "!";
41 SupportsDebugInformation = true;
42
43 ExceptionsType = ExceptionHandling::DwarfCFI;
44
45 UsesELFSectionDirectiveForBSS = true;
46}
47
48const MCExpr*
49SparcELFMCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
50 unsigned Encoding,
51 MCStreamer &Streamer) const {
52 if (Encoding & dwarf::DW_EH_PE_pcrel) {
53 MCContext &Ctx = Streamer.getContext();
54 return MCSpecifierExpr::create(Sym, S: ELF::R_SPARC_DISP32, Ctx);
55 }
56
57 return MCAsmInfo::getExprForPersonalitySymbol(Sym, Encoding, Streamer);
58}
59
60const MCExpr*
61SparcELFMCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
62 unsigned Encoding,
63 MCStreamer &Streamer) const {
64 if (Encoding & dwarf::DW_EH_PE_pcrel) {
65 MCContext &Ctx = Streamer.getContext();
66 return MCSpecifierExpr::create(Sym, S: ELF::R_SPARC_DISP32, Ctx);
67 }
68 return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);
69}
70
71void SparcELFMCAsmInfo::printSpecifierExpr(raw_ostream &OS,
72 const MCSpecifierExpr &Expr) const {
73 StringRef S = Sparc::getSpecifierName(S: Expr.getSpecifier());
74 if (!S.empty())
75 OS << '%' << S << '(';
76 printExpr(OS, *Expr.getSubExpr());
77 if (!S.empty())
78 OS << ')';
79}
80