Kill the Mach-O writer, and temporarily make filetype=obj an error.
The MCStreamer based assemblers will take over for this functionality.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95033 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp
index 837e184..0c2fd8b 100644
--- a/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/lib/CodeGen/LLVMTargetMachine.cpp
@@ -115,10 +115,7 @@
       return FileModel::Error;
     return FileModel::AsmFile;
   case TargetMachine::ObjectFile:
-    if (!addObjectFileEmitter(PM, OptLevel, Out))
-      return FileModel::MachOFile;
-    else if (getELFWriterInfo())
-      return FileModel::ElfFile; 
+    return FileModel::Error;
   }
   return FileModel::Error;
 }
@@ -136,17 +133,6 @@
   return false;
 }
 
-bool LLVMTargetMachine::addObjectFileEmitter(PassManagerBase &PM,
-                                             CodeGenOpt::Level OptLevel,
-                                             formatted_raw_ostream &Out) {
-  MCCodeEmitter *Emitter = getTarget().createCodeEmitter(*this);
-  if (!Emitter)
-    return true;
-  
-  PM.add(createMachOWriter(Out, *this, getMCAsmInfo(), Emitter));
-  return false;
-}
-
 /// addPassesToEmitFileFinish - If the passes to emit the specified file had to
 /// be split up (e.g., to add an object writer pass), this method can be used to
 /// finish up adding passes to emit the file, if necessary.
@@ -194,8 +180,6 @@
   // Make sure the code model is set.
   setCodeModelForStatic();
   
-  if (OCE)
-    addSimpleCodeEmitter(PM, OptLevel, *OCE);
   if (PrintEmittedAsm)
     addAssemblyEmitter(PM, OptLevel, true, ferrs());
 
