[llvm] [TableGen] Allow emitter callbacks to use `const RecordKeeper &` (PR #104716)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 23 04:10:23 PDT 2024
" + sys::path::filename(Record.getInputFilename()),"
In-Reply-To: <llvm.org/llvm/llvm-project/pull/104716 at github.com>
================
@@ -12,22 +12,65 @@
#include "llvm/TableGen/TableGenBackend.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
using namespace llvm;
+using namespace TableGen::Emitter;
const size_t MAX_LINE_LEN = 80U;
-namespace llvm::TableGen::Emitter {
-ManagedStatic<cl::opt<FnT>, OptCreatorT> Action;
-void *OptCreatorT::call() {
- return new cl::opt<FnT>(cl::desc("Action to perform:"));
+// CommandLine options of class type are not directly supported with some
+// specific exceptions like std::string which are safe to copy. In our case,
+// the `FnT` function_ref object is also safe to copy. So provide a
+// specialization of `OptionValue` for `FnT` type that stores it as a copy.
+// This is essentially similar to OptionValue<std::string> specialization for
+// strings.
+template <> struct cl::OptionValue<FnT> final : cl::OptionValueCopy<FnT> {
+ OptionValue() = default;
+
+ OptionValue(const FnT &V) { this->setValue(V); }
+
+ OptionValue<FnT> &operator=(const FnT &V) {
+ setValue(V);
+ return *this;
+ }
+
+private:
+ void anchor() override {}
----------------
Pierre-vh wrote:
I don't think you need an anchor if the class is contained inside a .cpp file, it's just useful in headers IIRC
https://github.com/llvm/llvm-project/pull/104716
More information about the llvm-commits
mailing list