llvm.org GIT mirror llvm / 99cfb5c
dwarfgen: Don't create an AsmPrinter with an invalid ObjFile lowering The AsmPrinter created in the tests contained an uninitialized TargetLoweringObjectFile. Things mostly worked regardless, because we used a separate instance of that class to specify sections to emit. This rearanges the object construction order so that we can avoid creating two lowering objects. Instead, we properly initialize the object in the AsmPrinter, and have the DWARF generator store a pointer to it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338026 91177308-0d34-0410-b5e6-96231b3b80d8 Pavel Labath 1 year, 2 months ago
2 changed file(s) with 18 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
2929 #include "llvm/PassAnalysisSupport.h"
3030 #include "llvm/Support/TargetRegistry.h"
3131 #include "llvm/Support/raw_ostream.h"
32 #include "llvm/Target/TargetLoweringObjectFile.h"
3233 #include "llvm/Target/TargetMachine.h"
3334 #include "llvm/Target/TargetOptions.h"
3435
371372 return make_error("no asm info for target " + TripleName,
372373 inconvertibleErrorCode());
373374
374 MOFI.reset(new MCObjectFileInfo);
375 MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
376 MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC);
377
378375 MSTI.reset(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
379376 if (!MSTI)
380377 return make_error("no subtarget info for target " + TripleName,
391388 return make_error("no instr info info for target " +
392389 TripleName,
393390 inconvertibleErrorCode());
391
392 TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
393 None));
394 if (!TM)
395 return make_error("no target machine for target " + TripleName,
396 inconvertibleErrorCode());
397
398 TLOF = TM->getObjFileLowering();
399 MC.reset(new MCContext(MAI.get(), MRI.get(), TLOF));
400 TLOF->Initialize(*MC, *TM);
394401
395402 MCE = TheTarget->createMCCodeEmitter(*MII, *MRI, *MC);
396403 if (!MCE)
409416 TripleName,
410417 inconvertibleErrorCode());
411418
419
412420 // Finally create the AsmPrinter we'll use to emit the DIEs.
413 TM.reset(TheTarget->createTargetMachine(TripleName, "", "", TargetOptions(),
414 None));
415 if (!TM)
416 return make_error("no target machine for target " + TripleName,
417 inconvertibleErrorCode());
418
419421 Asm.reset(TheTarget->createAsmPrinter(*TM, std::unique_ptr(MS)));
420422 if (!Asm)
421423 return make_error("no asm printer for target " + TripleName,
446448 SecOffset += CUOffset;
447449 CU->setLength(CUOffset - 4);
448450 }
449 Abbreviations.Emit(Asm.get(), MOFI->getDwarfAbbrevSection());
450 StringPool->emit(*Asm, MOFI->getDwarfStrSection());
451 MS->SwitchSection(MOFI->getDwarfInfoSection());
451 Abbreviations.Emit(Asm.get(), TLOF->getDwarfAbbrevSection());
452 StringPool->emit(*Asm, TLOF->getDwarfStrSection());
453 MS->SwitchSection(TLOF->getDwarfInfoSection());
452454 for (auto &CU : CompileUnits) {
453455 uint16_t Version = CU->getVersion();
454456 auto Length = CU->getLength();
467469 Asm->emitDwarfDIE(*CU->getUnitDIE().Die);
468470 }
469471
470 MS->SwitchSection(MOFI->getDwarfLineSection());
472 MS->SwitchSection(TLOF->getDwarfLineSection());
471473 for (auto < : LineTables)
472474 LT->generate(*MC, *Asm);
473475
3535 class MCContext;
3636 struct MCDwarfLineTableParams;
3737 class MCInstrInfo;
38 class MCObjectFileInfo;
3938 class MCRegisterInfo;
4039 class MCStreamer;
4140 class MCSubtargetInfo;
4241 class raw_fd_ostream;
42 class TargetLoweringObjectFile;
4343 class TargetMachine;
4444 class Triple;
4545
226226 class Generator {
227227 std::unique_ptr MRI;
228228 std::unique_ptr MAI;
229 std::unique_ptr MOFI;
230229 std::unique_ptr MC;
231230 MCAsmBackend *MAB; // Owned by MCStreamer
232231 std::unique_ptr MII;
234233 MCCodeEmitter *MCE; // Owned by MCStreamer
235234 MCStreamer *MS; // Owned by AsmPrinter
236235 std::unique_ptr TM;
236 TargetLoweringObjectFile *TLOF; // Owned by TargetMachine;
237237 std::unique_ptr Asm;
238238 BumpPtrAllocator Allocator;
239239 std::unique_ptr StringPool; // Entries owned by Allocator.