From 79ec0cfdb5f3461c763e0bf712cf42eb87fccb90 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 10 Dec 2019 10:02:19 -0500 Subject: DownstreamCompiler abstraction (#1149) * CPPCompiler -> DownstreamCompiler * Added DownstreamCompileResult to start abstraction such that we don't need files. * * Split out slang-blob.cpp * Made CompileResult hold a DownstreamCompileResult - for access to binary or ISlangSharedLibrary * Keep temporary files in scope. * Add a hash to the hex dump stream. * Move all file tracking into DownstreamCompiler. --- source/slang/slang-compiler.h | 55 ++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'source/slang/slang-compiler.h') diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 9950764e4..c33b2cf28 100644 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -4,7 +4,7 @@ #include "../core/slang-basic.h" #include "../core/slang-shared-library.h" -#include "../core/slang-cpp-compiler.h" +#include "../core/slang-downstream-compiler.h" #include "../../slang-com-ptr.h" @@ -92,7 +92,6 @@ namespace Slang None, Text, Binary, - SharedLibrary, }; // When storing the layout for a matrix-type @@ -135,21 +134,20 @@ namespace Slang { public: CompileResult() = default; - CompileResult(String const& str) : format(ResultFormat::Text), outputString(str) {} - CompileResult(List const& buffer) : format(ResultFormat::Binary), outputBinary(buffer) {} - CompileResult(ISlangSharedLibrary* inSharedLibrary) : format(ResultFormat::SharedLibrary), sharedLibrary(inSharedLibrary) {} + explicit CompileResult(String const& str) : format(ResultFormat::Text), outputString(str) {} + explicit CompileResult(ISlangBlob* inBlob) : format(ResultFormat::Binary), blob(inBlob) {} + explicit CompileResult(DownstreamCompileResult* inDownstreamResult): format(ResultFormat::Binary), downstreamResult(inDownstreamResult) {} + explicit CompileResult(const UnownedStringSlice& slice ) : format(ResultFormat::Text), outputString(slice) {} - void append(CompileResult const& result); - - SlangResult getBlob(ComPtr& outBlob); + SlangResult getBlob(ComPtr& outBlob) const; SlangResult getSharedLibrary(ComPtr& outSharedLibrary); ResultFormat format = ResultFormat::None; - String outputString; - List outputBinary; + String outputString; ///< Only set if result type is ResultFormat::Text + + mutable ComPtr blob; - ComPtr sharedLibrary; - ComPtr blob; + RefPtr downstreamResult; }; /// Information collected about global or entry-point shader parameters @@ -1073,15 +1071,10 @@ namespace Slang List searchDirectories; }; - /// Create a blob that will retain (a copy of) raw data. - /// - ComPtr createRawBlob(void const* data, size_t size); - - /// Given a target returns the required downstream compiler PassThroughMode getDownstreamCompilerRequiredForTarget(CodeGenTarget target); - PassThroughMode getPassThroughModeForCPPCompiler(CPPCompiler::CompilerType type); + PassThroughMode getPassThroughModeForCPPCompiler(DownstreamCompiler::CompilerType type); /// A context for loading and re-using code modules. @@ -1777,6 +1770,11 @@ namespace Slang char const* text, CodeGenTarget target); + void maybeDumpIntermediate( + BackEndCompileRequest* compileRequest, + 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 */ @@ -1836,9 +1834,9 @@ namespace Slang SLANG_NO_THROW SlangPassThrough SLANG_MCALL getDefaultDownstreamCompiler(SlangSourceLanguage sourceLanguage) override; /// Get the specified compiler - CPPCompiler* getCPPCompiler(PassThroughMode downstreamCompiler); + DownstreamCompiler* getDownstreamCompiler(PassThroughMode downstreamCompiler); /// Get the default cpp compiler for a language - CPPCompiler* getDefaultCPPCompiler(SourceLanguage sourceLanguage); + DownstreamCompiler* getDefaultCPPCompiler(SourceLanguage sourceLanguage); enum class SharedLibraryFuncType { @@ -1894,7 +1892,7 @@ namespace Slang RefPtr stringType; RefPtr enumTypeType; - RefPtr cppCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow) + RefPtr cppCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow) ComPtr sharedLibraryLoader; ///< The shared library loader (never null) ComPtr sharedLibraries[int(SharedLibraryType::CountOf)]; ///< The loaded shared libraries @@ -1976,7 +1974,7 @@ namespace Slang const String& getDownstreamCompilerPrelude(PassThroughMode mode) { return m_downstreamCompilerPreludes[int(mode)]; } /// Finds out what compilers are present and caches the result - CPPCompilerSet* requireCPPCompilerSet(); + DownstreamCompilerSet* requireCPPCompilerSet(); Session(); @@ -2095,20 +2093,7 @@ SLANG_FORCE_INLINE EndToEndCompileRequest* asInternal(SlangCompileRequest* reque return reinterpret_cast(request); } -class ListBlob : public ISlangBlob, public RefObject -{ -public: - SLANG_REF_OBJECT_IUNKNOWN_ALL - - // ISlangBlob - SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_data.getBuffer(); } - SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_data.getCount(); } - - List m_data; -protected: - ISlangUnknown* getInterface(const Guid& guid); -}; } -- cgit v1.2.3