|
34 | 34 | #include "dxc/Support/HLSLOptions.h" |
35 | 35 | #include "dxc/Support/WinAdapter.h" |
36 | 36 | #include "dxc/Support/dxcapi.use.h" |
| 37 | +#include "dxc/Support/exception.h" |
37 | 38 | #include "dxc/dxcapi.h" |
38 | 39 | #include "lib/dxil2spv.h" |
39 | 40 | #include "clang/Frontend/CompilerInstance.h" |
|
43 | 44 | #include "llvm/Support/FileSystem.h" |
44 | 45 | #include "llvm/Support/MSFileSystem.h" |
45 | 46 | #include "llvm/Support/raw_ostream.h" |
| 47 | +#include <cstdlib> |
| 48 | +#include <exception> |
46 | 49 | #include <string> |
47 | 50 |
|
48 | 51 | // Command line options for dxil2spv. The general approach is to mirror the |
@@ -82,24 +85,37 @@ int main(int argc, const char **argv_) { |
82 | 85 | return EXIT_SUCCESS; |
83 | 86 | } |
84 | 87 |
|
85 | | - // Setup a compiler instance with diagnostics. |
86 | | - clang::CompilerInstance instance; |
87 | | - auto *diagnosticPrinter = new clang::TextDiagnosticPrinter( |
88 | | - llvm::errs(), new clang::DiagnosticOptions()); |
89 | | - instance.createDiagnostics(diagnosticPrinter, false); |
90 | | - instance.setOutStream(&llvm::outs()); |
| 88 | + try { |
| 89 | + // Setup a compiler instance with diagnostics. |
| 90 | + clang::CompilerInstance instance; |
| 91 | + auto *diagnosticPrinter = new clang::TextDiagnosticPrinter( |
| 92 | + llvm::errs(), new clang::DiagnosticOptions()); |
| 93 | + instance.createDiagnostics(diagnosticPrinter, false); |
| 94 | + instance.setOutStream(&llvm::outs()); |
91 | 95 |
|
92 | | - // TODO: Allow configuration of targetEnv via options. |
93 | | - instance.getCodeGenOpts().SpirvOptions.targetEnv = "vulkan1.0"; |
| 96 | + // TODO: Allow configuration of targetEnv via options. |
| 97 | + instance.getCodeGenOpts().SpirvOptions.targetEnv = "vulkan1.0"; |
94 | 98 |
|
95 | | - // Set input and ouptut filenames. |
96 | | - instance.getCodeGenOpts().MainFileName = optInputFilename; |
97 | | - instance.getFrontendOpts().OutputFile = optOutputFilename; |
| 99 | + // Set input and ouptut filenames. |
| 100 | + instance.getCodeGenOpts().MainFileName = optInputFilename; |
| 101 | + instance.getFrontendOpts().OutputFile = optOutputFilename; |
98 | 102 |
|
99 | | - // Run translator. |
100 | | - clang::dxil2spv::Translator translator(instance); |
101 | | - translator.Run(); |
| 103 | + // Run translator. |
| 104 | + clang::dxil2spv::Translator translator(instance); |
| 105 | + translator.Run(); |
102 | 106 |
|
103 | | - return instance.getDiagnosticClient().getNumErrors() > 0 ? EXIT_FAILURE |
104 | | - : EXIT_SUCCESS; |
| 107 | + if (instance.getDiagnosticClient().getNumErrors() > 0) |
| 108 | + return EXIT_FAILURE; |
| 109 | + } catch (const hlsl::Exception& ex) { |
| 110 | + llvm::errs() << "Exception: " << ex.msg << "(HRESULT: " << ex.hr << ")\n"; |
| 111 | + return EXIT_FAILURE; |
| 112 | + } catch (const std::exception &ex) { |
| 113 | + llvm::errs() << "Exception: " << ex.what() << "\n"; |
| 114 | + return EXIT_FAILURE; |
| 115 | + } catch (...) { |
| 116 | + llvm::errs() << "Unknown exception\n"; |
| 117 | + return EXIT_FAILURE; |
| 118 | + } |
| 119 | + |
| 120 | + return EXIT_SUCCESS; |
105 | 121 | } |
0 commit comments