summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/slang-test/slangc-tool.cpp73
1 files changed, 32 insertions, 41 deletions
diff --git a/tools/slang-test/slangc-tool.cpp b/tools/slang-test/slangc-tool.cpp
index 4757f2fff..25b973421 100644
--- a/tools/slang-test/slangc-tool.cpp
+++ b/tools/slang-test/slangc-tool.cpp
@@ -6,8 +6,6 @@
using namespace Slang;
-SLANG_API void spSetCommandLineCompilerMode(SlangCompileRequest* request);
-
static void _diagnosticCallback(char const* message, void* /*userData*/)
{
auto stdError = StdWriters::getError();
@@ -15,13 +13,35 @@ static void _diagnosticCallback(char const* message, void* /*userData*/)
stdError.flush();
}
-static SlangResult _compile(SlangCompileRequest* compileRequest, int argc, const char*const* argv)
+SlangResult SlangCTool::innerMain(StdWriters* stdWriters, slang::IGlobalSession* sharedSession, int argc, const char*const* argv)
{
- spSetDiagnosticCallback(compileRequest, &_diagnosticCallback, nullptr);
- spSetCommandLineCompilerMode(compileRequest);
+ StdWriters::setSingleton(stdWriters);
+
+ // Assume we will used the shared session
+ ComPtr<slang::IGlobalSession> session(sharedSession);
+ // The sharedSession always has a pre-loaded stdlib.
+ // This differed test checks if the command line has an option to setup the stdlib.
+ // If so we *don't* use the sharedSession, and create a new stdlib-less session just for this compilation.
+ if (TestToolUtil::hasDeferredStdLib(Index(argc - 1), argv + 1))
{
- const SlangResult res = spProcessCommandLineArguments(compileRequest, &argv[1], argc - 1);
+ SLANG_RETURN_ON_FAIL(slang_createGlobalSessionWithoutStdLib(SLANG_API_VERSION, session.writeRef()));
+ }
+
+ ComPtr<slang::ICompileRequest> compileRequest;
+ SLANG_RETURN_ON_FAIL(session->createCompileRequest(compileRequest.writeRef()));
+
+ // Do any app specific configuration
+ for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i)
+ {
+ compileRequest->setWriter(SlangWriterChannel(i), stdWriters->getWriter(i));
+ }
+
+ compileRequest->setDiagnosticCallback(&_diagnosticCallback, nullptr);
+ compileRequest->setCommandLineCompilerMode();
+
+ {
+ const SlangResult res = compileRequest->processCommandLineArguments(&argv[1], argc - 1);
if (SLANG_FAILED(res))
{
// TODO: print usage message
@@ -29,55 +49,26 @@ static SlangResult _compile(SlangCompileRequest* compileRequest, int argc, const
}
}
- SlangResult res = SLANG_OK;
+ SlangResult compileRes = SLANG_OK;
#ifndef _DEBUG
try
#endif
{
// Run the compiler (this will produce any diagnostics through SLANG_WRITER_TARGET_TYPE_DIAGNOSTIC).
- res = spCompile(compileRequest);
+ compileRes = compileRequest->compile();
+
// 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;
+ compileRes = SLANG_FAILED(compileRes) ? SLANG_E_INTERNAL_FAIL : compileRes;
}
#ifndef _DEBUG
catch (const Exception& e)
{
StdWriters::getOut().print("internal compiler error: %S\n", e.Message.toWString().begin());
- res = SLANG_FAIL;
+ compileRes = SLANG_FAIL;
}
#endif
- return res;
-}
-
-SlangResult SlangCTool::innerMain(StdWriters* stdWriters, slang::IGlobalSession* sharedSession, int argc, const char*const* argv)
-{
- StdWriters::setSingleton(stdWriters);
-
- // Assume we will used the shared session
- ComPtr<slang::IGlobalSession> session(sharedSession);
-
- // The sharedSession always has a pre-loaded stdlib.
- // This differed test checks if the command line has an option to setup the stdlib.
- // If so we *don't* use the sharedSession, and create a new stdlib-less session just for this compilation.
- if (TestToolUtil::hasDeferredStdLib(Index(argc - 1), argv + 1))
- {
- SLANG_RETURN_ON_FAIL(slang_createGlobalSessionWithoutStdLib(SLANG_API_VERSION, session.writeRef()));
- }
-
- SlangCompileRequest* compileRequest = spCreateCompileRequest(session);
-
- // Do any app specific configuration
- for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i)
- {
- spSetWriter(compileRequest, SlangWriterChannel(i), stdWriters->getWriter(i));
- }
-
- SlangResult res = _compile(compileRequest, argc, argv);
- // Now that we are done, clean up after ourselves
- spDestroyCompileRequest(compileRequest);
-
- return res;
+ return compileRes;
}