llvm-mc: Start MCAssembler and MCMachOStreamer.

 - Together these form the (Mach-O) back end of the assembler.

 - MCAssembler is the actual assembler backend, which is designed to have a
   reasonable API. This will eventually grow to support multiple object file
   implementations, but for now its Mach-O/i386 only.

 - MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
   e.g. converting the various directives into fragments, managing state like
   the current section, and so on.

 - llvm-mc will use the new backend via '-filetype=obj', which may eventually
   be, but is not yet, since I hear that people like assemblers which actually
   assemble.

 - The only thing that works at the moment is changing sections. For the time
   being I have a Python Mach-O dumping tool in test/scripts so this stuff can
   be easily tested, eventually I expect to replace this with a real LLVM tool.

 - More doxyments to come.

I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79612 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp
index fcbf944..302ddb1 100644
--- a/tools/llvm-mc/llvm-mc.cpp
+++ b/tools/llvm-mc/llvm-mc.cpp
@@ -38,6 +38,20 @@
 OutputFilename("o", cl::desc("Output filename"),
                cl::value_desc("filename"));
 
+enum OutputFileType {
+  OFT_AssemblyFile,
+  OFT_ObjectFile
+};
+static cl::opt<OutputFileType>
+FileType("filetype", cl::init(OFT_AssemblyFile),
+  cl::desc("Choose an output file type:"),
+  cl::values(
+       clEnumValN(OFT_AssemblyFile, "asm",
+                  "Emit an assembly ('.s') file"),
+       clEnumValN(OFT_ObjectFile, "obj",
+                  "Emit a native object ('.o') file"),
+       clEnumValEnd));
+
 static cl::opt<bool>
 Force("f", cl::desc("Overwrite output files"));
 
@@ -221,11 +235,19 @@
     return 1;
   }
 
-  const TargetAsmInfo *TAI = TheTarget->createAsmInfo(TripleName);
-  assert(TAI && "Unable to create target asm info!");
+  OwningPtr<AsmPrinter> AP;
+  OwningPtr<MCStreamer> Str;
 
-  OwningPtr<AsmPrinter> AP(TheTarget->createAsmPrinter(*Out, *TM, TAI, true));
-  OwningPtr<MCStreamer> Str(createAsmStreamer(Ctx, *Out, *TAI, AP.get()));
+  if (FileType == OFT_AssemblyFile) {
+    const TargetAsmInfo *TAI = TheTarget->createAsmInfo(TripleName);
+    assert(TAI && "Unable to create target asm info!");
+
+    AP.reset(TheTarget->createAsmPrinter(*Out, *TM, TAI, true));
+    Str.reset(createAsmStreamer(Ctx, *Out, *TAI, AP.get()));
+  } else {
+    assert(FileType == OFT_ObjectFile && "Invalid file type!");
+    Str.reset(createMachOStreamer(Ctx, *Out));
+  }
 
   // FIXME: Target hook & command line option for initial section.
   Str.get()->SwitchSection(MCSectionMachO::Create("__TEXT","__text",