From a2d4d447639a1860f9de4ba9e2435f1d40ff3669 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Thu, 12 Dec 2019 16:14:27 -0500 Subject: Feature/source downstream compiler (#1153) * 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. * WIP support for nvrtc. * WIP: Adding support for nvrtc compiler. Adding enum types, wiring up the nvrtc into slang. * Fix remaining CPPCompiler references. * Fix order issue on target string matching. * Use ISlangSharedLibrary for nvrtc. * Use DownstreamCompiler for nvrtc. * WIP first pass at compilation win nvrtc. * Added testing if file is on file system into CommandLineDownstreamCompiler. Added sourceContentsPath. * Make test cuda-compile.cu work by just compiling not comparing output. * Genearlize DownstreamCompiler usage. * Fix warning on clang. * Remove CompilerType from DownstreamCompiler. * Use DownstreamCompiler interface for all compilers. NOTE for FXC, DXC and GLSLANG this doesn't mean using 'compile' - it's still extracting functions from shared library. * Replace DownstreamCompiler::SourceType -> SlangSourceLanguage * Replace _canCompile with something data driven. * Fix compiling on gcc/clang for DownstreamCompiler. * Moved some text conversions into DownstreamCompiler. * Fix problem on non-vc builds with not having return on locateCompilers for VS. * Change so no warning for code not reachable on locateCompilers for vs. --- tools/render-test/options.cpp | 33 ++---------------------- tools/slang-test/slang-test-main.cpp | 50 +++++------------------------------- tools/slang-test/test-context.cpp | 4 +-- tools/slang-test/test-context.h | 2 +- 4 files changed, 11 insertions(+), 78 deletions(-) (limited to 'tools') diff --git a/tools/render-test/options.cpp b/tools/render-test/options.cpp index 7d3fd27b5..a614336e7 100644 --- a/tools/render-test/options.cpp +++ b/tools/render-test/options.cpp @@ -11,6 +11,7 @@ #include "../../source/core/slang-list.h" #include "../../source/core/slang-string-util.h" +#include "../../source/core/slang-downstream-compiler.h" namespace renderer_test { using namespace Slang; @@ -44,36 +45,6 @@ static SlangResult _setRendererType(RendererType type, const char* arg, Slang::W return SLANG_OK; } -static SlangSourceLanguage _findSourceLanguage(const UnownedStringSlice& text) -{ - if (text == "c" || text == "C") - { - return SLANG_SOURCE_LANGUAGE_C; - } - else if (text == "cpp" || text == "c++" || text == "C++" || text == "cxx") - { - return SLANG_SOURCE_LANGUAGE_CPP; - } - else if (text == "slang") - { - return SLANG_SOURCE_LANGUAGE_SLANG; - } - else if (text == "glsl") - { - return SLANG_SOURCE_LANGUAGE_GLSL; - } - else if (text == "hlsl") - { - return SLANG_SOURCE_LANGUAGE_HLSL; - } - else if (text == "cu" || text == "cuda") - { - return SLANG_SOURCE_LANGUAGE_CUDA; - } - return SLANG_SOURCE_LANGUAGE_UNKNOWN; -} - - SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper stdError) { using namespace Slang; @@ -250,7 +221,7 @@ SlangResult parseOptions(int argc, const char*const* argv, Slang::WriterHelper s } UnownedStringSlice sourceLanguageText(*argCursor++); - SlangSourceLanguage sourceLanguage = _findSourceLanguage(sourceLanguageText); + SlangSourceLanguage sourceLanguage = DownstreamCompiler::getSourceLanguageFromName(sourceLanguageText); if (sourceLanguage == SLANG_SOURCE_LANGUAGE_UNKNOWN) { stdError.print("error: expecting unknown source language name '%s' for '%s'\n", String(sourceLanguageText).getBuffer(), arg); diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index 44cc73b4e..cdfe6a1a7 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -495,44 +495,6 @@ static bool _hasOption(const List& args, const String& argName) return args.indexOf(argName) != Index(-1); } -static SlangPassThrough _toPassThroughType(const UnownedStringSlice& slice) -{ - if (slice == "dxc") - { - return SLANG_PASS_THROUGH_DXC; - } - else if (slice == "fxc") - { - return SLANG_PASS_THROUGH_FXC; - } - else if (slice == "glslang") - { - return SLANG_PASS_THROUGH_GLSLANG; - } - else if (slice == "c" || slice == "cpp") - { - return SLANG_PASS_THROUGH_GENERIC_C_CPP; - } - else if (slice == "clang") - { - return SLANG_PASS_THROUGH_CLANG; - } - else if (slice == "gcc") - { - return SLANG_PASS_THROUGH_GCC; - } - else if (slice == "vs" || slice == "visualstudio") - { - return SLANG_PASS_THROUGH_VISUAL_STUDIO; - } - else if (slice == "nvrtc") - { - return SLANG_PASS_THROUGH_NVRTC; - } - - return SLANG_PASS_THROUGH_NONE; -} - static PassThroughFlags _getPassThroughFlagsForTarget(SlangCompileTarget target) { switch (target) @@ -740,7 +702,7 @@ static SlangResult _extractSlangCTestRequirements(const CommandLine& cmdLine, Te String passThrough; if (SLANG_SUCCEEDED(_extractArg(cmdLine, "-pass-through", passThrough))) { - ioRequirements->addUsedBackEnd(_toPassThroughType(passThrough.getUnownedSlice())); + ioRequirements->addUsedBackEnd(DownstreamCompiler::getPassThroughFromName(passThrough.getUnownedSlice())); } } @@ -1293,7 +1255,7 @@ static String _calcModulePath(const TestInput& input) static TestResult runCPPCompilerCompile(TestContext* context, TestInput& input) { - DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP); + DownstreamCompiler* compiler = context->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP); if (!compiler) { return TestResult::Ignored; @@ -1335,7 +1297,7 @@ static TestResult runCPPCompilerCompile(TestContext* context, TestInput& input) static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& input) { - DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP); + DownstreamCompiler* compiler = context->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP); if (!compiler) { return TestResult::Ignored; @@ -1365,7 +1327,7 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i // Set up the compilation options DownstreamCompiler::CompileOptions options; - options.sourceType = (ext == "c") ? DownstreamCompiler::SourceType::C : DownstreamCompiler::SourceType::CPP; + options.sourceLanguage = (ext == "c") ? SLANG_SOURCE_LANGUAGE_C : SLANG_SOURCE_LANGUAGE_CPP; // Build a shared library options.targetType = DownstreamCompiler::TargetType::SharedLibrary; @@ -1453,7 +1415,7 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input) { - DownstreamCompiler* compiler = context->getDefaultCompiler(DownstreamCompiler::SourceType::CPP); + DownstreamCompiler* compiler = context->getDefaultCompiler(SLANG_SOURCE_LANGUAGE_CPP); if (!compiler) { return TestResult::Ignored; @@ -1487,7 +1449,7 @@ static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input) // Set up the compilation options DownstreamCompiler::CompileOptions options; - options.sourceType = (ext == "c") ? DownstreamCompiler::SourceType::C : DownstreamCompiler::SourceType::CPP; + options.sourceLanguage = (ext == "c") ? SLANG_SOURCE_LANGUAGE_C : SLANG_SOURCE_LANGUAGE_CPP; // Compile this source options.sourceFiles.add(filePath); diff --git a/tools/slang-test/test-context.cpp b/tools/slang-test/test-context.cpp index ee5629900..0a0931596 100644 --- a/tools/slang-test/test-context.cpp +++ b/tools/slang-test/test-context.cpp @@ -104,9 +104,9 @@ DownstreamCompilerSet* TestContext::getCompilerSet() return compilerSet; } -Slang::DownstreamCompiler* TestContext::getDefaultCompiler(DownstreamCompiler::SourceType sourceType) +Slang::DownstreamCompiler* TestContext::getDefaultCompiler(SlangSourceLanguage sourceLanguage) { DownstreamCompilerSet* set = getCompilerSet(); - return set ? set->getDefaultCompiler(sourceType) : nullptr; + return set ? set->getDefaultCompiler(sourceLanguage) : nullptr; } diff --git a/tools/slang-test/test-context.h b/tools/slang-test/test-context.h index 520e0bf1d..e10b8d60b 100644 --- a/tools/slang-test/test-context.h +++ b/tools/slang-test/test-context.h @@ -97,7 +97,7 @@ class TestContext /// Get compiler set Slang::DownstreamCompilerSet* getCompilerSet(); - Slang::DownstreamCompiler* getDefaultCompiler(Slang::DownstreamCompiler::SourceType sourceType); + Slang::DownstreamCompiler* getDefaultCompiler(SlangSourceLanguage sourceLanguage); /// Ctor TestContext(); -- cgit v1.2.3