From 7b2a549fcf04263e07127315d72c8570e8063828 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 6 Jul 2018 11:51:19 -0400 Subject: 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. --- tools/slang-reflection-test/main.cpp | 42 ++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'tools/slang-reflection-test/main.cpp') diff --git a/tools/slang-reflection-test/main.cpp b/tools/slang-reflection-test/main.cpp index b900f3f62..667a0ddf7 100644 --- a/tools/slang-reflection-test/main.cpp +++ b/tools/slang-reflection-test/main.cpp @@ -6,6 +6,7 @@ #include #include +#include struct PrettyWriter { @@ -854,10 +855,17 @@ void emitReflectionJSON( emitReflectionJSON(writer, programReflection); } +static SlangResult maybeDumpDiagnostic(SlangResult res, SlangCompileRequest* request) +{ + const char* diagnostic; + if (SLANG_FAILED(res) && (diagnostic = spGetDiagnosticOutput(request))) + { + fputs(diagnostic, stderr); + } + return res; +} -int main( - int argc, - char** argv) +static SlangResult innerMain(int argc, char*const*argv) { // Parse any command-line options @@ -865,22 +873,10 @@ int main( SlangCompileRequest* request = spCreateCompileRequest(session); char const* appName = "slang-reflection-test"; - if(argc > 0) appName = argv[0]; - - int err = spProcessCommandLineArguments(request, &argv[1], argc - 1); - if( err ) - { - char const* output = spGetDiagnosticOutput(request); - fputs(output, stderr); - exit(1); - } + if (argc > 0) appName = argv[0]; - if( spCompile(request) != 0 ) - { - char const* output = spGetDiagnosticOutput(request); - fputs(output, stderr); - exit(1); - } + SLANG_RETURN_ON_FAIL(maybeDumpDiagnostic(spProcessCommandLineArguments(request, &argv[1], argc - 1), request)); + SLANG_RETURN_ON_FAIL(maybeDumpDiagnostic(spCompile(request), request)); // Okay, let's go through and emit reflection info on whatever // we have. @@ -891,5 +887,13 @@ int main( spDestroyCompileRequest(request); spDestroySession(session); - return 0; + return SLANG_OK; +} + +int main( + int argc, + char** argv) +{ + SlangResult res = innerMain(argc, argv); + return SLANG_FAILED(res) ? 1 : 0; } -- cgit v1.2.3