MIR Serialization: Connect the machine function analysis pass to the MIR parser.

This commit connects the machine function analysis pass (which creates machine
functions) to the MIR parser, which will initialize the machine functions 
with the state from the MIR file and reconstruct the machine IR.

This commit introduces a new interface called 'MachineFunctionInitializer',
which can be used to provide custom initialization for the machine functions.

This commit also introduces a new diagnostic class called 
'DiagnosticInfoMIRParser' which is used for MIR parsing errors.
This commit modifies the default diagnostic handling in LLVMContext - now the
the diagnostics are printed directly into llvm::errs() so that the MIR parsing 
errors can be printed with colours.  

Reviewers: Justin Bogner

Differential Revision: http://reviews.llvm.org/D9928

llvm-svn: 239753
diff --git a/llvm/test/CodeGen/MIR/function-missing-machine-function.mir b/llvm/test/CodeGen/MIR/function-missing-machine-function.mir
new file mode 100644
index 0000000..71b5b28
--- /dev/null
+++ b/llvm/test/CodeGen/MIR/function-missing-machine-function.mir
@@ -0,0 +1,13 @@
+# RUN: not llc -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
+# This test verifies that an error is reported when a MIR file has some
+# function but is missing a corresponding machine function.
+
+# CHECK: no machine function information for function 'foo' in the MIR file
+
+--- |
+
+  define i32 @foo() {
+    ret i32 0
+  }
+
+...
diff --git a/llvm/test/CodeGen/MIR/llvm-ir-error-reported.mir b/llvm/test/CodeGen/MIR/llvm-ir-error-reported.mir
index 013b28c..3508c34 100644
--- a/llvm/test/CodeGen/MIR/llvm-ir-error-reported.mir
+++ b/llvm/test/CodeGen/MIR/llvm-ir-error-reported.mir
@@ -4,7 +4,7 @@
 
 --- |
   
-  ; CHECK: [[@LINE+3]]:15: error: use of undefined value '%a'
+  ; CHECK: [[@LINE+3]]:15: use of undefined value '%a'
   define i32 @foo(i32 %x, i32 %y) {
     %z = alloca i32, align 4
     store i32 %a, i32* %z, align 4
diff --git a/llvm/test/CodeGen/MIR/llvmIR.mir b/llvm/test/CodeGen/MIR/llvmIR.mir
index 7a7b46b..4d7fde2 100644
--- a/llvm/test/CodeGen/MIR/llvmIR.mir
+++ b/llvm/test/CodeGen/MIR/llvmIR.mir
@@ -30,3 +30,6 @@
   }
   
 ...
+---
+name: foo
+...
diff --git a/llvm/test/CodeGen/MIR/machine-function-missing-name.mir b/llvm/test/CodeGen/MIR/machine-function-missing-name.mir
index 54668f1..b16156e 100644
--- a/llvm/test/CodeGen/MIR/machine-function-missing-name.mir
+++ b/llvm/test/CodeGen/MIR/machine-function-missing-name.mir
@@ -14,7 +14,7 @@
 
 ...
 ---
-# CHECK: [[@LINE+1]]:1: error: missing required key 'name'
+# CHECK: [[@LINE+1]]:1: missing required key 'name'
 nme:             foo
 ...
 ---