diff --git a/lib/CodeGen/MachOWriter.cpp b/lib/CodeGen/MachOWriter.cpp
deleted file mode 100644
index e8bbe21..0000000
--- a/lib/CodeGen/MachOWriter.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-//===-- MachOWriter.cpp - Target-independent Mach-O Writer code -----------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements the target-independent Mach-O writer.  This file writes
-// out the Mach-O file in the following order:
-//
-//  #1 FatHeader (universal-only)
-//  #2 FatArch (universal-only, 1 per universal arch)
-//  Per arch:
-//    #3 Header
-//    #4 Load Commands
-//    #5 Sections
-//    #6 Relocations
-//    #7 Symbols
-//    #8 Strings
-//
-//===----------------------------------------------------------------------===//
-
-#include "MachOWriter.h"
-#include "llvm/Function.h"
-#include "llvm/CodeGen/FileWriters.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/MC/MCAsmInfo.h"
-#include "llvm/MC/MCContext.h"
-#include "llvm/MC/MCCodeEmitter.h"
-#include "llvm/MC/MCInst.h"
-#include "llvm/MC/MCStreamer.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/Mangler.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetLowering.h"
-#include "llvm/Target/TargetLoweringObjectFile.h"
-using namespace llvm;
-
-namespace llvm { 
-MachineFunctionPass *createMachOWriter(formatted_raw_ostream &O,
-                                       TargetMachine &TM,
-                                       const MCAsmInfo *T, 
-                                       MCCodeEmitter *MCE) { 
-  return new MachOWriter(O, TM, T, MCE);
-}
-}
-
-//===----------------------------------------------------------------------===//
-//                          MachOWriter Implementation
-//===----------------------------------------------------------------------===//
-
-char MachOWriter::ID = 0;
-
-MachOWriter::MachOWriter(formatted_raw_ostream &o, TargetMachine &tm,
-                         const MCAsmInfo *T, MCCodeEmitter *MCE)
-  : MachineFunctionPass(&ID), O(o), TM(tm), MAI(T), MCCE(MCE),
-    OutContext(*new MCContext()),
-    OutStreamer(*createMachOStreamer(OutContext, O, MCCE)) { 
-}
-
-MachOWriter::~MachOWriter() {
-  delete &OutStreamer;
-  delete &OutContext;
-  delete MCCE;
-}
-
-bool MachOWriter::doInitialization(Module &M) {
-  // Initialize TargetLoweringObjectFile.
-  TM.getTargetLowering()->getObjFileLowering().Initialize(OutContext, TM);
-
-  return false;
-}
-
-/// doFinalization - Now that the module has been completely processed, emit
-/// the Mach-O file to 'O'.
-bool MachOWriter::doFinalization(Module &M) {
-  OutStreamer.Finish();
-  return false;
-}
-
-bool MachOWriter::runOnMachineFunction(MachineFunction &MF) {
-  const Function *F = MF.getFunction();
-  TargetLoweringObjectFile &TLOF = TM.getTargetLowering()->getObjFileLowering();
-  const MCSection *S = TLOF.SectionForGlobal(F, Mang, TM);
-  OutStreamer.SwitchSection(S);
-
-  for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
-       I != E; ++I) {
-    // Print a label for the basic block.
-    for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
-         II != IE; ++II) {
-      const MachineInstr *MI = II;
-      MCInst OutMI;
-      OutMI.setOpcode(MI->getOpcode());
-
-      for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
-        const MachineOperand &MO = MI->getOperand(i);
-        MCOperand MCOp;
-
-        switch (MO.getType()) {
-          default:
-            MI->dump();
-            llvm_unreachable("unknown operand type");
-          case MachineOperand::MO_Register:
-            // Ignore all implicit register operands.
-            if (MO.isImplicit()) continue;
-            MCOp = MCOperand::CreateReg(MO.getReg());
-            break;
-          case MachineOperand::MO_Immediate:
-            MCOp = MCOperand::CreateImm(MO.getImm());
-            break;
-        }
-        OutMI.addOperand(MCOp);
-      }
-      
-      OutStreamer.EmitInstruction(OutMI);
-    }
-  }
-
-  return false;
-}
diff --git a/lib/CodeGen/MachOWriter.h b/lib/CodeGen/MachOWriter.h
deleted file mode 100644
index 2e7e67d..0000000
--- a/lib/CodeGen/MachOWriter.h
+++ /dev/null
@@ -1,88 +0,0 @@
-//=== MachOWriter.h - Target-independent Mach-O writer support --*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines the MachOWriter class.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef MACHOWRITER_H
-#define MACHOWRITER_H
-
-#include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/Target/TargetMachine.h"
-
-namespace llvm {
-  class GlobalVariable;
-  class Mangler;
-  class MCCodeEmitter;
-  class MCContext;
-  class MCStreamer;
-  
-  /// MachOWriter - This class implements the common target-independent code for
-  /// writing Mach-O files.  Targets should derive a class from this to
-  /// parameterize the output format.
-  ///
-  class MachOWriter : public MachineFunctionPass {
-    static char ID;
-
-  protected:
-    /// Output stream to send the resultant object file to.
-    ///
-    formatted_raw_ostream &O;
-
-    /// Target machine description.
-    ///
-    TargetMachine &TM;
-
-    /// Target Asm Printer information.
-    ///
-    const MCAsmInfo *MAI;
-    
-    /// MCCE - The MCCodeEmitter object that we are exposing to emit machine
-    /// code for functions to the .o file.
-    MCCodeEmitter *MCCE;
-    
-    /// OutContext - This is the context for the output file that we are
-    /// streaming.  This owns all of the global MC-related objects for the
-    /// generated translation unit.
-    MCContext &OutContext;
-    
-    /// OutStreamer - This is the MCStreamer object for the file we are
-    /// generating.  This contains the transient state for the current
-    /// translation unit that we are generating (such as the current section
-    /// etc).
-    MCStreamer &OutStreamer;
-    
-    /// Name-mangler for global names.
-    ///
-    Mangler *Mang;
-    
-    /// doInitialization - Emit the file header and all of the global variables
-    /// for the module to the Mach-O file.
-    bool doInitialization(Module &M);
-
-    /// doFinalization - Now that the module has been completely processed, emit
-    /// the Mach-O file to 'O'.
-    bool doFinalization(Module &M);
-
-    bool runOnMachineFunction(MachineFunction &MF);
-    
-  public:
-    explicit MachOWriter(formatted_raw_ostream &O, TargetMachine &TM,
-                         const MCAsmInfo *T, MCCodeEmitter *MCE);
-    
-    virtual ~MachOWriter();
-    
-    virtual const char *getPassName() const {
-      return "Mach-O Writer";
-    }
-  };
-}
-
-#endif