From 4d20fd329956ac89408b1628a8291fea01bc9a6d Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 20 Feb 2024 12:24:00 -0800 Subject: Refactor compiler option representations. (#3598) * Refactor compiler option representation. * Fix binary compatibility. * Add a test for specifying compiler options at link time. * Fix binary compatibility. * Fix binary compatibility. * Fix backward compatibility on matrix layout. * Fix. * Fix. * Fix. * Fix gfx. * Fix gfx. * Fix dynamic dispatch. * Polish. --- source/compiler-core/slang-command-line-args.cpp | 42 +++++++++++++++++++++++- source/compiler-core/slang-command-line-args.h | 13 ++++---- 2 files changed, 48 insertions(+), 7 deletions(-) (limited to 'source/compiler-core') diff --git a/source/compiler-core/slang-command-line-args.cpp b/source/compiler-core/slang-command-line-args.cpp index 813d2dd26..b69836030 100644 --- a/source/compiler-core/slang-command-line-args.cpp +++ b/source/compiler-core/slang-command-line-args.cpp @@ -2,7 +2,8 @@ #include "../core/slang-process-util.h" #include "../core/slang-string-escape-util.h" - +#include "../core/slang-string-util.h" +#include "../core/slang-type-text-util.h" #include "slang-core-diagnostics.h" namespace Slang { @@ -63,6 +64,27 @@ bool CommandLineArgs::hasArgs(const char*const* args, Index count) const return true; } +String CommandLineArgs::serialize() +{ + StringBuilder sb; + for (auto& arg : m_args) + sb << arg.value << "\n"; + return sb.produceString(); +} + +void CommandLineArgs::deserialize(String content) +{ + List slices; + StringUtil::split(content.getUnownedSlice(), '\n', slices); + for (auto arg : slices) + { + Arg v; + v.value = arg; + v.loc = SourceLoc(); + m_args.add(v); + } +} + /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CommandLineReader @@ -118,6 +140,24 @@ SlangResult CommandLineReader::expectArg(CommandLineArg& outArg) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ +DownstreamArgs::DownstreamArgs(CommandLineContext* context) + : m_context(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) + { + addName(TypeTextUtil::getPassThroughName(SlangPassThrough(i))); + } + + // Generic downstream tool + addName("downstream"); + // Generic downstream linker + addName("linker"); + } +} + + Index DownstreamArgs::addName(const String& name) { Index index = findName(name); diff --git a/source/compiler-core/slang-command-line-args.h b/source/compiler-core/slang-command-line-args.h index b2bd48c61..0c11a3c46 100644 --- a/source/compiler-core/slang-command-line-args.h +++ b/source/compiler-core/slang-command-line-args.h @@ -69,6 +69,9 @@ struct CommandLineArgs //String m_executablePath; ///< Can be optionally be set List m_args; ///< The args RefPtr m_context; ///< The context, which mainly has source manager + + String serialize(); + void deserialize(String content); }; struct CommandLineReader @@ -155,18 +158,16 @@ struct DownstreamArgs CommandLineContext* getContext() const { return m_context; } /// Ctor - DownstreamArgs(CommandLineContext* context): - m_context(context) - { - } + DownstreamArgs(CommandLineContext* context); + /// Default ctor - for convenience, should really use with context normally DownstreamArgs() {} + List m_entries; ///< All of the entries + protected: Index _findOrAddName(SourceLoc loc, const UnownedStringSlice& name, Flags flags, DiagnosticSink* sink); - List m_entries; ///< All of the entries - RefPtr m_context; ///< The context that is being used (primarily for loc tracking) across all entries/args }; -- cgit v1.2.3