Coverage Report

Created: 2025-11-16 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/lib/MC/MCAsmInfo.cpp
Line
Count
Source
1
//===-- MCAsmInfo.cpp - Asm Info -------------------------------------------==//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file defines target asm properties related what form asm statements
11
// should take.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#include "llvm/MC/MCAsmInfo.h"
16
#include "llvm/MC/MCContext.h"
17
#include "llvm/MC/MCExpr.h"
18
#include "llvm/MC/MCStreamer.h"
19
#include "llvm/Support/DataTypes.h"
20
#include "llvm/Support/Dwarf.h"
21
#include <cctype>
22
#include <cstring>
23
using namespace llvm_ks;
24
25
117k
MCAsmInfo::MCAsmInfo() {
26
117k
  PointerSize = 4;
27
117k
  CalleeSaveStackSlotSize = 4;
28
29
117k
  IsLittleEndian = true;
30
117k
  StackGrowsUp = false;
31
117k
  HasSubsectionsViaSymbols = false;
32
117k
  HasMachoZeroFillDirective = false;
33
117k
  HasMachoTBSSDirective = false;
34
117k
  HasStaticCtorDtorReferenceInStaticMode = false;
35
117k
  MaxInstLength = 4;
36
117k
  MinInstAlignment = 1;
37
117k
  DollarIsPC = false;
38
117k
  SeparatorString = ";";
39
117k
  CommentString = "#";
40
117k
  LabelSuffix = ":";
41
117k
  UseAssignmentForEHBegin = false;
42
117k
  NeedsLocalForSize = false;
43
117k
  PrivateGlobalPrefix = "L";
44
117k
  PrivateLabelPrefix = PrivateGlobalPrefix;
45
117k
  LinkerPrivateGlobalPrefix = "";
46
117k
  InlineAsmStart = "APP";
47
117k
  InlineAsmEnd = "NO_APP";
48
117k
  Code16Directive = ".code16";
49
117k
  Code32Directive = ".code32";
50
117k
  Code64Directive = ".code64";
51
117k
  AssemblerDialect = 0;
52
117k
  AllowAtInName = false;
53
117k
  SupportsQuotedNames = true;
54
117k
  UseDataRegionDirectives = false;
55
117k
  ZeroDirective = "\t.zero\t";
56
117k
  AsciiDirective = "\t.ascii\t";
57
117k
  AscizDirective = "\t.asciz\t";
58
117k
  Data8bitsDirective = "\t.byte\t";
59
117k
  Data16bitsDirective = "\t.short\t";
60
117k
  Data32bitsDirective = "\t.long\t";
61
117k
  Data64bitsDirective = "\t.quad\t";
62
117k
  SunStyleELFSectionSwitchSyntax = false;
63
117k
  UsesELFSectionDirectiveForBSS = false;
64
117k
  AlignmentIsInBytes = true;
65
117k
  TextAlignFillValue = 0;
66
117k
  GPRel64Directive = nullptr;
67
117k
  GPRel32Directive = nullptr;
68
117k
  GlobalDirective = "\t.globl\t";
69
117k
  SetDirectiveSuppressesReloc = false;
70
117k
  HasAggressiveSymbolFolding = true;
71
117k
  COMMDirectiveAlignmentIsInBytes = true;
72
117k
  LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
73
117k
  HasFunctionAlignment = true;
74
117k
  HasDotTypeDotSizeDirective = true;
75
117k
  HasSingleParameterDotFile = true;
76
117k
  HasIdentDirective = false;
77
117k
  HasNoDeadStrip = false;
78
117k
  WeakDirective = "\t.weak\t";
79
117k
  WeakRefDirective = nullptr;
80
117k
  HasWeakDefDirective = false;
81
117k
  HasWeakDefCanBeHiddenDirective = false;
82
117k
  HasLinkOnceDirective = false;
83
117k
  HiddenVisibilityAttr = MCSA_Hidden;
84
117k
  HiddenDeclarationVisibilityAttr = MCSA_Hidden;
85
117k
  ProtectedVisibilityAttr = MCSA_Protected;
86
117k
  SupportsDebugInformation = false;
87
117k
  ExceptionsType = ExceptionHandling::None;
88
117k
  WinEHEncodingType = WinEH::EncodingType::Invalid;
89
117k
  DwarfUsesRelocationsAcrossSections = true;
90
117k
  DwarfFDESymbolsUseAbsDiff = false;
91
117k
  DwarfRegNumForCFI = false;
92
117k
  NeedsDwarfSectionOffsetDirective = false;
93
117k
  UseParensForSymbolVariant = false;
94
117k
  UseLogicalShr = true;
95
96
  // FIXME: Clang's logic should be synced with the logic used to initialize
97
  //        this member and the two implementations should be merged.
98
  // For reference:
99
  // - Solaris always enables the integrated assembler by default
100
  //   - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case
101
  // - Windows always enables the integrated assembler by default
102
  //   - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft?
103
  // - MachO targets always enables the integrated assembler by default
104
  //   - MCAsmInfoDarwin is handling this case
105
  // - Generic_GCC toolchains enable the integrated assembler on a per
106
  //   architecture basis.
107
  //   - The target subclasses for AArch64, ARM, and X86 handle these cases
108
117k
  UseIntegratedAssembler = false;
109
110
117k
  CompressDebugSections = false;
111
117k
}
112
113
117k
MCAsmInfo::~MCAsmInfo() {
114
117k
}
115
116
0
bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
117
0
  return false;
118
0
}
119
120
const MCExpr *
121
MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
122
                                       unsigned Encoding,
123
0
                                       MCStreamer &Streamer) const {
124
0
  return getExprForFDESymbol(Sym, Encoding, Streamer);
125
0
}
126
127
const MCExpr *
128
MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym,
129
                               unsigned Encoding,
130
0
                               MCStreamer &Streamer) const {
131
0
  if (!(Encoding & dwarf::DW_EH_PE_pcrel))
132
0
    return MCSymbolRefExpr::create(Sym, Streamer.getContext());
133
134
0
  MCContext &Context = Streamer.getContext();
135
0
  const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context);
136
0
  MCSymbol *PCSym = Context.createTempSymbol();
137
0
  Streamer.EmitLabel(PCSym);
138
0
  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context);
139
0
  return MCBinaryExpr::createSub(Res, PC, Context);
140
0
}
141
142
0
static bool isAcceptableChar(char C) {
143
0
  return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') ||
144
0
         (C >= '0' && C <= '9') || C == '_' || C == '$' || C == '.' || C == '@';
145
0
}
146
147
0
bool MCAsmInfo::isValidUnquotedName(StringRef Name) const {
148
0
  if (Name.empty())
149
0
    return false;
150
151
  // If any of the characters in the string is an unacceptable character, force
152
  // quotes.
153
0
  for (char C : Name) {
154
0
    if (!isAcceptableChar(C))
155
0
      return false;
156
0
  }
157
158
0
  return true;
159
0
}
160
161
0
bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const {
162
  // FIXME: Does .section .bss/.data/.text work everywhere??
163
0
  return SectionName == ".text" || SectionName == ".data" ||
164
0
        (SectionName == ".bss" && !usesELFSectionDirectiveForBSS());
165
0
}