diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2018-07-06 11:51:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-06 11:51:19 -0400 |
| commit | 7b2a549fcf04263e07127315d72c8570e8063828 (patch) | |
| tree | 8dd94dc20d8537f1c8406f5a9e561c9a68d599db /source/slangc/main.cpp | |
| parent | 338a7701b37fe133eba2f72455ba7c1790a8a1f5 (diff) | |
spCompile/spProcessCommandLineArguments return SlangResult (#610)
* * Make spCompile return SlangResult
* Make spProcessCommandLineArguments return SlangResult (and not internally exit)
* Remove calls to exit()
* Fix typos
* Make all output from spProcessCommandLineArguments get sent to diagnostic sink.
Diffstat (limited to 'source/slangc/main.cpp')
| -rw-r--r-- | source/slangc/main.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/source/slangc/main.cpp b/source/slangc/main.cpp index 376b75212..ba83a9bdf 100644 --- a/source/slangc/main.cpp +++ b/source/slangc/main.cpp @@ -26,7 +26,10 @@ static void diagnosticCallback( #define MAIN main #endif -int MAIN(int argc, char** argv) +// Used to identify that compilation was the failure - with a unique 'internal' code +#define SLANG_E_INTERNAL_COMPILE_FAILED SLANG_MAKE_ERROR(SLANG_FACILITY_INTERNAL, 0x7fab) + +static SlangResult innerMain(int argc, char** argv) { // Parse any command-line options @@ -41,28 +44,28 @@ int MAIN(int argc, char** argv) spSetCommandLineCompilerMode(compileRequest); char const* appName = "slangc"; - if(argc > 0) appName = argv[0]; + if (argc > 0) appName = argv[0]; - int err = spProcessCommandLineArguments(compileRequest, &argv[1], argc - 1); - if( err ) { - // TODO: print usage message - exit(1); + const SlangResult res = spProcessCommandLineArguments(compileRequest, &argv[1], argc - 1); + if (SLANG_FAILED(res)) + { + // TODO: print usage message + return res; + } } - // Invoke the compiler - #ifndef _DEBUG try #endif { // Run the compiler (this will produce any diagnostics through // our callback above). - int result = spCompile(compileRequest); - if( result != 0 ) + if (SLANG_FAILED(spCompile(compileRequest))) { // If the compilation failed, then get out of here... - exit(-1); + // Turn into an internal Result -> such that return code can be used to vary result to match previous behavior + return SLANG_E_INTERNAL_COMPILE_FAILED; } // Now that we are done, clean up after ourselves @@ -74,11 +77,25 @@ int MAIN(int argc, char** argv) catch (Exception & e) { printf("internal compiler error: %S\n", e.Message.ToWString().begin()); - return 1; + return SLANG_FAIL; } #endif + return SLANG_OK; +} - return 0; +int MAIN(int argc, char** argv) +{ + SlangResult res = innerMain(argc, argv); + + if (SLANG_SUCCEEDED(res)) + { + return 0; + } + else if (res == SLANG_E_INTERNAL_COMPILE_FAILED) + { + return -1; + } + return 1; } #ifdef _WIN32 |
