summaryrefslogtreecommitdiffstats
path: root/source/core
diff options
context:
space:
mode:
Diffstat (limited to 'source/core')
-rw-r--r--source/core/core.vcxproj6
-rw-r--r--source/core/core.vcxproj.filters18
-rw-r--r--source/core/slang-app-context.cpp67
-rw-r--r--source/core/slang-app-context.h60
-rw-r--r--source/core/slang-std-writers.cpp43
-rw-r--r--source/core/slang-std-writers.h44
-rw-r--r--source/core/slang-test-tool-util.cpp21
-rw-r--r--source/core/slang-test-tool-util.h25
-rw-r--r--source/core/slang-writer.h2
9 files changed, 150 insertions, 136 deletions
diff --git a/source/core/core.vcxproj b/source/core/core.vcxproj
index 5dad716fb..bebf7350c 100644
--- a/source/core/core.vcxproj
+++ b/source/core/core.vcxproj
@@ -182,7 +182,6 @@
<ClInclude Include="list.h" />
<ClInclude Include="platform.h" />
<ClInclude Include="secure-crt.h" />
- <ClInclude Include="slang-app-context.h" />
<ClInclude Include="slang-byte-encode-util.h" />
<ClInclude Include="slang-cpu-defines.h" />
<ClInclude Include="slang-free-list.h" />
@@ -192,9 +191,11 @@
<ClInclude Include="slang-object-scope-manager.h" />
<ClInclude Include="slang-random-generator.h" />
<ClInclude Include="slang-shared-library.h" />
+ <ClInclude Include="slang-std-writers.h" />
<ClInclude Include="slang-string-slice-pool.h" />
<ClInclude Include="slang-string-util.h" />
<ClInclude Include="slang-string.h" />
+ <ClInclude Include="slang-test-tool-util.h" />
<ClInclude Include="slang-writer.h" />
<ClInclude Include="smart-pointer.h" />
<ClInclude Include="stream.h" />
@@ -204,7 +205,6 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="platform.cpp" />
- <ClCompile Include="slang-app-context.cpp" />
<ClCompile Include="slang-byte-encode-util.cpp" />
<ClCompile Include="slang-free-list.cpp" />
<ClCompile Include="slang-io.cpp" />
@@ -212,9 +212,11 @@
<ClCompile Include="slang-object-scope-manager.cpp" />
<ClCompile Include="slang-random-generator.cpp" />
<ClCompile Include="slang-shared-library.cpp" />
+ <ClCompile Include="slang-std-writers.cpp" />
<ClCompile Include="slang-string-slice-pool.cpp" />
<ClCompile Include="slang-string-util.cpp" />
<ClCompile Include="slang-string.cpp" />
+ <ClCompile Include="slang-test-tool-util.cpp" />
<ClCompile Include="slang-writer.cpp" />
<ClCompile Include="stream.cpp" />
<ClCompile Include="text-io.cpp" />
diff --git a/source/core/core.vcxproj.filters b/source/core/core.vcxproj.filters
index c5c1fc733..dd33b61f9 100644
--- a/source/core/core.vcxproj.filters
+++ b/source/core/core.vcxproj.filters
@@ -45,9 +45,6 @@
<ClInclude Include="secure-crt.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="slang-app-context.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="slang-byte-encode-util.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -75,6 +72,9 @@
<ClInclude Include="slang-shared-library.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="slang-std-writers.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="slang-string-slice-pool.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -84,6 +84,9 @@
<ClInclude Include="slang-string.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="slang-test-tool-util.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
<ClInclude Include="slang-writer.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -107,9 +110,6 @@
<ClCompile Include="platform.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="slang-app-context.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="slang-byte-encode-util.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -131,6 +131,9 @@
<ClCompile Include="slang-shared-library.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="slang-std-writers.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="slang-string-slice-pool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -140,6 +143,9 @@
<ClCompile Include="slang-string.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="slang-test-tool-util.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
<ClCompile Include="slang-writer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
diff --git a/source/core/slang-app-context.cpp b/source/core/slang-app-context.cpp
deleted file mode 100644
index 2b3f32cbc..000000000
--- a/source/core/slang-app-context.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-
-#include "slang-app-context.h"
-
-#include "slang-writer.h"
-
-namespace Slang
-{
-
-/* static */AppContext* AppContext::s_singleton = nullptr;
-
-
-/* static */AppContext* AppContext::getDefault()
-{
- static AppContext* 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 AppContext 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 */AppContext* AppContext::initDefault()
-{
- AppContext* context = getDefault();
- setSingleton(context);
- return context;
-}
-
-/* static */int AppContext::getReturnCode(SlangResult res)
-{
- if (SLANG_SUCCEEDED(res))
- {
- return 0;
- }
- else if (res == SLANG_E_INTERNAL_FAIL)
- {
- return -1;
- }
- return 1;
-}
-
-void AppContext::setRequestWriters(SlangCompileRequest* request)
-{
- for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i)
- {
- if (m_replaceWriterFlags & (1 << i))
- {
- spSetWriter(request, SlangWriterChannel(i), m_writers[i]);
- }
- }
-}
-
-void AppContext::configureRequest(SlangCompileRequest* request)
-{
- setRequestWriters(request);
-}
-
-}
-
diff --git a/source/core/slang-app-context.h b/source/core/slang-app-context.h
deleted file mode 100644
index 9f1eb306c..000000000
--- a/source/core/slang-app-context.h
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef SLANG_APP_CONTEXT_H
-#define SLANG_APP_CONTEXT_H
-
-#include "slang-writer.h"
-#include "../../slang-com-ptr.h"
-
-namespace Slang
-{
-
-#ifdef SLANG_SHARED_LIBRARY_TOOL
-# define SLANG_SHARED_LIBRARY_TOOL_API SLANG_EXTERN_C SLANG_DLL_EXPORT
-#else
-# define SLANG_SHARED_LIBRARY_TOOL_API
-#endif
-
-/* A structure to hold general state shared across an application */
-class AppContext
-{
-public:
-
- ISlangWriter * getWriter(SlangWriterChannel chan) const { return m_writers[chan]; }
- void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; }
-
- /// Make modifications to the request
- void configureRequest(SlangCompileRequest* request);
-
- void setRequestWriters(SlangCompileRequest* request);
-
- void setReplaceWriterFlagsAll() { setReplaceWriterFlags((1 << SLANG_WRITER_CHANNEL_COUNT_OF) - 1); }
- void setReplaceWriterFlags(int flags) { m_replaceWriterFlags = flags; }
- int getReplaceWriterFlags() const { return m_replaceWriterFlags; }
-
- /// Ctor
- AppContext() : m_replaceWriterFlags(0) {}
-
- /// Initialize a default context
- static AppContext* initDefault();
-
- static AppContext* getDefault();
-
- static AppContext* getSingleton() { return s_singleton; }
- static void setSingleton(AppContext* context) { s_singleton = context; }
-
- static WriterHelper getStdError() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_ERROR); }
- static WriterHelper getStdOut() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT); }
- static WriterHelper getDiagnostic() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC); }
-
- static int getReturnCode(SlangResult res);
-
-protected:
-
- ComPtr<ISlangWriter> m_writers[SLANG_WRITER_CHANNEL_COUNT_OF];
- int m_replaceWriterFlags; ///< Bit for each writer
-
- static AppContext* s_singleton;
-};
-
-}
-
-#endif
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]);
+ }
+}
+
+}
+
diff --git a/source/core/slang-std-writers.h b/source/core/slang-std-writers.h
new file mode 100644
index 000000000..d580842eb
--- /dev/null
+++ b/source/core/slang-std-writers.h
@@ -0,0 +1,44 @@
+#ifndef SLANG_STD_WRITERS_H
+#define SLANG_STD_WRITERS_H
+
+#include "slang-writer.h"
+#include "../../slang-com-ptr.h"
+
+namespace Slang
+{
+
+/* Holds standard writers for the channels */
+class StdWriters
+{
+public:
+ ISlangWriter * getWriter(SlangWriterChannel chan) const { return m_writers[chan]; }
+ void setWriter(SlangWriterChannel chan, ISlangWriter* writer) { m_writers[chan] = writer; }
+
+ /// Set the writers on the SlangCompileRequest
+ void setRequestWriters(SlangCompileRequest* request);
+
+ /// Ctor
+ StdWriters() {}
+
+ /// Initialize a default context
+ static StdWriters* initDefault();
+
+ static StdWriters* getDefault();
+
+ static StdWriters* getSingleton() { return s_singleton; }
+ static void setSingleton(StdWriters* context) { s_singleton = context; }
+
+ static WriterHelper getError() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_ERROR); }
+ static WriterHelper getOut() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_STD_OUTPUT); }
+ static WriterHelper getDiagnostic() { return getSingleton()->getWriter(SLANG_WRITER_CHANNEL_DIAGNOSTIC); }
+
+protected:
+
+ ComPtr<ISlangWriter> m_writers[SLANG_WRITER_CHANNEL_COUNT_OF];
+
+ static StdWriters* s_singleton;
+};
+
+}
+
+#endif
diff --git a/source/core/slang-test-tool-util.cpp b/source/core/slang-test-tool-util.cpp
new file mode 100644
index 000000000..7ecfacefa
--- /dev/null
+++ b/source/core/slang-test-tool-util.cpp
@@ -0,0 +1,21 @@
+
+#include "slang-test-tool-util.h"
+
+namespace Slang
+{
+
+/* static */int TestToolUtil::getReturnCode(SlangResult res)
+{
+ if (SLANG_SUCCEEDED(res))
+ {
+ return 0;
+ }
+ else if (res == SLANG_E_INTERNAL_FAIL)
+ {
+ return -1;
+ }
+ return 1;
+}
+
+}
+
diff --git a/source/core/slang-test-tool-util.h b/source/core/slang-test-tool-util.h
new file mode 100644
index 000000000..615bbe10d
--- /dev/null
+++ b/source/core/slang-test-tool-util.h
@@ -0,0 +1,25 @@
+#ifndef SLANG_TEST_TOOL_UTIL_H
+#define SLANG_TEST_TOOL_UTIL_H
+
+#include "slang-std-writers.h"
+
+namespace Slang {
+
+#ifdef SLANG_SHARED_LIBRARY_TOOL
+# define SLANG_TEST_TOOL_API SLANG_EXTERN_C SLANG_DLL_EXPORT
+#else
+# define SLANG_TEST_TOOL_API
+#endif
+
+/* Utility functions for 'test tools' */
+struct TestToolUtil
+{
+ typedef SlangResult(*InnerMainFunc)(Slang::StdWriters* stdWriters, SlangSession* session, int argc, const char*const* argv);
+
+ /// Given a slang result, returns a return code that can be returned from an executable
+ static int getReturnCode(SlangResult res);
+};
+
+} // namespace Slang
+
+#endif // SLANG_TEST_TOOL_H
diff --git a/source/core/slang-writer.h b/source/core/slang-writer.h
index b18af373f..463450ac9 100644
--- a/source/core/slang-writer.h
+++ b/source/core/slang-writer.h
@@ -45,7 +45,7 @@ public:
// ISlangUnknown
SLANG_REF_OBJECT_IUNKNOWN_QUERY_INTERFACE
SLANG_REF_OBJECT_IUNKNOWN_ADD_REF
- SLANG_NO_THROW uint32_t SLANG_MCALL release() { return (m_flags & WriterFlag::IsStatic) ? 1 : (uint32_t)releaseReference(); }
+ SLANG_NO_THROW uint32_t SLANG_MCALL release() { return (m_flags & WriterFlag::IsStatic) ? (uint32_t)decreaseReference() : (uint32_t)releaseReference(); }
// ISlangWriter - default impl
SLANG_NO_THROW virtual void SLANG_MCALL flush() SLANG_OVERRIDE {}