From 34a1ff5226a526cc17c5baecd63637f69c324fc7 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Sat, 22 May 2021 16:03:30 -0400 Subject: Improvements in -X support (#1852) * #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. * Make render test use x-args parsing and CommandArgReader. * Added missing diagnostics. * More DownstreamArgs to linkage so can be seen by 'components'. Added dxc-x-arg test. * Used combination of name and args instead of two Lists, which whilst equivalent was perhaps a little confusing. * Added documentation for -X support. * Added test for x-args parsing diagnostic. Improved diagnostic with list of known names. * Fix issues from merge. * Fix lookup for -matrix-layout-column-major in render test. * Remove commented out line. --- source/compiler-core/slang-command-line-args.cpp | 44 ++++++++++++++++++------ 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'source/compiler-core/slang-command-line-args.cpp') diff --git a/source/compiler-core/slang-command-line-args.cpp b/source/compiler-core/slang-command-line-args.cpp index 1d452bb10..d7a053b00 100644 --- a/source/compiler-core/slang-command-line-args.cpp +++ b/source/compiler-core/slang-command-line-args.cpp @@ -63,7 +63,6 @@ bool CommandLineArgs::hasArgs(const char*const* args, Index count) const return true; } - /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CommandLineReader @@ -121,14 +120,11 @@ SlangResult CommandLineReader::expectArg(CommandLineArg& outArg) Index DownstreamArgs::addName(const String& name) { - Index index = m_names.indexOf(name); + Index index = findName(name); if (index < 0) { - index = m_names.getCount(); - m_names.add(name); - - CommandLineArgs args(m_context); - m_args.add(args); + index = m_entries.getCount(); + m_entries.add(Entry{name, CommandLineArgs(m_context) }); } return index; } @@ -137,7 +133,10 @@ Index DownstreamArgs::_findOrAddName(SourceLoc loc, const UnownedStringSlice& na { if (name.getLength() <= 0) { - sink->diagnose(loc, MiscDiagnostics::downstreamToolNameNotDefined); + if (sink) + { + sink->diagnose(loc, MiscDiagnostics::downstreamToolNameNotDefined); + } return -1; } @@ -152,15 +151,38 @@ Index DownstreamArgs::_findOrAddName(SourceLoc loc, const UnownedStringSlice& na return index; } - sink->diagnose(loc, MiscDiagnostics::downstreamNameNotKnown); + if (sink) + { + StringBuilder names; + + names << "[ "; + for (Index i = 0; i < m_entries.getCount(); ++i) + { + if (i) + { + names << ", "; + } + names << m_entries[i].name; + } + names << " ]"; + + sink->diagnose(loc, MiscDiagnostics::downstreamNameNotKnown, names); + } return -1; } CommandLineArgs& DownstreamArgs::getArgsByName(char* name) { - Index index = findName(name); + const Index index = findName(name); + SLANG_ASSERT(index >= 0); + return m_entries[index].args; +} + +const CommandLineArgs& DownstreamArgs::getArgsByName(char* name) const +{ + const Index index = findName(name); SLANG_ASSERT(index >= 0); - return m_args[index]; + return m_entries[index].args; } SlangResult DownstreamArgs::stripDownstreamArgs(CommandLineArgs& ioArgs, Flags flags, DiagnosticSink* sink) -- cgit v1.2.3