25
25
using namespace llvm ;
26
26
using namespace llvm ::codeview;
27
27
28
- CodeViewContext::~CodeViewContext () {
29
- // If someone inserted strings into the string table but never actually
30
- // emitted them somewhere, clean up the fragment.
31
- if (!InsertedStrTabFragment && StrTabFragment)
32
- StrTabFragment->destroy ();
28
+ void CodeViewContext::finish () {
29
+ if (StrTabFragment)
30
+ StrTabFragment->setContents (StrTab);
33
31
}
34
32
35
33
// / This is a valid number for use with .cv_loc if we've already seen a .cv_file
@@ -133,26 +131,15 @@ void CodeViewContext::recordCVLoc(MCContext &Ctx, const MCSymbol *Label,
133
131
Label, FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt});
134
132
}
135
133
136
- MCDataFragment *CodeViewContext::getStringTableFragment () {
137
- if (!StrTabFragment) {
138
- StrTabFragment = MCCtx->allocFragment <MCDataFragment>();
139
- // Start a new string table out with a null byte.
140
- StrTabFragment->appendContents (1 , ' \0 ' );
141
- }
142
- return StrTabFragment;
143
- }
144
-
145
134
std::pair<StringRef, unsigned > CodeViewContext::addToStringTable (StringRef S) {
146
- SmallVectorImpl<char > &Contents = getStringTableFragment ()->getContents ();
147
135
auto Insertion =
148
- StringTable.insert (std::make_pair (S, unsigned (Contents .size ())));
136
+ StringTable.insert (std::make_pair (S, unsigned (StrTab .size ())));
149
137
// Return the string from the table, since it is stable.
150
138
std::pair<StringRef, unsigned > Ret =
151
139
std::make_pair (Insertion.first ->first (), Insertion.first ->second );
152
140
if (Insertion.second ) {
153
141
// The string map key is always null terminated.
154
- StrTabFragment->appendContents (
155
- ArrayRef (Ret.first .begin (), Ret.first .end () + 1 ));
142
+ StrTab.append (Ret.first .begin (), Ret.first .end () + 1 );
156
143
}
157
144
return Ret;
158
145
}
@@ -178,9 +165,9 @@ void CodeViewContext::emitStringTable(MCObjectStreamer &OS) {
178
165
// Put the string table data fragment here, if we haven't already put it
179
166
// somewhere else. If somebody wants two string tables in their .s file, one
180
167
// will just be empty.
181
- if (!InsertedStrTabFragment ) {
182
- OS. insert ( getStringTableFragment () );
183
- InsertedStrTabFragment = true ;
168
+ if (!StrTabFragment ) {
169
+ StrTabFragment = Ctx. allocFragment <MCDataFragment>( );
170
+ OS. insert (StrTabFragment) ;
184
171
}
185
172
186
173
OS.emitValueToAlignment (Align (4 ), 0 );
@@ -375,11 +362,9 @@ void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS,
375
362
return Loc.getFileNum () != CurFileNum;
376
363
});
377
364
unsigned EntryCount = FileSegEnd - I;
378
- OS.AddComment (
379
- " Segment for file '" +
380
- Twine (getStringTableFragment ()
381
- ->getContents ()[Files[CurFileNum - 1 ].StringTableOffset ]) +
382
- " ' begins" );
365
+ OS.AddComment (" Segment for file '" +
366
+ Twine (StrTab[Files[CurFileNum - 1 ].StringTableOffset ]) +
367
+ " ' begins" );
383
368
OS.emitCVFileChecksumOffsetDirective (CurFileNum);
384
369
OS.emitInt32 (EntryCount);
385
370
uint32_t SegmentSize = 12 ;
0 commit comments