Improvements to disassembly within PassManager (#4677)

* PassManager: Print errors occurring during disassembly

Otherwise one could be greeted by the following text when running
spirv-opt withe the `--print-all` flag:

    ; IR before pass wrap-opkill

    ; IR before pass eliminate-dead-branches

    ; IR before pass merge-return

With this commit, one will instead get:

    error: line 143: Invalid opcode: 400
    warning: line 0: Disassembly failed before pass wrap-opkill

    error: line 143: Invalid opcode: 400
    warning: line 0: Disassembly failed before pass eliminate-dead-branches

    error: line 143: Invalid opcode: 400
    warning: line 0: Disassembly failed before pass merge-return

* PassManager: Use the right target environment when disassembling

Disassembly would fail if features from a newer version of SPIR-V than
1.2 were used.
diff --git a/source/opt/pass_manager.cpp b/source/opt/pass_manager.cpp
index be53d34..a73ff7c 100644
--- a/source/opt/pass_manager.cpp
+++ b/source/opt/pass_manager.cpp
@@ -35,10 +35,18 @@
     if (print_all_stream_) {
       std::vector<uint32_t> binary;
       context->module()->ToBinary(&binary, false);
-      SpirvTools t(SPV_ENV_UNIVERSAL_1_2);
+      SpirvTools t(target_env_);
+      t.SetMessageConsumer(consumer());
       std::string disassembly;
-      t.Disassemble(binary, &disassembly, 0);
-      *print_all_stream_ << preamble << (pass ? pass->name() : "") << "\n"
+      std::string pass_name = (pass ? pass->name() : "");
+      if (!t.Disassemble(binary, &disassembly, 0)) {
+        std::string msg = "Disassembly failed before pass ";
+        msg += pass_name + "\n";
+        spv_position_t null_pos{0, 0, 0};
+        consumer()(SPV_MSG_WARNING, "", null_pos, msg.c_str());
+        return;
+      }
+      *print_all_stream_ << preamble << pass_name << "\n"
                          << disassembly << std::endl;
     }
   };