2525using namespace llvm ;
2626using namespace llvm ::codeview;
2727
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);
3331}
3432
3533// / 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,
133131 Label, FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt});
134132}
135133
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-
145134std::pair<StringRef, unsigned > CodeViewContext::addToStringTable (StringRef S) {
146- SmallVectorImpl<char > &Contents = getStringTableFragment ()->getContents ();
147135 auto Insertion =
148- StringTable.insert (std::make_pair (S, unsigned (Contents .size ())));
136+ StringTable.insert (std::make_pair (S, unsigned (StrTab .size ())));
149137 // Return the string from the table, since it is stable.
150138 std::pair<StringRef, unsigned > Ret =
151139 std::make_pair (Insertion.first ->first (), Insertion.first ->second );
152140 if (Insertion.second ) {
153141 // 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 );
156143 }
157144 return Ret;
158145}
@@ -178,9 +165,9 @@ void CodeViewContext::emitStringTable(MCObjectStreamer &OS) {
178165 // Put the string table data fragment here, if we haven't already put it
179166 // somewhere else. If somebody wants two string tables in their .s file, one
180167 // 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) ;
184171 }
185172
186173 OS.emitValueToAlignment (Align (4 ), 0 );
@@ -375,11 +362,9 @@ void CodeViewContext::emitLineTableForFunction(MCObjectStreamer &OS,
375362 return Loc.getFileNum () != CurFileNum;
376363 });
377364 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" );
383368 OS.emitCVFileChecksumOffsetDirective (CurFileNum);
384369 OS.emitInt32 (EntryCount);
385370 uint32_t SegmentSize = 12 ;
0 commit comments