yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
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{ 20CompilationFailed = -1 ,///< Compilation failure (-1 to maintain compatibility). This may still 21///< produce output and may mean a test was successful. 22Success = 0 ,///< Tool ran normally 23Failed ,///< Tool failed 24Ignored ,///< The run was ignored because it couldn't be run (because some optional feature was 25///< not present for example) 26FailedToRun ,///< Could not even run the test 27}; 28 29enum class ToolReturnCodeSpan 30{ 31// Span of all valid values 32First = int (ToolReturnCode ::CompilationFailed ), 33Last = int (ToolReturnCode ::FailedToRun ), 34// Span of all values that indicate the test is 'done' 35FirstIsDone = int (ToolReturnCode ::Ignored ), 36LastIsDone = int (ToolReturnCode ::FailedToRun ) 37}; 38 39/* Utility functions for 'test tools' */ 40struct TestToolUtil 41{ 42typedef SlangResult (* InnerMainFunc )( 43Slang ::StdWriters * stdWriters , 44SlangSession * session , 45int argc , 46const char * const * argv ); 47 48/// If the test failed to run or was ignored then we are done 49static bool isDone (ToolReturnCode code ) 50 { 51return int (code ) >=int (ToolReturnCodeSpan ::FirstIsDone )&& 52int (code ) <=int (ToolReturnCodeSpan ::LastIsDone ); 53 } 54 55/// Convert from an int 56static ToolReturnCode getReturnCodeFromInt (int code ); 57 58/// Given a slang result, returns a return code that can be returned from an executable 59static 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 63static SlangResult getRootPath (const char * exePath ,String & outRootPath ); 64 65/// Given the exePath, give return the absolute path to the directory the exe is in 66static SlangResult getExeDirectoryPath (const char * exePath ,String & outExeDirectoryPath ); 67 68/// Sets the default preludes on the session based on an explicit path 69static SlangResult setSessionDefaultPreludeFromRootPath ( 70const String & rootPath , 71slang ::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) 75static SlangResult getIncludePath ( 76const String & parentPath , 77const char * relPath , 78String & outIncludePath ); 79 80 81/// Sets the default preludes on the session based on the executable path 82static SlangResult setSessionDefaultPreludeFromExePath ( 83const char * exePath , 84slang ::IGlobalSession * session ); 85 86/// Returns true if the core module should not be initialized immediately (eg when doing a 87/// -load-core-module). 88static bool hasDeferredCoreModule (Index numArgs ,const char * const * args ); 89 90static SlangResult getDllDirectoryPath (const char * exePath ,String & outDllDirectoryPath ); 91}; 92 93}// namespace Slang 94 95#endif // SLANG_TEST_TOOL_H