summaryrefslogtreecommitdiff
path: root/source/compiler-core/slang-command-line-args.h
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-05-22 16:03:30 -0400
committerGitHub <noreply@github.com>2021-05-22 16:03:30 -0400
commit34a1ff5226a526cc17c5baecd63637f69c324fc7 (patch)
tree3bbaf2a2812bc121210d0b1142a303e6aab01a68 /source/compiler-core/slang-command-line-args.h
parent7f8a9994d0bd99a171a1daa0bce46d92c02ccffd (diff)
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.
Diffstat (limited to 'source/compiler-core/slang-command-line-args.h')
-rw-r--r--source/compiler-core/slang-command-line-args.h21
1 files changed, 16 insertions, 5 deletions
diff --git a/source/compiler-core/slang-command-line-args.h b/source/compiler-core/slang-command-line-args.h
index 7500c1a91..c18996005 100644
--- a/source/compiler-core/slang-command-line-args.h
+++ b/source/compiler-core/slang-command-line-args.h
@@ -17,6 +17,9 @@ struct CommandLineArg
SourceLoc loc; ///< The location of the arg
};
+/* This type ends up being really just a container for the sourceManager that has the CommandLine specific SourceLocs.
+That it would perhaps be better to just have SourceManager derive from RefObject, and then we could remove this
+type. */
class CommandLineContext : public RefObject
{
public:
@@ -27,6 +30,8 @@ public:
{
m_sourceManager.initialize(nullptr, fileSystemExt);
// Make range start from high value, so can be differentiated from other uses
+ // That this doesn't not assume exclusive use of this range - just that in normal use scenarios
+ // there is no confusion, and using the wrong source manager, will typically report nothing is found.
m_sourceManager.allocateSourceRange(~(~SourceLoc::RawValue(0) >> 1));
}
@@ -128,15 +133,22 @@ struct DownstreamArgs
};
};
+ struct Entry
+ {
+ String name; ///< The name of the 'tool' that these args are associated with
+ CommandLineArgs args; ///< The args to be passed to the tool
+ };
+
/// Add a name, returns the index
Index addName(const String& name);
/// Find the index of a name. Returns < 0 if not found.
- Index findName(const String& name) const { return m_names.indexOf(name); }
+ Index findName(const String& name) const { return m_entries.findFirstIndex([&](const Entry& entry) -> bool { return entry.name == name; }); }
/// Get the args at the nameIndex
- CommandLineArgs& getArgsAt(Index nameIndex) { return m_args[nameIndex]; }
+ CommandLineArgs& getArgsAt(Index nameIndex) { return m_entries[nameIndex].args; }
/// Get args by name - will assert if name isn't found
CommandLineArgs& getArgsByName(char* name);
+ const CommandLineArgs& getArgsByName(char* name) const;
/// Looks for '-X' expressions, removing them from ioArgs and putting in appropriate args
SlangResult stripDownstreamArgs(CommandLineArgs& ioArgs, Flags flags, DiagnosticSink* sink);
@@ -155,10 +167,9 @@ struct DownstreamArgs
protected:
Index _findOrAddName(SourceLoc loc, const UnownedStringSlice& name, Flags flags, DiagnosticSink* sink);
- List<String> m_names;
- List<CommandLineArgs> m_args;
+ List<Entry> m_entries; ///< All of the entries
- RefPtr<CommandLineContext> m_context;
+ RefPtr<CommandLineContext> m_context; ///< The context that is being used (primarily for loc tracking) across all entries/args
};