diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-12-01 17:29:01 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-01 17:29:01 -0500 |
| commit | 200e236d64a02d9e85cb4a459477e073b81f5182 (patch) | |
| tree | 7c1c7b75eb8d95238afe154ff826ec065767104b | |
| parent | 339422dc91e10d15cf861ba3006025e3cec250c5 (diff) | |
Make SlangCompileRequest COM type (#1620)
* #include an absolute path didn't work - because paths were taken to always be relative.
* WIP for COM CompileRequest.
* Add more methods to IGlobalSession.
* Fix createCompileRequest.
Made slangc tool use COM style methods.
* m_ prefix variables in EndToEndCompileRequest
| -rw-r--r-- | slang.h | 1042 | ||||
| -rw-r--r-- | source/slang/slang-check-shader.cpp | 10 | ||||
| -rw-r--r-- | source/slang/slang-check.cpp | 4 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.cpp | 20 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 149 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 28 | ||||
| -rw-r--r-- | source/slang/slang-options.h | 5 | ||||
| -rw-r--r-- | source/slang/slang-repro.cpp | 12 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 1453 | ||||
| -rw-r--r-- | tools/slang-test/slangc-tool.cpp | 73 |
10 files changed, 1706 insertions, 1090 deletions
@@ -1140,23 +1140,22 @@ extern "C" namespace slang { struct IGlobalSession; + struct ICompileRequest; } // namespace slang /*! @brief An instance of the Slang library. */ typedef slang::IGlobalSession SlangSession; + typedef struct SlangProgramLayout SlangProgramLayout; /*! @brief A request for one or more compilation actions to be performed. */ - typedef struct SlangCompileRequest SlangCompileRequest; + typedef struct slang::ICompileRequest SlangCompileRequest; - namespace slang { - struct IGlobalSession; - } // namespace slang /*! @brief Initialize an instance of the Slang library. @@ -1169,133 +1168,113 @@ extern "C" SLANG_API void spDestroySession( SlangSession* session); - /*! - @brief Set the session shared library loader. If this changes the loader, it may cause shared libraries to be unloaded - @param session Session to set the loader on - @param loader The loader to set. Setting nullptr sets the default loader. + /** @see slang::IGlobalSession::setSharedLibraryLoader */ SLANG_API void spSessionSetSharedLibraryLoader( SlangSession* session, ISlangSharedLibraryLoader* loader); - /*! - @brief Gets the currently set shared library loader - @param session Session to get the loader from - @return Gets the currently set loader. If returns nullptr, it's the default loader + /** @see slang::IGlobalSession::getSharedLibraryLoader */ SLANG_API ISlangSharedLibraryLoader* spSessionGetSharedLibraryLoader( SlangSession* session); - /*! - @brief Returns SLANG_OK if a the compilation target is supported for this session - @param session Session - @param target The compilation target to test - @return SLANG_OK if the target is available - SLANG_E_NOT_IMPLEMENTED if not implemented in this build - SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found - SLANG_FAIL other kinds of failures */ + /** @see slang::IGlobalSession::checkCompileTargetSupport + */ SLANG_API SlangResult spSessionCheckCompileTargetSupport( SlangSession* session, SlangCompileTarget target); - /*! - @brief Returns SLANG_OK if a the pass through support is supported for this session - @param session Session - @param target The compilation target to test - @return SLANG_OK if the target is available - SLANG_E_NOT_IMPLEMENTED if not implemented in this build - SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found - SLANG_FAIL other kinds of failures */ + /** @see slang::IGlobalSession::checkPassThroughSupport + */ SLANG_API SlangResult spSessionCheckPassThroughSupport( SlangSession* session, SlangPassThrough passThrough ); - /*! - @brief Add new builtin declarations to be used in subsequent compiles. + /** @see slang::IGlobalSession::addBuiltins */ SLANG_API void spAddBuiltins( SlangSession* session, char const* sourcePath, char const* sourceString); + /*! + @brief Callback type used for diagnostic output. + */ + typedef void(*SlangDiagnosticCallback)( + char const* message, + void* userData); + /*! - @brief Create a compile request. + @brief Get the build version 'tag' string. The string is the same as produced via `git describe --tags` + for the project. If Slang is built separately from the automated build scripts + the contents will by default be 'unknown'. Any string can be set by changing the + contents of 'slang-tag-version.h' file and recompiling the project. + + This function will return exactly the same result as the method getBuildTag string on IGlobalSession. + + An advantage of using this function over the method is that doing so does not require the creation of + a session, which can be a fairly costly operation. + + @return The build tag string + */ + SLANG_API const char* spGetBuildTagString(); + + /* @see slang::IGlobalSession::createCompileRequest */ SLANG_API SlangCompileRequest* spCreateCompileRequest( SlangSession* session); /*! @brief Destroy a compile request. + Note a request is a COM object and can be destroyed via 'Release'. */ SLANG_API void spDestroyCompileRequest( SlangCompileRequest* request); - /** Set the filesystem hook to use for a compile request - - The provided `fileSystem` will be used to load any files that - need to be loaded during processing of the compile `request`. - This includes: - - - Source files loaded via `spAddTranslationUnitSourceFile` - - Files referenced via `#include` - - Files loaded to resolve `#import` operations - - */ + /*! @see slang::ICompileRequest::setFileSystem */ SLANG_API void spSetFileSystem( SlangCompileRequest* request, ISlangFileSystem* fileSystem); - - /*! - @brief Set flags to be used for compilation. - */ + /*! @see slang::ICompileRequest::setCompileFlags */ SLANG_API void spSetCompileFlags( SlangCompileRequest* request, SlangCompileFlags flags); - /*! - @brief Set whether to dump intermediate results (for debugging) or not. - */ + /*! @see slang::ICompileRequest::setDumpIntermediates */ SLANG_API void spSetDumpIntermediates( SlangCompileRequest* request, int enable); + /*! @see slang::ICompileRequest::setDumpIntermediatePrefix */ SLANG_API void spSetDumpIntermediatePrefix( SlangCompileRequest* request, const char* prefix); - /*! - @brief Set whether (and how) `#line` directives should be output. - */ + /*! @see slang::ICompileRequest::setLineDirectiveMode */ SLANG_API void spSetLineDirectiveMode( SlangCompileRequest* request, SlangLineDirectiveMode mode); - /*! - @brief Sets the target for code generation. - @param request The compilation context. - @param target The code generation target. Possible values are: - - SLANG_GLSL. Generates GLSL code. - - SLANG_HLSL. Generates HLSL code. - - SLANG_SPIRV. Generates SPIR-V code. - */ + /*! @see slang::ICompileRequest::setCodeGenTarget */ SLANG_API void spSetCodeGenTarget( SlangCompileRequest* request, SlangCompileTarget target); - /*! - @brief Add a code-generation target to be used. - */ + /*! @see slang::ICompileRequest::addCodeGenTarget */ SLANG_API int spAddCodeGenTarget( SlangCompileRequest* request, SlangCompileTarget target); + /*! @see slang::ICompileRequest::setTargetProfile */ SLANG_API void spSetTargetProfile( SlangCompileRequest* request, int targetIndex, SlangProfileID profile); + /*! @see slang::ICompileRequest::setTargetFlags */ SLANG_API void spSetTargetFlags( SlangCompileRequest* request, int targetIndex, @@ -1303,9 +1282,7 @@ extern "C" - /*! - @brief Set the floating point mode (e.g., precise or fast) to use a target. - */ + /*! @see slang::ICompileRequest::setTargetFloatingPointMode */ SLANG_API void spSetTargetFloatingPointMode( SlangCompileRequest* request, int targetIndex, @@ -1317,122 +1294,80 @@ extern "C" int targetIndex, SlangMatrixLayoutMode mode); + /*! @see slang::ICompileRequest::setMatrixLayoutMode */ SLANG_API void spSetMatrixLayoutMode( SlangCompileRequest* request, SlangMatrixLayoutMode mode); - /*! - @brief Set the level of debug information to produce. - */ + /*! @see slang::ICompileRequest::setDebugInfoLevel */ SLANG_API void spSetDebugInfoLevel( SlangCompileRequest* request, SlangDebugInfoLevel level); - /*! - @brief Set the level of optimization to perform. - */ + /*! @see slang::ICompileRequest::setOptimizationLevel */ SLANG_API void spSetOptimizationLevel( SlangCompileRequest* request, SlangOptimizationLevel level); - /*! - @brief Get the build version 'tag' string. The string is the same as produced via `git describe --tags` - for the project. If Slang is built separately from the automated build scripts - the contents will by default be 'unknown'. Any string can be set by changing the - contents of 'slang-tag-version.h' file and recompiling the project. - - This function will return exactly the same result as the method getBuildTag string on IGlobalSession. - - An advantage of using this function over the method is that doing so does not require the creation of - a session, which can be a fairly costly operation. - - @return The build tag string - */ - SLANG_API const char* spGetBuildTagString(); - - /*! - @brief Set the container format to be used for binary output. - */ + + /*! @see slang::ICompileRequest::setOutputContainerFormat */ SLANG_API void spSetOutputContainerFormat( SlangCompileRequest* request, SlangContainerFormat format); + /*! @see slang::ICompileRequest::setPassThrough */ SLANG_API void spSetPassThrough( SlangCompileRequest* request, SlangPassThrough passThrough); - typedef void(*SlangDiagnosticCallback)( - char const* message, - void* userData); - + /*! @see slang::ICompileRequest::setDiagnosticCallback */ SLANG_API void spSetDiagnosticCallback( SlangCompileRequest* request, SlangDiagnosticCallback callback, void const* userData); + /*! @see slang::ICompileRequest::setWriter */ SLANG_API void spSetWriter( SlangCompileRequest* request, SlangWriterChannel channel, ISlangWriter* writer); + /*! @see slang::ICompileRequest::getWriter */ SLANG_API ISlangWriter* spGetWriter( SlangCompileRequest* request, SlangWriterChannel channel); - /*! - @brief Add a path to use when searching for referenced files. - This will be used for both `#include` directives and also for explicit `__import` declarations. - @param ctx The compilation context. - @param searchDir The additional search directory. - */ + /*! @see slang::ICompileRequest::addSearchPath */ SLANG_API void spAddSearchPath( SlangCompileRequest* request, const char* searchDir); - /*! - @brief Add a macro definition to be used during preprocessing. - @param key The name of the macro to define. - @param value The value of the macro to define. - */ + /*! @see slang::ICompileRequest::addPreprocessorDefine */ SLANG_API void spAddPreprocessorDefine( SlangCompileRequest* request, const char* key, const char* value); - /*! - @brief Set options using arguments as if specified via command line. - @return Returns SlangResult. On success SLANG_SUCCEEDED(result) is true. - */ + /*! @see slang::ICompileRequest::processCommandLineArguments */ SLANG_API SlangResult spProcessCommandLineArguments( SlangCompileRequest* request, char const* const* args, int argCount); - /** Add a distinct translation unit to the compilation request - - `name` is optional. - Returns the zero-based index of the translation unit created. - */ + /*! @see slang::ICompileRequest::addTranslationUnit */ SLANG_API int spAddTranslationUnit( SlangCompileRequest* request, SlangSourceLanguage language, char const* name); - /** Set a default module name. Translation units will default to this module name if one is not - passed. If not set each translation unit will get a unique name. - */ + /*! @see slang::ICompileRequest::setDefaultModuleName */ SLANG_API void spSetDefaultModuleName( SlangCompileRequest* request, const char* defaultModuleName); - /** Add a preprocessor definition that is scoped to a single translation unit. - - @param translationUnitIndex The index of the translation unit to get the definition. - @param key The name of the macro to define. - @param value The value of the macro to define. - */ + /*! @see slang::ICompileRequest::addPreprocessorDefine */ SLANG_API void spTranslationUnit_addPreprocessorDefine( SlangCompileRequest* request, int translationUnitIndex, @@ -1440,36 +1375,13 @@ extern "C" const char* value); - /** Add a source file to the given translation unit. - - If a user-defined file system has been specified via - `spSetFileSystem`, then it will be used to load the - file at `path`. Otherwise, Slang will use the OS - file system. - - This function does *not* search for a file using - the registered search paths (`spAddSearchPath`), - and instead using the given `path` as-is. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceFile */ SLANG_API void spAddTranslationUnitSourceFile( SlangCompileRequest* request, int translationUnitIndex, char const* path); - /** Add a source string to the given translation unit. - - @param request The compile request that owns the translation unit. - @param translationUnitIndex The index of the translation unit to add source to. - @param path The file-system path that should be assumed for the source code. - @param source A null-terminated UTF-8 encoded string of source code. - - The implementation will make a copy of the source code data. - An application may free the buffer immediately after this call returns. - - The `path` will be used in any diagnostic output, as well - as to determine the base path when resolving relative - `#include`s. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceString */ SLANG_API void spAddTranslationUnitSourceString( SlangCompileRequest* request, int translationUnitIndex, @@ -1477,33 +1389,13 @@ extern "C" char const* source); - /** Add a slang library - such that its contents can be referenced during linking. - This is equivalent to the -r command line option. - - @param request The compile request - @param libData The library data - @param libDataSize The size of the library data - */ + /*! @see slang::ICompileRequest::addLibraryReference */ SLANG_API SlangResult spAddLibraryReference( SlangCompileRequest* request, const void* libData, size_t libDataSize); - /** Add a source string to the given translation unit. - - @param request The compile request that owns the translation unit. - @param translationUnitIndex The index of the translation unit to add source to. - @param path The file-system path that should be assumed for the source code. - @param sourceBegin A pointer to a buffer of UTF-8 encoded source code. - @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` - - The implementation will make a copy of the source code data. - An application may free the buffer immediately after this call returns. - - The `path` will be used in any diagnostic output, as well - as to determine the base path when resolving relative - `#include`s. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceStringSpan */ SLANG_API void spAddTranslationUnitSourceStringSpan( SlangCompileRequest* request, int translationUnitIndex, @@ -1511,46 +1403,26 @@ extern "C" char const* sourceBegin, char const* sourceEnd); - /** Add a blob of source code to the given translation unit. - - @param request The compile request that owns the translation unit. - @param translationUnitIndex The index of the translation unit to add source to. - @param path The file-system path that should be assumed for the source code. - @param sourceBlob A blob containing UTF-8 encoded source code. - @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` - - The compile request will retain a reference to the blob. - - The `path` will be used in any diagnostic output, as well - as to determine the base path when resolving relative - `#include`s. - */ + /*! @see slang::ICompileRequest::addTranslationUnitSourceBlob */ SLANG_API void spAddTranslationUnitSourceBlob( SlangCompileRequest* request, int translationUnitIndex, char const* path, ISlangBlob* sourceBlob); - /** Look up a compilation profile by name. - - For example, one could look up the string `"ps_5_0"` to find the corresponding target ID. - */ + /*! @see slang::ICompileRequest::findProfile */ SLANG_API SlangProfileID spFindProfile( SlangSession* session, char const* name); - /** Add an entry point in a particular translation unit - */ + /*! @see slang::ICompileRequest::addEntryPoint */ SLANG_API int spAddEntryPoint( SlangCompileRequest* request, int translationUnitIndex, char const* name, SlangStage stage); - /** Add an entry point in a particular translation unit, - with additional arguments that specify the concrete - type names for entry-point generic type parameters. - */ + /*! @see slang::ICompileRequest::addEntryPointEx */ SLANG_API int spAddEntryPointEx( SlangCompileRequest* request, int translationUnitIndex, @@ -1559,248 +1431,121 @@ extern "C" int genericArgCount, char const** genericArgs); - /** Specify the arguments to use for global generic parameters. - */ + /*! @see slang::ICompileRequest::setGlobalGenericArgs */ SLANG_API SlangResult spSetGlobalGenericArgs( SlangCompileRequest* request, int genericArgCount, char const** genericArgs); - /** Specify the concrete type to be used for a global "existential slot." - - Every shader parameter (or leaf field of a `struct`-type shader parameter) - that has an interface or array-of-interface type introduces an existential - slot. The number of slots consumed by a shader parameter, and the starting - slot of each parameter can be queried via the reflection API using - `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. - - In order to generate specialized code, a concrete type needs to be specified - for each existential slot. This function specifies the name of the type - (or in general a type *expression*) to use for a specific slot at the - global scope. - */ + /*! @see slang::ICompileRequest::setTypeNameForGlobalExistentialTypeParam */ SLANG_API SlangResult spSetTypeNameForGlobalExistentialTypeParam( SlangCompileRequest* request, int slotIndex, char const* typeName); - /** Specify the concrete type to be used for an entry-point "existential slot." - - Every shader parameter (or leaf field of a `struct`-type shader parameter) - that has an interface or array-of-interface type introduces an existential - slot. The number of slots consumed by a shader parameter, and the starting - slot of each parameter can be queried via the reflection API using - `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. - - In order to generate specialized code, a concrete type needs to be specified - for each existential slot. This function specifies the name of the type - (or in general a type *expression*) to use for a specific slot at the - entry-point scope. - */ + /*! @see slang::ICompileRequest::setTypeNameForEntryPointExistentialTypeParam */ SLANG_API SlangResult spSetTypeNameForEntryPointExistentialTypeParam( SlangCompileRequest* request, int entryPointIndex, int slotIndex, char const* typeName); - /** Execute the compilation request. - - @returns SlangResult, SLANG_OK on success. Use SLANG_SUCCEEDED() and SLANG_FAILED() to test SlangResult. - */ + /*! @see slang::ICompileRequest::compile */ SLANG_API SlangResult spCompile( SlangCompileRequest* request); - /** Get any diagnostic messages reported by the compiler. - - @returns A null-terminated UTF-8 encoded string of diagnostic messages. - - The returned pointer is only guaranteed to be valid - until `request` is destroyed. Applications that wish to - hold on to the diagnostic output for longer should use - `spGetDiagnosticOutputBlob`. - */ + /*! @see slang::ICompileRequest::getDiagnosticOutput */ SLANG_API char const* spGetDiagnosticOutput( SlangCompileRequest* request); - /** Get diagnostic messages reported by the compiler. - - @param request The compile request to get output from. - @param outBlob A pointer to receive a blob holding a nul-terminated UTF-8 encoded string of diagnostic messages. - @returns A `SlangResult` indicating success or failure. - */ + /*! @see slang::ICompileRequest::getDiagnosticOutputBlob */ SLANG_API SlangResult spGetDiagnosticOutputBlob( SlangCompileRequest* request, ISlangBlob** outBlob); - /** Get the number of files that this compilation depended on. - - This includes both the explicit source files, as well as any - additional files that were transitively referenced (e.g., via - a `#include` directive). - */ + /*! @see slang::ICompileRequest::getDependencyFileCount */ SLANG_API int spGetDependencyFileCount( SlangCompileRequest* request); - /** Get the path to a file this compilation depended on. - */ + /*! @see slang::ICompileRequest::getDependencyFilePath */ SLANG_API char const* spGetDependencyFilePath( SlangCompileRequest* request, int index); - /** Get the number of translation units associated with the compilation request - */ + /*! @see slang::ICompileRequest::getTranslationUnitCount */ SLANG_API int spGetTranslationUnitCount( SlangCompileRequest* request); - /** Get the output source code associated with a specific entry point. - - The lifetime of the output pointer is the same as `request`. - */ + /*! @see slang::ICompileRequest::getEntryPointSource */ SLANG_API char const* spGetEntryPointSource( SlangCompileRequest* request, int entryPointIndex); - /** Get the output bytecode associated with a specific entry point. - - The lifetime of the output pointer is the same as `request`. - */ + /*! @see slang::ICompileRequest::getEntryPointCode */ SLANG_API void const* spGetEntryPointCode( SlangCompileRequest* request, int entryPointIndex, size_t* outSize); - /** Get the output code associated with a specific entry point. - - @param request The request - @param entryPointIndex The index of the entry point to get code for. - @param targetIndex The index of the target to get code for (default: zero). - @param outBlob A pointer that will receive the blob of code - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getEntryPointCodeBlob */ SLANG_API SlangResult spGetEntryPointCodeBlob( SlangCompileRequest* request, int entryPointIndex, int targetIndex, ISlangBlob** outBlob); - /** Get entry point 'callable' functions accessible through the ISlangSharedLibrary interface. - - That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. - - NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. - - @param request The request - @param entryPointIndex The index of the entry point to get code for. - @param targetIndex The index of the target to get code for (default: zero). - @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getEntryPointHostCallable */ SLANG_API SlangResult spGetEntryPointHostCallable( SlangCompileRequest* request, int entryPointIndex, int targetIndex, ISlangSharedLibrary** outSharedLibrary); - /** Get the output code associated with a specific target. - - @param request The request - @param targetIndex The index of the target to get code for (default: zero). - @param outBlob A pointer that will receive the blob of code - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getTargetCodeBlob */ SLANG_API SlangResult spGetTargetCodeBlob( SlangCompileRequest* request, int targetIndex, ISlangBlob** outBlob); - /** Get 'callable' functions for a target accessible through the ISlangSharedLibrary interface. - - That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. - - NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. - - @param request The request - @param targetIndex The index of the target to get code for (default: zero). - @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getTargetHostCallable */ SLANG_API SlangResult spGetTargetHostCallable( SlangCompileRequest* request, int targetIndex, ISlangSharedLibrary** outSharedLibrary); - /** Get the output bytecode associated with an entire compile request. - - The lifetime of the output pointer is the same as `request` and the last spCompile. - - @param request The request - @param outSize The size of the containers contents in bytes. Will be zero if there is no code available. - @returns Pointer to start of the contained data, or nullptr if there is no code available. - */ + /*! @see slang::ICompileRequest::getCompileRequestCode */ SLANG_API void const* spGetCompileRequestCode( SlangCompileRequest* request, size_t* outSize); - /** Return the container code as a blob. The container blob is created as part of a compilation (with spCompile), - and a container is produced with a suitable ContainerFormat. - - @param request The request - @param outSize The blob containing the container data. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::getContainerCode */ SLANG_API SlangResult spGetContainerCode( SlangCompileRequest* request, ISlangBlob** outBlob); - /** Load repro from memory specified. - - Should only be performed on a newly created request. - - NOTE! When using the fileSystem, files will be loaded via their `unique names` as if they are part of the flat file system. This - mechanism is described more fully in docs/repro.md. - - @param request The request - @param fileSystem An (optional) filesystem. Pass nullptr to just use contents of repro held in data. - @param data The data to load from. - @param size The size of the data to load from. - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::loadRepro */ SLANG_API SlangResult spLoadRepro( SlangCompileRequest* request, ISlangFileSystem* fileSystem, const void* data, size_t size); - /** Save repro state. Should *typically* be performed after spCompile, so that everything - that is needed for a compilation is available. - - @param request The request - @param outBlob Blob that will hold the serialized state - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::saveRepro */ SLANG_API SlangResult spSaveRepro( SlangCompileRequest* request, ISlangBlob** outBlob ); - /** Enable repro capture. - - Should be set after any ISlangFileSystem has been set, but before any compilation. It ensures that everything - that the ISlangFileSystem accesses will be correctly recorded. - Note that if a ISlangFileSystem/ISlangFileSystemExt isn't explicitly set (ie the default is used), then the - request will automatically be set up to record everything appropriate. - - @param request The request - @returns A `SlangResult` to indicate success or failure. - */ + /*! @see slang::ICompileRequest::enableReproCapture */ SLANG_API SlangResult spEnableReproCapture( SlangCompileRequest* request); + /** Extract contents of a repro. Writes the contained files and manifest with their 'unique' names into fileSystem. For more details read the @@ -3032,7 +2777,48 @@ namespace slang SlangSourceLanguage sourceLanguage, ISlangBlob** outPrelude) = 0; - + /** Create a compile request. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL createCompileRequest( + slang::ICompileRequest** outCompileRequest) = 0; + + /** Add new builtin declarations to be used in subsequent compiles. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addBuiltins( + char const* sourcePath, + char const* sourceString) = 0; + + /** Set the session shared library loader. If this changes the loader, it may cause shared libraries to be unloaded + @param loader The loader to set. Setting nullptr sets the default loader. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setSharedLibraryLoader( + ISlangSharedLibraryLoader* loader) = 0; + + /** Gets the currently set shared library loader + @return Gets the currently set loader. If returns nullptr, it's the default loader + */ + virtual SLANG_NO_THROW ISlangSharedLibraryLoader* SLANG_MCALL getSharedLibraryLoader() = 0; + + /** Returns SLANG_OK if a the compilation target is supported for this session + + @param target The compilation target to test + @return SLANG_OK if the target is available + SLANG_E_NOT_IMPLEMENTED if not implemented in this build + SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found + SLANG_FAIL other kinds of failures */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL checkCompileTargetSupport( + SlangCompileTarget target) = 0; + + /** Returns SLANG_OK if a the pass through support is supported for this session + @param session Session + @param target The compilation target to test + @return SLANG_OK if the target is available + SLANG_E_NOT_IMPLEMENTED if not implemented in this build + SLANG_E_NOT_FOUND if other resources (such as shared libraries) required to make target work could not be found + SLANG_FAIL other kinds of failures */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL checkPassThroughSupport( + SlangPassThrough passThrough) = 0; + /** Compile from (embedded source) the StdLib on the session. Will return a failure if there is already a StdLib available NOTE! API is experimental and not ready for production code @@ -3051,6 +2837,541 @@ namespace slang #define SLANG_UUID_IGlobalSession { 0xc140b5fd, 0xc78, 0x452e, { 0xba, 0x7c, 0x1a, 0x1e, 0x70, 0xc7, 0xf7, 0x1c } }; + /*! + @brief A request for one or more compilation actions to be performed. + */ + struct ICompileRequest : public ISlangUnknown + { + public: + + /** Set the filesystem hook to use for a compile request + + The provided `fileSystem` will be used to load any files that + need to be loaded during processing of the compile `request`. + This includes: + + - Source files loaded via `spAddTranslationUnitSourceFile` + - Files referenced via `#include` + - Files loaded to resolve `#import` operations + */ + virtual SLANG_NO_THROW void SLANG_MCALL setFileSystem( + ISlangFileSystem* fileSystem) = 0; + + /*! + @brief Set flags to be used for compilation. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setCompileFlags( + SlangCompileFlags flags) = 0; + + /*! + @brief Set whether to dump intermediate results (for debugging) or not. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setDumpIntermediates( + int enable) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setDumpIntermediatePrefix( + const char* prefix) = 0; + + /*! + @brief Set whether (and how) `#line` directives should be output. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setLineDirectiveMode( + SlangLineDirectiveMode mode) = 0; + + /*! + @brief Sets the target for code generation. + @param target The code generation target. Possible values are: + - SLANG_GLSL. Generates GLSL code. + - SLANG_HLSL. Generates HLSL code. + - SLANG_SPIRV. Generates SPIR-V code. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setCodeGenTarget( + SlangCompileTarget target) = 0; + + /*! + @brief Add a code-generation target to be used. + */ + virtual SLANG_NO_THROW int SLANG_MCALL addCodeGenTarget( + SlangCompileTarget target) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setTargetProfile( + int targetIndex, + SlangProfileID profile) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setTargetFlags( + int targetIndex, + SlangTargetFlags flags) = 0; + + + /*! + @brief Set the floating point mode (e.g., precise or fast) to use a target. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setTargetFloatingPointMode( + int targetIndex, + SlangFloatingPointMode mode) = 0; + + /* DEPRECATED: use `spSetMatrixLayoutMode` instead. */ + virtual SLANG_NO_THROW void SLANG_MCALL setTargetMatrixLayoutMode( + int targetIndex, + SlangMatrixLayoutMode mode) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setMatrixLayoutMode( + SlangMatrixLayoutMode mode) = 0; + + /*! + @brief Set the level of debug information to produce. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setDebugInfoLevel( + SlangDebugInfoLevel level) = 0; + + /*! + @brief Set the level of optimization to perform. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setOptimizationLevel( + SlangOptimizationLevel level) = 0; + + + + /*! + @brief Set the container format to be used for binary output. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setOutputContainerFormat( + SlangContainerFormat format) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setPassThrough( + SlangPassThrough passThrough) = 0; + + + virtual SLANG_NO_THROW void SLANG_MCALL setDiagnosticCallback( + SlangDiagnosticCallback callback, + void const* userData) = 0; + + virtual SLANG_NO_THROW void SLANG_MCALL setWriter( + SlangWriterChannel channel, + ISlangWriter* writer) = 0; + + virtual SLANG_NO_THROW ISlangWriter* SLANG_MCALL getWriter( + SlangWriterChannel channel) = 0; + + /*! + @brief Add a path to use when searching for referenced files. + This will be used for both `#include` directives and also for explicit `__import` declarations. + @param ctx The compilation context. + @param searchDir The additional search directory. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addSearchPath( + const char* searchDir) = 0; + + /*! + @brief Add a macro definition to be used during preprocessing. + @param key The name of the macro to define. + @param value The value of the macro to define. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addPreprocessorDefine( + const char* key, + const char* value) = 0; + + /*! + @brief Set options using arguments as if specified via command line. + @return Returns SlangResult. On success SLANG_SUCCEEDED(result) is true. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL processCommandLineArguments( + char const* const* args, + int argCount) = 0; + + /** Add a distinct translation unit to the compilation request + + `name` is optional. + Returns the zero-based index of the translation unit created. + */ + virtual SLANG_NO_THROW int SLANG_MCALL addTranslationUnit( + SlangSourceLanguage language, + char const* name) = 0; + + + /** Set a default module name. Translation units will default to this module name if one is not + passed. If not set each translation unit will get a unique name. + */ + virtual SLANG_NO_THROW void SLANG_MCALL setDefaultModuleName( + const char* defaultModuleName) = 0; + + /** Add a preprocessor definition that is scoped to a single translation unit. + + @param translationUnitIndex The index of the translation unit to get the definition. + @param key The name of the macro to define. + @param value The value of the macro to define. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitPreprocessorDefine( + int translationUnitIndex, + const char* key, + const char* value) = 0; + + + /** Add a source file to the given translation unit. + + If a user-defined file system has been specified via + `spSetFileSystem`, then it will be used to load the + file at `path`. Otherwise, Slang will use the OS + file system. + + This function does *not* search for a file using + the registered search paths (`spAddSearchPath`), + and instead using the given `path` as-is. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceFile( + int translationUnitIndex, + char const* path) = 0; + + /** Add a source string to the given translation unit. + + @param translationUnitIndex The index of the translation unit to add source to. + @param path The file-system path that should be assumed for the source code. + @param source A null-terminated UTF-8 encoded string of source code. + + The implementation will make a copy of the source code data. + An application may free the buffer immediately after this call returns. + + The `path` will be used in any diagnostic output, as well + as to determine the base path when resolving relative + `#include`s. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceString( + int translationUnitIndex, + char const* path, + char const* source) = 0; + + + /** Add a slang library - such that its contents can be referenced during linking. + This is equivalent to the -r command line option. + + @param libData The library data + @param libDataSize The size of the library data + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL addLibraryReference( + const void* libData, + size_t libDataSize) = 0; + + /** Add a source string to the given translation unit. + + @param translationUnitIndex The index of the translation unit to add source to. + @param path The file-system path that should be assumed for the source code. + @param sourceBegin A pointer to a buffer of UTF-8 encoded source code. + @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` + + The implementation will make a copy of the source code data. + An application may free the buffer immediately after this call returns. + + The `path` will be used in any diagnostic output, as well + as to determine the base path when resolving relative + `#include`s. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceStringSpan( + int translationUnitIndex, + char const* path, + char const* sourceBegin, + char const* sourceEnd) = 0; + + /** Add a blob of source code to the given translation unit. + + @param translationUnitIndex The index of the translation unit to add source to. + @param path The file-system path that should be assumed for the source code. + @param sourceBlob A blob containing UTF-8 encoded source code. + @param sourceEnd A pointer to to the end of the buffer specified in `sourceBegin` + + The compile request will retain a reference to the blob. + + The `path` will be used in any diagnostic output, as well + as to determine the base path when resolving relative + `#include`s. + */ + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceBlob( + int translationUnitIndex, + char const* path, + ISlangBlob* sourceBlob) = 0; + + /** Add an entry point in a particular translation unit + */ + virtual SLANG_NO_THROW int SLANG_MCALL addEntryPoint( + int translationUnitIndex, + char const* name, + SlangStage stage) = 0; + + /** Add an entry point in a particular translation unit, + with additional arguments that specify the concrete + type names for entry-point generic type parameters. + */ + virtual SLANG_NO_THROW int SLANG_MCALL addEntryPointEx( + int translationUnitIndex, + char const* name, + SlangStage stage, + int genericArgCount, + char const** genericArgs) = 0; + + /** Specify the arguments to use for global generic parameters. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setGlobalGenericArgs( + int genericArgCount, + char const** genericArgs) = 0; + + /** Specify the concrete type to be used for a global "existential slot." + + Every shader parameter (or leaf field of a `struct`-type shader parameter) + that has an interface or array-of-interface type introduces an existential + slot. The number of slots consumed by a shader parameter, and the starting + slot of each parameter can be queried via the reflection API using + `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. + + In order to generate specialized code, a concrete type needs to be specified + for each existential slot. This function specifies the name of the type + (or in general a type *expression*) to use for a specific slot at the + global scope. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setTypeNameForGlobalExistentialTypeParam( + int slotIndex, + char const* typeName) = 0; + + /** Specify the concrete type to be used for an entry-point "existential slot." + + Every shader parameter (or leaf field of a `struct`-type shader parameter) + that has an interface or array-of-interface type introduces an existential + slot. The number of slots consumed by a shader parameter, and the starting + slot of each parameter can be queried via the reflection API using + `SLANG_PARAMETER_CATEGORY_EXISTENTIAL_TYPE_PARAM`. + + In order to generate specialized code, a concrete type needs to be specified + for each existential slot. This function specifies the name of the type + (or in general a type *expression*) to use for a specific slot at the + entry-point scope. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setTypeNameForEntryPointExistentialTypeParam( + int entryPointIndex, + int slotIndex, + char const* typeName) = 0; + + /** Execute the compilation request. + + @returns SlangResult, SLANG_OK on success. Use SLANG_SUCCEEDED() and SLANG_FAILED() to test SlangResult. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile() = 0; + + + /** Get any diagnostic messages reported by the compiler. + + @returns A null-terminated UTF-8 encoded string of diagnostic messages. + + The returned pointer is only guaranteed to be valid + until `request` is destroyed. Applications that wish to + hold on to the diagnostic output for longer should use + `getDiagnosticOutputBlob`. + */ + virtual SLANG_NO_THROW char const* SLANG_MCALL getDiagnosticOutput() = 0; + + /** Get diagnostic messages reported by the compiler. + + @param outBlob A pointer to receive a blob holding a nul-terminated UTF-8 encoded string of diagnostic messages. + @returns A `SlangResult` indicating success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getDiagnosticOutputBlob( + ISlangBlob** outBlob) = 0; + + + /** Get the number of files that this compilation depended on. + + This includes both the explicit source files, as well as any + additional files that were transitively referenced (e.g., via + a `#include` directive). + */ + virtual SLANG_NO_THROW int SLANG_MCALL getDependencyFileCount() = 0; + + /** Get the path to a file this compilation depended on. + */ + virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath( + int index) = 0; + + /** Get the number of translation units associated with the compilation request + */ + virtual SLANG_NO_THROW int SLANG_MCALL getTranslationUnitCount() = 0; + + /** Get the output source code associated with a specific entry point. + + The lifetime of the output pointer is the same as `request`. + */ + virtual SLANG_NO_THROW char const* SLANG_MCALL getEntryPointSource( + int entryPointIndex) = 0; + + /** Get the output bytecode associated with a specific entry point. + + The lifetime of the output pointer is the same as `request`. + */ + virtual SLANG_NO_THROW void const* SLANG_MCALL getEntryPointCode( + int entryPointIndex, + size_t* outSize) = 0; + + /** Get the output code associated with a specific entry point. + + @param entryPointIndex The index of the entry point to get code for. + @param targetIndex The index of the target to get code for (default: zero). + @param outBlob A pointer that will receive the blob of code + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCodeBlob( + int entryPointIndex, + int targetIndex, + ISlangBlob** outBlob) = 0; + + /** Get entry point 'callable' functions accessible through the ISlangSharedLibrary interface. + + That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. + + NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. + + @param entryPointIndex The index of the entry point to get code for. + @param targetIndex The index of the target to get code for (default: zero). + @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointHostCallable( + int entryPointIndex, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) = 0; + + /** Get the output code associated with a specific target. + + @param targetIndex The index of the target to get code for (default: zero). + @param outBlob A pointer that will receive the blob of code + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCodeBlob( + int targetIndex, + ISlangBlob** outBlob) = 0; + + /** Get 'callable' functions for a target accessible through the ISlangSharedLibrary interface. + + That the functions remain in scope as long as the ISlangSharedLibrary interface is in scope. + + NOTE! Requires a compilation target of SLANG_HOST_CALLABLE. + + @param targetIndex The index of the target to get code for (default: zero). + @param outSharedLibrary A pointer to a ISharedLibrary interface which functions can be queried on. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetHostCallable( + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) = 0; + + /** Get the output bytecode associated with an entire compile request. + + The lifetime of the output pointer is the same as `request` and the last spCompile. + + @param outSize The size of the containers contents in bytes. Will be zero if there is no code available. + @returns Pointer to start of the contained data, or nullptr if there is no code available. + */ + virtual SLANG_NO_THROW void const* SLANG_MCALL getCompileRequestCode( + size_t* outSize) = 0; + + /** Return the container code as a blob. The container blob is created as part of a compilation (with spCompile), + and a container is produced with a suitable ContainerFormat. + + @param outSize The blob containing the container data. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getContainerCode( + ISlangBlob** outBlob) = 0; + + /** Load repro from memory specified. + + Should only be performed on a newly created request. + + NOTE! When using the fileSystem, files will be loaded via their `unique names` as if they are part of the flat file system. This + mechanism is described more fully in docs/repro.md. + + @param fileSystem An (optional) filesystem. Pass nullptr to just use contents of repro held in data. + @param data The data to load from. + @param size The size of the data to load from. + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadRepro( + ISlangFileSystem* fileSystem, + const void* data, + size_t size) = 0; + + /** Save repro state. Should *typically* be performed after spCompile, so that everything + that is needed for a compilation is available. + + @param outBlob Blob that will hold the serialized state + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveRepro( + ISlangBlob** outBlob) = 0; + + /** Enable repro capture. + + Should be set after any ISlangFileSystem has been set, but before any compilation. It ensures that everything + that the ISlangFileSystem accesses will be correctly recorded. + Note that if a ISlangFileSystem/ISlangFileSystemExt isn't explicitly set (ie the default is used), then the + request will automatically be set up to record everything appropriate. + + @returns A `SlangResult` to indicate success or failure. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL enableReproCapture() = 0; + + /** Get the (linked) program for a compile request. + + The linked program will include all of the global-scope modules for the + translation units in the program, plus any modules that they `import` + (transitively), specialized to any global specialization arguments that + were provided via the API. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getProgram( + slang::IComponentType** outProgram) = 0; + + /** Get the (partially linked) component type for an entry point. + + The returned component type will include the entry point at the + given index, and will be specialized using any specialization arguments + that were provided for it via the API. + + The returned component will *not* include the modules representing + the global scope and its dependencies/specialization, so a client + program will typically want to compose this component type with + the one returned by `spCompileRequest_getProgram` to get a complete + and usable component type from which kernel code can be requested. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPoint( + SlangInt entryPointIndex, + slang::IComponentType** outEntryPoint) = 0; + + /** Get the (un-linked) module for a translation unit. + + The returned module will not be linked against any dependencies, + nor against any entry points (even entry points declared inside + the module). Similarly, the module will not be specialized + to the arguments that might have been provided via the API. + + This function provides an atomic unit of loaded code that + is suitable for looking up types and entry points in the + given module, and for linking together to produce a composite + program that matches the needs of an application. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getModule( + SlangInt translationUnitIndex, + slang::IModule** outModule) = 0; + + /** Get the `ISession` handle behind the `SlangCompileRequest`. + TODO(JS): Arguably this should just return the session pointer. + */ + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getSession( + slang::ISession** outSession) = 0; + + /** get reflection data from a compilation request */ + virtual SLANG_NO_THROW SlangReflection* SLANG_MCALL getReflection() = 0; + + /** Make output specially handled for command line output */ + virtual SLANG_NO_THROW void SLANG_MCALL setCommandLineCompilerMode() = 0; + }; + + #define SLANG_UUID_ICompileRequest { 0x96d33993, 0x317c, 0x4db5, { 0xaf, 0xd8, 0x66, 0x6e, 0xe7, 0x72, 0x48, 0xe2 } }; + /** Description of a code generation target. */ struct TargetDesc @@ -3225,7 +3546,7 @@ namespace slang TypeReflection* interfaceType, ISlangBlob** outNameBlob) = 0; - /** Get the sequantial ID used to identify a type witness in a dynamic object. + /** Get the sequential ID used to identify a type witness in a dynamic object. */ virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTypeConformanceWitnessSequentialID( slang::TypeReflection* type, @@ -3471,52 +3792,27 @@ namespace slang } } -/** Get the (linked) program for a compile request. - -The linked program will include all of the global-scope modules for the -translation units in the program, plus any modules that they `import` -(transitively), specialized to any global specialization arguments that -were provided via the API. +/** @see slang::ICompileRequest::getProgram */ SLANG_API SlangResult spCompileRequest_getProgram( SlangCompileRequest* request, slang::IComponentType** outProgram); -/** Get the (partially linked) component type for an entry point. - -The returned component type will include the entry point at the -given index, and will be specialized using any specialization arguments -that were provided for it via the API. - -The returned component will *not* include the modules representing -the global scope and its dependencies/specialization, so a client -program will typically want to compose this component type with -the one returned by `spCompileRequest_getProgram` to get a complete -and usable component type from which kernel code can be requested. +/** @see slang::ICompileRequest::getEntryPoint */ SLANG_API SlangResult spCompileRequest_getEntryPoint( SlangCompileRequest* request, SlangInt entryPointIndex, slang::IComponentType** outEntryPoint); -/** Get the (un-linked) module for a translation unit. - -The returned module will not be linked against any dependencies, -nor against any entry points (even entry points declared inside -the module). Similarly, the module will not be specialized -to the arguments that might have been provided via the API. - -This function provides an atomic unit of loaded code that -is suitable for looking up types and entry points in the -given module, and for linking together to produce a composite -program that matches the needs of an application. +/** @see slang::ICompileRequest::getModule */ SLANG_API SlangResult spCompileRequest_getModule( SlangCompileRequest* request, SlangInt translationUnitIndex, slang::IModule** outModule); -/** Get the `ISession` handle behind the `SlangCompileRequest`. +/** @see slang::ICompileRequest::getSession */ SLANG_API SlangResult spCompileRequest_getSession( SlangCompileRequest* request, diff --git a/source/slang/slang-check-shader.cpp b/source/slang/slang-check-shader.cpp index 7793dfcbc..800a0519f 100644 --- a/source/slang/slang-check-shader.cpp +++ b/source/slang/slang-check-shader.cpp @@ -1513,7 +1513,7 @@ namespace Slang List<Expr*> globalSpecializationArgs; parseSpecializationArgStrings( endToEndReq, - endToEndReq->globalSpecializationArgStrings, + endToEndReq->m_globalSpecializationArgStrings, globalSpecializationArgs); // Don't proceed further if anything failed to parse. @@ -1548,11 +1548,11 @@ namespace Slang // ahead and consider all the entry points that were found // by the front-end. // - Index entryPointCount = endToEndReq->entryPoints.getCount(); + Index entryPointCount = endToEndReq->m_entryPoints.getCount(); if( entryPointCount == 0 ) { entryPointCount = unspecializedProgram->getEntryPointCount(); - endToEndReq->entryPoints.setCount(entryPointCount); + endToEndReq->m_entryPoints.setCount(entryPointCount); } return specializedProgram; @@ -1617,7 +1617,7 @@ namespace Slang // We will thus draw a distinction between the "specified" entry points, // and the "found" entry points. // - auto specifiedEntryPointCount = endToEndReq->entryPoints.getCount(); + auto specifiedEntryPointCount = endToEndReq->m_entryPoints.getCount(); auto foundEntryPointCount = unspecializedGlobalAndEntryPointsComponentType->getEntryPointCount(); SLANG_ASSERT(foundEntryPointCount >= specifiedEntryPointCount); @@ -1627,7 +1627,7 @@ namespace Slang // for(Index ii = 0; ii < specifiedEntryPointCount; ++ii) { - auto& entryPointInfo = endToEndReq->entryPoints[ii]; + auto& entryPointInfo = endToEndReq->m_entryPoints[ii]; auto unspecializedEntryPoint = unspecializedGlobalAndEntryPointsComponentType->getEntryPoint(ii); auto specializedEntryPoint = createSpecializedEntryPoint(endToEndReq, unspecializedEntryPoint, entryPointInfo); diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index bf004817b..7f378f7b7 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -80,7 +80,7 @@ namespace Slang } } - void Session::setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) + void Session::_setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) { if (m_sharedLibraryLoader != loader) { @@ -117,7 +117,7 @@ namespace Slang if (type == PassThroughMode::GenericCCpp) { - // try testing for availablilty on all C/C++ compilers + // try testing for availability on all C/C++ compilers getOrLoadDownstreamCompiler(PassThroughMode::Clang, sink); getOrLoadDownstreamCompiler(PassThroughMode::Gcc, sink); getOrLoadDownstreamCompiler(PassThroughMode::VisualStudio, sink); diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 306119b5f..0d92fbacc 100755 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -516,14 +516,6 @@ namespace Slang return PassThroughMode::None; } - SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target) - { - const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target); - return (mode != PassThroughMode::None) ? - checkExternalCompilerSupport(session, mode) : - SLANG_OK; - } - bool isPassThroughEnabled( EndToEndCompileRequest* endToEndReq) { // If there isn't an end-to-end compile going on, @@ -534,7 +526,7 @@ namespace Slang // And if pass-through isn't set, we don't need // access to the translation unit. // - if(endToEndReq->passThrough == PassThroughMode::None) return false; + if(endToEndReq->m_passThrough == PassThroughMode::None) return false; return true; } /// If there is a pass-through compile going on, find the translation unit for the given entry point. @@ -544,7 +536,7 @@ namespace Slang Int entryPointIndex) { SLANG_ASSERT(endToEndReq); - SLANG_ASSERT(endToEndReq->passThrough != PassThroughMode::None); + SLANG_ASSERT(endToEndReq->m_passThrough != PassThroughMode::None); auto frontEndReq = endToEndReq->getFrontEndReq(); auto entryPointReq = frontEndReq->getEntryPointReq(entryPointIndex); auto translationUnit = entryPointReq->getTranslationUnit(); @@ -1241,7 +1233,7 @@ SlangResult dissassembleDXILUsingDXC( CodeGenTarget sourceTarget = CodeGenTarget::None; SourceLanguage sourceLanguage = SourceLanguage::Unknown; - PassThroughMode downstreamCompiler = endToEndReq ? endToEndReq->passThrough : PassThroughMode::None; + PassThroughMode downstreamCompiler = endToEndReq ? endToEndReq->m_passThrough : PassThroughMode::None; // If we are not in pass through, lookup the default compiler for the emitted source type if (downstreamCompiler == PassThroughMode::None) @@ -2147,7 +2139,7 @@ SlangResult dissassembleDXILUsingDXC( // get paths specified via command-line options. // RefPtr<EndToEndCompileRequest::TargetInfo> targetInfo; - if (compileRequest->targetInfos.TryGetValue(targetReq, targetInfo)) + if (compileRequest->m_targetInfos.TryGetValue(targetReq, targetInfo)) { String outputPath = targetInfo->wholeTargetOutputPath; if (outputPath != "") @@ -2183,7 +2175,7 @@ SlangResult dissassembleDXILUsingDXC( // RefPtr<EndToEndCompileRequest::TargetInfo> targetInfo; auto entryPoint = currentProgram->getEntryPoint(entryPointIndex); - if(compileRequest->targetInfos.TryGetValue(targetReq, targetInfo)) + if(compileRequest->m_targetInfos.TryGetValue(targetReq, targetInfo)) { String outputPath; if(targetInfo->entryPointOutputPaths.TryGetValue(entryPointIndex, outputPath)) @@ -2481,7 +2473,7 @@ SlangResult dissassembleDXILUsingDXC( // If we are in command-line mode, we might be expected to actually // write output to one or more files here. - if (compileRequest->isCommandLineCompile) + if (compileRequest->m_isCommandLineCompile) { auto linkage = compileRequest->getLinkage(); auto program = compileRequest->getSpecializedGlobalAndEntryPointsComponentType(); diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index fdd32ee81..2388f5247 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -32,6 +32,8 @@ namespace Slang class TargetRequest; class TypeLayout; + extern const Guid IID_EndToEndCompileRequest; + enum class CompilerMode { ProduceLibrary, @@ -1805,6 +1807,9 @@ namespace Slang RefPtr<ComponentType> m_program; }; + // UUID to identify EndToEndCompileRequest from an interface + #define SLANG_UUID_EndToEndCompileRequest { 0xce6d2383, 0xee1b, 0x4fd7, { 0xa0, 0xf, 0xb8, 0xb6, 0x33, 0x12, 0x95, 0xc8 } }; + /// A compile request that spans the front and back ends of the compiler /// /// This is what the command-line `slangc` uses, as well as the legacy @@ -1813,9 +1818,74 @@ namespace Slang /// number of additional features that primarily make sense for /// command-line usage. /// - class EndToEndCompileRequest : public RefObject + class EndToEndCompileRequest : public RefObject, public slang::ICompileRequest { public: + // ISlangUnknown + SLANG_NO_THROW SlangResult SLANG_MCALL queryInterface(SlangUUID const& uuid, void** outObject) SLANG_OVERRIDE; + SLANG_REF_OBJECT_IUNKNOWN_ADD_REF + SLANG_REF_OBJECT_IUNKNOWN_RELEASE + + // slang::ICompileRequest + virtual SLANG_NO_THROW void SLANG_MCALL setFileSystem(ISlangFileSystem* fileSystem) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setCompileFlags(SlangCompileFlags flags) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setDumpIntermediates(int enable) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setDumpIntermediatePrefix(const char* prefix) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setLineDirectiveMode(SlangLineDirectiveMode mode) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setCodeGenTarget(SlangCompileTarget target) SLANG_OVERRIDE; + virtual SLANG_NO_THROW int SLANG_MCALL addCodeGenTarget(SlangCompileTarget target) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setTargetProfile(int targetIndex, SlangProfileID profile) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setTargetFlags(int targetIndex, SlangTargetFlags flags) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setTargetFloatingPointMode(int targetIndex, SlangFloatingPointMode mode) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setTargetMatrixLayoutMode(int targetIndex, SlangMatrixLayoutMode mode) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setMatrixLayoutMode(SlangMatrixLayoutMode mode) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setDebugInfoLevel(SlangDebugInfoLevel level) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setOptimizationLevel(SlangOptimizationLevel level) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setOutputContainerFormat(SlangContainerFormat format) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setPassThrough(SlangPassThrough passThrough) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setDiagnosticCallback(SlangDiagnosticCallback callback, void const* userData) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setWriter(SlangWriterChannel channel, ISlangWriter* writer) SLANG_OVERRIDE; + virtual SLANG_NO_THROW ISlangWriter* SLANG_MCALL getWriter(SlangWriterChannel channel) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addSearchPath(const char* searchDir) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addPreprocessorDefine(const char* key, const char* value) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL processCommandLineArguments(char const* const* args, int argCount) SLANG_OVERRIDE; + virtual SLANG_NO_THROW int SLANG_MCALL addTranslationUnit(SlangSourceLanguage language, char const* name) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setDefaultModuleName(const char* defaultModuleName) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitPreprocessorDefine(int translationUnitIndex, const char* key, const char* value) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceFile(int translationUnitIndex, char const* path) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceString(int translationUnitIndex, char const* path, char const* source) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL addLibraryReference(const void* libData, size_t libDataSize) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceStringSpan(int translationUnitIndex, char const* path, char const* sourceBegin, char const* sourceEnd) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL addTranslationUnitSourceBlob(int translationUnitIndex, char const* path, ISlangBlob* sourceBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW int SLANG_MCALL addEntryPoint(int translationUnitIndex, char const* name, SlangStage stage) SLANG_OVERRIDE; + virtual SLANG_NO_THROW int SLANG_MCALL addEntryPointEx(int translationUnitIndex, char const* name, SlangStage stage, int genericArgCount, char const** genericArgs) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setGlobalGenericArgs(int genericArgCount, char const** genericArgs) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setTypeNameForGlobalExistentialTypeParam(int slotIndex, char const* typeName) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL setTypeNameForEntryPointExistentialTypeParam(int entryPointIndex, int slotIndex, char const* typeName) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL compile() SLANG_OVERRIDE; + virtual SLANG_NO_THROW char const* SLANG_MCALL getDiagnosticOutput() SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getDiagnosticOutputBlob(ISlangBlob** outBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW int SLANG_MCALL getDependencyFileCount() SLANG_OVERRIDE; + virtual SLANG_NO_THROW char const* SLANG_MCALL getDependencyFilePath(int index) SLANG_OVERRIDE; + virtual SLANG_NO_THROW int SLANG_MCALL getTranslationUnitCount() SLANG_OVERRIDE; + virtual SLANG_NO_THROW char const* SLANG_MCALL getEntryPointSource(int entryPointIndex) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void const* SLANG_MCALL getEntryPointCode(int entryPointIndex, size_t* outSize) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointCodeBlob(int entryPointIndex, int targetIndex, ISlangBlob** outBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPointHostCallable(int entryPointIndex, int targetIndex, ISlangSharedLibrary** outSharedLibrary) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetCodeBlob(int targetIndex, ISlangBlob** outBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getTargetHostCallable(int targetIndex, ISlangSharedLibrary** outSharedLibrary) SLANG_OVERRIDE; + virtual SLANG_NO_THROW void const* SLANG_MCALL getCompileRequestCode(size_t* outSize) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getContainerCode(ISlangBlob** outBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadRepro(ISlangFileSystem* fileSystem, const void* data, size_t size) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL saveRepro(ISlangBlob** outBlob) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL enableReproCapture() SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getProgram(slang::IComponentType** outProgram) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getEntryPoint(SlangInt entryPointIndex, slang::IComponentType** outEntryPoint) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getModule(SlangInt translationUnitIndex, slang::IModule** outModule) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangResult SLANG_MCALL getSession(slang::ISession** outSession) SLANG_OVERRIDE; + virtual SLANG_NO_THROW SlangReflection* SLANG_MCALL getReflection() SLANG_OVERRIDE; + virtual SLANG_NO_THROW void SLANG_MCALL setCommandLineCompilerMode() SLANG_OVERRIDE; + EndToEndCompileRequest( Session* session); @@ -1834,27 +1904,27 @@ namespace Slang String m_containerOutputPath; // Should we just pass the input to another compiler? - PassThroughMode passThrough = PassThroughMode::None; + PassThroughMode m_passThrough = PassThroughMode::None; /// Source code for the specialization arguments to use for the global specialization parameters of the program. - List<String> globalSpecializationArgStrings; + List<String> m_globalSpecializationArgStrings; - bool shouldSkipCodegen = false; + bool m_shouldSkipCodegen = false; // Are we being driven by the command-line `slangc`, and should act accordingly? - bool isCommandLineCompile = false; + bool m_isCommandLineCompile = false; - String mDiagnosticOutput; + String m_diagnosticOutput; // If set, will dump the compilation state - String dumpRepro; + String m_dumpRepro; /// If set, if a compilation failure occurs will attempt to save off a dump repro with a unique name - bool dumpReproOnError = false; + bool m_dumpReproOnError = false; /// A blob holding the diagnostic output - ComPtr<ISlangBlob> diagnosticOutputBlob; + ComPtr<ISlangBlob> m_diagnosticOutputBlob; /// Per-entry-point information not tracked by other compile requests class EntryPointInfo : public RefObject @@ -1863,7 +1933,7 @@ namespace Slang /// Source code for the specialization arguments to use for the specialization parameters of the entry point. List<String> specializationArgStrings; }; - List<EntryPointInfo> entryPoints; + List<EntryPointInfo> m_entryPoints; /// Per-target information only needed for command-line compiles class TargetInfo : public RefObject @@ -1875,7 +1945,7 @@ namespace Slang Dictionary<Int, String> entryPointOutputPaths; String wholeTargetOutputPath; }; - Dictionary<TargetRequest*, RefPtr<TargetInfo>> targetInfos; + Dictionary<TargetRequest*, RefPtr<TargetInfo>> m_targetInfos; /// Writes the modules in a container to the stream SlangResult writeContainerToStream(Stream* stream); @@ -1923,6 +1993,9 @@ namespace Slang } private: + + ISlangUnknown* getInterface(const Guid& guid); + void init(); Session* m_session = nullptr; @@ -1960,11 +2033,8 @@ namespace Slang DownstreamCompileResult* compileResult, CodeGenTarget target); - /* Returns SLANG_OK if a codeGen target is available. */ - SlangResult checkCompileTargetSupport(Session* session, CodeGenTarget target); /* Returns SLANG_OK if pass through support is available */ SlangResult checkExternalCompilerSupport(Session* session, PassThroughMode passThrough); - /* Report an error appearing from external compiler to the diagnostic sink error to the diagnostic sink. @param compilerName The name of the compiler the error came for (or nullptr if not known) @param res Result associated with the error. The error code will be reported. (Can take HRESULT - and will expand to string if known) @@ -2050,36 +2120,27 @@ namespace Slang ISlangUnknown* getInterface(const Guid& guid); - /** Create a new linkage. - */ - SLANG_NO_THROW SlangResult SLANG_MCALL createSession( - slang::SessionDesc const& desc, - slang::ISession** outSession) override; - - SLANG_NO_THROW SlangProfileID SLANG_MCALL findProfile( - char const* name) override; - - SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPath( - SlangPassThrough passThrough, - char const* path) override; - - SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPrelude( - SlangPassThrough inPassThrough, - char const* prelude) override; - - SLANG_NO_THROW void SLANG_MCALL getDownstreamCompilerPrelude( - SlangPassThrough inPassThrough, - ISlangBlob** outPrelude) override; - + // slang::IGlobalSession + SLANG_NO_THROW SlangResult SLANG_MCALL createSession(slang::SessionDesc const& desc, slang::ISession** outSession) override; + SLANG_NO_THROW SlangProfileID SLANG_MCALL findProfile(char const* name) override; + SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPath(SlangPassThrough passThrough, char const* path) override; + SLANG_NO_THROW void SLANG_MCALL setDownstreamCompilerPrelude(SlangPassThrough inPassThrough, char const* prelude) override; + SLANG_NO_THROW void SLANG_MCALL getDownstreamCompilerPrelude(SlangPassThrough inPassThrough, ISlangBlob** outPrelude) override; SLANG_NO_THROW const char* SLANG_MCALL getBuildTagString() override; - SLANG_NO_THROW SlangResult SLANG_MCALL setDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage, SlangPassThrough defaultCompiler) override; - SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override; SLANG_NO_THROW void SLANG_MCALL setLanguagePrelude(SlangSourceLanguage inSourceLanguage, char const* prelude) override; SLANG_NO_THROW void SLANG_MCALL getLanguagePrelude(SlangSourceLanguage inSourceLanguage, ISlangBlob** outPrelude) override; + SLANG_NO_THROW SlangResult SLANG_MCALL createCompileRequest(slang::ICompileRequest** outCompileRequest) override; + + SLANG_NO_THROW void SLANG_MCALL addBuiltins(char const* sourcePath, char const* sourceString) override; + SLANG_NO_THROW void SLANG_MCALL setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) override; + SLANG_NO_THROW ISlangSharedLibraryLoader* SLANG_MCALL getSharedLibraryLoader() override; + SLANG_NO_THROW SlangResult SLANG_MCALL checkCompileTargetSupport(SlangCompileTarget target) override; + SLANG_NO_THROW SlangResult SLANG_MCALL checkPassThroughSupport(SlangPassThrough passThrough) override; + SLANG_NO_THROW SlangResult SLANG_MCALL compileStdLib() override; SLANG_NO_THROW SlangResult SLANG_MCALL loadStdLib() override; SLANG_NO_THROW SlangResult SLANG_MCALL saveStdLib() override; @@ -2145,7 +2206,7 @@ namespace Slang // - void setSharedLibraryLoader(ISlangSharedLibraryLoader* loader); + void _setSharedLibraryLoader(ISlangSharedLibraryLoader* loader); /// Will try to load the library by specified name (using the set loader), if not one already available. DownstreamCompiler* getOrLoadDownstreamCompiler(PassThroughMode type, DiagnosticSink* sink); @@ -2261,16 +2322,20 @@ SLANG_FORCE_INLINE slang::TypeLayoutReflection* asExternal(TypeLayout* type) SLANG_FORCE_INLINE SlangCompileRequest* asExternal(EndToEndCompileRequest* request) { - return reinterpret_cast<SlangCompileRequest*>(request); + return static_cast<SlangCompileRequest*>(request); } SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* request) { - return reinterpret_cast<EndToEndCompileRequest*>(request); + // Converts to the internal type -- does a runtime type check through queryInterfae + SLANG_ASSERT(request); + EndToEndCompileRequest* endToEndRequest = nullptr; + // NOTE! We aren't using to access an interface, so *doesn't* return with a refcount + request->queryInterface(IID_EndToEndCompileRequest, (void**)&endToEndRequest); + SLANG_ASSERT(endToEndRequest); + return endToEndRequest; } - - } #endif diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 60d41ee5c..ab88b489a 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -488,12 +488,12 @@ struct OptionsParser } else if (argStr == "-dump-repro") { - SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, requestImpl->dumpRepro)); + SLANG_RETURN_ON_FAIL(tryReadCommandLineArgument(sink, arg, &argCursor, argEnd, requestImpl->m_dumpRepro)); spEnableReproCapture(compileRequest); } else if (argStr == "-dump-repro-on-error") { - requestImpl->dumpReproOnError = true; + requestImpl->m_dumpReproOnError = true; } else if (argStr == "-extract-repro") { @@ -597,7 +597,7 @@ struct OptionsParser } else if(argStr == "-skip-codegen" ) { - requestImpl->shouldSkipCodegen = true; + requestImpl->m_shouldSkipCodegen = true; } else if(argStr == "-parameter-blocks-use-register-spaces" ) { @@ -1170,7 +1170,7 @@ struct OptionsParser // because fxc/dxc/glslang don't have a facility for taking // a named entry point and pulling its stage from an attribute. // - if(_passThroughRequiresStage(requestImpl->passThrough) ) + if(_passThroughRequiresStage(requestImpl->m_passThrough) ) { for( auto& rawEntryPoint : rawEntryPoints ) { @@ -1513,10 +1513,10 @@ struct OptionsParser auto targetID = rawTargets[rawOutput.targetIndex].targetID; auto target = requestImpl->getLinkage()->targets[targetID]; RefPtr<EndToEndCompileRequest::TargetInfo> targetInfo; - if( !requestImpl->targetInfos.TryGetValue(target, targetInfo) ) + if( !requestImpl->m_targetInfos.TryGetValue(target, targetInfo) ) { targetInfo = new EndToEndCompileRequest::TargetInfo(); - requestImpl->targetInfos[target] = targetInfo; + requestImpl->m_targetInfos[target] = targetInfo; } if (rawOutput.isWholeProgram) @@ -1556,14 +1556,14 @@ struct OptionsParser SlangResult parseOptions( - SlangCompileRequest* compileRequestIn, + SlangCompileRequest* inCompileRequest, int argc, char const* const* argv) { - Slang::EndToEndCompileRequest* compileRequest = (Slang::EndToEndCompileRequest*) compileRequestIn; + Slang::EndToEndCompileRequest* compileRequest = asInternal(inCompileRequest); OptionsParser parser; - parser.compileRequest = compileRequestIn; + parser.compileRequest = inCompileRequest; parser.requestImpl = compileRequest; parser.session = (SlangSession*)compileRequest->getSession(); @@ -1573,7 +1573,7 @@ SlangResult parseOptions( if (sink->getErrorCount() > 0) { // Put the errors in the diagnostic - compileRequest->mDiagnosticOutput = sink->outputBuffer.ProduceString(); + compileRequest->m_diagnosticOutput = sink->outputBuffer.ProduceString(); } return res; @@ -1582,10 +1582,4 @@ SlangResult parseOptions( } // namespace Slang -SLANG_API SlangResult spProcessCommandLineArguments( - SlangCompileRequest* request, - char const* const* args, - int argCount) -{ - return Slang::parseOptions(request, argCount, args); -} + diff --git a/source/slang/slang-options.h b/source/slang/slang-options.h index 517975d29..2426c08cb 100644 --- a/source/slang/slang-options.h +++ b/source/slang/slang-options.h @@ -10,5 +10,10 @@ namespace Slang UnownedStringSlice getCodeGenTargetName(SlangCompileTarget target); +SlangResult parseOptions( + SlangCompileRequest* compileRequestIn, + int argc, + char const* const* argv); + } #endif diff --git a/source/slang/slang-repro.cpp b/source/slang/slang-repro.cpp index f9cc415c0..14e341bbc 100644 --- a/source/slang/slang-repro.cpp +++ b/source/slang/slang-repro.cpp @@ -352,7 +352,7 @@ static bool _isStorable(const PathInfo::Type type) dst->debugInfoLevel = linkage->debugInfoLevel; dst->optimizationLevel = linkage->optimizationLevel; dst->containerFormat = request->m_containerFormat; - dst->passThroughMode = request->passThrough; + dst->passThroughMode = request->m_passThrough; dst->useUnknownImageFormatAsDefault = request->getBackEndReq()->useUnknownImageFormatAsDefault; @@ -364,7 +364,7 @@ static bool _isStorable(const PathInfo::Type type) // Entry points { const auto& srcEntryPoints = request->getFrontEndReq()->m_entryPointReqs; - const auto& srcEndToEndEntryPoints = request->entryPoints; + const auto& srcEndToEndEntryPoints = request->m_entryPoints; SLANG_ASSERT(srcEntryPoints.getCount() == srcEndToEndEntryPoints.getCount()); @@ -424,7 +424,7 @@ static bool _isStorable(const PathInfo::Type type) // Copy the entry point/target output names { - const auto& srcTargetInfos = request->targetInfos; + const auto& srcTargetInfos = request->m_targetInfos; if (RefPtr<EndToEndCompileRequest::TargetInfo>* infosPtr = srcTargetInfos.TryGetValue(srcTargetRequest)) { @@ -871,7 +871,7 @@ struct LoadContext // TODO(JS): Really should be more exhaustive here, and set up to initial state ideally // Reset state { - request->targetInfos.Clear(); + request->m_targetInfos.Clear(); // Remove any requests linkage->targets.clear(); } @@ -887,7 +887,7 @@ struct LoadContext spSetDebugInfoLevel(externalRequest, SlangDebugInfoLevel(requestState->debugInfoLevel)); spSetOptimizationLevel(externalRequest, SlangOptimizationLevel(requestState->optimizationLevel)); spSetOutputContainerFormat(externalRequest, SlangContainerFormat(requestState->containerFormat)); - spSetPassThrough(externalRequest, SlangPassThrough(request->passThrough)); + spSetPassThrough(externalRequest, SlangPassThrough(request->m_passThrough)); request->getBackEndReq()->useUnknownImageFormatAsDefault = requestState->useUnknownImageFormatAsDefault; linkage->m_obfuscateCode = requestState->obfuscateCode; @@ -914,7 +914,7 @@ struct LoadContext if (src.outputStates.getCount()) { RefPtr<EndToEndCompileRequest::TargetInfo> dstTargetInfo(new EndToEndCompileRequest::TargetInfo); - request->targetInfos[dstTarget] = dstTargetInfo; + request->m_targetInfos[dstTarget] = dstTargetInfo; for (const auto& srcOutputStateOffset : src.outputStates) { diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 063a84bbe..d31b0302b 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -14,6 +14,8 @@ #include "slang-reflection.h" #include "slang-type-layout.h" +#include "slang-options.h" + #include "slang-repro.h" #include "slang-file-system.h" @@ -111,6 +113,11 @@ static const Guid IID_ISession = SLANG_UUID_ISession; static const Guid IID_ISlangBlob = SLANG_UUID_ISlangBlob; static const Guid IID_ISlangUnknown = SLANG_UUID_ISlangUnknown; +static const Guid IID_ICompileRequest = SLANG_UUID_ICompileRequest; + +// Available to other modules so not static +const Guid IID_EndToEndCompileRequest = SLANG_UUID_EndToEndCompileRequest; + void Session::init() { SLANG_ASSERT(BaseTypeInfo::check()); @@ -189,6 +196,45 @@ void Session::init() m_languagePreludes[Index(SourceLanguage::HLSL)] = get_slang_hlsl_prelude(); } +void Session::addBuiltins( + char const* sourcePath, + char const* sourceString) +{ + // TODO(tfoley): Add ability to directly new builtins to the appropriate scope + addBuiltinSource( + coreLanguageScope, + sourcePath, + sourceString); +} + +void Session::setSharedLibraryLoader(ISlangSharedLibraryLoader* loader) +{ + // External API allows passing of nullptr to reset the loader + loader = loader ? loader : DefaultSharedLibraryLoader::getSingleton(); + + _setSharedLibraryLoader(loader); +} + +ISlangSharedLibraryLoader* Session::getSharedLibraryLoader() +{ + return (m_sharedLibraryLoader == DefaultSharedLibraryLoader::getSingleton()) ? nullptr : m_sharedLibraryLoader.get(); +} + +SlangResult Session::checkCompileTargetSupport(SlangCompileTarget inTarget) +{ + auto target = CodeGenTarget(inTarget); + + const PassThroughMode mode = getDownstreamCompilerRequiredForTarget(target); + return (mode != PassThroughMode::None) ? + checkPassThroughSupport(SlangPassThrough(mode)) : + SLANG_OK; +} + +SlangResult Session::checkPassThroughSupport(SlangPassThrough inPassThrough) +{ + return checkExternalCompilerSupport(this, PassThroughMode(inPassThrough)); +} + SlangResult Session::compileStdLib() { if (m_builtinLinkage->mapNameToLoadedModules.Count()) @@ -377,6 +423,19 @@ SLANG_NO_THROW SlangResult SLANG_MCALL Session::createSession( return SLANG_OK; } +SLANG_NO_THROW SlangResult SLANG_MCALL Session::createCompileRequest(slang::ICompileRequest** outCompileRequest) +{ + auto req = new EndToEndCompileRequest(this); + + // Give it a ref (for output) + req->addRef(); + // Check it is what we think it should be + SLANG_ASSERT(req->debugGetReferenceCount() == 1); + + *outCompileRequest = req; + return SLANG_OK; +} + SLANG_NO_THROW SlangProfileID SLANG_MCALL Session::findProfile( char const* name) { @@ -1686,6 +1745,26 @@ EndToEndCompileRequest::EndToEndCompileRequest( init(); } +SLANG_NO_THROW SlangResult SLANG_MCALL EndToEndCompileRequest::queryInterface(SlangUUID const& uuid, void** outObject) +{ + if (uuid == IID_EndToEndCompileRequest) + { + // Special case to cast directly into internal type + // NOTE! No addref(!) + *outObject = this; + return SLANG_OK; + } + + if (uuid == IID_ISlangUnknown && uuid == IID_ICompileRequest) + { + addReference(); + *outObject = static_cast<slang::ICompileRequest*>(this); + return SLANG_OK; + } + + return SLANG_E_NO_INTERFACE; +} + void EndToEndCompileRequest::init() { m_sink.setSourceManager(m_linkage->getSourceManager()); @@ -1730,7 +1809,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() // We only do parsing and semantic checking if we *aren't* doing // a pass-through compilation. // - if (passThrough == PassThroughMode::None) + if (m_passThrough == PassThroughMode::None) { SLANG_RETURN_ON_FAIL(getFrontEndReq()->executeActionsInner()); } @@ -1738,7 +1817,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() // If command line specifies to skip codegen, we exit here. // Note: this is a debugging option. // - if (shouldSkipCodegen || + if (m_shouldSkipCodegen || ((getFrontEndReq()->compileFlags & SLANG_COMPILE_FLAG_NO_CODEGEN) != 0)) { // We will use the program (and matching layout information) @@ -1758,7 +1837,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() // If codegen is enabled, we need to move along to // apply any generic specialization that the user asked for. // - if (passThrough == PassThroughMode::None) + if (m_passThrough == PassThroughMode::None) { m_specializedGlobalComponentType = createSpecializedGlobalComponentType(this); if (getSink()->getErrorCount() != 0) @@ -1821,7 +1900,7 @@ SlangResult EndToEndCompileRequest::executeActionsInner() SlangResult EndToEndCompileRequest::executeActions() { SlangResult res = executeActionsInner(); - mDiagnosticOutput = getSink()->outputBuffer.ProduceString(); + m_diagnosticOutput = getSink()->outputBuffer.ProduceString(); return res; } @@ -1945,8 +2024,8 @@ int EndToEndCompileRequest::addEntryPoint( for (auto typeName : genericTypeNames) entryPointInfo.specializationArgStrings.add(typeName); - Index result = entryPoints.getCount(); - entryPoints.add(_Move(entryPointInfo)); + Index result = m_entryPoints.getCount(); + m_entryPoints.add(_Move(entryPointInfo)); return (int) result; } @@ -3246,337 +3325,210 @@ SLANG_API void spAddBuiltins( char const* sourcePath, char const* sourceString) { - auto s = Slang::asInternal(session); - s->addBuiltinSource( - - // TODO(tfoley): Add ability to directly new builtins to the approriate scope - s->coreLanguageScope, - - sourcePath, - sourceString); + session->addBuiltins(sourcePath, sourceString); } SLANG_API void spSessionSetSharedLibraryLoader( SlangSession* session, ISlangSharedLibraryLoader* loader) { - auto s = Slang::asInternal(session); - loader = loader ? loader : Slang::DefaultSharedLibraryLoader::getSingleton(); - s->setSharedLibraryLoader(loader); + session->setSharedLibraryLoader(loader); } SLANG_API ISlangSharedLibraryLoader* spSessionGetSharedLibraryLoader( SlangSession* session) { - auto s = Slang::asInternal(session); - return (s->m_sharedLibraryLoader == Slang::DefaultSharedLibraryLoader::getSingleton()) ? nullptr : s->m_sharedLibraryLoader.get(); + return session->getSharedLibraryLoader(); } SLANG_API SlangResult spSessionCheckCompileTargetSupport( SlangSession* session, SlangCompileTarget target) { - auto s = Slang::asInternal(session); - return Slang::checkCompileTargetSupport(s, Slang::CodeGenTarget(target)); + return session->checkCompileTargetSupport(target); } SLANG_API SlangResult spSessionCheckPassThroughSupport( SlangSession* session, SlangPassThrough passThrough) { - auto s = Slang::asInternal(session); - return Slang::checkExternalCompilerSupport(s, Slang::PassThroughMode(passThrough)); + return session->checkPassThroughSupport(passThrough); } SLANG_API SlangCompileRequest* spCreateCompileRequest( SlangSession* session) { - auto s = Slang::asInternal(session); - auto req = new Slang::EndToEndCompileRequest(s); - return asExternal(req); + slang::ICompileRequest* request = nullptr; + // Will return with suitable ref count + session->createCompileRequest(&request); + return request; } -/*! -@brief Destroy a compile request. -*/ -SLANG_API void spDestroyCompileRequest( - SlangCompileRequest* request) +SLANG_API SlangProfileID spFindProfile( + SlangSession* session, + char const* name) { - if(!request) return; - auto req = Slang::asInternal(request); - - delete req; + return session->findProfile(name); } -SLANG_API void spSetFileSystem( - SlangCompileRequest* request, - ISlangFileSystem* fileSystem) +/* !!!!!!!!!!!!!!!!!! EndToEndCompileRequestImpl !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +namespace Slang +{ + +void EndToEndCompileRequest::setFileSystem(ISlangFileSystem* fileSystem) { - if(!request) return; - Slang::asInternal(request)->getLinkage()->setFileSystem(fileSystem); + getLinkage()->setFileSystem(fileSystem); } -SLANG_API void spSetCompileFlags( - SlangCompileRequest* request, - SlangCompileFlags flags) +void EndToEndCompileRequest::setCompileFlags(SlangCompileFlags flags) { - Slang::asInternal(request)->getFrontEndReq()->compileFlags = flags; + getFrontEndReq()->compileFlags = flags; } -SLANG_API void spSetDumpIntermediates( - SlangCompileRequest* request, - int enable) +void EndToEndCompileRequest::setDumpIntermediates(int enable) { - Slang::asInternal(request)->getBackEndReq()->shouldDumpIntermediates = enable != 0; + getBackEndReq()->shouldDumpIntermediates = (enable != 0); } -SLANG_API void spSetDumpIntermediatePrefix( - SlangCompileRequest* request, - const char* prefix) +void EndToEndCompileRequest::setDumpIntermediatePrefix(const char* prefix) { - Slang::asInternal(request)->getBackEndReq()->m_dumpIntermediatePrefix = prefix; + getBackEndReq()->m_dumpIntermediatePrefix = prefix; } -SLANG_API void spSetLineDirectiveMode( - SlangCompileRequest* request, - SlangLineDirectiveMode mode) +void EndToEndCompileRequest::setLineDirectiveMode(SlangLineDirectiveMode mode) { // TODO: validation - - Slang::asInternal(request)->getBackEndReq()->lineDirectiveMode = Slang::LineDirectiveMode(mode); + getBackEndReq()->lineDirectiveMode = LineDirectiveMode(mode); } -SLANG_API void spSetCommandLineCompilerMode( - SlangCompileRequest* request) +void EndToEndCompileRequest::setCommandLineCompilerMode() { - Slang::asInternal(request)->isCommandLineCompile = true; - + m_isCommandLineCompile = true; } -SLANG_API void spSetCodeGenTarget( - SlangCompileRequest* request, - SlangCompileTarget target) +void EndToEndCompileRequest::setCodeGenTarget(SlangCompileTarget target) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); + auto linkage = getLinkage(); linkage->targets.clear(); - linkage->addTarget(Slang::CodeGenTarget(target)); + linkage->addTarget(CodeGenTarget(target)); } -SLANG_API int spAddCodeGenTarget( - SlangCompileRequest* request, - SlangCompileTarget target) +int EndToEndCompileRequest::addCodeGenTarget(SlangCompileTarget target) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - return (int) linkage->addTarget(Slang::CodeGenTarget(target)); + return (int)getLinkage()->addTarget(CodeGenTarget(target)); } -SLANG_API void spSetTargetProfile( - SlangCompileRequest* request, - int targetIndex, - SlangProfileID profile) +void EndToEndCompileRequest::setTargetProfile(int targetIndex, SlangProfileID profile) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->targets[targetIndex]->targetProfile = Slang::Profile(profile); + getLinkage()->targets[targetIndex]->targetProfile = Profile(profile); } -SLANG_API void spSetTargetFlags( - SlangCompileRequest* request, - int targetIndex, - SlangTargetFlags flags) +void EndToEndCompileRequest::setTargetFlags(int targetIndex, SlangTargetFlags flags) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->targets[targetIndex]->targetFlags = flags; + getLinkage()->targets[targetIndex]->targetFlags = flags; } -SLANG_API void spSetTargetFloatingPointMode( - SlangCompileRequest* request, - int targetIndex, - SlangFloatingPointMode mode) +void EndToEndCompileRequest::setTargetFloatingPointMode(int targetIndex, SlangFloatingPointMode mode) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->targets[targetIndex]->floatingPointMode = Slang::FloatingPointMode(mode); + getLinkage()->targets[targetIndex]->floatingPointMode = FloatingPointMode(mode); } -SLANG_API void spSetMatrixLayoutMode( - SlangCompileRequest* request, - SlangMatrixLayoutMode mode) +void EndToEndCompileRequest::setMatrixLayoutMode(SlangMatrixLayoutMode mode) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->setMatrixLayoutMode(mode); + getLinkage()->setMatrixLayoutMode(mode); } -SLANG_API void spSetTargetMatrixLayoutMode( - SlangCompileRequest* request, - int targetIndex, - SlangMatrixLayoutMode mode) +void EndToEndCompileRequest::setTargetMatrixLayoutMode(int targetIndex, SlangMatrixLayoutMode mode) { SLANG_UNUSED(targetIndex); - spSetMatrixLayoutMode(request, mode); + setMatrixLayoutMode(mode); } -/*! -@brief Set the level of debug information to produce. -*/ -SLANG_API void spSetDebugInfoLevel( - SlangCompileRequest* request, - SlangDebugInfoLevel level) +void EndToEndCompileRequest::setDebugInfoLevel(SlangDebugInfoLevel level) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->debugInfoLevel = Slang::DebugInfoLevel(level); + getLinkage()->debugInfoLevel = DebugInfoLevel(level); } -/*! -@brief Set the level of optimization to perform. -*/ -SLANG_API void spSetOptimizationLevel( - SlangCompileRequest* request, - SlangOptimizationLevel level) +void EndToEndCompileRequest::setOptimizationLevel(SlangOptimizationLevel level) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->optimizationLevel = Slang::OptimizationLevel(level); + getLinkage()->optimizationLevel = OptimizationLevel(level); } - -SLANG_API void spSetOutputContainerFormat( - SlangCompileRequest* request, - SlangContainerFormat format) +void EndToEndCompileRequest::setOutputContainerFormat(SlangContainerFormat format) { - auto req = Slang::asInternal(request); - req->m_containerFormat = Slang::ContainerFormat(format); + m_containerFormat = ContainerFormat(format); } - -SLANG_API void spSetPassThrough( - SlangCompileRequest* request, - SlangPassThrough passThrough) +void EndToEndCompileRequest::setPassThrough(SlangPassThrough inPassThrough) { - Slang::asInternal(request)->passThrough = Slang::PassThroughMode(passThrough); + m_passThrough = PassThroughMode(inPassThrough); } -SLANG_API void spSetDiagnosticCallback( - SlangCompileRequest* request, - SlangDiagnosticCallback callback, - void const* userData) +void EndToEndCompileRequest::setDiagnosticCallback(SlangDiagnosticCallback callback, void const* userData) { - using namespace Slang; - - if(!request) return; - auto req = Slang::asInternal(request); - ComPtr<ISlangWriter> writer(new CallbackWriter(callback, userData, WriterFlag::IsConsole)); - req->setWriter(WriterChannel::Diagnostic, writer); + setWriter(WriterChannel::Diagnostic, writer); } -SLANG_API void spSetWriter( - SlangCompileRequest* request, - SlangWriterChannel chan, - ISlangWriter* writer) +void EndToEndCompileRequest::setWriter(SlangWriterChannel chan, ISlangWriter* writer) { - if (!request) return; - auto req = Slang::asInternal(request); - - req->setWriter(Slang::WriterChannel(chan), writer); + setWriter(WriterChannel(chan), writer); } -SLANG_API ISlangWriter* spGetWriter( - SlangCompileRequest* request, - SlangWriterChannel chan) +ISlangWriter* EndToEndCompileRequest::getWriter(SlangWriterChannel chan) { - if (!request) return nullptr; - auto req = Slang::asInternal(request); - return req->getWriter(Slang::WriterChannel(chan)); + return getWriter(WriterChannel(chan)); } -SLANG_API void spAddSearchPath( - SlangCompileRequest* request, - const char* path) +void EndToEndCompileRequest::addSearchPath(const char* path) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->addSearchPath(path); + getLinkage()->addSearchPath(path); } -SLANG_API void spAddPreprocessorDefine( - SlangCompileRequest* request, - const char* key, - const char* value) +void EndToEndCompileRequest::addPreprocessorDefine(const char* key, const char* value) { - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - linkage->addPreprocessorDefine(key, value); + getLinkage()->addPreprocessorDefine(key, value); } -SLANG_API char const* spGetDiagnosticOutput( - SlangCompileRequest* request) +char const* EndToEndCompileRequest::getDiagnosticOutput() { - if(!request) return 0; - auto req = Slang::asInternal(request); - return req->mDiagnosticOutput.begin(); + return m_diagnosticOutput.begin(); } -SLANG_API SlangResult spGetDiagnosticOutputBlob( - SlangCompileRequest* request, - ISlangBlob** outBlob) +SlangResult EndToEndCompileRequest::getDiagnosticOutputBlob(ISlangBlob** outBlob) { - if(!request) return SLANG_ERROR_INVALID_PARAMETER; - if(!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - - auto req = Slang::asInternal(request); + if (!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - if(!req->diagnosticOutputBlob) + if (!m_diagnosticOutputBlob) { - req->diagnosticOutputBlob = Slang::StringUtil::createStringBlob(req->mDiagnosticOutput); + m_diagnosticOutputBlob = StringUtil::createStringBlob(m_diagnosticOutput); } - Slang::ComPtr<ISlangBlob> resultBlob = req->diagnosticOutputBlob; + ComPtr<ISlangBlob> resultBlob = m_diagnosticOutputBlob; *outBlob = resultBlob.detach(); return SLANG_OK; } -// New-fangled compilation API - -SLANG_API int spAddTranslationUnit( - SlangCompileRequest* request, - SlangSourceLanguage language, - char const* inName) +int EndToEndCompileRequest::addTranslationUnit(SlangSourceLanguage language, char const* inName) { - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - - Slang::NamePool* namePool = req->getFrontEndReq()->getNamePool(); + auto frontEndReq = getFrontEndReq(); + NamePool* namePool = frontEndReq->getNamePool(); // Work out a module name. Can be nullptr if so will generate a name - Slang::Name* moduleName = inName ? namePool->getName(inName) : frontEndReq->m_defaultModuleName; + Name* moduleName = inName ? namePool->getName(inName) : frontEndReq->m_defaultModuleName; // If moduleName is nullptr a name will be generated - - return frontEndReq->addTranslationUnit( - Slang::SourceLanguage(language), - moduleName); + return frontEndReq->addTranslationUnit(Slang::SourceLanguage(language), moduleName); } -SLANG_API void spSetDefaultModuleName( - SlangCompileRequest* request, - const char* defaultModuleName) +void EndToEndCompileRequest::setDefaultModuleName(const char* defaultModuleName) { - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - - Slang::NamePool* namePool = req->getFrontEndReq()->getNamePool(); - + auto frontEndReq = getFrontEndReq(); + NamePool* namePool = frontEndReq->getNamePool(); frontEndReq->m_defaultModuleName = namePool->getName(defaultModuleName); } -namespace Slang -{ SlangResult _addLibraryReference(EndToEndCompileRequest* req, Stream* stream) { // Load up the module @@ -3626,172 +3578,82 @@ SlangResult _addLibraryReference(EndToEndCompileRequest* req, Stream* stream) return SLANG_OK; } -} - -SLANG_API SlangResult spAddLibraryReference( - SlangCompileRequest* request, - const void* libData, - size_t libDataSize) +SlangResult EndToEndCompileRequest::addLibraryReference(const void* libData, size_t libDataSize) { - using namespace Slang; - auto req = Slang::asInternal(request); - // We need to deserialize and add the modules MemoryStreamBase fileStream(FileAccess::Read, libData, libDataSize); - - return _addLibraryReference(req, &fileStream); + return _addLibraryReference(this, &fileStream); } -SLANG_API void spTranslationUnit_addPreprocessorDefine( - SlangCompileRequest* request, - int translationUnitIndex, - const char* key, - const char* value) +void EndToEndCompileRequest::addTranslationUnitPreprocessorDefine(int translationUnitIndex, const char* key, const char* value) { - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - - frontEndReq->translationUnits[translationUnitIndex]->preprocessorDefinitions[key] = value; + getFrontEndReq()->translationUnits[translationUnitIndex]->preprocessorDefinitions[key] = value; } -SLANG_API void spAddTranslationUnitSourceFile( - SlangCompileRequest* request, - int translationUnitIndex, - char const* path) +void EndToEndCompileRequest::addTranslationUnitSourceFile(int translationUnitIndex, char const* path) { - if(!request) return; - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - if(!path) return; - if(translationUnitIndex < 0) return; - if(Slang::Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return; + auto frontEndReq = getFrontEndReq(); + if (!path) return; + if (translationUnitIndex < 0) return; + if (Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return; - frontEndReq->addTranslationUnitSourceFile( - translationUnitIndex, - path); + frontEndReq->addTranslationUnitSourceFile(translationUnitIndex, path); } -SLANG_API void spAddTranslationUnitSourceString( - SlangCompileRequest* request, - int translationUnitIndex, - char const* path, - char const* source) +void EndToEndCompileRequest::addTranslationUnitSourceString(int translationUnitIndex, char const* path, char const* source) { - if(!source) return; - spAddTranslationUnitSourceStringSpan( - request, - translationUnitIndex, - path, - source, - source + strlen(source)); + if (!source) return; + addTranslationUnitSourceStringSpan(translationUnitIndex, path, source, source + strlen(source)); } -SLANG_API void spAddTranslationUnitSourceStringSpan( - SlangCompileRequest* request, - int translationUnitIndex, - char const* path, - char const* sourceBegin, - char const* sourceEnd) +void EndToEndCompileRequest::addTranslationUnitSourceStringSpan(int translationUnitIndex, char const* path, char const* sourceBegin, char const* sourceEnd) { - using namespace Slang; - if(!request) return; - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - if(!sourceBegin) return; - if(translationUnitIndex < 0) return; - if(Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return; + auto frontEndReq = getFrontEndReq(); + if (!sourceBegin) return; + if (translationUnitIndex < 0) return; + if (Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return; - if(!path) path = ""; + if (!path) path = ""; - frontEndReq->addTranslationUnitSourceString( - translationUnitIndex, - path, - UnownedStringSlice(sourceBegin, sourceEnd)); + frontEndReq->addTranslationUnitSourceString(translationUnitIndex, path, UnownedStringSlice(sourceBegin, sourceEnd)); } -SLANG_API void spAddTranslationUnitSourceBlob( - SlangCompileRequest* request, - int translationUnitIndex, - char const* path, - ISlangBlob* sourceBlob) +void EndToEndCompileRequest::addTranslationUnitSourceBlob(int translationUnitIndex, char const* path, ISlangBlob* sourceBlob) { - if(!request) return; - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - if(!sourceBlob) return; - if(translationUnitIndex < 0) return; - if(Slang::Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return; + auto frontEndReq = getFrontEndReq(); + if (!sourceBlob) return; + if (translationUnitIndex < 0) return; + if (Slang::Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return; - if(!path) path = ""; + if (!path) path = ""; - frontEndReq->addTranslationUnitSourceBlob( - translationUnitIndex, - path, - sourceBlob); + frontEndReq->addTranslationUnitSourceBlob(translationUnitIndex, path, sourceBlob); } - - - - -SLANG_API SlangProfileID spFindProfile( - SlangSession*, - char const* name) -{ - return Slang::Profile::lookUp(name).raw; -} - -SLANG_API int spAddEntryPoint( - SlangCompileRequest* request, - int translationUnitIndex, - char const* name, - SlangStage stage) +int EndToEndCompileRequest::addEntryPoint(int translationUnitIndex, char const* name, SlangStage stage) { - return spAddEntryPointEx( - request, - translationUnitIndex, - name, - stage, - 0, - nullptr); + return addEntryPointEx(translationUnitIndex, name, stage, 0, nullptr); } -SLANG_API int spAddEntryPointEx( - SlangCompileRequest* request, - int translationUnitIndex, - char const* name, - SlangStage stage, - int genericParamTypeNameCount, - char const ** genericParamTypeNames) +int EndToEndCompileRequest::addEntryPointEx(int translationUnitIndex, char const* name, SlangStage stage, int genericParamTypeNameCount, char const** genericParamTypeNames) { - using namespace Slang; - if (!request) return -1; - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); + auto frontEndReq = getFrontEndReq(); if (!name) return -1; if (translationUnitIndex < 0) return -1; if (Index(translationUnitIndex) >= frontEndReq->translationUnits.getCount()) return -1; + List<String> typeNames; for (int i = 0; i < genericParamTypeNameCount; i++) typeNames.add(genericParamTypeNames[i]); - return req->addEntryPoint( - translationUnitIndex, - name, - Profile(Stage(stage)), - typeNames); + + return addEntryPoint(translationUnitIndex, name, Profile(Stage(stage)), typeNames); } -SLANG_API SlangResult spSetGlobalGenericArgs( - SlangCompileRequest* request, - int genericArgCount, - char const** genericArgs) +SlangResult EndToEndCompileRequest::setGlobalGenericArgs(int genericArgCount, char const** genericArgs) { - if (!request) return SLANG_FAIL; - auto req = Slang::asInternal(request); - - auto& argStrings = req->globalSpecializationArgStrings; + auto& argStrings = m_globalSpecializationArgStrings; argStrings.clear(); for (int i = 0; i < genericArgCount; i++) argStrings.add(genericArgs[i]); @@ -3799,55 +3661,37 @@ SLANG_API SlangResult spSetGlobalGenericArgs( return SLANG_OK; } -SLANG_API SlangResult spSetTypeNameForGlobalExistentialTypeParam( - SlangCompileRequest* request, - int slotIndex, - char const* typeName) +SlangResult EndToEndCompileRequest::setTypeNameForGlobalExistentialTypeParam(int slotIndex, char const* typeName) { - using namespace Slang; - if(!request) return SLANG_FAIL; - if(slotIndex < 0) return SLANG_FAIL; - if(!typeName) return SLANG_FAIL; - - auto req = Slang::asInternal(request); - auto& typeArgStrings = req->globalSpecializationArgStrings; - if(Index(slotIndex) >= typeArgStrings.getCount()) - typeArgStrings.setCount(slotIndex+1); + if (slotIndex < 0) return SLANG_FAIL; + if (!typeName) return SLANG_FAIL; + + auto& typeArgStrings = m_globalSpecializationArgStrings; + if (Index(slotIndex) >= typeArgStrings.getCount()) + typeArgStrings.setCount(slotIndex + 1); typeArgStrings[slotIndex] = String(typeName); return SLANG_OK; } -SLANG_API SlangResult spSetTypeNameForEntryPointExistentialTypeParam( - SlangCompileRequest* request, - int entryPointIndex, - int slotIndex, - char const* typeName) +SlangResult EndToEndCompileRequest::setTypeNameForEntryPointExistentialTypeParam(int entryPointIndex, int slotIndex, char const* typeName) { - using namespace Slang; - if(!request) return SLANG_FAIL; - if(entryPointIndex < 0) return SLANG_FAIL; - if(slotIndex < 0) return SLANG_FAIL; - if(!typeName) return SLANG_FAIL; + if (entryPointIndex < 0) return SLANG_FAIL; + if (slotIndex < 0) return SLANG_FAIL; + if (!typeName) return SLANG_FAIL; - auto req = Slang::asInternal(request); - if(Index(entryPointIndex) >= req->entryPoints.getCount()) + if (Index(entryPointIndex) >=m_entryPoints.getCount()) return SLANG_FAIL; - auto& entryPointInfo = req->entryPoints[entryPointIndex]; + auto& entryPointInfo = m_entryPoints[entryPointIndex]; auto& typeArgStrings = entryPointInfo.specializationArgStrings; - if(Index(slotIndex) >= typeArgStrings.getCount()) - typeArgStrings.setCount(slotIndex+1); + if (Index(slotIndex) >= typeArgStrings.getCount()) + typeArgStrings.setCount(slotIndex + 1); typeArgStrings[slotIndex] = String(typeName); return SLANG_OK; } -// Compile in a context that already has its translation units specified -SLANG_API SlangResult spCompile( - SlangCompileRequest* request) +SlangResult EndToEndCompileRequest::EndToEndCompileRequest::compile() { - using namespace Slang; - auto req = asInternal(request); - SlangResult res = SLANG_FAIL; #if !defined(SLANG_DEBUG_INTERNAL_ERROR) @@ -3860,10 +3704,10 @@ SLANG_API SlangResult spCompile( // // TODO: Consider supporting Windows "Structured Exception Handling" // so that we can also recover from a wider class of crashes. - + try { - res = req->executeActions(); + res = executeActions(); } catch (const AbortCompilationException&) { @@ -3877,7 +3721,7 @@ SLANG_API SlangResult spCompile( // We will print out information on the exception to help out the user // in either filing a bug, or locating what in their code created // a problem. - req->getSink()->diagnose(SourceLoc(), Diagnostics::compilationAbortedDueToException, typeid(e).name(), e.Message); + getSink()->diagnose(SourceLoc(), Diagnostics::compilationAbortedDueToException, typeid(e).name(), e.Message); } catch (...) { @@ -3885,10 +3729,10 @@ SLANG_API SlangResult spCompile( // `Exception`, so something really fishy is going on. We want to // let the user know that we messed up, so they know to blame Slang // and not some other component in their system. - req->getSink()->diagnose(SourceLoc(), Diagnostics::compilationAborted); + getSink()->diagnose(SourceLoc(), Diagnostics::compilationAborted); } - req->mDiagnosticOutput = req->getSink()->outputBuffer.ProduceString(); - + m_diagnosticOutput = getSink()->outputBuffer.ProduceString(); + #else // When debugging, we probably don't want to filter out any errors, since // we are probably trying to root-cause and *fix* those errors. @@ -3899,29 +3743,29 @@ SLANG_API SlangResult spCompile( // Repro dump handling { - if (req->dumpRepro.getLength()) + if (m_dumpRepro.getLength()) { - SlangResult saveRes = ReproUtil::saveState(req, req->dumpRepro); + SlangResult saveRes = ReproUtil::saveState(this, m_dumpRepro); if (SLANG_FAILED(saveRes)) { - req->getSink()->diagnose(SourceLoc(), Diagnostics::unableToWriteReproFile, req->dumpRepro); + getSink()->diagnose(SourceLoc(), Diagnostics::unableToWriteReproFile, m_dumpRepro); return saveRes; } } - else if (req->dumpReproOnError && SLANG_FAILED(res)) + else if (m_dumpReproOnError && SLANG_FAILED(res)) { String reproFileName; SlangResult saveRes = SLANG_FAIL; RefPtr<Stream> stream; - if (SLANG_SUCCEEDED(ReproUtil::findUniqueReproDumpStream(req, reproFileName, stream))) + if (SLANG_SUCCEEDED(ReproUtil::findUniqueReproDumpStream(this, reproFileName, stream))) { - saveRes = ReproUtil::saveState(req, stream); + saveRes = ReproUtil::saveState(this, stream); } if (SLANG_FAILED(saveRes)) { - req->getSink()->diagnose(SourceLoc(), Diagnostics::unableToWriteReproFile, reproFileName); + getSink()->diagnose(SourceLoc(), Diagnostics::unableToWriteReproFile, reproFileName); } } } @@ -3929,65 +3773,35 @@ SLANG_API SlangResult spCompile( return res; } -SLANG_API int -spGetDependencyFileCount( - SlangCompileRequest* request) +int EndToEndCompileRequest::getDependencyFileCount() { - if(!request) return 0; - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); + auto frontEndReq = getFrontEndReq(); auto program = frontEndReq->getGlobalAndEntryPointsComponentType(); - return (int) program->getFilePathDependencies().getCount(); + return (int)program->getFilePathDependencies().getCount(); } -/** Get the path to a file this compilation dependend on. -*/ -SLANG_API char const* -spGetDependencyFilePath( - SlangCompileRequest* request, - int index) +char const* EndToEndCompileRequest::getDependencyFilePath(int index) { - if(!request) return 0; - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); + auto frontEndReq = getFrontEndReq(); auto program = frontEndReq->getGlobalAndEntryPointsComponentType(); return program->getFilePathDependencies()[index].begin(); } -SLANG_API int -spGetTranslationUnitCount( - SlangCompileRequest* request) -{ - auto req = Slang::asInternal(request); - auto frontEndReq = req->getFrontEndReq(); - return (int) frontEndReq->translationUnits.getCount(); -} - -// Get the output code associated with a specific translation unit -SLANG_API char const* spGetTranslationUnitSource( - SlangCompileRequest* /*request*/, - int /*translationUnitIndex*/) +int EndToEndCompileRequest::getTranslationUnitCount() { - fprintf(stderr, "DEPRECATED: spGetTranslationUnitSource()\n"); - return nullptr; + return (int)getFrontEndReq()->translationUnits.getCount(); } -SLANG_API void const* spGetEntryPointCode( - SlangCompileRequest* request, - int entryPointIndex, - size_t* outSize) +void const* EndToEndCompileRequest::getEntryPointCode(int entryPointIndex, size_t* outSize) { - using namespace Slang; - // Zero the size initially, in case need to return nullptr for error. if (outSize) { *outSize = 0; } - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); + auto linkage = getLinkage(); + auto program = getSpecializedGlobalAndEntryPointsComponentType(); // TODO: We should really accept a target index in this API Index targetIndex = 0; @@ -3997,12 +3811,12 @@ SLANG_API void const* spGetEntryPointCode( auto targetReq = linkage->targets[targetIndex]; - if(entryPointIndex < 0) return nullptr; - if(Index(entryPointIndex) >= program->getEntryPointCount()) return nullptr; + if (entryPointIndex < 0) return nullptr; + if (Index(entryPointIndex) >= program->getEntryPointCount()) return nullptr; auto entryPoint = program->getEntryPoint(entryPointIndex); auto targetProgram = program->getTargetProgram(targetReq); - if(!targetProgram) + if (!targetProgram) return nullptr; CompileResult& result = targetProgram->getExistingEntryPointResult(entryPointIndex); @@ -4018,15 +3832,11 @@ SLANG_API void const* spGetEntryPointCode( } static SlangResult _getEntryPointResult( - SlangCompileRequest* request, + EndToEndCompileRequest* req, int entryPointIndex, int targetIndex, Slang::CompileResult** outCompileResult) { - using namespace Slang; - if (!request) return SLANG_ERROR_INVALID_PARAMETER; - - auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); @@ -4037,7 +3847,7 @@ static SlangResult _getEntryPointResult( } auto targetReq = linkage->targets[targetIndex]; - Index entryPointCount = req->entryPoints.getCount(); + Index entryPointCount = req->m_entryPoints.getCount(); if ((entryPointIndex < 0) || (entryPointIndex >= entryPointCount)) { return SLANG_ERROR_INVALID_PARAMETER; @@ -4053,15 +3863,10 @@ static SlangResult _getEntryPointResult( } static SlangResult _getWholeProgramResult( - SlangCompileRequest* request, + EndToEndCompileRequest* req, int targetIndex, Slang::CompileResult** outCompileResult) { - using namespace Slang; - if (!request) - return SLANG_ERROR_INVALID_PARAMETER; - - auto req = Slang::asInternal(request); auto linkage = req->getLinkage(); auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); @@ -4079,16 +3884,12 @@ static SlangResult _getWholeProgramResult( return SLANG_OK; } -SLANG_API SlangResult spGetEntryPointCodeBlob( - SlangCompileRequest* request, - int entryPointIndex, - int targetIndex, - ISlangBlob** outBlob) +SlangResult EndToEndCompileRequest::getEntryPointCodeBlob(int entryPointIndex, int targetIndex, ISlangBlob** outBlob) { - using namespace Slang; - if(!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - Slang::CompileResult* compileResult = nullptr; - SLANG_RETURN_ON_FAIL(_getEntryPointResult(request, entryPointIndex, targetIndex, &compileResult)); + if (!outBlob) return SLANG_ERROR_INVALID_PARAMETER; + + CompileResult* compileResult = nullptr; + SLANG_RETURN_ON_FAIL(_getEntryPointResult(this, entryPointIndex, targetIndex, &compileResult)); ComPtr<ISlangBlob> blob; SLANG_RETURN_ON_FAIL(compileResult->getBlob(blob)); @@ -4096,17 +3897,12 @@ SLANG_API SlangResult spGetEntryPointCodeBlob( return SLANG_OK; } -SLANG_API SlangResult spGetEntryPointHostCallable( - SlangCompileRequest* request, - int entryPointIndex, - int targetIndex, - ISlangSharedLibrary** outSharedLibrary) +SlangResult EndToEndCompileRequest::getEntryPointHostCallable(int entryPointIndex, int targetIndex, ISlangSharedLibrary** outSharedLibrary) { - using namespace Slang; if (!outSharedLibrary) return SLANG_ERROR_INVALID_PARAMETER; - Slang::CompileResult* compileResult = nullptr; - SLANG_RETURN_ON_FAIL(_getEntryPointResult(request, entryPointIndex, targetIndex, &compileResult)); + CompileResult* compileResult = nullptr; + SLANG_RETURN_ON_FAIL(_getEntryPointResult(this, entryPointIndex, targetIndex, &compileResult)); ComPtr<ISlangSharedLibrary> sharedLibrary; SLANG_RETURN_ON_FAIL(compileResult->getSharedLibrary(sharedLibrary)); @@ -4114,17 +3910,13 @@ SLANG_API SlangResult spGetEntryPointHostCallable( return SLANG_OK; } -SLANG_API SlangResult spGetTargetCodeBlob( - SlangCompileRequest* request, - int targetIndex, - ISlangBlob** outBlob) +SlangResult EndToEndCompileRequest::getTargetCodeBlob(int targetIndex, ISlangBlob** outBlob) { - using namespace Slang; if (!outBlob) return SLANG_ERROR_INVALID_PARAMETER; - Slang::CompileResult* compileResult = nullptr; - SLANG_RETURN_ON_FAIL( - _getWholeProgramResult(request, targetIndex, &compileResult)); + + CompileResult* compileResult = nullptr; + SLANG_RETURN_ON_FAIL(_getWholeProgramResult(this, targetIndex, &compileResult)); ComPtr<ISlangBlob> blob; SLANG_RETURN_ON_FAIL(compileResult->getBlob(blob)); @@ -4132,18 +3924,13 @@ SLANG_API SlangResult spGetTargetCodeBlob( return SLANG_OK; } -SLANG_API SlangResult spGetTargetHostCallable( - SlangCompileRequest* request, - int targetIndex, - ISlangSharedLibrary** outSharedLibrary) +SlangResult EndToEndCompileRequest::getTargetHostCallable(int targetIndex,ISlangSharedLibrary** outSharedLibrary) { - using namespace Slang; if (!outSharedLibrary) return SLANG_ERROR_INVALID_PARAMETER; - Slang::CompileResult* compileResult = nullptr; - SLANG_RETURN_ON_FAIL( - _getWholeProgramResult(request, targetIndex, &compileResult)); + CompileResult* compileResult = nullptr; + SLANG_RETURN_ON_FAIL(_getWholeProgramResult(this, targetIndex, &compileResult)); ComPtr<ISlangSharedLibrary> sharedLibrary; SLANG_RETURN_ON_FAIL(compileResult->getSharedLibrary(sharedLibrary)); @@ -4151,24 +3938,17 @@ SLANG_API SlangResult spGetTargetHostCallable( return SLANG_OK; } -SLANG_API char const* spGetEntryPointSource( - SlangCompileRequest* request, - int entryPointIndex) +char const* EndToEndCompileRequest::getEntryPointSource(int entryPointIndex) { - return (char const*) spGetEntryPointCode(request, entryPointIndex, nullptr); + return (char const*)getEntryPointCode(entryPointIndex, nullptr); } -SLANG_API void const* spGetCompileRequestCode( - SlangCompileRequest* inRequest, - size_t* outSize) +void const* EndToEndCompileRequest::getCompileRequestCode(size_t* outSize) { - using namespace Slang; - auto request = asInternal(inRequest); - - if (request->m_containerBlob) + if (m_containerBlob) { - *outSize = request->m_containerBlob->getBufferSize(); - return request->m_containerBlob->getBufferPointer(); + *outSize = m_containerBlob->getBufferSize(); + return m_containerBlob->getBufferPointer(); } // Container blob does not have any contents @@ -4176,14 +3956,9 @@ SLANG_API void const* spGetCompileRequestCode( return nullptr; } -SLANG_API SlangResult spGetContainerCode( - SlangCompileRequest* inRequest, - ISlangBlob** outBlob) +SlangResult EndToEndCompileRequest::getContainerCode(ISlangBlob** outBlob) { - using namespace Slang; - auto request = asInternal(inRequest); - - ISlangBlob* containerBlob = request->m_containerBlob; + ISlangBlob* containerBlob = m_containerBlob; if (containerBlob) { containerBlob->addRef(); @@ -4194,15 +3969,8 @@ SLANG_API SlangResult spGetContainerCode( return SLANG_FAIL; } -SLANG_API SlangResult spLoadRepro( - SlangCompileRequest* inRequest, - ISlangFileSystem* fileSystem, - const void* data, - size_t size) +SlangResult EndToEndCompileRequest::loadRepro(ISlangFileSystem* fileSystem, const void* data, size_t size) { - using namespace Slang; - auto request = asInternal(inRequest); - List<uint8_t> buffer; SLANG_RETURN_ON_FAIL(ReproUtil::loadState((const uint8_t*)data, size, buffer)); @@ -4211,20 +3979,15 @@ SLANG_API SlangResult spLoadRepro( ReproUtil::RequestState* requestState = ReproUtil::getRequest(buffer); - SLANG_RETURN_ON_FAIL(ReproUtil::load(base, requestState, fileSystem, request)); + SLANG_RETURN_ON_FAIL(ReproUtil::load(base, requestState, fileSystem, this)); return SLANG_OK; } -SLANG_API SlangResult spSaveRepro( - SlangCompileRequest* inRequest, - ISlangBlob** outBlob) +SlangResult EndToEndCompileRequest::saveRepro(ISlangBlob** outBlob) { - using namespace Slang; - auto request = asInternal(inRequest); - OwnedMemoryStream stream(FileAccess::Write); - SLANG_RETURN_ON_FAIL(ReproUtil::saveState(request, &stream)); + SLANG_RETURN_ON_FAIL(ReproUtil::saveState(this, &stream)); RefPtr<ListBlob> listBlob(new ListBlob); @@ -4235,139 +3998,649 @@ SLANG_API SlangResult spSaveRepro( return SLANG_OK; } -SLANG_API SlangResult spEnableReproCapture( - SlangCompileRequest* inRequest) +SlangResult EndToEndCompileRequest::enableReproCapture() { - using namespace Slang; - auto request = asInternal(inRequest); + getLinkage()->setRequireCacheFileSystem(true); + return SLANG_OK; +} + +SlangResult EndToEndCompileRequest::processCommandLineArguments(char const* const* args, int argCount) +{ + return parseOptions(this, argCount, args); +} - request->getLinkage()->setRequireCacheFileSystem(true); +SlangReflection* EndToEndCompileRequest::getReflection() +{ + auto linkage = getLinkage(); + auto program = getSpecializedGlobalAndEntryPointsComponentType(); + + // Note(tfoley): The API signature doesn't let the client + // specify which target they want to access reflection + // information for, so for now we default to the first one. + // + // TODO: Add a new `spGetReflectionForTarget(req, targetIndex)` + // so that we can do this better, and make it clear that + // `spGetReflection()` is shorthand for `targetIndex == 0`. + // + Slang::Index targetIndex = 0; + auto targetCount = linkage->targets.getCount(); + if (targetIndex >= targetCount) + return nullptr; + + auto targetReq = linkage->targets[targetIndex]; + auto targetProgram = program->getTargetProgram(targetReq); + auto programLayout = targetProgram->getExistingLayout(); + + return (SlangReflection*)programLayout; +} + +SlangResult EndToEndCompileRequest::getProgram(slang::IComponentType** outProgram) +{ + auto program = getSpecializedGlobalComponentType(); + *outProgram = Slang::ComPtr<slang::IComponentType>(program).detach(); return SLANG_OK; } -SLANG_API SlangResult spExtractRepro(SlangSession* session, const void* reproData, size_t reproDataSize, ISlangMutableFileSystem* fileSystem) +SlangResult EndToEndCompileRequest::getModule(SlangInt translationUnitIndex, slang::IModule** outModule) { - using namespace Slang; - SLANG_UNUSED(session); + auto module = getFrontEndReq()->getTranslationUnit(translationUnitIndex)->getModule(); - List<uint8_t> buffer; + *outModule = Slang::ComPtr<slang::IModule>(module).detach(); + return SLANG_OK; +} + +SlangResult EndToEndCompileRequest::getSession(slang::ISession** outSession) +{ + auto session = getLinkage(); + *outSession = Slang::ComPtr<slang::ISession>(session).detach(); + return SLANG_OK; +} + +SlangResult EndToEndCompileRequest::getEntryPoint(SlangInt entryPointIndex, slang::IComponentType** outEntryPoint) +{ + auto entryPoint = getSpecializedEntryPointComponentType(entryPointIndex); + *outEntryPoint = Slang::ComPtr<slang::IComponentType>(entryPoint).detach(); + return SLANG_OK; +} + +} // namespace Slang + +/* !!!!!!!!!!!!!!!!!!SlangCompileRequest API!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +/*! +@brief Destroy a compile request. +*/ +SLANG_API void spDestroyCompileRequest( + slang::ICompileRequest* request) +{ + if (request) { - MemoryStreamBase memoryStream(FileAccess::Read, reproData, reproDataSize); - SLANG_RETURN_ON_FAIL(ReproUtil::loadState(&memoryStream, buffer)); + request->release(); } +} - MemoryOffsetBase base; - base.set(buffer.getBuffer(), buffer.getCount()); +/* All other functions just call into the ICompileResult interface. */ - ReproUtil::RequestState* requestState = ReproUtil::getRequest(buffer); - return ReproUtil::extractFiles(base, requestState, fileSystem); +SLANG_API void spSetFileSystem( + slang::ICompileRequest* request, + ISlangFileSystem* fileSystem) +{ + SLANG_ASSERT(request); + request->setFileSystem(fileSystem); } -SLANG_API SlangResult spLoadReproAsFileSystem( - SlangSession* session, - const void* reproData, - size_t reproDataSize, - ISlangFileSystem* replaceFileSystem, - ISlangFileSystemExt** outFileSystem) +SLANG_API void spSetCompileFlags( + slang::ICompileRequest* request, + SlangCompileFlags flags) { - using namespace Slang; + SLANG_ASSERT(request); + request->setCompileFlags(flags); +} - SLANG_UNUSED(session); - - MemoryStreamBase stream(FileAccess::Read, reproData, reproDataSize); +SLANG_API void spSetDumpIntermediates( + slang::ICompileRequest* request, + int enable) +{ + SLANG_ASSERT(request); + request->setDumpIntermediates(enable); +} - List<uint8_t> buffer; - SLANG_RETURN_ON_FAIL(ReproUtil::loadState(&stream, buffer)); +SLANG_API void spSetDumpIntermediatePrefix( + slang::ICompileRequest* request, + const char* prefix) +{ + SLANG_ASSERT(request); + request->setDumpIntermediatePrefix(prefix); +} - auto requestState = ReproUtil::getRequest(buffer); - MemoryOffsetBase base; - base.set(buffer.getBuffer(), buffer.getCount()); +SLANG_API void spSetLineDirectiveMode( + slang::ICompileRequest* request, + SlangLineDirectiveMode mode) +{ + SLANG_ASSERT(request); + request->setLineDirectiveMode(mode); +} - RefPtr<CacheFileSystem> cacheFileSystem; - SLANG_RETURN_ON_FAIL(ReproUtil::loadFileSystem(base, requestState, replaceFileSystem, cacheFileSystem)); +SLANG_API void spSetCommandLineCompilerMode( + slang::ICompileRequest* request) +{ + SLANG_ASSERT(request); + request->setCommandLineCompilerMode(); +} - *outFileSystem = cacheFileSystem.detach(); - return SLANG_OK; +SLANG_API void spSetCodeGenTarget( + slang::ICompileRequest* request, + SlangCompileTarget target) +{ + SLANG_ASSERT(request); + request->setCodeGenTarget(target); } -// Reflection API +SLANG_API int spAddCodeGenTarget( + slang::ICompileRequest* request, + SlangCompileTarget target) +{ + SLANG_ASSERT(request); + return request->addCodeGenTarget(target); +} + +SLANG_API void spSetTargetProfile( + slang::ICompileRequest* request, + int targetIndex, + SlangProfileID profile) +{ + SLANG_ASSERT(request); + request->setTargetProfile(targetIndex, profile); +} + +SLANG_API void spSetTargetFlags( + slang::ICompileRequest* request, + int targetIndex, + SlangTargetFlags flags) +{ + SLANG_ASSERT(request); + request->setTargetFlags(targetIndex, flags); +} + +SLANG_API void spSetTargetFloatingPointMode( + slang::ICompileRequest* request, + int targetIndex, + SlangFloatingPointMode mode) +{ + SLANG_ASSERT(request); + request->setTargetFloatingPointMode(targetIndex, mode); +} + +SLANG_API void spSetMatrixLayoutMode( + slang::ICompileRequest* request, + SlangMatrixLayoutMode mode) +{ + SLANG_ASSERT(request); + request->setMatrixLayoutMode(mode); +} + +SLANG_API void spSetTargetMatrixLayoutMode( + slang::ICompileRequest* request, + int targetIndex, + SlangMatrixLayoutMode mode) +{ + SLANG_ASSERT(request); + request->setTargetMatrixLayoutMode(targetIndex, mode); +} + +SLANG_API void spSetDebugInfoLevel( + slang::ICompileRequest* request, + SlangDebugInfoLevel level) +{ + SLANG_ASSERT(request); + request->setDebugInfoLevel(level); +} + +SLANG_API void spSetOptimizationLevel( + slang::ICompileRequest* request, + SlangOptimizationLevel level) +{ + SLANG_ASSERT(request); + request->setOptimizationLevel(level); +} + +SLANG_API void spSetOutputContainerFormat( + slang::ICompileRequest* request, + SlangContainerFormat format) +{ + SLANG_ASSERT(request); + request->setOutputContainerFormat(format); +} + +SLANG_API void spSetPassThrough( + slang::ICompileRequest* request, + SlangPassThrough passThrough) +{ + SLANG_ASSERT(request); + request->setPassThrough(passThrough); +} + +SLANG_API void spSetDiagnosticCallback( + slang::ICompileRequest* request, + SlangDiagnosticCallback callback, + void const* userData) +{ + SLANG_ASSERT(request); + request->setDiagnosticCallback(callback, userData); +} + +SLANG_API void spSetWriter( + slang::ICompileRequest* request, + SlangWriterChannel chan, + ISlangWriter* writer) +{ + SLANG_ASSERT(request); + request->setWriter(chan, writer); +} + +SLANG_API ISlangWriter* spGetWriter( + slang::ICompileRequest* request, + SlangWriterChannel chan) +{ + SLANG_ASSERT(request); + return request->getWriter(chan); +} + +SLANG_API void spAddSearchPath( + slang::ICompileRequest* request, + const char* path) +{ + SLANG_ASSERT(request); + request->addSearchPath(path); +} + +SLANG_API void spAddPreprocessorDefine( + slang::ICompileRequest* request, + const char* key, + const char* value) +{ + SLANG_ASSERT(request); + request->addPreprocessorDefine(key, value); +} + +SLANG_API char const* spGetDiagnosticOutput( + slang::ICompileRequest* request) +{ + SLANG_ASSERT(request); + return request->getDiagnosticOutput(); +} + +SLANG_API SlangResult spGetDiagnosticOutputBlob( + slang::ICompileRequest* request, + ISlangBlob** outBlob) +{ + SLANG_ASSERT(request); + return request->getDiagnosticOutputBlob(outBlob); +} + +// New-fangled compilation API + +SLANG_API int spAddTranslationUnit( + slang::ICompileRequest* request, + SlangSourceLanguage language, + char const* inName) +{ + SLANG_ASSERT(request); + return request->addTranslationUnit(language, inName); +} + +SLANG_API void spSetDefaultModuleName( + slang::ICompileRequest* request, + const char* defaultModuleName) +{ + SLANG_ASSERT(request); + request->setDefaultModuleName(defaultModuleName); +} + +SLANG_API SlangResult spAddLibraryReference( + slang::ICompileRequest* request, + const void* libData, + size_t libDataSize) +{ + SLANG_ASSERT(request); + return request->addLibraryReference(libData, libDataSize); +} + +SLANG_API void spTranslationUnit_addPreprocessorDefine( + slang::ICompileRequest* request, + int translationUnitIndex, + const char* key, + const char* value) +{ + SLANG_ASSERT(request); + request->addTranslationUnitPreprocessorDefine(translationUnitIndex, key, value); +} + +SLANG_API void spAddTranslationUnitSourceFile( + slang::ICompileRequest* request, + int translationUnitIndex, + char const* path) +{ + SLANG_ASSERT(request); + request->addTranslationUnitSourceFile(translationUnitIndex, path); +} + +SLANG_API void spAddTranslationUnitSourceString( + slang::ICompileRequest* request, + int translationUnitIndex, + char const* path, + char const* source) +{ + SLANG_ASSERT(request); + request->addTranslationUnitSourceString(translationUnitIndex, path, source); +} + +SLANG_API void spAddTranslationUnitSourceStringSpan( + slang::ICompileRequest* request, + int translationUnitIndex, + char const* path, + char const* sourceBegin, + char const* sourceEnd) +{ + SLANG_ASSERT(request); + request->addTranslationUnitSourceStringSpan(translationUnitIndex, path, sourceBegin, sourceEnd); +} + +SLANG_API void spAddTranslationUnitSourceBlob( + slang::ICompileRequest* request, + int translationUnitIndex, + char const* path, + ISlangBlob* sourceBlob) +{ + SLANG_ASSERT(request); + request->addTranslationUnitSourceBlob(translationUnitIndex, path, sourceBlob); +} + +SLANG_API int spAddEntryPoint( + slang::ICompileRequest* request, + int translationUnitIndex, + char const* name, + SlangStage stage) +{ + SLANG_ASSERT(request); + return request->addEntryPoint(translationUnitIndex, name, stage); +} + +SLANG_API int spAddEntryPointEx( + slang::ICompileRequest* request, + int translationUnitIndex, + char const* name, + SlangStage stage, + int genericParamTypeNameCount, + char const ** genericParamTypeNames) +{ + SLANG_ASSERT(request); + return request->addEntryPointEx(translationUnitIndex, name, stage, genericParamTypeNameCount, genericParamTypeNames); +} + +SLANG_API SlangResult spSetGlobalGenericArgs( + slang::ICompileRequest* request, + int genericArgCount, + char const** genericArgs) +{ + SLANG_ASSERT(request); + return request->setGlobalGenericArgs(genericArgCount, genericArgs); +} + +SLANG_API SlangResult spSetTypeNameForGlobalExistentialTypeParam( + slang::ICompileRequest* request, + int slotIndex, + char const* typeName) +{ + SLANG_ASSERT(request); + return request->setTypeNameForGlobalExistentialTypeParam(slotIndex, typeName); +} + +SLANG_API SlangResult spSetTypeNameForEntryPointExistentialTypeParam( + slang::ICompileRequest* request, + int entryPointIndex, + int slotIndex, + char const* typeName) +{ + SLANG_ASSERT(request); + return request->setTypeNameForEntryPointExistentialTypeParam(entryPointIndex, slotIndex, typeName); +} + +SLANG_API SlangResult spCompile( + slang::ICompileRequest* request) +{ + SLANG_ASSERT(request); + return request->compile(); +} + +SLANG_API int +spGetDependencyFileCount( + slang::ICompileRequest* request) +{ + SLANG_ASSERT(request); + return request->getDependencyFileCount(); +} + +SLANG_API char const* +spGetDependencyFilePath( + slang::ICompileRequest* request, + int index) +{ + SLANG_ASSERT(request); + return request->getDependencyFilePath(index); +} + +SLANG_API int +spGetTranslationUnitCount( + slang::ICompileRequest* request) +{ + SLANG_ASSERT(request); + return request->getTranslationUnitCount(); +} + +SLANG_API void const* spGetEntryPointCode( + slang::ICompileRequest* request, + int entryPointIndex, + size_t* outSize) +{ + SLANG_ASSERT(request); + return request->getEntryPointCode(entryPointIndex, outSize); +} + +SLANG_API SlangResult spGetEntryPointCodeBlob( + slang::ICompileRequest* request, + int entryPointIndex, + int targetIndex, + ISlangBlob** outBlob) +{ + SLANG_ASSERT(request); + return request->getEntryPointCodeBlob(entryPointIndex, targetIndex, outBlob); +} + +SLANG_API SlangResult spGetEntryPointHostCallable( + slang::ICompileRequest* request, + int entryPointIndex, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) +{ + SLANG_ASSERT(request); + return request->getEntryPointHostCallable(entryPointIndex, targetIndex, outSharedLibrary); +} + +SLANG_API SlangResult spGetTargetCodeBlob( + slang::ICompileRequest* request, + int targetIndex, + ISlangBlob** outBlob) +{ + SLANG_ASSERT(request); + return request->getTargetCodeBlob(targetIndex, outBlob); +} + +SLANG_API SlangResult spGetTargetHostCallable( + slang::ICompileRequest* request, + int targetIndex, + ISlangSharedLibrary** outSharedLibrary) +{ + SLANG_ASSERT(request); + return request->getTargetHostCallable(targetIndex, outSharedLibrary); +} + +SLANG_API char const* spGetEntryPointSource( + slang::ICompileRequest* request, + int entryPointIndex) +{ + SLANG_ASSERT(request); + return request->getEntryPointSource(entryPointIndex); +} + +SLANG_API void const* spGetCompileRequestCode( + slang::ICompileRequest* request, + size_t* outSize) +{ + SLANG_ASSERT(request); + return request->getCompileRequestCode(outSize); +} + +SLANG_API SlangResult spGetContainerCode( + slang::ICompileRequest* request, + ISlangBlob** outBlob) +{ + SLANG_ASSERT(request); + return request->getContainerCode(outBlob); +} + +SLANG_API SlangResult spLoadRepro( + slang::ICompileRequest* request, + ISlangFileSystem* fileSystem, + const void* data, + size_t size) +{ + SLANG_ASSERT(request); + return request->loadRepro(fileSystem, data, size); +} + +SLANG_API SlangResult spSaveRepro( + slang::ICompileRequest* request, + ISlangBlob** outBlob) +{ + SLANG_ASSERT(request); + return request->saveRepro(outBlob); +} + +SLANG_API SlangResult spEnableReproCapture( + slang::ICompileRequest* request) +{ + SLANG_ASSERT(request); + return request->enableReproCapture(); +} SLANG_API SlangResult spCompileRequest_getProgram( - SlangCompileRequest* request, + slang::ICompileRequest* request, slang::IComponentType** outProgram) { - if( !request ) return SLANG_ERROR_INVALID_PARAMETER; - auto req = Slang::asInternal(request); - auto program = req->getSpecializedGlobalComponentType(); - - *outProgram = Slang::ComPtr<slang::IComponentType>(program).detach(); - return SLANG_OK; + SLANG_ASSERT(request); + return request->getProgram(outProgram); } SLANG_API SlangResult spCompileRequest_getModule( - SlangCompileRequest* request, + slang::ICompileRequest* request, SlangInt translationUnitIndex, slang::IModule** outModule) { - if( !request ) return SLANG_ERROR_INVALID_PARAMETER; - auto req = Slang::asInternal(request); - - auto module = req->getFrontEndReq()->getTranslationUnit(translationUnitIndex)->getModule(); - - *outModule = Slang::ComPtr<slang::IModule>(module).detach(); - return SLANG_OK; + SLANG_ASSERT(request); + return request->getModule(translationUnitIndex, outModule); } SLANG_API SlangResult spCompileRequest_getSession( - SlangCompileRequest* request, + slang::ICompileRequest* request, slang::ISession** outSession) { - auto session = Slang::asInternal(request)->getLinkage(); - *outSession = Slang::ComPtr<slang::ISession>(session).detach(); - return SLANG_OK; + SLANG_ASSERT(request); + return request->getSession(outSession); } SLANG_API SlangResult spCompileRequest_getEntryPoint( - SlangCompileRequest* request, + slang::ICompileRequest* request, SlangInt entryPointIndex, slang::IComponentType** outEntryPoint) { - if( !request ) return SLANG_ERROR_INVALID_PARAMETER; - auto req = Slang::asInternal(request); + SLANG_ASSERT(request); + return request->getEntryPoint(entryPointIndex, outEntryPoint); +} - auto entryPoint = req->getSpecializedEntryPointComponentType(entryPointIndex); +// Get the output code associated with a specific translation unit +SLANG_API char const* spGetTranslationUnitSource( + slang::ICompileRequest* /*request*/, + int /*translationUnitIndex*/) +{ + fprintf(stderr, "DEPRECATED: spGetTranslationUnitSource()\n"); + return nullptr; +} - *outEntryPoint = Slang::ComPtr<slang::IComponentType>(entryPoint).detach(); - return SLANG_OK; +SLANG_API SlangResult spProcessCommandLineArguments( + SlangCompileRequest* request, + char const* const* args, + int argCount) +{ + return request->processCommandLineArguments(args, argCount); } +// Reflection API SLANG_API SlangReflection* spGetReflection( - SlangCompileRequest* request) + slang::ICompileRequest* request) { - if( !request ) return 0; - auto req = Slang::asInternal(request); - auto linkage = req->getLinkage(); - auto program = req->getSpecializedGlobalAndEntryPointsComponentType(); + SLANG_ASSERT(request); + return request->getReflection(); +} - // Note(tfoley): The API signature doesn't let the client - // specify which target they want to access reflection - // information for, so for now we default to the first one. - // - // TODO: Add a new `spGetReflectionForTarget(req, targetIndex)` - // so that we can do this better, and make it clear that - // `spGetReflection()` is shorthand for `targetIndex == 0`. - // - Slang::Index targetIndex = 0; - auto targetCount = linkage->targets.getCount(); - if (targetIndex >= targetCount) - return nullptr; +// ... rest of reflection API implementation is in `Reflection.cpp` - auto targetReq = linkage->targets[targetIndex]; - auto targetProgram = program->getTargetProgram(targetReq); - auto programLayout = targetProgram->getExistingLayout(); +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Session !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ - return (SlangReflection*) programLayout; +SLANG_API SlangResult spExtractRepro(SlangSession* session, const void* reproData, size_t reproDataSize, ISlangMutableFileSystem* fileSystem) +{ + using namespace Slang; + SLANG_UNUSED(session); + + List<uint8_t> buffer; + { + MemoryStreamBase memoryStream(FileAccess::Read, reproData, reproDataSize); + SLANG_RETURN_ON_FAIL(ReproUtil::loadState(&memoryStream, buffer)); + } + + MemoryOffsetBase base; + base.set(buffer.getBuffer(), buffer.getCount()); + + ReproUtil::RequestState* requestState = ReproUtil::getRequest(buffer); + return ReproUtil::extractFiles(base, requestState, fileSystem); } -// ... rest of reflection API implementation is in `Reflection.cpp` +SLANG_API SlangResult spLoadReproAsFileSystem( + SlangSession* session, + const void* reproData, + size_t reproDataSize, + ISlangFileSystem* replaceFileSystem, + ISlangFileSystemExt** outFileSystem) +{ + using namespace Slang; + + SLANG_UNUSED(session); + + MemoryStreamBase stream(FileAccess::Read, reproData, reproDataSize); + + List<uint8_t> buffer; + SLANG_RETURN_ON_FAIL(ReproUtil::loadState(&stream, buffer)); + + auto requestState = ReproUtil::getRequest(buffer); + MemoryOffsetBase base; + base.set(buffer.getBuffer(), buffer.getCount()); + + RefPtr<CacheFileSystem> cacheFileSystem; + SLANG_RETURN_ON_FAIL(ReproUtil::loadFileSystem(base, requestState, replaceFileSystem, cacheFileSystem)); + + *outFileSystem = cacheFileSystem.detach(); + return SLANG_OK; +} + + diff --git a/tools/slang-test/slangc-tool.cpp b/tools/slang-test/slangc-tool.cpp index 4757f2fff..25b973421 100644 --- a/tools/slang-test/slangc-tool.cpp +++ b/tools/slang-test/slangc-tool.cpp @@ -6,8 +6,6 @@ using namespace Slang; -SLANG_API void spSetCommandLineCompilerMode(SlangCompileRequest* request); - static void _diagnosticCallback(char const* message, void* /*userData*/) { auto stdError = StdWriters::getError(); @@ -15,13 +13,35 @@ static void _diagnosticCallback(char const* message, void* /*userData*/) stdError.flush(); } -static SlangResult _compile(SlangCompileRequest* compileRequest, int argc, const char*const* argv) +SlangResult SlangCTool::innerMain(StdWriters* stdWriters, slang::IGlobalSession* sharedSession, int argc, const char*const* argv) { - spSetDiagnosticCallback(compileRequest, &_diagnosticCallback, nullptr); - spSetCommandLineCompilerMode(compileRequest); + StdWriters::setSingleton(stdWriters); + + // Assume we will used the shared session + ComPtr<slang::IGlobalSession> session(sharedSession); + // The sharedSession always has a pre-loaded stdlib. + // This differed test checks if the command line has an option to setup the stdlib. + // If so we *don't* use the sharedSession, and create a new stdlib-less session just for this compilation. + if (TestToolUtil::hasDeferredStdLib(Index(argc - 1), argv + 1)) { - const SlangResult res = spProcessCommandLineArguments(compileRequest, &argv[1], argc - 1); + SLANG_RETURN_ON_FAIL(slang_createGlobalSessionWithoutStdLib(SLANG_API_VERSION, session.writeRef())); + } + + ComPtr<slang::ICompileRequest> compileRequest; + SLANG_RETURN_ON_FAIL(session->createCompileRequest(compileRequest.writeRef())); + + // Do any app specific configuration + for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i) + { + compileRequest->setWriter(SlangWriterChannel(i), stdWriters->getWriter(i)); + } + + compileRequest->setDiagnosticCallback(&_diagnosticCallback, nullptr); + compileRequest->setCommandLineCompilerMode(); + + { + const SlangResult res = compileRequest->processCommandLineArguments(&argv[1], argc - 1); if (SLANG_FAILED(res)) { // TODO: print usage message @@ -29,55 +49,26 @@ static SlangResult _compile(SlangCompileRequest* compileRequest, int argc, const } } - SlangResult res = SLANG_OK; + SlangResult compileRes = SLANG_OK; #ifndef _DEBUG try #endif { // Run the compiler (this will produce any diagnostics through SLANG_WRITER_TARGET_TYPE_DIAGNOSTIC). - res = spCompile(compileRequest); + compileRes = compileRequest->compile(); + // If the compilation failed, then get out of here... // Turn into an internal Result -> such that return code can be used to vary result to match previous behavior - res = SLANG_FAILED(res) ? SLANG_E_INTERNAL_FAIL : res; + compileRes = SLANG_FAILED(compileRes) ? SLANG_E_INTERNAL_FAIL : compileRes; } #ifndef _DEBUG catch (const Exception& e) { StdWriters::getOut().print("internal compiler error: %S\n", e.Message.toWString().begin()); - res = SLANG_FAIL; + compileRes = SLANG_FAIL; } #endif - return res; -} - -SlangResult SlangCTool::innerMain(StdWriters* stdWriters, slang::IGlobalSession* sharedSession, int argc, const char*const* argv) -{ - StdWriters::setSingleton(stdWriters); - - // Assume we will used the shared session - ComPtr<slang::IGlobalSession> session(sharedSession); - - // The sharedSession always has a pre-loaded stdlib. - // This differed test checks if the command line has an option to setup the stdlib. - // If so we *don't* use the sharedSession, and create a new stdlib-less session just for this compilation. - if (TestToolUtil::hasDeferredStdLib(Index(argc - 1), argv + 1)) - { - SLANG_RETURN_ON_FAIL(slang_createGlobalSessionWithoutStdLib(SLANG_API_VERSION, session.writeRef())); - } - - SlangCompileRequest* compileRequest = spCreateCompileRequest(session); - - // Do any app specific configuration - for (int i = 0; i < SLANG_WRITER_CHANNEL_COUNT_OF; ++i) - { - spSetWriter(compileRequest, SlangWriterChannel(i), stdWriters->getWriter(i)); - } - - SlangResult res = _compile(compileRequest, argc, argv); - // Now that we are done, clean up after ourselves - spDestroyCompileRequest(compileRequest); - - return res; + return compileRes; } |
