Skip to content

Commit

Permalink
Bug #546 WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalroz committed Oct 11, 2023
1 parent e51f7a7 commit 151954c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 31 deletions.
26 changes: 0 additions & 26 deletions src/cuda/rtc/compilation_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,32 +471,6 @@ class compilation_options_t<cuda_cpp> final :
};


namespace detail_ {

inline const char* true_or_false(bool b) { return b ? "true" : "false"; }

template <typename Delimiter>
struct opt_start_t {
bool ever_used;
Delimiter delimiter_;

opt_start_t(Delimiter delimiter) : ever_used(false), delimiter_(delimiter){ }
};

} // namespace detail_

template <typename MarshalTarget, typename Delimiter>
MarshalTarget& operator<<(MarshalTarget& mt, detail_::opt_start_t<Delimiter>& 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)
Expand Down
44 changes: 39 additions & 5 deletions src/cuda/rtc/detail/marshalled_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Delimiter>
struct opt_start_t {
bool ever_used;
Delimiter delimiter_;

opt_start_t(Delimiter delimiter) : ever_used(false), delimiter_(delimiter){ }
};

inline void optend() {}

template<typename T>
struct is_marshalling_control : ::std::false_type {};

template<typename Delimiter>
struct is_marshalling_control<opt_start_t<Delimiter>> : ::std::true_type {};

template<>
struct is_marshalling_control<decltype(optend())> : ::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,
Expand Down Expand Up @@ -49,7 +76,7 @@ class marshalled_options_t {
return oss.tellp() == 0;
}

template <typename T>
template <typename T, typename = ::cuda::detail_::enable_if_t<not detail_::is_marshalling_control<typename ::std::decay<T>::type>::value>>
marshalled_options_t& operator<<(T&& x)
{
oss << x;
Expand All @@ -75,11 +102,18 @@ class marshalled_options_t {
}
};

namespace detail_ {

inline void optend() { }
template <typename MarshalTarget, typename Delimiter>
MarshalTarget& operator<<(MarshalTarget& mt, detail_::opt_start_t<Delimiter>& 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))
{
Expand Down

0 comments on commit 151954c

Please sign in to comment.