change MCContext to always have an MCAsmInfo.
authorChris Lattner <sabre@nondot.org>
Thu, 11 Mar 2010 22:53:35 +0000 (22:53 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 11 Mar 2010 22:53:35 +0000 (22:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98293 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
lib/CodeGen/ELFWriter.cpp
lib/CodeGen/LLVMTargetMachine.cpp
lib/MC/MCContext.cpp
tools/edis/EDDisassembler.cpp
tools/llvm-mc/llvm-mc.cpp

index f2f1456c4a9a0c38a40eee6e99bb18c27701e6bf..c4f009ff05bd0cd81cfdc472c6e4d8714e20bfaa 100644 (file)
@@ -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<MCSection*> Sections;
 
     /// Symbols - Bindings of names to symbols.
     StringMap<MCSymbol*> 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
     /// @{
index 0979c04ea8aafa21340bb5b0de157ba91d9d9894..a748b8bb4cdc4746e1e71c3866af5e8cb6d8f41e 100644 (file)
@@ -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()),
index 23ef8ba7ce44fc3a71073192470dddfe6b27de48..0174d559125503a8359c94ce8d3d8d1ce4084e4b 100644 (file)
@@ -121,14 +121,14 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
   if (addCommonCodeGenPasses(PM, OptLevel, DisableVerify))
     return true;
 
-  OwningPtr<MCContext> Context(new MCContext());
+  const MCAsmInfo &MAI = *getMCAsmInfo();
+  OwningPtr<MCContext> Context(new MCContext(MAI));
   OwningPtr<MCStreamer> 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,
index cf8177c63a1bfc6655395932e680790e696800c0..46eb02f32cc1f26373a412e6267763ad4aa104f7 100644 (file)
@@ -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() {
index 99864fb322ca2d8519a123e023fb870b1bbe29fd..f2b2f91577542ba0e6abed7833cf9239c18c7c76 100644 (file)
@@ -341,19 +341,17 @@ int EDDisassembler::parseInst(SmallVectorImpl<MCParsedAsmOperand*> &operands,
   
   SourceMgr sourceMgr;
   sourceMgr.AddNewSourceBuffer(buf, SMLoc()); // ownership of buf handed over
-  MCContext context;
-  OwningPtr<MCStreamer> streamer
-    (createNullStreamer(context));
+  MCContext context(*AsmInfo);
+  OwningPtr<MCStreamer> streamer(createNullStreamer(context));
   AsmParser genericParser(sourceMgr, context, *streamer, *AsmInfo);
-  OwningPtr<TargetAsmParser> specificParser
-    (Tgt->createAsmParser(genericParser));
+  OwningPtr<TargetAsmParser> 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 {
index fa87238a029e35a2c54e6e9b2ad4d903ba948b17..b3c442e29ef4fe0c92866486bbecbc981fd3c0a4 100644 (file)
@@ -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<MCStreamer> Str;
   OwningPtr<TargetAsmBackend> 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)