diff options
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-check.cpp | 10 | ||||
| -rw-r--r-- | source/slang/slang-compiler.cpp | 354 | ||||
| -rw-r--r-- | source/slang/slang-compiler.h | 55 | ||||
| -rw-r--r-- | source/slang/slang-emit.cpp | 2 | ||||
| -rw-r--r-- | source/slang/slang-file-system.h | 2 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 85 | ||||
| -rw-r--r-- | source/slang/slang.vcxproj | 2 |
7 files changed, 146 insertions, 364 deletions
diff --git a/source/slang/slang-check.cpp b/source/slang/slang-check.cpp index 704d37d01..3586fcf25 100644 --- a/source/slang/slang-check.cpp +++ b/source/slang/slang-check.cpp @@ -121,20 +121,20 @@ namespace Slang return func; } - CPPCompilerSet* Session::requireCPPCompilerSet() + DownstreamCompilerSet* Session::requireCPPCompilerSet() { if (cppCompilerSet == nullptr) { - cppCompilerSet = new CPPCompilerSet; + cppCompilerSet = new DownstreamCompilerSet; - typedef CPPCompiler::CompilerType CompilerType; - CPPCompilerUtil::InitializeSetDesc desc; + typedef DownstreamCompiler::CompilerType CompilerType; + DownstreamCompilerUtil::InitializeSetDesc desc; desc.paths[int(CompilerType::GCC)] = m_downstreamCompilerPaths[int(PassThroughMode::Gcc)]; desc.paths[int(CompilerType::Clang)] = m_downstreamCompilerPaths[int(PassThroughMode::Clang)]; desc.paths[int(CompilerType::VisualStudio)] = m_downstreamCompilerPaths[int(PassThroughMode::VisualStudio)]; - CPPCompilerUtil::initializeSet(desc, cppCompilerSet); + DownstreamCompilerUtil::initializeSet(desc, cppCompilerSet); } SLANG_ASSERT(cppCompilerSet); return cppCompilerSet; diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 6cb3603b9..9ac49f60c 100644 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -130,48 +130,16 @@ namespace Slang return StringUtil::getAtInSplit(s_codeGenTargetInfos[int(target)].names, ',', 0); } - // CompileResult - - void CompileResult::append(CompileResult const& result) - { - // Find which to append to - ResultFormat appendTo = ResultFormat::None; - - if (format == ResultFormat::None) - { - format = result.format; - appendTo = result.format; - } - else if (format == result.format) - { - appendTo = format; - } - - if (appendTo == ResultFormat::Text) - { - outputString.append(result.outputString.getBuffer()); - } - else if (appendTo == ResultFormat::Binary) - { - outputBinary.addRange(result.outputBinary.getBuffer(), result.outputBinary.getCount()); - } - else if (appendTo == ResultFormat::SharedLibrary) - { - SLANG_ASSERT(!"Trying to append to a shared library"); - } - } - SlangResult CompileResult::getSharedLibrary(ComPtr<ISlangSharedLibrary>& outSharedLibrary) { - if (format == ResultFormat::SharedLibrary && sharedLibrary) + if (downstreamResult) { - outSharedLibrary = sharedLibrary; - return SLANG_OK; + return downstreamResult->getHostCallableSharedLibrary(outSharedLibrary); } return SLANG_FAIL; } - SlangResult CompileResult::getBlob(ComPtr<ISlangBlob>& outBlob) + SlangResult CompileResult::getBlob(ComPtr<ISlangBlob>& outBlob) const { if(!blob) { @@ -184,28 +152,12 @@ namespace Slang case ResultFormat::Text: blob = StringUtil::createStringBlob(outputString); break; - case ResultFormat::Binary: - blob = createRawBlob(outputBinary.getBuffer(), outputBinary.getCount()); - break; - case ResultFormat::SharedLibrary: { - // TODO(JS): Could do something more sophisticated to check this cast is safe (like have an interface to get the path), but this - // is simple and works with current impl - TemporarySharedLibrary* tempLibrary = static_cast<TemporarySharedLibrary*>(sharedLibrary.get()); - - SLANG_ASSERT(sharedLibrary); - List<uint8_t> contents; - try + if (downstreamResult) { - // We can read it from the shared library... - contents = File::readAllBytes(tempLibrary->getPath()); + SLANG_RETURN_ON_FAIL(downstreamResult->getBinary(blob)); } - catch (const Slang::IOException&) - { - return SLANG_E_CANNOT_OPEN; - } - blob = createRawBlob(contents.getBuffer(), contents.getCount()); break; } } @@ -520,19 +472,19 @@ namespace Slang } case PassThroughMode::Clang: { - return session->requireCPPCompilerSet()->hasCompiler(CPPCompiler::CompilerType::Clang) ? SLANG_OK: SLANG_E_NOT_FOUND; + return session->requireCPPCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::Clang) ? SLANG_OK: SLANG_E_NOT_FOUND; } case PassThroughMode::VisualStudio: { - return session->requireCPPCompilerSet()->hasCompiler(CPPCompiler::CompilerType::VisualStudio) ? SLANG_OK: SLANG_E_NOT_FOUND; + return session->requireCPPCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::VisualStudio) ? SLANG_OK: SLANG_E_NOT_FOUND; } case PassThroughMode::Gcc: { - return session->requireCPPCompilerSet()->hasCompiler(CPPCompiler::CompilerType::GCC) ? SLANG_OK: SLANG_E_NOT_FOUND; + return session->requireCPPCompilerSet()->hasCompiler(DownstreamCompiler::CompilerType::GCC) ? SLANG_OK: SLANG_E_NOT_FOUND; } case PassThroughMode::GenericCCpp: { - List<CPPCompiler::Desc> descs; + List<DownstreamCompiler::Desc> descs; session->requireCPPCompilerSet()->getCompilerDescs(descs); return descs.getCount() ? SLANG_OK: SLANG_E_NOT_FOUND; @@ -597,9 +549,9 @@ namespace Slang return PassThroughMode::None; } - PassThroughMode getPassThroughModeForCPPCompiler(CPPCompiler::CompilerType type) + PassThroughMode getPassThroughModeForCPPCompiler(DownstreamCompiler::CompilerType type) { - typedef CPPCompiler::CompilerType CompilerType; + typedef DownstreamCompiler::CompilerType CompilerType; switch (type) { @@ -1330,8 +1282,7 @@ SlangResult dissassembleDXILUsingDXC( Int entryPointIndex, TargetRequest* targetReq, EndToEndCompileRequest* endToEndReq, - ComPtr<ISlangSharedLibrary>& outSharedLib, - List<uint8_t>& outBin) + RefPtr<DownstreamCompileResult>& outResult) { auto sink = slangRequest->getSink(); @@ -1339,9 +1290,8 @@ SlangResult dissassembleDXILUsingDXC( const String originalSourcePath = calcSourcePathForEntryPoint(endToEndReq, entryPointIndex); - outBin.clear(); - outSharedLib.setNull(); - + outResult.setNull(); + PassThroughMode downstreamCompiler = endToEndReq->passThrough; // If we are not in pass through, lookup the default compiler for the emitted source type @@ -1351,7 +1301,7 @@ SlangResult dissassembleDXILUsingDXC( } // Get the required downstream CPP compiler - CPPCompiler* compiler = session->getCPPCompiler(downstreamCompiler); + DownstreamCompiler* compiler = session->getDownstreamCompiler(downstreamCompiler); if (!compiler) { @@ -1367,19 +1317,14 @@ SlangResult dissassembleDXILUsingDXC( return SLANG_FAIL; } - TemporaryFileSet temporaryFileSet; - - bool useOriginalFile = false; - - String compileSourcePath; - - String rawSource; - SourceLanguage rawSourceLanguage = SourceLanguage::Unknown; Dictionary<String, String> preprocessorDefinitions; List<String> includePaths; + typedef DownstreamCompiler::CompileOptions CompileOptions; + CompileOptions options; + /* This is more convoluted than the other scenarios, because when we invoke C/C++ compiler we would ideally like to use the original file. We want to do this because we want includes relative to the source file to work, and for that to work most easily we want to use the original file, if there is one */ @@ -1437,7 +1382,7 @@ SlangResult dissassembleDXILUsingDXC( const PathInfo& pathInfo = sourceFile->getPathInfo(); if (pathInfo.type == PathInfo::Type::FoundPath || pathInfo.type == PathInfo::Type::Normal) { - compileSourcePath = pathInfo.foundPath; + String compileSourcePath = pathInfo.foundPath; // We can see if we can load it if (File::exists(compileSourcePath)) { @@ -1454,7 +1399,11 @@ SlangResult dissassembleDXILUsingDXC( { String readContents = File::readAllText(compileSourcePath); // We should see if they are the same - useOriginalFile = (sourceFile->getContent() == readContents.getUnownedSlice()); + if ((sourceFile->getContent() == readContents.getUnownedSlice())) + { + // We just say use this file + options.sourceFiles.add(compileSourcePath); + } } catch (const Slang::IOException&) { @@ -1463,114 +1412,53 @@ SlangResult dissassembleDXILUsingDXC( } } - if (!useOriginalFile) + // If can't just use file, concat together and make + if (options.sourceFiles.getCount() == 0) { StringBuilder codeBuilder; for (auto sourceFile : translationUnit->getSourceFiles()) { _appendCodeWithPath(sourceFile->getPathInfo().foundPath.getUnownedSlice(), sourceFile->getContent(), codeBuilder); } - rawSource = codeBuilder.ProduceString(); + options.sourceContents = codeBuilder.ProduceString(); } } else { - rawSource = emitCPPForEntryPoint( + options.sourceContents = emitCPPForEntryPoint( slangRequest, entryPointIndex, targetReq, endToEndReq); - maybeDumpIntermediate(slangRequest, rawSource.getBuffer(), CodeGenTarget::CPPSource); + maybeDumpIntermediate(slangRequest, options.sourceContents.getBuffer(), CodeGenTarget::CPPSource); rawSourceLanguage = SourceLanguage::CPP; } - // Generate a path a temporary filename for output module - String modulePath; - SLANG_RETURN_ON_FAIL(File::generateTemporary(UnownedStringSlice::fromLiteral("slang-generated"), modulePath)); - - if (!useOriginalFile) - { - // We need to create a new file which has the source. We'll use the module generated name as the basis - compileSourcePath = modulePath; - - // NOTE: Strictly speaking producing filenames by modifying the generateTemporary path that may introduce a temp filename clash, but in practice is extraordinary unlikely - - compileSourcePath.append("-src"); - - // Make the temporary filename have the appropriate extension. - if (rawSourceLanguage == SourceLanguage::C) - { - compileSourcePath.append(".c"); - } - else - { - compileSourcePath.append(".cpp"); - } - - // Delete this path at end of execution - temporaryFileSet.add(compileSourcePath); - - try - { - File::writeAllText(compileSourcePath, rawSource); - } - catch (...) - { - sink->diagnose(SourceLoc(), Diagnostics::unableToWriteFile, compileSourcePath); - return SLANG_FAIL; - } - } - - typedef CPPCompiler::CompileOptions CompileOptions; - CompileOptions options; - // Set the source type - options.sourceType = (rawSourceLanguage == SourceLanguage::C) ? CPPCompiler::SourceType::C : CPPCompiler::SourceType::CPP; + options.sourceType = (rawSourceLanguage == SourceLanguage::C) ? DownstreamCompiler::SourceType::C : DownstreamCompiler::SourceType::CPP; // Disable exceptions and security checks options.flags &= ~(CompileOptions::Flag::EnableExceptionHandling | CompileOptions::Flag::EnableSecurityChecks); - // Remove the temporary path/file when done - temporaryFileSet.add(modulePath); - - options.modulePath = modulePath; - options.sourceFiles.add(compileSourcePath); - // Set what kind of target we should build switch (targetReq->target) { case CodeGenTarget::HostCallable: case CodeGenTarget::SharedLibrary: { - options.targetType = CPPCompiler::TargetType::SharedLibrary; + options.targetType = DownstreamCompiler::TargetType::SharedLibrary; break; } case CodeGenTarget::Executable: { - options.targetType = CPPCompiler::TargetType::Executable; + options.targetType = DownstreamCompiler::TargetType::Executable; break; } default: break; } - String moduleFilePath; - - { - StringBuilder builder; - SLANG_RETURN_ON_FAIL(compiler->calcModuleFilePath(options, builder)); - moduleFilePath = builder.ProduceString(); - } - - // Find all the files that will be produced - TemporaryFileSet productFileSet; - { - List<String> paths; - SLANG_RETURN_ON_FAIL(compiler->calcCompileProducts(options, CPPCompiler::ProductFlag::All, paths)); - productFileSet.add(paths); - } - // Need to configure for the compilation { @@ -1578,28 +1466,28 @@ SlangResult dissassembleDXILUsingDXC( switch (linkage->optimizationLevel) { - case OptimizationLevel::None: options.optimizationLevel = CPPCompiler::OptimizationLevel::None; break; - case OptimizationLevel::Default: options.optimizationLevel = CPPCompiler::OptimizationLevel::Default; break; - case OptimizationLevel::High: options.optimizationLevel = CPPCompiler::OptimizationLevel::High; break; - case OptimizationLevel::Maximal: options.optimizationLevel = CPPCompiler::OptimizationLevel::Maximal; break; + case OptimizationLevel::None: options.optimizationLevel = DownstreamCompiler::OptimizationLevel::None; break; + case OptimizationLevel::Default: options.optimizationLevel = DownstreamCompiler::OptimizationLevel::Default; break; + case OptimizationLevel::High: options.optimizationLevel = DownstreamCompiler::OptimizationLevel::High; break; + case OptimizationLevel::Maximal: options.optimizationLevel = DownstreamCompiler::OptimizationLevel::Maximal; break; default: SLANG_ASSERT(!"Unhandled optimization level"); break; } switch (linkage->debugInfoLevel) { - case DebugInfoLevel::None: options.debugInfoType = CPPCompiler::DebugInfoType::None; break; - case DebugInfoLevel::Minimal: options.debugInfoType = CPPCompiler::DebugInfoType::Minimal; break; + case DebugInfoLevel::None: options.debugInfoType = DownstreamCompiler::DebugInfoType::None; break; + case DebugInfoLevel::Minimal: options.debugInfoType = DownstreamCompiler::DebugInfoType::Minimal; break; - case DebugInfoLevel::Standard: options.debugInfoType = CPPCompiler::DebugInfoType::Standard; break; - case DebugInfoLevel::Maximal: options.debugInfoType = CPPCompiler::DebugInfoType::Maximal; break; + case DebugInfoLevel::Standard: options.debugInfoType = DownstreamCompiler::DebugInfoType::Standard; break; + case DebugInfoLevel::Maximal: options.debugInfoType = DownstreamCompiler::DebugInfoType::Maximal; break; default: SLANG_ASSERT(!"Unhandled debug level"); break; } switch( targetReq->floatingPointMode ) { - case FloatingPointMode::Default: options.floatingPointMode = CPPCompiler::FloatingPointMode::Default; break; - case FloatingPointMode::Precise: options.floatingPointMode = CPPCompiler::FloatingPointMode::Precise; break; - case FloatingPointMode::Fast: options.floatingPointMode = CPPCompiler::FloatingPointMode::Fast; break; + case FloatingPointMode::Default: options.floatingPointMode = DownstreamCompiler::FloatingPointMode::Default; break; + case FloatingPointMode::Precise: options.floatingPointMode = DownstreamCompiler::FloatingPointMode::Precise; break; + case FloatingPointMode::Fast: options.floatingPointMode = DownstreamCompiler::FloatingPointMode::Fast; break; default: SLANG_ASSERT(!"Unhanlde floating point mode"); } @@ -1610,7 +1498,7 @@ SlangResult dissassembleDXILUsingDXC( { for(auto& def : preprocessorDefinitions) { - CPPCompiler::Define define; + DownstreamCompiler::Define define; define.nameWithSig = def.Key; define.value = def.Value; @@ -1620,8 +1508,10 @@ SlangResult dissassembleDXILUsingDXC( } // Compile - CPPCompiler::Output output; - SLANG_RETURN_ON_FAIL(compiler->compile(options, output)); + RefPtr<DownstreamCompileResult> downstreamCompileResult; + SLANG_RETURN_ON_FAIL(compiler->compile(options, downstreamCompileResult)); + + const auto& diagnostics = downstreamCompileResult->getDiagnostics(); { StringBuilder compilerText; @@ -1629,9 +1519,9 @@ SlangResult dissassembleDXILUsingDXC( StringBuilder builder; - typedef CPPCompiler::Diagnostic Diagnostic; + typedef DownstreamDiagnostic Diagnostic; - for (const auto& diagnostic : output.diagnostics) + for (const auto& diagnostic : diagnostics.diagnostics) { builder.Clear(); @@ -1676,63 +1566,12 @@ SlangResult dissassembleDXILUsingDXC( } // If any errors are emitted, then we are done - if (output.has(CPPCompiler::Diagnostic::Type::Error)) + if (diagnostics.has(DownstreamDiagnostic::Type::Error)) { return SLANG_FAIL; } - // If callable we need to load the shared library - if (targetReq->target == CodeGenTarget::HostCallable) - { - // Try loading the shared library - SharedLibrary::Handle handle; - if (SLANG_FAILED(SharedLibrary::loadWithPlatformPath(moduleFilePath.getBuffer(), handle))) - { - sink->diagnose(SourceLoc(), Diagnostics::unableToReadFile, moduleFilePath); - return SLANG_FAIL; - } - RefPtr<TemporarySharedLibrary> sharedLib(new TemporarySharedLibrary(handle, moduleFilePath)); - sharedLib->m_temporaryFileSet = productFileSet; - productFileSet.clear(); - - // Copy the paths in the temporary file set - // We particularly want to do this to keep the source - sharedLib->m_temporaryFileSet.add(temporaryFileSet.m_paths); - temporaryFileSet.clear(); - - // Output the shared library - outSharedLib = sharedLib; - } - else - { - // Read the binary - try - { - // TODO(JS): We have a problem here.. productFileSet will clear up all temporaries - // and although we return the binary here (through outBin), we don't return debug info - // which is separate (say with a pdb). To work around this we reevaluate productFileSet, - // so we don't include debug info. The executable will presumably be reconstructed from - // outBin - // The problem is that these files have no specific lifetime (unlike with HostCallable). - - CPPCompiler::ProductFlags flags = CPPCompiler::ProductFlag::All; - flags &= ~CPPCompiler::ProductFlag::Debug; - - List<String> paths; - SLANG_RETURN_ON_FAIL(compiler->calcCompileProducts(options, flags, paths)); - productFileSet.clear(); - productFileSet.add(paths); - - // Read the contents of the binary - outBin = File::readAllBytes(moduleFilePath); - } - catch (const Slang::IOException&) - { - sink->diagnose(SourceLoc(), Diagnostics::unableToReadFile, moduleFilePath); - return SLANG_FAIL; - } - } - + outResult = downstreamCompileResult; return SLANG_OK; } @@ -1851,26 +1690,18 @@ SlangResult dissassembleDXILUsingDXC( case CodeGenTarget::SharedLibrary: case CodeGenTarget::Executable: { - ComPtr<ISlangSharedLibrary> sharedLibrary; + RefPtr<DownstreamCompileResult> downstreamResult; - List<uint8_t> code; if (SLANG_SUCCEEDED(emitCPUBinaryForEntryPoint( compileRequest, entryPointIndex, targetReq, endToEndReq, - sharedLibrary, - code))) + downstreamResult))) { - if (target == CodeGenTarget::HostCallable) - { - result = CompileResult(sharedLibrary); - } - else - { - maybeDumpIntermediate(compileRequest, code.getBuffer(), code.getCount(), target); - result = CompileResult(code); - } + maybeDumpIntermediate(compileRequest, downstreamResult, target); + + result = CompileResult(downstreamResult); } } break; @@ -1901,11 +1732,13 @@ SlangResult dissassembleDXILUsingDXC( case CodeGenTarget::CPPSource: case CodeGenTarget::CSource: { - return emitEntryPointSource( + String code = emitEntryPointSource( compileRequest, entryPointIndex, target, targetReq); + maybeDumpIntermediate(compileRequest, code.getBuffer(), target); + result = CompileResult(code); } break; @@ -1922,7 +1755,8 @@ SlangResult dissassembleDXILUsingDXC( code))) { maybeDumpIntermediate(compileRequest, code.getBuffer(), code.getCount(), target); - result = CompileResult(code); + + result = CompileResult(ListBlob::moveCreate(code)); } } break; @@ -1958,7 +1792,7 @@ SlangResult dissassembleDXILUsingDXC( code))) { maybeDumpIntermediate(compileRequest, code.getBuffer(), code.getCount(), target); - result = CompileResult(code); + result = CompileResult(ListBlob::moveCreate(code)); } } break; @@ -1983,7 +1817,8 @@ SlangResult dissassembleDXILUsingDXC( maybeDumpIntermediate(compileRequest, assembly.getBuffer(), target); - result = CompileResult(assembly); + // Write as text, even if stored in uint8_t array + result = CompileResult(UnownedStringSlice((const char*)code.getBuffer(), code.getCount())); } } break; @@ -2001,7 +1836,7 @@ SlangResult dissassembleDXILUsingDXC( code))) { maybeDumpIntermediate(compileRequest, code.getBuffer(), code.getCount(), target); - result = CompileResult(code); + result = CompileResult(ListBlob::moveCreate(code)); } } break; @@ -2125,11 +1960,12 @@ SlangResult dissassembleDXILUsingDXC( case ResultFormat::Binary: { - auto& data = result.outputBinary; + ComPtr<ISlangBlob> blob; + result.getBlob(blob); writeOutputFile(compileRequest, outputPath, - data.begin(), - data.end() - data.begin(), + blob->getBufferPointer(), + blob->getBufferSize(), OutputFileKind::Binary); } break; @@ -2165,13 +2001,18 @@ SlangResult dissassembleDXILUsingDXC( writeOutputToConsole(writer, result.outputString); break; - case ResultFormat::SharedLibrary: - break; - case ResultFormat::Binary: { - auto& data = result.outputBinary; - + ComPtr<ISlangBlob> blob; + if (SLANG_FAILED(result.getBlob(blob))) + { + return; + } + + const void* blobData = blob->getBufferPointer(); + size_t blobSize = blob->getBufferSize(); + + if (writer->isConsole()) { // Writing to console, so we need to generate text output. @@ -2182,9 +2023,7 @@ SlangResult dissassembleDXILUsingDXC( case CodeGenTarget::DXBytecode: { String assembly; - dissassembleDXBC(backEndReq, - data.begin(), - data.end() - data.begin(), assembly); + dissassembleDXBC(backEndReq, blobData, blobSize, assembly); writeOutputToConsole(writer, assembly); } break; @@ -2194,10 +2033,7 @@ SlangResult dissassembleDXILUsingDXC( case CodeGenTarget::DXIL: { String assembly; - dissassembleDXILUsingDXC(backEndReq, - data.begin(), - data.end() - data.begin(), - assembly); + dissassembleDXILUsingDXC(backEndReq, blobData, blobSize, assembly); writeOutputToConsole(writer, assembly); } break; @@ -2206,16 +2042,15 @@ SlangResult dissassembleDXILUsingDXC( case CodeGenTarget::SPIRV: { String assembly; - dissassembleSPIRV(backEndReq, - data.begin(), - data.end() - data.begin(), assembly); + dissassembleSPIRV(backEndReq, blobData, blobSize, assembly); writeOutputToConsole(writer, assembly); } break; + case CodeGenTarget::HostCallable: case CodeGenTarget::SharedLibrary: case CodeGenTarget::Executable: - HexDumpUtil::dumpWithMarkers(data, 24, writer); + HexDumpUtil::dumpWithMarkers((const uint8_t*)blobData, blobSize, 24, writer); break; default: @@ -2232,8 +2067,8 @@ SlangResult dissassembleDXILUsingDXC( backEndReq, writer, "stdout", - data.begin(), - data.end() - data.begin()); + blobData, + blobSize); } } break; @@ -2627,6 +2462,21 @@ SlangResult dissassembleDXILUsingDXC( void maybeDumpIntermediate( BackEndCompileRequest* compileRequest, + DownstreamCompileResult* compileResult, + CodeGenTarget target) + { + if (!compileRequest->shouldDumpIntermediates) + return; + + ComPtr<ISlangBlob> blob; + if (SLANG_SUCCEEDED(compileResult->getBinary(blob))) + { + maybeDumpIntermediate(compileRequest, blob->getBufferPointer(), blob->getBufferSize(), target); + } + } + + void maybeDumpIntermediate( + BackEndCompileRequest* compileRequest, void const* data, size_t size, CodeGenTarget target) 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<uint8_t> 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<ISlangBlob>& outBlob); + SlangResult getBlob(ComPtr<ISlangBlob>& outBlob) const; SlangResult getSharedLibrary(ComPtr<ISlangSharedLibrary>& outSharedLibrary); ResultFormat format = ResultFormat::None; - String outputString; - List<uint8_t> outputBinary; + String outputString; ///< Only set if result type is ResultFormat::Text + + mutable ComPtr<ISlangBlob> blob; - ComPtr<ISlangSharedLibrary> sharedLibrary; - ComPtr<ISlangBlob> blob; + RefPtr<DownstreamCompileResult> downstreamResult; }; /// Information collected about global or entry-point shader parameters @@ -1073,15 +1071,10 @@ namespace Slang List<SearchDirectory> searchDirectories; }; - /// Create a blob that will retain (a copy of) raw data. - /// - ComPtr<ISlangBlob> 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<Type> stringType; RefPtr<Type> enumTypeType; - RefPtr<CPPCompilerSet> cppCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow) + RefPtr<DownstreamCompilerSet> cppCompilerSet; ///< Information about available C/C++ compilers. null unless information is requested (because slow) ComPtr<ISlangSharedLibraryLoader> sharedLibraryLoader; ///< The shared library loader (never null) ComPtr<ISlangSharedLibrary> 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<EndToEndCompileRequest*>(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<uint8_t> m_data; -protected: - ISlangUnknown* getInterface(const Guid& guid); -}; } diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 710c1731f..755a005d1 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -583,7 +583,7 @@ String emitEntryPointSource( { const SourceLanguage sourceLanguage = (sourceStyle == SourceStyle::C) ? SourceLanguage::C : SourceLanguage::CPP; // Get the compiler used for the language - CPPCompiler* compiler = session->getDefaultCPPCompiler(sourceLanguage); + DownstreamCompiler* compiler = session->getDefaultCPPCompiler(sourceLanguage); if (compiler) { passThru = getPassThroughModeForCPPCompiler(compiler->getDesc().type); diff --git a/source/slang/slang-file-system.h b/source/slang/slang-file-system.h index 3d2bfe3c1..199cafe24 100644 --- a/source/slang/slang-file-system.h +++ b/source/slang/slang-file-system.h @@ -5,6 +5,8 @@ #include "../../slang-com-helper.h" #include "../../slang-com-ptr.h" +#include "../core/slang-blob.h" + #include "../core/slang-string-util.h" #include "../core/slang-dictionary.h" diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index 339ace54f..faf748098 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -278,23 +278,23 @@ SlangPassThrough SLANG_MCALL Session::getDefaultDownstreamCompiler(SlangSourceLa return SlangPassThrough(m_defaultDownstreamCompilers[int(sourceLanguage)]); } -CPPCompiler* Session::getCPPCompiler(PassThroughMode compiler) +DownstreamCompiler* Session::getDownstreamCompiler(PassThroughMode compiler) { - CPPCompilerSet* compilerSet = requireCPPCompilerSet(); + DownstreamCompilerSet* compilerSet = requireCPPCompilerSet(); switch (compiler) { case PassThroughMode::GenericCCpp: return compilerSet->getDefaultCompiler(); - case PassThroughMode::Clang: return CPPCompilerUtil::findCompiler(compilerSet, CPPCompilerUtil::MatchType::Newest, CPPCompiler::Desc(CPPCompiler::CompilerType::Clang)); - case PassThroughMode::VisualStudio: return CPPCompilerUtil::findCompiler(compilerSet, CPPCompilerUtil::MatchType::Newest, CPPCompiler::Desc(CPPCompiler::CompilerType::VisualStudio)); - case PassThroughMode::Gcc: return CPPCompilerUtil::findCompiler(compilerSet, CPPCompilerUtil::MatchType::Newest, CPPCompiler::Desc(CPPCompiler::CompilerType::GCC)); + case PassThroughMode::Clang: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::Clang)); + case PassThroughMode::VisualStudio: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::VisualStudio)); + case PassThroughMode::Gcc: return DownstreamCompilerUtil::findCompiler(compilerSet, DownstreamCompilerUtil::MatchType::Newest, DownstreamCompiler::Desc(DownstreamCompiler::CompilerType::GCC)); default: break; } return nullptr; } -CPPCompiler* Session::getDefaultCPPCompiler(SourceLanguage sourceLanguage) +DownstreamCompiler* Session::getDefaultCPPCompiler(SourceLanguage sourceLanguage) { - return getCPPCompiler(m_defaultDownstreamCompilers[int(sourceLanguage)]); + return getDownstreamCompiler(m_defaultDownstreamCompilers[int(sourceLanguage)]); } ISlangFileSystemExt* IncludeHandlerImpl::_getFileSystemExt() @@ -689,56 +689,7 @@ SlangResult Linkage::setMatrixLayoutMode( return SLANG_OK; } -/** Base class for simple blobs. -*/ -class BlobBase : public ISlangBlob, public RefObject -{ -public: - // ISlangUnknown - SLANG_REF_OBJECT_IUNKNOWN_ALL - -protected: - SLANG_FORCE_INLINE ISlangUnknown* getInterface(const Guid& guid) - { - return (guid == IID_ISlangUnknown || guid == IID_ISlangBlob) ? static_cast<ISlangBlob*>(this) : nullptr; - } -}; -/** A blob that manages some raw data that it owns. -*/ -class RawBlob : public BlobBase -{ -public: - // ISlangBlob - SLANG_NO_THROW void const* SLANG_MCALL getBufferPointer() SLANG_OVERRIDE { return m_data; } - SLANG_NO_THROW size_t SLANG_MCALL getBufferSize() SLANG_OVERRIDE { return m_size; } - - // Ctor - RawBlob(const void* data, size_t size): - m_size(size) - { - m_data = malloc(size); - memcpy(m_data, data, size); - } - ~RawBlob() - { - free(m_data); - } - -protected: - void* m_data; - size_t m_size; -}; - -ComPtr<ISlangBlob> createRawBlob(void const* inData, size_t size) -{ - return ComPtr<ISlangBlob>(new RawBlob(inData, size)); -} - -ISlangUnknown* ListBlob::getInterface(const Guid& guid) -{ - return (guid == IID_ISlangUnknown || guid == IID_ISlangBlob) ? static_cast<ISlangBlob*>(this) : nullptr; -} // // TargetRequest // @@ -3387,24 +3338,18 @@ SLANG_API void const* spGetEntryPointCode( void const* data = nullptr; size_t size = 0; - switch (result.format) + ComPtr<ISlangBlob> blob; + if (SLANG_SUCCEEDED(result.getBlob(blob))) { - case ResultFormat::None: - default: - break; - - case ResultFormat::Binary: - data = result.outputBinary.getBuffer(); - size = result.outputBinary.getCount(); - break; + data = blob->getBufferPointer(); + size = blob->getBufferSize(); + } - case ResultFormat::Text: - data = result.outputString.getBuffer(); - size = result.outputString.getLength(); - break; + if (outSize) + { + *outSize = size; } - if(outSize) *outSize = size; return data; } diff --git a/source/slang/slang.vcxproj b/source/slang/slang.vcxproj index a9c7f4558..8c8a712ce 100644 --- a/source/slang/slang.vcxproj +++ b/source/slang/slang.vcxproj @@ -373,4 +373,4 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project>
\ No newline at end of file +</Project>
\ No newline at end of file |
