summaryrefslogtreecommitdiffstats
path: root/source/core/slang-std-writers.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2018-12-21 11:00:28 -0500
committerGitHub <noreply@github.com>2018-12-21 11:00:28 -0500
commitefa2c8f41aa5cd2c27990fd9b57ea0eff06976e7 (patch)
tree4c1a4d8e6e71e81c42cfbf315610e380d75527bf /source/core/slang-std-writers.cpp
parentb5bda9b3d155234be079debe6997cbc900773cf2 (diff)
Feature/remove app context (#765)
* Remove AppContext. Use StdChannels to hold writers, and TestToolUtil to hold test tool specific functionality. * StdChannels -> StdWriters * getStdOut -> getOut, getStdError -> getError
Diffstat (limited to 'source/core/slang-std-writers.cpp')
-rw-r--r--source/core/slang-std-writers.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/source/core/slang-std-writers.cpp b/source/core/slang-std-writers.cpp
new file mode 100644
index 000000000..963af9ef5
--- /dev/null
+++ b/source/core/slang-std-writers.cpp
@@ -0,0 +1,43 @@
+
+#include "slang-std-writers.h"
+
+namespace Slang
+{
+
+/* static */StdWriters* StdWriters::s_singleton = nullptr;
+
+/* static */StdWriters* StdWriters::getDefault()
+{
+ static StdWriters* s_context = nullptr;
+
+ if (!s_context)
+ {
+ static FileWriter s_stdError(stderr, WriterFlag::IsStatic | WriterFlag::IsUnowned | WriterFlag::AutoFlush);
+ static FileWriter s_stdOut(stdout, WriterFlag::IsStatic | WriterFlag::IsUnowned | WriterFlag::AutoFlush);
+
+ static StdWriters s_contextVar;
+ s_context = &s_contextVar;
+
+ s_context->setWriter(SLANG_WRITER_CHANNEL_STD_ERROR, &s_stdError);
+ s_context->setWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT, &s_stdOut);
+ }
+ return s_context;
+}
+
+/* static */StdWriters* StdWriters::initDefault()
+{
+ StdWriters* context = getDefault();
+ setSingleton(context);
+ return context;
+}
+
+void StdWriters::setRequestWriters(SlangCompileRequest* request)
+{
+ for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i)
+ {
+ spSetWriter(request, SlangWriterChannel(i), m_writers[i]);
+ }
+}
+
+}
+