xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Sparc/MCTargetDesc/SparcMCAsmInfo.cpp (revision a7623790fb345e6dc986dfd31df0ace115e6f2e4)
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 "SparcMCExpr.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/BinaryFormat/Dwarf.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCStreamer.h"
19 #include "llvm/MC/MCTargetOptions.h"
20 
21 using namespace llvm;
22 
23 void SparcELFMCAsmInfo::anchor() {}
24 
25 SparcELFMCAsmInfo::SparcELFMCAsmInfo(const Triple &TheTriple) {
26   bool isV9 = (TheTriple.getArch() == Triple::sparcv9);
27   IsLittleEndian = (TheTriple.getArch() == Triple::sparcel);
28 
29   if (isV9) {
30     CodePointerSize = CalleeSaveStackSlotSize = 8;
31   }
32 
33   Data16bitsDirective = "\t.half\t";
34   Data32bitsDirective = "\t.word\t";
35   // .xword is only supported by V9.
36   Data64bitsDirective = (isV9) ? "\t.xword\t" : nullptr;
37   ZeroDirective = "\t.skip\t";
38   CommentString = "!";
39   SupportsDebugInformation = true;
40 
41   ExceptionsType = ExceptionHandling::DwarfCFI;
42 
43   SunStyleELFSectionSwitchSyntax = true;
44   UsesELFSectionDirectiveForBSS = true;
45 }
46 
47 const MCExpr*
48 SparcELFMCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
49                                                unsigned Encoding,
50                                                MCStreamer &Streamer) const {
51   if (Encoding & dwarf::DW_EH_PE_pcrel) {
52     MCContext &Ctx = Streamer.getContext();
53     return SparcMCExpr::create(SparcMCExpr::VK_Sparc_R_DISP32,
54                                MCSymbolRefExpr::create(Sym, Ctx), Ctx);
55   }
56 
57   return MCAsmInfo::getExprForPersonalitySymbol(Sym, Encoding, Streamer);
58 }
59 
60 const MCExpr*
61 SparcELFMCAsmInfo::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 SparcMCExpr::create(SparcMCExpr::VK_Sparc_R_DISP32,
67                                MCSymbolRefExpr::create(Sym, Ctx), Ctx);
68   }
69   return MCAsmInfo::getExprForFDESymbol(Sym, Encoding, Streamer);
70 }
71