yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
3.4 KiB95 linesraw
1#ifndef SLANG_CORE_TEST_TOOL_UTIL_H
2#define SLANG_CORE_TEST_TOOL_UTIL_H
3
4#include "slang-std-writers.h"
5
6namespace Slang
7{
8
9#ifdef SLANG_SHARED_LIBRARY_TOOL
10#define SLANG_TEST_TOOL_API SLANG_EXTERN_C SLANG_DLL_EXPORT
11#else
12#define SLANG_TEST_TOOL_API
13#endif
14
15/* When a tool is run as an executable the return code is the code returned from
16the last return of main. On unix this can be up to 8 bits.
17By normal command line tool conventions returning 0 means success. */
18enum class ToolReturnCode
19{
20    CompilationFailed = -1, ///< Compilation failure (-1 to maintain compatibility). This may still
21                            ///< produce output and may mean a test was successful.
22    Success = 0,            ///< Tool ran normally
23    Failed,                 ///< Tool failed
24    Ignored, ///< The run was ignored because it couldn't be run (because some optional feature was
25             ///< not present for example)
26    FailedToRun, ///< Could not even run the test
27};
28
29enum class ToolReturnCodeSpan
30{
31    // Span of all valid values
32    First = int(ToolReturnCode::CompilationFailed),
33    Last = int(ToolReturnCode::FailedToRun),
34    // Span of all values that indicate the test is 'done'
35    FirstIsDone = int(ToolReturnCode::Ignored),
36    LastIsDone = int(ToolReturnCode::FailedToRun)
37};
38
39/* Utility functions for 'test tools' */
40struct TestToolUtil
41{
42    typedef SlangResult (*InnerMainFunc)(
43        Slang::StdWriters* stdWriters,
44        SlangSession* session,
45        int argc,
46        const char* const* argv);
47
48    /// If the test failed to run or was ignored then we are done
49    static bool isDone(ToolReturnCode code)
50    {
51        return int(code) >= int(ToolReturnCodeSpan::FirstIsDone) &&
52               int(code) <= int(ToolReturnCodeSpan::LastIsDone);
53    }
54
55    /// Convert from an int
56    static ToolReturnCode getReturnCodeFromInt(int code);
57
58    /// Given a slang result, returns a return code that can be returned from an executable
59    static ToolReturnCode getReturnCode(SlangResult res);
60
61    /// Given the executable path (as located in Slang directory hierarchy), works out the absolute
62    /// path to the root
63    static SlangResult getRootPath(const char* exePath, String& outRootPath);
64
65    /// Given the exePath, give return the absolute path to the directory the exe is in
66    static SlangResult getExeDirectoryPath(const char* exePath, String& outExeDirectoryPath);
67
68    /// Sets the default preludes on the session based on an explicit path
69    static SlangResult setSessionDefaultPreludeFromRootPath(
70        const String& rootPath,
71        slang::IGlobalSession* session);
72
73    /// Calculates the path that is the combination of parentPath, and relPath
74    /// And converts such that can be used as an include path (handling slashes)
75    static SlangResult getIncludePath(
76        const String& parentPath,
77        const char* relPath,
78        String& outIncludePath);
79
80
81    /// Sets the default preludes on the session based on the executable path
82    static SlangResult setSessionDefaultPreludeFromExePath(
83        const char* exePath,
84        slang::IGlobalSession* session);
85
86    /// Returns true if the core module should not be initialized immediately (eg when doing a
87    /// -load-core-module).
88    static bool hasDeferredCoreModule(Index numArgs, const char* const* args);
89
90    static SlangResult getDllDirectoryPath(const char* exePath, String& outDllDirectoryPath);
91};
92
93} // namespace Slang
94
95#endif // SLANG_TEST_TOOL_H