summaryrefslogtreecommitdiffstats
path: root/tools/slang-reflection-test/main.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-07-06 11:51:19 -0400
committerGitHub <noreply@github.com>2018-07-06 11:51:19 -0400
commit7b2a549fcf04263e07127315d72c8570e8063828 (patch)
tree8dd94dc20d8537f1c8406f5a9e561c9a68d599db /tools/slang-reflection-test/main.cpp
parent338a7701b37fe133eba2f72455ba7c1790a8a1f5 (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 'tools/slang-reflection-test/main.cpp')
-rw-r--r--tools/slang-reflection-test/main.cpp42
1 files changed, 23 insertions, 19 deletions
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 <string.h>
#include <slang.h>
+#include <slang-com-helper.h>
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;
}