Coverage Report

Created: 2026-06-05 03:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/Users/runner/work/slang/slang/source/compiler-core/slang-downstream-compiler-util.h
Line
Count
Source
1
#ifndef SLANG_DOWNSTREAM_COMPILER_UTIL_H
2
#define SLANG_DOWNSTREAM_COMPILER_UTIL_H
3
4
#include "slang-downstream-compiler-set.h"
5
#include "slang-downstream-compiler.h"
6
7
namespace Slang
8
{
9
10
typedef SlangResult (*DownstreamCompilerLocatorFunc)(
11
    const String& path,
12
    ISlangSharedLibraryLoader* loader,
13
    DownstreamCompilerSet* set);
14
15
struct DownstreamCompilerInfo
16
{
17
    typedef DownstreamCompilerInfo This;
18
    typedef uint32_t SourceLanguageFlags;
19
    struct SourceLanguageFlag
20
    {
21
        enum Enum : SourceLanguageFlags
22
        {
23
            Unknown = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_UNKNOWN,
24
            Slang = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_SLANG,
25
            HLSL = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_HLSL,
26
            GLSL = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_GLSL,
27
            C = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_C,
28
            CPP = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_CPP,
29
            CUDA = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_CUDA,
30
            SPIRV = SourceLanguageFlags(1) << SLANG_SOURCE_LANGUAGE_SPIRV,
31
        };
32
    };
33
34
    /// Get info for a compiler type
35
    static const This& getInfo(SlangPassThrough compiler);
36
    /// True if this compiler can compile the specified language
37
    static bool canCompile(SlangPassThrough compiler, SlangSourceLanguage sourceLanguage);
38
39
    DownstreamCompilerInfo()
40
1.99k
        : sourceLanguageFlags(0)
41
1.99k
    {
42
1.99k
    }
43
44
    DownstreamCompilerInfo(SourceLanguageFlags inSourceLanguageFlags)
45
1.19k
        : sourceLanguageFlags(inSourceLanguageFlags)
46
1.19k
    {
47
1.19k
    }
48
    SourceLanguageFlags sourceLanguageFlags;
49
};
50
51
52
// Combination of a downstream compiler type (pass through) and
53
// a match version.
54
struct DownstreamCompilerMatchVersion
55
{
56
    DownstreamCompilerMatchVersion(SlangPassThrough inType, MatchSemanticVersion inMatchVersion)
57
        : type(inType), matchVersion(inMatchVersion)
58
0
    {
59
0
    }
60
61
    DownstreamCompilerMatchVersion()
62
88
        : type(SLANG_PASS_THROUGH_NONE)
63
88
    {
64
88
    }
65
66
    SlangPassThrough type;             ///< The type of the compiler
67
    MatchSemanticVersion matchVersion; ///< The match version
68
};
69
70
struct DownstreamCompilerUtil : public DownstreamCompilerUtilBase
71
{
72
    enum class MatchType
73
    {
74
        MinGreaterEqual,
75
        MinAbsolute,
76
        Newest,
77
    };
78
79
    /// Find a compiler
80
    static IDownstreamCompiler* findCompiler(
81
        const DownstreamCompilerSet* set,
82
        MatchType matchType,
83
        const DownstreamCompilerDesc& desc);
84
    static IDownstreamCompiler* findCompiler(
85
        const List<IDownstreamCompiler*>& compilers,
86
        MatchType matchType,
87
        const DownstreamCompilerDesc& desc);
88
89
    static IDownstreamCompiler* findCompiler(
90
        const List<IDownstreamCompiler*>& compilers,
91
        SlangPassThrough type,
92
        const SemanticVersion& version);
93
    static IDownstreamCompiler* findCompiler(
94
        const List<IDownstreamCompiler*>& compilers,
95
        const DownstreamCompilerDesc& desc);
96
97
    /// Find all the compilers with the version
98
    static void findVersions(
99
        const List<IDownstreamCompiler*>& compilers,
100
        SlangPassThrough compiler,
101
        List<SemanticVersion>& versions);
102
103
104
    /// Find the compiler closest to the desc
105
    static IDownstreamCompiler* findClosestCompiler(
106
        const List<IDownstreamCompiler*>& compilers,
107
        const DownstreamCompilerMatchVersion& version);
108
    static IDownstreamCompiler* findClosestCompiler(
109
        const DownstreamCompilerSet* set,
110
        const DownstreamCompilerMatchVersion& version);
111
112
    /// Get the information on the compiler used to compile this source
113
    static DownstreamCompilerMatchVersion getCompiledVersion();
114
115
    static void updateDefault(DownstreamCompilerSet* set, SlangSourceLanguage sourceLanguage);
116
    static void updateDefaults(DownstreamCompilerSet* set);
117
118
    static void setDefaultLocators(
119
        DownstreamCompilerLocatorFunc outFuncs[int(SLANG_PASS_THROUGH_COUNT_OF)]);
120
121
    /// Attempts to determine what 'path' is and load appropriately. Is it a path to a shared
122
    /// library? Is it a directory holding the libraries? Some downstream shared libraries need
123
    /// other shared libraries to be loaded before the main shared library, such that they are in
124
    /// the same directory otherwise the shared library could come from some unwanted location.
125
    /// dependentNames names shared libraries which should be attempted to be loaded in the path of
126
    /// the main shared library. The list is optional (nullptr can be passed in), and the list is
127
    /// terminated by nullptr.
128
    static SlangResult loadSharedLibrary(
129
        const String& path,
130
        ISlangSharedLibraryLoader* loader,
131
        const char* const* dependantNames,
132
        const char* libraryName,
133
        ComPtr<ISlangSharedLibrary>& outSharedLib);
134
135
    /// Append the desc as text
136
    static void appendAsText(const DownstreamCompilerDesc& desc, StringBuilder& out);
137
};
138
139
} // namespace Slang
140
141
#endif