diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2021-05-21 18:41:54 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-21 15:41:54 -0700 |
| commit | 172538fdb418f7a2faab1f5a410f3b2cb8e18ba5 (patch) | |
| tree | b17fd1cae7ace4bb3f2dbdd4ad29f4f57df0b286 /source/slang | |
| parent | 0389546b0b065303d3c6874891a9fab4428910b9 (diff) | |
Downstream option handling (#1850)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Added SourceLoc handling for command line parsing.
* Fix typo in debug.
* Fix issue around the DiagnosticSink used in options parsing not having a writer available - by having DiagnosticSink parenting.
* Small rename for clarity.
* WIP extracting command line args for downstream tools.
* Unit tests/bug fixes around extracting args.
* Use DownstreamArgs in the EndToEndCompileRequest
* Passing downstream compiler options downstream.
* Fix issue with endToEndReq being nullptr.
* Fix issue with diagnostics number change.
* Small improvements to how the source line is displayed if it's too long.
Default to 120, as suggested in previous review.
Co-authored-by: T. Foley <tfoleyNV@users.noreply.github.com>
Diffstat (limited to 'source/slang')
| -rwxr-xr-x | source/slang/slang-compiler.cpp | 17 | ||||
| -rwxr-xr-x | source/slang/slang-compiler.h | 5 | ||||
| -rw-r--r-- | source/slang/slang-options.cpp | 18 | ||||
| -rw-r--r-- | source/slang/slang.cpp | 17 |
4 files changed, 47 insertions, 10 deletions
diff --git a/source/slang/slang-compiler.cpp b/source/slang/slang-compiler.cpp index 3850615b4..31ead4cc3 100755 --- a/source/slang/slang-compiler.cpp +++ b/source/slang/slang-compiler.cpp @@ -964,6 +964,23 @@ namespace Slang typedef DownstreamCompiler::CompileOptions CompileOptions; CompileOptions options; + /* Let's set the compiler specific options + + We can only do this if the endToEndReq is set. */ + if (endToEndReq) + { + auto name = TypeTextUtil::getPassThroughName((SlangPassThrough)downstreamCompiler); + const Index nameIndex = endToEndReq->m_downstreamArgs.findName(name); + if (nameIndex >= 0) + { + auto& args = endToEndReq->m_downstreamArgs.getArgsAt(nameIndex); + for (const auto& arg : args.m_args) + { + options.compilerSpecificArguments.add(arg.value); + } + } + } + /* 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 */ diff --git a/source/slang/slang-compiler.h b/source/slang/slang-compiler.h index 08eb93b41..54c61bd75 100755 --- a/source/slang/slang-compiler.h +++ b/source/slang/slang-compiler.h @@ -9,6 +9,7 @@ #include "../compiler-core/slang-downstream-compiler.h" #include "../compiler-core/slang-name.h" #include "../compiler-core/slang-include-system.h" +#include "../compiler-core/slang-command-line-args.h" #include "../core/slang-std-writers.h" @@ -22,7 +23,6 @@ #include "slang-syntax.h" - #include "slang-serialize-ir-types.h" #include "../../slang.h" @@ -2022,6 +2022,9 @@ namespace Slang }; Dictionary<TargetRequest*, RefPtr<TargetInfo>> m_targetInfos; + /// Holds any args that are destined for downstream compilers/tools etc + DownstreamArgs m_downstreamArgs; + /// Writes the modules in a container to the stream SlangResult writeContainerToStream(Stream* stream); diff --git a/source/slang/slang-options.cpp b/source/slang/slang-options.cpp index 4566bf5ec..f4cd2e4ef 100644 --- a/source/slang/slang-options.cpp +++ b/source/slang/slang-options.cpp @@ -410,13 +410,8 @@ struct OptionsParser DiagnosticSink* requestSink = requestImpl->getSink(); - SourceManager* parentSourceManager = requestSink->getSourceManager(); - - // We need a new source manager to track our command line 'source' - - SourceManager sourceManager; - sourceManager.initialize(parentSourceManager, parentSourceManager->getFileSystemExt()); - + CommandLineContext* cmdLineContext = requestImpl->m_downstreamArgs.getContext(); + // Why create a new DiagnosticSink? // We *don't* want the lexer that comes as default (it's for Slang source!) // We may want to set flags that are different @@ -432,7 +427,7 @@ struct OptionsParser // // The solution used here is to have DiagnosticsSink have a 'parent' that also gets diagnostics reported to. - DiagnosticSink parseSink(&sourceManager, nullptr); + DiagnosticSink parseSink(cmdLineContext->getSourceManager(), nullptr); { parseSink.setFlags(requestSink->getFlags()); @@ -451,9 +446,14 @@ struct OptionsParser DiagnosticSink* sink = &parseSink; // Set up the args - CommandLineArgs args(&sourceManager); + CommandLineArgs args(cmdLineContext); + // Converts input args into args in 'args'. + // Doing so will allocate some SourceLoc space from the CommandLineContext. args.setArgs(argv, argc); + // Before we do anything else lets strip out all of the downstream arguments. + SLANG_RETURN_ON_FAIL(requestImpl->m_downstreamArgs.stripDownstreamArgs(args, 0, sink)); + CommandLineReader reader(&args, sink); SlangMatrixLayoutMode defaultMatrixLayoutMode = SLANG_MATRIX_LAYOUT_MODE_UNKNOWN; diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index d16770a1d..8479a0e99 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -4,6 +4,7 @@ #include "../core/slang-string-util.h" #include "../core/slang-shared-library.h" #include "../core/slang-archive-file-system.h" +#include "../core/slang-type-text-util.h" #include "slang-check.h" #include "slang-parameter-binding.h" @@ -2029,6 +2030,22 @@ void EndToEndCompileRequest::init() m_frontEndReq = new FrontEndCompileRequest(getLinkage(), m_writers, getSink()); m_backEndReq = new BackEndCompileRequest(getLinkage(), getSink()); + + RefPtr<CommandLineContext> context = new CommandLineContext; + m_downstreamArgs = DownstreamArgs(context); + + // Add all of the possible names we allow for downstream tools + { + for (Index i = SLANG_PASS_THROUGH_NONE + 1; i < SLANG_PASS_THROUGH_COUNT_OF; ++i) + { + m_downstreamArgs.addName(TypeTextUtil::getPassThroughName(SlangPassThrough(i))); + } + + // Generic downstream tool + m_downstreamArgs.addName("downstream"); + // Generic downstream linker + m_downstreamArgs.addName("linker"); + } } SlangResult EndToEndCompileRequest::executeActionsInner() |
