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/compiler-core/slang-command-line-args.h | |
| 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/compiler-core/slang-command-line-args.h')
| -rw-r--r-- | source/compiler-core/slang-command-line-args.h | 88 |
1 files changed, 80 insertions, 8 deletions
diff --git a/source/compiler-core/slang-command-line-args.h b/source/compiler-core/slang-command-line-args.h index 6dea7408c..7500c1a91 100644 --- a/source/compiler-core/slang-command-line-args.h +++ b/source/compiler-core/slang-command-line-args.h @@ -17,6 +17,23 @@ struct CommandLineArg SourceLoc loc; ///< The location of the arg }; +class CommandLineContext : public RefObject +{ +public: + /// Get the source manager + SourceManager* getSourceManager() { return &m_sourceManager; } + + CommandLineContext(ISlangFileSystemExt* fileSystemExt = nullptr) + { + m_sourceManager.initialize(nullptr, fileSystemExt); + // Make range start from high value, so can be differentiated from other uses + m_sourceManager.allocateSourceRange(~(~SourceLoc::RawValue(0) >> 1)); + } + +protected: + SourceManager m_sourceManager; +}; + struct CommandLineArgs { typedef CommandLineArg Arg; @@ -30,18 +47,23 @@ struct CommandLineArgs /// NOTE! Should NOT include the executable name void setArgs(const char*const* args, size_t argCount); - /// Ctor with a source manager - CommandLineArgs(SourceManager* manager): - m_sourceManager(manager), - m_sourceView(nullptr) + /// True if has args in same order + bool hasArgs(const char*const* args, Index count) const; + + /// Add an arg + void add(const Arg& arg) { m_args.add(arg); } + + /// Ctor with a context + CommandLineArgs(CommandLineContext* context): + m_context(context) { } + /// Default Ctor + CommandLineArgs() {} - String m_executablePath; ///< Can be optionally be set - + //String m_executablePath; ///< Can be optionally be set List<Arg> m_args; ///< The args - SourceManager* m_sourceManager; ///< The source manager and associated diagnostics sink - SourceView* m_sourceView; ///< contains the command line as source + RefPtr<CommandLineContext> m_context; ///< The context, which mainly has source manager }; struct CommandLineReader @@ -77,6 +99,11 @@ struct CommandLineReader SlangResult expectArg(String& outArg); SlangResult expectArg(CommandLineArg& outArg); + /// Get the current index + Index getIndex() const { return m_index; } + /// Set the current index + void setIndex(Index index) { SLANG_ASSERT(index >= 0 && index <= m_args->getArgCount()); m_index = index; } + /// Set up reader with args CommandLineReader(CommandLineArgs* args, DiagnosticSink* sink): m_args(args), @@ -90,6 +117,51 @@ struct CommandLineReader Index m_index; }; +struct DownstreamArgs +{ + typedef uint32_t Flags; + struct Flag + { + enum Enum : Flags + { + AllowNewNames = 0x01, + }; + }; + + /// 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); } + + /// Get the args at the nameIndex + CommandLineArgs& getArgsAt(Index nameIndex) { return m_args[nameIndex]; } + /// Get args by name - will assert if name isn't found + CommandLineArgs& getArgsByName(char* name); + + /// Looks for '-X' expressions, removing them from ioArgs and putting in appropriate args + SlangResult stripDownstreamArgs(CommandLineArgs& ioArgs, Flags flags, DiagnosticSink* sink); + + /// Get the context used + CommandLineContext* getContext() const { return m_context; } + + /// Ctor + DownstreamArgs(CommandLineContext* context): + m_context(context) + { + } + /// Default ctor - for convenience, should really use with context normally + DownstreamArgs() {} + +protected: + Index _findOrAddName(SourceLoc loc, const UnownedStringSlice& name, Flags flags, DiagnosticSink* sink); + + List<String> m_names; + List<CommandLineArgs> m_args; + + RefPtr<CommandLineContext> m_context; +}; + + } // namespace Slang #endif |
