From d2ddc590601778f309c81f7d19d5e7fed34210de Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 17 Dec 2018 09:22:14 -0500 Subject: Feature/test tool shared libraries (#758) * Remove circular reference to renderer on Vk & D3D12 DescriptorSetImpl * Refactor Stbi image loading such that memory is correctly freed when goes out of scope. Added Crt memory dump at termination. Reduced erroneous reporting by scoping TestContext. * Used capitalized acronym for STBImage to keep Tim happy. * Split out TestReporter - to just handle reporting test results Split out Options Made TestContext hold options, and the reporter Removed remaining memory leaks. * Small optimization for rawWrite, such that it directly writes over print.. * Improve comments on TestCategorySet * Fix typos in TestCategorySet * Made slangc a cpp file as part of slang-test (removing need for separate project/shared library). * * Made all test tools only available as dlls. * Made possible to invoke test tool dll from command line slang-test slangc [--bindir xxx] options to slangc * Fix Visual Studio projects that are no longer needed. --- tools/slang-test/slangc-tool.cpp | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tools/slang-test/slangc-tool.cpp (limited to 'tools/slang-test/slangc-tool.cpp') diff --git a/tools/slang-test/slangc-tool.cpp b/tools/slang-test/slangc-tool.cpp new file mode 100644 index 000000000..3085e2ab5 --- /dev/null +++ b/tools/slang-test/slangc-tool.cpp @@ -0,0 +1,57 @@ +// test-context.cpp +#include "slangc-tool.h" + +using namespace Slang; + +SLANG_API void spSetCommandLineCompilerMode(SlangCompileRequest* request); + +static void _diagnosticCallback(char const* message, void* /*userData*/) +{ + auto stdError = AppContext::getStdError(); + stdError.put(message); + stdError.flush(); +} + +SlangResult SlangCTool::innerMain(AppContext* appContext, SlangSession* session, int argc, const char*const* argv) +{ + SlangCompileRequest* compileRequest = spCreateCompileRequest(session); + spSetDiagnosticCallback(compileRequest, &_diagnosticCallback, nullptr); + + spSetCommandLineCompilerMode(compileRequest); + // Do any app specific configuration + appContext->configureRequest(compileRequest); + + { + const SlangResult res = spProcessCommandLineArguments(compileRequest, &argv[1], argc - 1); + if (SLANG_FAILED(res)) + { + // TODO: print usage message + return res; + } + } + + SlangResult res = SLANG_OK; + +#ifndef _DEBUG + try +#endif + { + // Run the compiler (this will produce any diagnostics through SLANG_WRITER_TARGET_TYPE_DIAGNOSTIC). + res = spCompile(compileRequest); + // If the compilation failed, then get out of here... + // Turn into an internal Result -> such that return code can be used to vary result to match previous behavior + res = SLANG_FAILED(res) ? SLANG_E_INTERNAL_FAIL : res; + } +#ifndef _DEBUG + catch (Exception & e) + { + AppContext::getStdOut().print("internal compiler error: %S\n", e.Message.ToWString().begin()); + res = SLANG_FAIL; + } +#endif + + // Now that we are done, clean up after ourselves + spDestroyCompileRequest(compileRequest); + return res; +} + -- cgit v1.2.3