Coverage Report

Created: 2026-06-08 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/lib/MC/ConstantPools.cpp
Line
Count
Source
1
//===- ConstantPools.cpp - ConstantPool class --*- C++ -*---------===//
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 implements the ConstantPool and  AssemblerConstantPools classes.
11
//
12
//===----------------------------------------------------------------------===//
13
#include "llvm/ADT/MapVector.h"
14
#include "llvm/MC/ConstantPools.h"
15
#include "llvm/MC/MCContext.h"
16
#include "llvm/MC/MCExpr.h"
17
#include "llvm/MC/MCStreamer.h"
18
19
using namespace llvm_ks;
20
//
21
// ConstantPool implementation
22
//
23
// Emit the contents of the constant pool using the provided streamer.
24
449
void ConstantPool::emitEntries(MCStreamer &Streamer) {
25
449
  if (Entries.empty())
26
0
    return;
27
449
  Streamer.EmitDataRegion(MCDR_DataRegion);
28
449
  for (EntryVecTy::const_iterator I = Entries.begin(), E = Entries.end();
29
5.59k
       I != E; ++I) {
30
5.14k
    Streamer.EmitCodeAlignment(I->Size); // align naturally
31
5.14k
    Streamer.EmitLabel(I->Label);
32
5.14k
    Streamer.EmitValue(I->Value, I->Size, I->Loc);
33
5.14k
  }
34
449
  Streamer.EmitDataRegion(MCDR_DataRegionEnd);
35
449
  Entries.clear();
36
449
}
37
38
const MCExpr *ConstantPool::addEntry(const MCExpr *Value, MCContext &Context,
39
7.35k
                                     unsigned Size, SMLoc Loc) {
40
7.35k
  MCSymbol *CPEntryLabel = Context.createTempSymbol();
41
42
7.35k
  Entries.push_back(ConstantPoolEntry(CPEntryLabel, Value, Size, Loc));
43
7.35k
  return MCSymbolRefExpr::create(CPEntryLabel, Context);
44
7.35k
}
45
46
681
bool ConstantPool::empty() { return Entries.empty(); }
47
48
//
49
// AssemblerConstantPools implementation
50
//
51
3.35k
ConstantPool *AssemblerConstantPools::getConstantPool(MCSection *Section) {
52
3.35k
  ConstantPoolMapTy::iterator CP = ConstantPools.find(Section);
53
3.35k
  if (CP == ConstantPools.end())
54
3.07k
    return nullptr;
55
56
272
  return &CP->second;
57
3.35k
}
58
59
ConstantPool &
60
7.35k
AssemblerConstantPools::getOrCreateConstantPool(MCSection *Section) {
61
7.35k
  return ConstantPools[Section];
62
7.35k
}
63
64
static void emitConstantPool(MCStreamer &Streamer, MCSection *Section,
65
681
                             ConstantPool &CP) {
66
681
  if (!CP.empty()) {
67
449
    Streamer.SwitchSection(Section);
68
449
    CP.emitEntries(Streamer);
69
449
  }
70
681
}
71
72
34.3k
void AssemblerConstantPools::emitAll(MCStreamer &Streamer) {
73
  // Dump contents of assembler constant pools.
74
34.3k
  for (ConstantPoolMapTy::iterator CPI = ConstantPools.begin(),
75
34.3k
                                   CPE = ConstantPools.end();
76
34.7k
       CPI != CPE; ++CPI) {
77
409
    MCSection *Section = CPI->first;
78
409
    ConstantPool &CP = CPI->second;
79
80
409
    emitConstantPool(Streamer, Section, CP);
81
409
  }
82
34.3k
}
83
84
3.35k
void AssemblerConstantPools::emitForCurrentSection(MCStreamer &Streamer) {
85
3.35k
  MCSection *Section = Streamer.getCurrentSection().first;
86
3.35k
  if (ConstantPool *CP = getConstantPool(Section)) {
87
272
    emitConstantPool(Streamer, Section, *CP);
88
272
  }
89
3.35k
}
90
91
const MCExpr *AssemblerConstantPools::addEntry(MCStreamer &Streamer,
92
                                               const MCExpr *Expr,
93
7.35k
                                               unsigned Size, SMLoc Loc) {
94
7.35k
  MCSection *Section = Streamer.getCurrentSection().first;
95
7.35k
  return getOrCreateConstantPool(Section).addEntry(Expr, Streamer.getContext(),
96
7.35k
                                                   Size, Loc);
97
7.35k
}