From e616dc551fdcb3e8abb38ab2ed8e275ee37f1c10 Mon Sep 17 00:00:00 2001 From: Eyal Rozenberg Date: Mon, 9 Oct 2023 14:52:58 +0300 Subject: [PATCH] WIP --- src/cuda/rtc/compilation_options.hpp | 26 ------------- src/cuda/rtc/detail/marshalled_options.hpp | 44 +++++++++++++++++++--- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/cuda/rtc/compilation_options.hpp b/src/cuda/rtc/compilation_options.hpp index bdf21576..346dde81 100644 --- a/src/cuda/rtc/compilation_options.hpp +++ b/src/cuda/rtc/compilation_options.hpp @@ -471,32 +471,6 @@ class compilation_options_t final : }; -namespace detail_ { - -inline const char* true_or_false(bool b) { return b ? "true" : "false"; } - -template -struct opt_start_t { - bool ever_used; - Delimiter delimiter_; - - opt_start_t(Delimiter delimiter) : ever_used(false), delimiter_(delimiter){ } -}; - -} // namespace detail_ - -template -MarshalTarget& operator<<(MarshalTarget& mt, detail_::opt_start_t& opt_start) -{ - if (not opt_start.ever_used) { - opt_start.ever_used = true; - } - else { - mt << opt_start.delimiter_; - } - return mt; -} - /** * Use the left-shift operator (<<) to render a delimited sequence of * command-line-argument-like options (with or without a value as relevant) diff --git a/src/cuda/rtc/detail/marshalled_options.hpp b/src/cuda/rtc/detail/marshalled_options.hpp index 6c491f6d..18e0a3f9 100644 --- a/src/cuda/rtc/detail/marshalled_options.hpp +++ b/src/cuda/rtc/detail/marshalled_options.hpp @@ -14,6 +14,33 @@ namespace cuda { namespace rtc { +namespace detail_ { + +// These two structs are streamed to a marshalled options object (see below) +// to indicate the start of a new option or the conclusion of all options, +// respectively + +template +struct opt_start_t { + bool ever_used; + Delimiter delimiter_; + + opt_start_t(Delimiter delimiter) : ever_used(false), delimiter_(delimiter){ } +}; + +inline void optend() {} + +template +struct is_marshalling_control : ::std::false_type {}; + +template +struct is_marshalling_control> : ::std::true_type {}; + +template<> +struct is_marshalling_control : ::std::true_type {}; + +} // namespace detail_ + /** * This class is necessary for realizing everything we need from * the marshalled options: Easy access using an array of pointers, @@ -49,7 +76,7 @@ class marshalled_options_t { return oss.tellp() == 0; } - template + template ::value>> marshalled_options_t& operator<<(T&& x) { oss << x; @@ -75,11 +102,18 @@ class marshalled_options_t { } }; -namespace detail_ { - -inline void optend() { } +template +MarshalTarget& operator<<(MarshalTarget& mt, detail_::opt_start_t& opt_start) +{ + if (not opt_start.ever_used) { + opt_start.ever_used = true; + } + else { + mt << opt_start.delimiter_; + } + return mt; +} -} // namespace detail_ inline marshalled_options_t& operator<< (marshalled_options_t& mo, decltype(detail_::optend)) {