1//===-- SystemZMCAsmInfo.cpp - SystemZ 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#include "SystemZMCAsmInfo.h"
10#include "llvm/ADT/Enum.h"
11#include "llvm/MC/MCContext.h"
12#include "llvm/MC/MCExpr.h"
13#include "llvm/MC/MCValue.h"
14
15using namespace llvm;
16
17constexpr EnumStringDef<MCAsmInfo::AtSpecifierKind> AtSpecifierDefs[] = {
18 {.Names: {"DTPOFF"}, .Value: SystemZ::S_DTPOFF}, {.Names: {"GOT"}, .Value: SystemZ::S_GOT},
19 {.Names: {"GOTENT"}, .Value: SystemZ::S_GOTENT}, {.Names: {"INDNTPOFF"}, .Value: SystemZ::S_INDNTPOFF},
20 {.Names: {"NTPOFF"}, .Value: SystemZ::S_NTPOFF}, {.Names: {"PLT"}, .Value: SystemZ::S_PLT},
21 {.Names: {"TLSGD"}, .Value: SystemZ::S_TLSGD}, {.Names: {"TLSLD"}, .Value: SystemZ::S_TLSLD},
22 {.Names: {"TLSLDM"}, .Value: SystemZ::S_TLSLDM},
23};
24constexpr auto atSpecifiers = BUILD_ENUM_STRINGS(AtSpecifierDefs);
25
26SystemZMCAsmInfoELF::SystemZMCAsmInfoELF(const Triple &TT,
27 const MCTargetOptions &Options)
28 : MCAsmInfoELF(Options) {
29 AssemblerDialect = AD_GNU;
30 CalleeSaveStackSlotSize = 8;
31 CodePointerSize = 8;
32 Data64bitsDirective = "\t.quad\t";
33 IsLittleEndian = false;
34 MaxInstLength = 6;
35 SupportsDebugInformation = true;
36 UsesELFSectionDirectiveForBSS = true;
37 ZeroDirective = "\t.space\t";
38
39 initializeAtSpecifiers(atSpecifiers);
40}
41
42SystemZMCAsmInfoGOFF::SystemZMCAsmInfoGOFF(const Triple &TT,
43 const MCTargetOptions &Options)
44 : MCAsmInfoGOFF(Options) {
45 AllowAdditionalComments = false;
46 AllowAtInName = true;
47 AllowAtAtStartOfIdentifier = true;
48 AllowDollarAtStartOfIdentifier = true;
49 AssemblerDialect = AD_HLASM;
50 CalleeSaveStackSlotSize = 8;
51 CodePointerSize = 8;
52 CommentString = "*";
53 UsesSetToEquateSymbol = true;
54 IsHLASM = true;
55 IsLittleEndian = false;
56 MaxInstLength = 6;
57 SupportsDebugInformation = true;
58
59 initializeAtSpecifiers(atSpecifiers);
60}
61
62const MCExpr *SystemZMCAsmInfoGOFF::getDwarfSectionOffsetExpr(
63 const MCSymbol *Sym, uint64_t Offset, MCContext &Ctx) const {
64 const MCExpr *Expr = MCSpecifierExpr::create(Sym, S: SystemZ::S_QCon, Ctx);
65 if (Offset)
66 Expr =
67 MCBinaryExpr::createAdd(LHS: Expr, RHS: MCConstantExpr::create(Value: Offset, Ctx), Ctx);
68 return Expr;
69}
70
71void SystemZMCAsmInfoGOFF::printSpecifierExpr(
72 raw_ostream &OS, const MCSpecifierExpr &Expr) const {
73 switch (Expr.getSpecifier()) {
74 case SystemZ::S_None:
75 OS << "AD";
76 break;
77 case SystemZ::S_QCon:
78 OS << "QD";
79 break;
80 case SystemZ::S_RCon:
81 OS << "RD";
82 break;
83 case SystemZ::S_VCon:
84 OS << "VD";
85 break;
86 default:
87 llvm_unreachable("Invalid kind");
88 }
89 OS << '(';
90 printExpr(OS, *Expr.getSubExpr());
91 OS << ')';
92}
93
94bool SystemZMCAsmInfoGOFF::evaluateAsRelocatableImpl(
95 const MCSpecifierExpr &Expr, MCValue &Res, const MCAssembler *Asm) const {
96 if (!Expr.getSubExpr()->evaluateAsRelocatable(Res, Asm))
97 return false;
98 Res.setSpecifier(Expr.getSpecifier());
99 return true;
100}
101