]>
git.proxmox.com Git - rustc.git/blob - src/llvm/lib/MC/ConstantPools.cpp
1 //===- ConstantPools.cpp - ConstantPool class --*- C++ -*---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the ConstantPool and AssemblerConstantPools classes.
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"
21 // ConstantPool implementation
23 // Emit the contents of the constant pool using the provided streamer.
24 void ConstantPool::emitEntries(MCStreamer
&Streamer
) {
27 Streamer
.EmitDataRegion(MCDR_DataRegion
);
28 for (EntryVecTy::const_iterator I
= Entries
.begin(), E
= Entries
.end();
30 Streamer
.EmitCodeAlignment(I
->Size
); // align naturally
31 Streamer
.EmitLabel(I
->Label
);
32 Streamer
.EmitValue(I
->Value
, I
->Size
);
34 Streamer
.EmitDataRegion(MCDR_DataRegionEnd
);
38 const MCExpr
*ConstantPool::addEntry(const MCExpr
*Value
, MCContext
&Context
,
40 MCSymbol
*CPEntryLabel
= Context
.CreateTempSymbol();
42 Entries
.push_back(ConstantPoolEntry(CPEntryLabel
, Value
, Size
));
43 return MCSymbolRefExpr::Create(CPEntryLabel
, Context
);
46 bool ConstantPool::empty() { return Entries
.empty(); }
49 // AssemblerConstantPools implementation
52 AssemblerConstantPools::getConstantPool(const MCSection
*Section
) {
53 ConstantPoolMapTy::iterator CP
= ConstantPools
.find(Section
);
54 if (CP
== ConstantPools
.end())
61 AssemblerConstantPools::getOrCreateConstantPool(const MCSection
*Section
) {
62 return ConstantPools
[Section
];
65 static void emitConstantPool(MCStreamer
&Streamer
, const MCSection
*Section
,
68 Streamer
.SwitchSection(Section
);
69 CP
.emitEntries(Streamer
);
73 void AssemblerConstantPools::emitAll(MCStreamer
&Streamer
) {
74 // Dump contents of assembler constant pools.
75 for (ConstantPoolMapTy::iterator CPI
= ConstantPools
.begin(),
76 CPE
= ConstantPools
.end();
78 const MCSection
*Section
= CPI
->first
;
79 ConstantPool
&CP
= CPI
->second
;
81 emitConstantPool(Streamer
, Section
, CP
);
85 void AssemblerConstantPools::emitForCurrentSection(MCStreamer
&Streamer
) {
86 const MCSection
*Section
= Streamer
.getCurrentSection().first
;
87 if (ConstantPool
*CP
= getConstantPool(Section
)) {
88 emitConstantPool(Streamer
, Section
, *CP
);
92 const MCExpr
*AssemblerConstantPools::addEntry(MCStreamer
&Streamer
,
95 const MCSection
*Section
= Streamer
.getCurrentSection().first
;
96 return getOrCreateConstantPool(Section
).addEntry(Expr
, Streamer
.getContext(),