[Mlir-commits] [mlir] [mlir][ODS] Add namespace filtering to `-gen-enum-*` (PR #89627)
Markus Böck
llvmlistbot at llvm.org
Mon Apr 22 12:53:58 PDT 2024
================
@@ -23,18 +25,32 @@
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
+using namespace mlir;
+using namespace mlir::tblgen;
+
using llvm::formatv;
using llvm::isDigit;
using llvm::PrintFatalError;
using llvm::raw_ostream;
using llvm::Record;
using llvm::RecordKeeper;
-using llvm::StringRef;
-using mlir::tblgen::Attribute;
-using mlir::tblgen::EnumAttr;
-using mlir::tblgen::EnumAttrCase;
-using mlir::tblgen::FmtContext;
-using mlir::tblgen::tgfmt;
+
+/// Returns true if 'subNamespace' is a sub-namespace of 'parentNamespace'.
+/// I.e. 'subNamespace' is contained within 'parentNamespace'.
+static bool isSubNamespace(ArrayRef<StringRef> subNamespace,
+ StringRef parentNamespace) {
+ SmallVector<StringRef> parentNamespaces;
+ llvm::SplitString(parentNamespace, parentNamespaces, "::");
----------------
zero9178 wrote:
I prototyped this real quick and I am not 100% sure how I feel about it.
What I like about the current solution is that its simple yet useful, and intuative in the way that C++ namespaces work. Specifying something like `-enum-namespace=test` e.g. simply generates all namespaces that have `test::` in them.
The equivalent regex to do so would be `^test(::.*)?$` (or just `test(::.*)?` on the CLI if we make the implementation wrap it in `^...$`).
What do you think?
https://github.com/llvm/llvm-project/pull/89627
More information about the Mlir-commits
mailing list