From c18409aed80ba1c6c5998befd3c3c8edc865c423 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 11 Mar 2010 22:53:35 +0000 Subject: [PATCH] change MCContext to always have an MCAsmInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98293 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 12 +++++++++++- lib/CodeGen/ELFWriter.cpp | 2 +- lib/CodeGen/LLVMTargetMachine.cpp | 4 ++-- lib/MC/MCContext.cpp | 2 +- tools/edis/EDDisassembler.cpp | 10 ++++------ tools/llvm-mc/llvm-mc.cpp | 9 +++++---- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index f2f1456c4a9..c4f009ff05b 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -15,6 +15,7 @@ #include "llvm/Support/Allocator.h" namespace llvm { + class MCAsmInfo; class MCExpr; class MCSection; class MCSymbol; @@ -28,20 +29,29 @@ namespace llvm { MCContext(const MCContext&); // DO NOT IMPLEMENT MCContext &operator=(const MCContext&); // DO NOT IMPLEMENT + /// The MCAsmInfo for this target. + const MCAsmInfo &MAI; + /// Sections - Bindings of names to allocated sections. StringMap Sections; /// Symbols - Bindings of names to symbols. StringMap Symbols; + /// NextUniqueID - The next ID to dole out to an unnamed assembler temporary + /// symbol. + unsigned NextUniqueID; + /// Allocator - Allocator object used for creating machine code objects. /// /// We use a bump pointer allocator to avoid the need to track all allocated /// objects. BumpPtrAllocator Allocator; public: - MCContext(); + MCContext(const MCAsmInfo &MAI); ~MCContext(); + + const MCAsmInfo &getAsmInfo() const { return MAI; } /// @name Symbol Managment /// @{ diff --git a/lib/CodeGen/ELFWriter.cpp b/lib/CodeGen/ELFWriter.cpp index 0979c04ea8a..a748b8bb4cd 100644 --- a/lib/CodeGen/ELFWriter.cpp +++ b/lib/CodeGen/ELFWriter.cpp @@ -64,7 +64,7 @@ char ELFWriter::ID = 0; ELFWriter::ELFWriter(raw_ostream &o, TargetMachine &tm) : MachineFunctionPass(&ID), O(o), TM(tm), - OutContext(*new MCContext()), + OutContext(*new MCContext(*TM.getMCAsmInfo())), TLOF(TM.getTargetLowering()->getObjFileLowering()), is64Bit(TM.getTargetData()->getPointerSizeInBits() == 64), isLittleEndian(TM.getTargetData()->isLittleEndian()), diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index 23ef8ba7ce4..0174d559125 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -121,14 +121,14 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, if (addCommonCodeGenPasses(PM, OptLevel, DisableVerify)) return true; - OwningPtr Context(new MCContext()); + const MCAsmInfo &MAI = *getMCAsmInfo(); + OwningPtr Context(new MCContext(MAI)); OwningPtr AsmStreamer; formatted_raw_ostream *LegacyOutput; switch (FileType) { default: return true; case CGFT_AssemblyFile: { - const MCAsmInfo &MAI = *getMCAsmInfo(); MCInstPrinter *InstPrinter = getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI, Out); AsmStreamer.reset(createAsmStreamer(*Context, Out, MAI, diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index cf8177c63a1..46eb02f32cc 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -14,7 +14,7 @@ #include "llvm/ADT/Twine.h" using namespace llvm; -MCContext::MCContext() { +MCContext::MCContext(const MCAsmInfo &mai) : MAI(mai), NextUniqueID(0) { } MCContext::~MCContext() { diff --git a/tools/edis/EDDisassembler.cpp b/tools/edis/EDDisassembler.cpp index 99864fb322c..f2b2f915775 100644 --- a/tools/edis/EDDisassembler.cpp +++ b/tools/edis/EDDisassembler.cpp @@ -341,19 +341,17 @@ int EDDisassembler::parseInst(SmallVectorImpl &operands, SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(buf, SMLoc()); // ownership of buf handed over - MCContext context; - OwningPtr streamer - (createNullStreamer(context)); + MCContext context(*AsmInfo); + OwningPtr streamer(createNullStreamer(context)); AsmParser genericParser(sourceMgr, context, *streamer, *AsmInfo); - OwningPtr specificParser - (Tgt->createAsmParser(genericParser)); + OwningPtr TargetParser(Tgt->createAsmParser(genericParser)); AsmToken OpcodeToken = genericParser.Lex(); if(OpcodeToken.is(AsmToken::Identifier)) { instName = OpcodeToken.getString(); instLoc = OpcodeToken.getLoc(); - if (specificParser->ParseInstruction(instName, instLoc, operands)) + if (TargetParser->ParseInstruction(instName, instLoc, operands)) ret = -1; } else { diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index fa87238a029..b3c442e29ef 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -242,7 +242,11 @@ static int AssembleInput(const char *ProgName) { // it later. SrcMgr.setIncludeDirs(IncludeDirs); - MCContext Ctx; + + const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); + assert(MAI && "Unable to create target asm info!"); + + MCContext Ctx(*MAI); formatted_raw_ostream *Out = GetOutputStream(); if (!Out) return 1; @@ -262,9 +266,6 @@ static int AssembleInput(const char *ProgName) { OwningPtr Str; OwningPtr TAB; - const MCAsmInfo *MAI = TheTarget->createAsmInfo(TripleName); - assert(MAI && "Unable to create target asm info!"); - if (FileType == OFT_AssemblyFile) { IP.reset(TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *Out)); if (ShowEncoding)