From d68c5a3c2193e959b817461067ec70f68b0e098e Mon Sep 17 00:00:00 2001 From: max Date: Fri, 3 Jan 2025 22:12:33 -0500 Subject: [PATCH] use llm lol for tblgen method --- build_tools/cmake/llvm_cache.cmake | 1 + projects/eudsl-tblgen/CMakeLists.txt | 16 +- projects/eudsl-tblgen/pyproject.toml | 2 + .../eudsl-tblgen/src/eudsl_tblgen/__init__.py | 39 ++ .../eudsl-tblgen/src/eudsl_tblgen_ext.cpp | 482 +++++++++++------- projects/eudsl-tblgen/tests/test_bindings.py | 258 +++++----- 6 files changed, 495 insertions(+), 303 deletions(-) diff --git a/build_tools/cmake/llvm_cache.cmake b/build_tools/cmake/llvm_cache.cmake index 573eb39..30542d7 100644 --- a/build_tools/cmake/llvm_cache.cmake +++ b/build_tools/cmake/llvm_cache.cmake @@ -15,6 +15,7 @@ set(LLVM_BUILD_TOOLS ON CACHE BOOL "") set(LLVM_BUILD_UTILS ON CACHE BOOL "") set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "") set(LLVM_INSTALL_UTILS ON CACHE BOOL "") +set(LLVM_ENABLE_DUMP ON CACHE BOOL "") set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "") # All the tools will use libllvm shared library diff --git a/projects/eudsl-tblgen/CMakeLists.txt b/projects/eudsl-tblgen/CMakeLists.txt index b80ac7c..90225a1 100644 --- a/projects/eudsl-tblgen/CMakeLists.txt +++ b/projects/eudsl-tblgen/CMakeLists.txt @@ -53,19 +53,27 @@ set(EUDSL_TBLGEN_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${EUDSL_TBLGEN_SRC_DIR}/eudsl_tblgen) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -nanobind_add_module(eudsl_tblgen_ext NB_STATIC STABLE_ABI +nanobind_add_module(eudsl_tblgen_ext NB_STATIC src/eudsl_tblgen_ext.cpp src/TGParser.cpp src/TGLexer.cpp ) target_link_libraries(eudsl_tblgen_ext PRIVATE LLVMTableGenCommon LLVMTableGen MLIRTableGen) -target_compile_options(eudsl_tblgen_ext - PUBLIC +set(nanobind_options -Wno-cast-qual + -Wno-deprecated-literal-operator + -Wno-covered-switch-default + -Wno-nested-anon-types + -Wno-zero-length-array + -Wno-c++98-compat-extra-semi + -Wno-c++20-extensions $<$:-fexceptions -frtti> $<$:-fexceptions -frtti> - $<$:/EHsc /GR>) + $<$:/EHsc /GR> +) +target_compile_options(eudslpy_ext PRIVATE ${nanobind_options}) +target_compile_options(nanobind-static PRIVATE ${nanobind_options}) # note WORKING_DIRECTORY set(NB_STUBGEN_CMD "${Python_EXECUTABLE}" "-m" "nanobind.stubgen" diff --git a/projects/eudsl-tblgen/pyproject.toml b/projects/eudsl-tblgen/pyproject.toml index 4a8d241..9ebdde2 100644 --- a/projects/eudsl-tblgen/pyproject.toml +++ b/projects/eudsl-tblgen/pyproject.toml @@ -22,6 +22,7 @@ cmake.source-dir = "." [tool.scikit-build.cmake.define] LLVM_DIR = { env = "LLVM_DIR", default = "EMPTY" } +MLIR_DIR = { env = "MLIR_DIR", default = "EMPTY" } CMAKE_CXX_VISIBILITY_PRESET = "hidden" CMAKE_C_COMPILER_LAUNCHER = { env = "CMAKE_C_COMPILER_LAUNCHER", default = "" } CMAKE_CXX_COMPILER_LAUNCHER = { env = "CMAKE_CXX_COMPILER_LAUNCHER", default = "" } @@ -34,6 +35,7 @@ archs = ["auto64"] manylinux-x86_64-image = "manylinux_2_28" environment-pass = [ "LLVM_DIR", + "MLIR_DIR", "CMAKE_GENERATOR", "CMAKE_PREFIX_PATH", "CC", diff --git a/projects/eudsl-tblgen/src/eudsl_tblgen/__init__.py b/projects/eudsl-tblgen/src/eudsl_tblgen/__init__.py index e21275a..bc7580f 100644 --- a/projects/eudsl-tblgen/src/eudsl_tblgen/__init__.py +++ b/projects/eudsl-tblgen/src/eudsl_tblgen/__init__.py @@ -4,3 +4,42 @@ # Copyright (c) 2024. from .eudsl_tblgen_ext import * + + +import re + + +def get_operation_name(def_record): + prefix = def_record.get_value_as_def("opDialect").get_value_as_string("name") + op_name = def_record.get_value_as_string("opName") + + if not prefix: + return op_name + return f"{prefix}.{op_name}" + + +def get_requested_op_definitions(records, op_inc_filter=None, op_exc_filter=None): + class_def = records.get_class("Op") + if not class_def: + raise RuntimeError("ERROR: Couldn't find the 'Op' class!") + + if op_inc_filter: + include_regex = re.compile(op_inc_filter) + if op_exc_filter: + exclude_regex = re.compile(op_exc_filter) + defs = [] + + for def_name in records.get_defs(): + def_record = records.get_defs()[def_name] + if not def_record.is_sub_class_of(class_def): + continue + # Include if no include filter or include filter matches. + if op_inc_filter and not include_regex.match(get_operation_name(def_record)): + continue + # Unless there is an exclude filter and it matches. + if op_exc_filter and exclude_regex.match(get_operation_name(def_record)): + continue + def_record.dump() + defs.append(def_record) + + return defs diff --git a/projects/eudsl-tblgen/src/eudsl_tblgen_ext.cpp b/projects/eudsl-tblgen/src/eudsl_tblgen_ext.cpp index 4c71a8b..f419d6a 100644 --- a/projects/eudsl-tblgen/src/eudsl_tblgen_ext.cpp +++ b/projects/eudsl-tblgen/src/eudsl_tblgen_ext.cpp @@ -113,16 +113,19 @@ NB_MODULE(eudsl_tblgen_ext, m) { .value("DagRecTyKind", RecTy::RecTyKind::DagRecTyKind) .value("RecordRecTyKind", RecTy::RecTyKind::RecordRecTyKind); - recty.def_prop_ro("rec_ty_kind", &RecTy::getRecTyKind) - .def_prop_ro("record_keeper", &RecTy::getRecordKeeper) - .def_prop_ro("as_string", &RecTy::getAsString) + recty.def("get_rec_ty_kind", &RecTy::getRecTyKind) + .def("get_record_keeper", &RecTy::getRecordKeeper, + nb::rv_policy::reference_internal) + .def("get_as_string", &RecTy::getAsString) .def("__str__", &RecTy::getAsString) .def("type_is_a", &RecTy::typeIsA, "rhs"_a) .def("type_is_convertible_to", &RecTy::typeIsConvertibleTo, "rhs"_a); nb::class_(m, "RecordRecTy") - .def_prop_ro("classes", coerceReturn>( - &RecordRecTy::getClasses, nb::const_)) + .def("get_classes", + coerceReturn>(&RecordRecTy::getClasses, + nb::const_), + nb::rv_policy::reference_internal) .def("is_sub_class_of", &RecordRecTy::isSubClassOf, "class_"_a); nb::enum_(m, "InitKind") @@ -153,8 +156,8 @@ NB_MODULE(eudsl_tblgen_ext, m) { .value("IK_ArgumentInit", HackInit::InitKind::IK_ArgumentInit); nb::class_(m, "Init") - .def_prop_ro("kind", &Init::getKind) - .def_prop_ro("as_string", &Init::getAsUnquotedString) + .def("get_kind", &Init::getKind) + .def("get_as_string", &Init::getAsUnquotedString) .def("__str__", &Init::getAsUnquotedString) .def("is_complete", &Init::isComplete) .def("is_concrete", &Init::isConcrete) @@ -164,32 +167,36 @@ NB_MODULE(eudsl_tblgen_ext, m) { nb::rv_policy::reference_internal); nb::class_(m, "TypedInit") - .def_prop_ro("record_keeper", &TypedInit::getRecordKeeper) - .def_prop_ro("type", &TypedInit::getType); + .def("get_record_keeper", &TypedInit::getRecordKeeper, + nb::rv_policy::reference_internal) + .def("get_type", &TypedInit::getType, nb::rv_policy::reference_internal); nb::class_(m, "UnsetInit"); nb::class_(m, "ArgumentInit") .def("is_positional", &ArgumentInit::isPositional) .def("is_named", &ArgumentInit::isNamed) - .def_prop_ro("value", &ArgumentInit::getValue) - .def_prop_ro("index", &ArgumentInit::getIndex) - .def_prop_ro("name", &ArgumentInit::getName); + .def("get_value", &ArgumentInit::getValue, + nb::rv_policy::reference_internal) + .def("get_index", &ArgumentInit::getIndex) + .def("get_name", &ArgumentInit::getName, + nb::rv_policy::reference_internal); nb::class_(m, "BitInit") - .def_prop_ro("value", &BitInit::getValue) + .def("get_value", &BitInit::getValue) .def("__bool__", &BitInit::getValue); nb::class_(m, "BitsInit") - .def_prop_ro("num_bits", &BitsInit::getNumBits) + .def("get_num_bits", &BitsInit::getNumBits) .def("all_incomplete", &BitsInit::allInComplete); nb::class_(m, "IntInit") - .def_prop_ro("value", &IntInit::getValue); + .def("get_value", &IntInit::getValue); nb::class_(m, "AnonymousNameInit") - .def_prop_ro("value", &AnonymousNameInit::getValue) - .def_prop_ro("name_init", &AnonymousNameInit::getNameInit); + .def("get_value", &AnonymousNameInit::getValue) + .def("get_name_init", &AnonymousNameInit::getNameInit, + nb::rv_policy::reference_internal); auto stringInit = nb::class_(m, "StringInit"); @@ -197,8 +204,8 @@ NB_MODULE(eudsl_tblgen_ext, m) { .value("SF_String", StringInit::StringFormat::SF_String) .value("SF_Code", StringInit::StringFormat::SF_Code); - stringInit.def_prop_ro("value", &StringInit::getValue) - .def_prop_ro("format", &StringInit::getFormat) + stringInit.def("get_value", &StringInit::getValue) + .def("get_format", &StringInit::getFormat) .def("has_code_format", &StringInit::hasCodeFormat); nb::class_(m, "ListInit") @@ -217,15 +224,16 @@ NB_MODULE(eudsl_tblgen_ext, m) { return v.getElement(nb::detail::wrap(i, v.size())); }, nb::rv_policy::reference_internal) - .def_prop_ro("element_type", &ListInit::getElementType) + .def("get_element_type", &ListInit::getElementType, + nb::rv_policy::reference_internal) .def("get_element_as_record", &ListInit::getElementAsRecord, "i"_a, nb::rv_policy::reference_internal) - .def_prop_ro("values", coerceReturn>( - &ListInit::getValues, nb::const_)); + .def("get_values", coerceReturn>( + &ListInit::getValues, nb::const_)); nb::class_(m, "OpInit") - .def_prop_ro("num_operands", &OpInit::getNumOperands) - .def("operand", &OpInit::getOperand, "i"_a, + .def("get_num_operands", &OpInit::getNumOperands) + .def("get_operand", &OpInit::getOperand, "i"_a, nb::rv_policy::reference_internal); auto unaryOpInit = nb::class_(m, "UnOpInit"); @@ -242,7 +250,7 @@ NB_MODULE(eudsl_tblgen_ext, m) { .value("LOG2", UnOpInit::UnaryOp::LOG2) .value("REPR", UnOpInit::UnaryOp::REPR) .value("LISTFLATTEN", UnOpInit::UnaryOp::LISTFLATTEN); - unaryOpInit.def_prop_ro("opcode", &UnOpInit::getOpcode); + unaryOpInit.def("get_opcode", &UnOpInit::getOpcode); auto binaryOpInit = nb::class_(m, "BinOpInit"); nb::enum_(m, "BinaryOp") @@ -274,9 +282,9 @@ NB_MODULE(eudsl_tblgen_ext, m) { .value("GETDAGARG", BinOpInit::BinaryOp::GETDAGARG) .value("GETDAGNAME", BinOpInit::BinaryOp::GETDAGNAME) .value("SETDAGOP", BinOpInit::BinaryOp::SETDAGOP); - binaryOpInit.def_prop_ro("opcode", &BinOpInit::getOpcode) - .def_prop_ro("lhs", &BinOpInit::getLHS) - .def_prop_ro("rhs", &BinOpInit::getRHS); + binaryOpInit.def("get_opcode", &BinOpInit::getOpcode) + .def("get_lhs", &BinOpInit::getLHS, nb::rv_policy::reference_internal) + .def("get_rhs", &BinOpInit::getRHS, nb::rv_policy::reference_internal); auto ternaryOpInit = nb::class_(m, "TernOpInit"); nb::enum_(m, "TernaryOp") @@ -290,10 +298,10 @@ NB_MODULE(eudsl_tblgen_ext, m) { .value("FIND", TernOpInit::TernaryOp::FIND) .value("SETDAGARG", TernOpInit::TernaryOp::SETDAGARG) .value("SETDAGNAME", TernOpInit::TernaryOp::SETDAGNAME); - ternaryOpInit.def_prop_ro("opcode", &TernOpInit::getOpcode) - .def_prop_ro("lhs", &TernOpInit::getLHS) - .def_prop_ro("mhs", &TernOpInit::getMHS) - .def_prop_ro("rhs", &TernOpInit::getRHS); + ternaryOpInit.def("get_opcode", &TernOpInit::getOpcode) + .def("get_lhs", &TernOpInit::getLHS, nb::rv_policy::reference_internal) + .def("get_mhs", &TernOpInit::getMHS, nb::rv_policy::reference_internal) + .def("get_rhs", &TernOpInit::getRHS, nb::rv_policy::reference_internal); nb::class_(m, "CondOpInit"); nb::class_(m, "FoldOpInit"); @@ -301,22 +309,27 @@ NB_MODULE(eudsl_tblgen_ext, m) { nb::class_(m, "ExistsOpInit"); nb::class_(m, "VarInit") - .def_prop_ro("name", &VarInit::getName) - .def_prop_ro("name_init", &VarInit::getNameInit) - .def_prop_ro("name_init_as_string", &VarInit::getNameInitAsString); + .def("get_name", &VarInit::getName, nb::rv_policy::reference_internal) + .def("get_name_init", &VarInit::getNameInit, + nb::rv_policy::reference_internal) + .def("get_name_init_as_string", &VarInit::getNameInitAsString, + nb::rv_policy::reference_internal); nb::class_(m, "VarBitInit") - .def_prop_ro("bit_var", &VarBitInit::getBitVar) - .def_prop_ro("bit_num", &VarBitInit::getBitNum); + .def("get_bit_var", &VarBitInit::getBitVar, + nb::rv_policy::reference_internal) + .def("get_bit_num", &VarBitInit::getBitNum); nb::class_(m, "DefInit") - .def_prop_ro("def_", &DefInit::getDef); + .def("get_def_", &DefInit::getDef, nb::rv_policy::reference_internal); nb::class_(m, "VarDefInit") .def("get_arg", &VarDefInit::getArg, "i"_a, nb::rv_policy::reference_internal) - .def_prop_ro("args", coerceReturn>( - &VarDefInit::args, nb::const_)) + .def("get_args", + coerceReturn>(&VarDefInit::args, + nb::const_), + nb::rv_policy::reference_internal) .def("__len__", [](const VarDefInit &v) { return v.args_size(); }) .def("__bool__", [](const VarDefInit &v) { return !v.args_empty(); }) .def( @@ -335,14 +348,19 @@ NB_MODULE(eudsl_tblgen_ext, m) { nb::rv_policy::reference_internal); nb::class_(m, "FieldInit") - .def_prop_ro("record", &FieldInit::getRecord) - .def_prop_ro("field_name", &FieldInit::getFieldName); + .def("get_record", &FieldInit::getRecord, + nb::rv_policy::reference_internal) + .def("get_field_name", &FieldInit::getFieldName, + nb::rv_policy::reference_internal); nb::class_(m, "DagInit") - .def_prop_ro("operator", &DagInit::getOperator) - .def_prop_ro("name_init", &DagInit::getName) - .def_prop_ro("name_str", &DagInit::getNameStr) - .def_prop_ro("num_args", &DagInit::getNumArgs) + .def("get_operator", &DagInit::getOperator, + nb::rv_policy::reference_internal) + .def("get_name_init", &DagInit::getName, + nb::rv_policy::reference_internal) + .def("get_name_str", &DagInit::getNameStr, + nb::rv_policy::reference_internal) + .def("get_num_args", &DagInit::getNumArgs) .def("get_arg", &DagInit::getArg, "num"_a, nb::rv_policy::reference_internal) .def("get_arg_no", &DagInit::getArgNo, "name"_a) @@ -375,81 +393,76 @@ NB_MODULE(eudsl_tblgen_ext, m) { nb::class_(m, "RecordVal") .def("dump", &RecordVal::dump) - .def_prop_ro("name", &RecordVal::getName) - .def_prop_ro("name_init_as_string", &RecordVal::getNameInitAsString) - .def_prop_ro("print_type", &RecordVal::getPrintType) - .def_prop_ro("record_keeper", &RecordVal::getRecordKeeper) - .def_prop_ro("type", &RecordVal::getType) - .def_prop_ro("is_nonconcrete_ok", &RecordVal::isNonconcreteOK) - .def_prop_ro("is_template_arg", &RecordVal::isTemplateArg) - .def_prop_ro("value", &RecordVal::getValue) + .def("get_name", &RecordVal::getName, nb::rv_policy::reference_internal) + .def("get_name_init_as_string", &RecordVal::getNameInitAsString) + .def("get_print_type", &RecordVal::getPrintType) + .def("get_record_keeper", &RecordVal::getRecordKeeper, + nb::rv_policy::reference_internal) + .def("get_type", &RecordVal::getType, nb::rv_policy::reference_internal) + .def("is_nonconcrete_ok", &RecordVal::isNonconcreteOK) + .def("is_template_arg", &RecordVal::isTemplateArg) + .def("get_value", &RecordVal::getValue, nb::rv_policy::reference_internal) .def("__str__", [](const RecordVal &self) { - return self.getValue()->getAsUnquotedString(); + return self.getValue() ? self.getValue()->getAsUnquotedString() + : "<>"; }) - .def_prop_ro("is_used", &RecordVal::isUsed); + .def("is_used", &RecordVal::isUsed); struct RecordValues {}; nb::class_(m, "RecordValues", nb::dynamic_attr()) - .def("__repr__", [](const nb::object &self) { - nb::str s{"RecordValues("}; - auto dic = nb::cast(nb::getattr(self, "__dict__")); - int i = 0; - for (auto [key, value] : dic) { - s += key + nb::str("=") + - nb::str(nb::cast(value) - .getValue() - ->getAsUnquotedString() - .c_str()); - if (i < dic.size() - 1) - s += nb::str(", "); - ++i; - } - s += nb::str(")"); - return s; - }); + .def("__repr__", + [](const nb::object &self) { + nb::str s{"RecordValues("}; + auto dic = nb::cast(nb::getattr(self, "__dict__")); + int i = 0; + for (auto [key, value] : dic) { + s += key + nb::str("=") + + nb::str(nb::cast(value) + .getValue() + ->getAsUnquotedString() + .c_str()); + if (i < dic.size() - 1) + s += nb::str(", "); + ++i; + } + s += nb::str(")"); + return s; + }) + .def( + "__iter__", + [](const nb::object &self) { + return nb::iter(getattr(self, "__dict__")); + }, + nb::rv_policy::reference_internal) + .def( + "keys", + [](const nb::object &self) { + return getattr(getattr(self, "__dict__"), "keys")(); + }, + nb::rv_policy::reference_internal) + .def( + "values", + [](const nb::object &self) { + return getattr(getattr(self, "__dict__"), "values")(); + }, + nb::rv_policy::reference_internal) + .def( + "items", + [](const nb::object &self) { + return getattr(getattr(self, "__dict__"), "items")(); + }, + nb::rv_policy::reference_internal); nb::class_(m, "Record") - .def_prop_ro("direct_super_classes", - [](const Record &self) -> std::vector { - SmallVector Classes; - self.getDirectSuperClasses(Classes); - return {Classes.begin(), Classes.end()}; - }) - .def_prop_ro("id", &Record::getID) - .def_prop_ro("name", &Record::getName) - .def_prop_ro("name_init_as_string", &Record::getNameInitAsString) - .def_prop_ro("records", &Record::getRecords) - .def_prop_ro("type", &Record::getType) - .def("get_value", nb::overload_cast(&Record::getValue), - "name"_a, nb::rv_policy::reference_internal) - .def("get_value_as_bit", &Record::getValueAsBit, "field_name"_a) - .def("get_value_as_def", &Record::getValueAsDef, "field_name"_a) - .def("get_value_as_int", &Record::getValueAsInt, "field_name"_a) - .def("get_value_as_list_of_defs", &Record::getValueAsListOfDefs, - "field_name"_a, nb::rv_policy::reference_internal) - .def("get_value_as_list_of_ints", &Record::getValueAsListOfInts, - "field_name"_a) - .def("get_value_as_list_of_strings", &Record::getValueAsListOfStrings, - "field_name"_a) - .def("get_value_as_optional_def", &Record::getValueAsOptionalDef, - "field_name"_a, nb::rv_policy::reference_internal) - .def("get_value_as_optional_string", &Record::getValueAsOptionalString, - nb::sig("def get_value_as_optional_string(self, field_name: str, /) " - "-> Optional[str]")) - .def("get_value_as_string", &Record::getValueAsString, "field_name"_a) - .def("get_value_as_bit_or_unset", &Record::getValueAsBitOrUnset, - "field_name"_a, "unset"_a) - .def("get_value_as_bits_init", &Record::getValueAsBitsInit, - "field_name"_a, nb::rv_policy::reference_internal) - .def("get_value_as_dag", &Record::getValueAsDag, "field_name"_a, - nb::rv_policy::reference_internal) - .def("get_value_as_list_init", &Record::getValueAsListInit, - "field_name"_a, nb::rv_policy::reference_internal) - .def("get_value_init", &Record::getValueInit, "field_name"_a, - nb::rv_policy::reference_internal) - .def_prop_ro( - "values", + .def("get_direct_super_classes", + [](const Record &self) -> std::vector { + SmallVector Classes; + self.getDirectSuperClasses(Classes); + return {Classes.begin(), Classes.end()}; + }) + .def( + "get_values", [](Record &self) { // you can't just call the class_->operator() nb::handle recordValsInstTy = nb::type(); @@ -466,24 +479,141 @@ NB_MODULE(eudsl_tblgen_ext, m) { nb::borrow(nb::cast(recordVal))); } return recordValsInst; - }) - .def("has_direct_super_class", &Record::hasDirectSuperClass, + }, + nb::rv_policy::reference_internal) + .def("get_template_args", + coerceReturn>(&Record::getTemplateArgs, + nb::const_), + nb::rv_policy::reference_internal) + .def_static("get_new_uid", &llvm::Record::getNewUID, "rk"_a) + .def("get_id", &llvm::Record::getID) + .def("get_name", &llvm::Record::getName) + .def("get_name_init", &llvm::Record::getNameInit, + nb::rv_policy::reference_internal) + .def("get_name_init_as_string", &llvm::Record::getNameInitAsString) + .def("set_name", &llvm::Record::setName, "name"_a) + .def("get_loc", &llvm::Record::getLoc) + .def("append_loc", &llvm::Record::appendLoc, "loc"_a) + .def("get_forward_declaration_locs", + &llvm::Record::getForwardDeclarationLocs) + .def("append_reference_loc", &llvm::Record::appendReferenceLoc, "loc"_a) + .def("get_reference_locs", &llvm::Record::getReferenceLocs) + .def("update_class_loc", &llvm::Record::updateClassLoc, "loc"_a) + .def("get_type", &llvm::Record::getType, + nb::rv_policy::reference_internal) + .def("get_def_init", &llvm::Record::getDefInit, + nb::rv_policy::reference_internal) + .def("is_class", &llvm::Record::isClass) + .def("is_multi_class", &llvm::Record::isMultiClass) + .def("is_anonymous", &llvm::Record::isAnonymous) + .def("get_template_args", &llvm::Record::getTemplateArgs) + .def("get_assertions", &llvm::Record::getAssertions) + .def("get_dumps", &llvm::Record::getDumps) + .def("get_super_classes", &llvm::Record::getSuperClasses) + .def("has_direct_super_class", &llvm::Record::hasDirectSuperClass, "super_class"_a) - .def_prop_ro("is_anonymous", &Record::isAnonymous) - .def_prop_ro("is_class", &Record::isClass) - .def_prop_ro("is_multi_class", &Record::isMultiClass) - .def("is_sub_class_of", - nb::overload_cast(&Record::isSubClassOf, nb::const_), - "r"_a) - .def("is_sub_class_of", - nb::overload_cast(&Record::isSubClassOf, nb::const_), - "name"_a) - .def("is_value_unset", &Record::isValueUnset, "field_name"_a) - .def_prop_ro("def_init", &Record::getDefInit) - .def_prop_ro("name_init", &Record::getNameInit) - .def_prop_ro("template_args", coerceReturn>( - &Record::getTemplateArgs, nb::const_)) - .def("is_template_arg", &Record::isTemplateArg, "name"_a); + .def("is_template_arg", &llvm::Record::isTemplateArg, "name"_a) + .def( + "get_value", + [](llvm::Record &self, const llvm::Init *Name) + -> const llvm::RecordVal * { return self.getValue(Name); }, + "name"_a, nb::rv_policy::reference_internal) + .def( + "get_value", + [](llvm::Record &self, llvm::StringRef Name) + -> const llvm::RecordVal * { return self.getValue(Name); }, + "name"_a, nb::rv_policy::reference_internal) + .def( + "get_value", + [](llvm::Record &self, const llvm::Init *Name) -> llvm::RecordVal * { + return self.getValue(Name); + }, + "name"_a, nb::rv_policy::reference_internal) + .def( + "get_value", + [](llvm::Record &self, llvm::StringRef Name) -> llvm::RecordVal * { + return self.getValue(Name); + }, + "name"_a, nb::rv_policy::reference_internal) + .def("add_template_arg", &llvm::Record::addTemplateArg, "name"_a) + .def("add_value", &llvm::Record::addValue, "rv"_a) + .def( + "remove_value", + [](llvm::Record &self, const llvm::Init *Name) -> void { + return self.removeValue(Name); + }, + "name"_a) + .def( + "remove_value", + [](llvm::Record &self, llvm::StringRef Name) -> void { + return self.removeValue(Name); + }, + "name"_a) + .def("add_assertion", &llvm::Record::addAssertion, "loc"_a, "condition"_a, + "message"_a) + .def("add_dump", &llvm::Record::addDump, "loc"_a, "message"_a) + .def("append_assertions", &llvm::Record::appendAssertions, "rec"_a) + .def("append_dumps", &llvm::Record::appendDumps, "rec"_a) + .def("check_record_assertions", &llvm::Record::checkRecordAssertions) + .def("emit_record_dumps", &llvm::Record::emitRecordDumps) + .def("check_unused_template_args", &llvm::Record::checkUnusedTemplateArgs) + .def( + "is_sub_class_of", + [](llvm::Record &self, const llvm::Record *R) -> bool { + return self.isSubClassOf(R); + }, + "r"_a) + .def( + "is_sub_class_of", + [](llvm::Record &self, llvm::StringRef Name) -> bool { + return self.isSubClassOf(Name); + }, + "name"_a) + .def("add_super_class", &llvm::Record::addSuperClass, "r"_a, "range"_a) + .def( + "resolve_references", + [](llvm::Record &self, const llvm::Init *NewName) -> void { + return self.resolveReferences(NewName); + }, + "new_name"_a) + .def( + "resolve_references", + [](llvm::Record &self, llvm::Resolver &R, + const llvm::RecordVal *SkipVal) -> void { + return self.resolveReferences(R, SkipVal); + }, + "r"_a, "skip_val"_a) + .def("get_records", &llvm::Record::getRecords, + nb::rv_policy::reference_internal) + .def("dump", [](llvm::Record &self) { self.dump(); }) + .def("get_field_loc", &llvm::Record::getFieldLoc, "field_name"_a) + .def("get_value_init", &llvm::Record::getValueInit, "field_name"_a, + nb::rv_policy::reference_internal) + .def("is_value_unset", &llvm::Record::isValueUnset, "field_name"_a) + .def("get_value_as_string", &llvm::Record::getValueAsString, + "field_name"_a) + .def("get_value_as_optional_string", + &llvm::Record::getValueAsOptionalString, "field_name"_a) + .def("get_value_as_bits_init", &llvm::Record::getValueAsBitsInit, + "field_name"_a, nb::rv_policy::reference_internal) + .def("get_value_as_list_init", &llvm::Record::getValueAsListInit, + "field_name"_a, nb::rv_policy::reference_internal) + .def("get_value_as_list_of_defs", &llvm::Record::getValueAsListOfDefs, + "field_name"_a) + .def("get_value_as_list_of_ints", &llvm::Record::getValueAsListOfInts, + "field_name"_a) + .def("get_value_as_list_of_strings", + &llvm::Record::getValueAsListOfStrings, "field_name"_a) + .def("get_value_as_def", &llvm::Record::getValueAsDef, "field_name"_a, + nb::rv_policy::reference_internal) + .def("get_value_as_optional_def", &llvm::Record::getValueAsOptionalDef, + "field_name"_a, nb::rv_policy::reference_internal) + .def("get_value_as_bit", &llvm::Record::getValueAsBit, "field_name"_a) + .def("get_value_as_bit_or_unset", &llvm::Record::getValueAsBitOrUnset, + "field_name"_a, "unset"_a) + .def("get_value_as_int", &llvm::Record::getValueAsInt, "field_name"_a) + .def("get_value_as_dag", &llvm::Record::getValueAsDag, "field_name"_a, + nb::rv_policy::reference_internal); using RecordMap = std::map, std::less<>>; using GlobalMap = std::map>; @@ -550,10 +680,37 @@ NB_MODULE(eudsl_tblgen_ext, m) { "input_filename"_a, "include_dirs"_a = nb::list(), "macro_names"_a = nb::list(), "no_warn_on_unused_template_args"_a = true) - .def_prop_ro("input_filename", &RecordKeeper::getInputFilename) - .def_prop_ro("classes", &RecordKeeper::getClasses) - .def_prop_ro("defs", &RecordKeeper::getDefs) - .def_prop_ro("globals", &RecordKeeper::getGlobals) + .def("get_input_filename", &llvm::RecordKeeper::getInputFilename) + .def("get_classes", &llvm::RecordKeeper::getClasses, + nb::rv_policy::reference_internal) + .def("get_defs", &llvm::RecordKeeper::getDefs, + nb::rv_policy::reference_internal) + .def("get_globals", &llvm::RecordKeeper::getGlobals, + nb::rv_policy::reference_internal) + .def("get_class", &llvm::RecordKeeper::getClass, "name"_a, + nb::rv_policy::reference_internal) + .def("get_def", &llvm::RecordKeeper::getDef, "name"_a, + nb::rv_policy::reference_internal) + .def("get_global", &llvm::RecordKeeper::getGlobal, "name"_a, + nb::rv_policy::reference_internal) + .def("save_input_filename", &llvm::RecordKeeper::saveInputFilename, + "filename"_a) + .def("add_class", &llvm::RecordKeeper::addClass, "r"_a) + .def("add_def", &llvm::RecordKeeper::addDef, "r"_a) + .def("add_extra_global", &llvm::RecordKeeper::addExtraGlobal, "name"_a, + "i"_a) + .def("get_new_anonymous_name", &llvm::RecordKeeper::getNewAnonymousName, + nb::rv_policy::reference_internal) + .def( + "get_all_derived_definitions", + [](llvm::RecordKeeper &self, + const llvm::ArrayRef ClassNames) + -> std::vector> { + return self.getAllDerivedDefinitions(ClassNames); + }, + "class_names"_a) + .def("dump", &llvm::RecordKeeper::dump) .def( "get_all_derived_definitions", [](RecordKeeper &self, @@ -2039,37 +2196,22 @@ NB_MODULE(eudsl_tblgen_ext, m) { .def("get_var_name", &mlir::tblgen::SymbolInfoMap::SymbolInfo::getVarName, "name"_a); + using SymbolInfoMapBaseT = + std::unordered_multimap; mlir_tblgen_SymbolInfoMap - .def( - "begin", - [](mlir::tblgen::SymbolInfoMap &self) - -> std::__hash_map_iterator, - void *> *>> { return self.begin(); }) - .def( - "end", - [](mlir::tblgen::SymbolInfoMap &self) - -> std::__hash_map_iterator, - void *> *>> { return self.end(); }) - .def( - "begin", - [](mlir::tblgen::SymbolInfoMap &self) - -> std::__hash_map_const_iterator< - std::__hash_const_iterator, - void *> *>> { return self.begin(); }) - .def( - "end", - [](mlir::tblgen::SymbolInfoMap &self) - -> std::__hash_map_const_iterator< - std::__hash_const_iterator, - void *> *>> { return self.end(); }) + .def("begin", + [](mlir::tblgen::SymbolInfoMap &self) + -> SymbolInfoMapBaseT::iterator { return self.begin(); }) + .def("end", + [](mlir::tblgen::SymbolInfoMap &self) + -> SymbolInfoMapBaseT::iterator { return self.end(); }) + .def("cbegin", + [](mlir::tblgen::SymbolInfoMap &self) + -> SymbolInfoMapBaseT::const_iterator { return self.begin(); }) + .def("cend", + [](mlir::tblgen::SymbolInfoMap &self) + -> SymbolInfoMapBaseT::const_iterator { return self.end(); }) .def("bind_op_argument", &mlir::tblgen::SymbolInfoMap::bindOpArgument, "node"_a, "symbol"_a, "op"_a, "arg_index"_a, "variadic_sub_index"_a) .def("bind_op_result", &mlir::tblgen::SymbolInfoMap::bindOpResult, @@ -2088,11 +2230,7 @@ NB_MODULE(eudsl_tblgen_ext, m) { [](mlir::tblgen::SymbolInfoMap &self, llvm::StringRef key, mlir::tblgen::DagNode node, const mlir::tblgen::Operator &op, int argIndex, std::optional variadicSubIndex) - -> std::__hash_map_const_iterator< - std::__hash_const_iterator, - void *> *>> { + -> SymbolInfoMapBaseT::const_iterator { return self.findBoundSymbol(key, node, op, argIndex, variadicSubIndex); }, @@ -2101,11 +2239,7 @@ NB_MODULE(eudsl_tblgen_ext, m) { "find_bound_symbol", [](mlir::tblgen::SymbolInfoMap &self, llvm::StringRef key, const mlir::tblgen::SymbolInfoMap::SymbolInfo &symbolInfo) - -> std::__hash_map_const_iterator< - std::__hash_const_iterator, - void *> *>> { + -> SymbolInfoMapBaseT::const_iterator { return self.findBoundSymbol(key, symbolInfo); }, "key"_a, "symbol_info"_a) diff --git a/projects/eudsl-tblgen/tests/test_bindings.py b/projects/eudsl-tblgen/tests/test_bindings.py index 8874b45..ace5410 100644 --- a/projects/eudsl-tblgen/tests/test_bindings.py +++ b/projects/eudsl-tblgen/tests/test_bindings.py @@ -6,7 +6,7 @@ from pathlib import Path import pytest -from eudsl_tblgen import RecordKeeper +from eudsl_tblgen import RecordKeeper, get_requested_op_definitions @pytest.fixture(scope="function") @@ -15,18 +15,18 @@ def json_record_keeper(): def test_json_record_keeper(json_record_keeper): - assert json_record_keeper.input_filename == str( + assert json_record_keeper.get_input_filename() == str( Path(__file__).parent / "td" / "JSON.td" ) - assert set(json_record_keeper.classes) == { + assert set(json_record_keeper.get_classes()) == { "Base", "Derived", "Intermediate", "Variables", } - assert set(json_record_keeper.defs.keys()) == { + assert set(json_record_keeper.get_defs().keys()) == { "D", "ExampleDagOp", "FieldKeywordTest", @@ -41,46 +41,49 @@ def test_json_record_keeper(json_record_keeper): assert len(json_record_keeper.get_all_derived_definitions("Intermediate")) == 1 assert len(json_record_keeper.get_all_derived_definitions("Derived")) == 0 - assert json_record_keeper.get_all_derived_definitions("Base")[0].name == "D" - assert json_record_keeper.get_all_derived_definitions("Intermediate")[0].name == "D" + assert json_record_keeper.get_all_derived_definitions("Base")[0].get_name() == "D" + assert ( + json_record_keeper.get_all_derived_definitions("Intermediate")[0].get_name() + == "D" + ) def test_record(json_record_keeper): - assert json_record_keeper.classes["Base"] - assert json_record_keeper.classes["Intermediate"] - assert json_record_keeper.classes["Derived"] - assert json_record_keeper.classes["Variables"] - - base_cl = json_record_keeper.classes["Base"] - interm_cl = json_record_keeper.classes["Intermediate"] - deriv_cl = json_record_keeper.classes["Derived"] - variab_cl = json_record_keeper.classes["Variables"] - - assert len(base_cl.direct_super_classes) == 0 - assert len(interm_cl.direct_super_classes) == 1 - assert len(deriv_cl.direct_super_classes) == 1 - assert len(variab_cl.direct_super_classes) == 0 - - assert interm_cl.direct_super_classes[0].name == "Base" - assert deriv_cl.direct_super_classes[0].name == "Intermediate" - - assert base_cl.name == "Base" - assert base_cl.name_init_as_string == "Base" - assert base_cl.records is json_record_keeper - assert base_cl.type - - assert repr(base_cl.values) == "RecordValues()" + assert json_record_keeper.get_classes()["Base"] + assert json_record_keeper.get_classes()["Intermediate"] + assert json_record_keeper.get_classes()["Derived"] + assert json_record_keeper.get_classes()["Variables"] + + base_cl = json_record_keeper.get_classes()["Base"] + interm_cl = json_record_keeper.get_classes()["Intermediate"] + deriv_cl = json_record_keeper.get_classes()["Derived"] + variab_cl = json_record_keeper.get_classes()["Variables"] + + assert len(base_cl.get_direct_super_classes()) == 0 + assert len(interm_cl.get_direct_super_classes()) == 1 + assert len(deriv_cl.get_direct_super_classes()) == 1 + assert len(variab_cl.get_direct_super_classes()) == 0 + + assert interm_cl.get_direct_super_classes()[0].get_name() == "Base" + assert deriv_cl.get_direct_super_classes()[0].get_name() == "Intermediate" + + assert base_cl.get_name() == "Base" + assert base_cl.get_name_init_as_string() == "Base" + assert base_cl.get_records() is json_record_keeper + assert base_cl.get_type() + + assert repr(base_cl.get_values()) == "RecordValues()" assert ( - repr(variab_cl.values) + repr(variab_cl.get_values()) == "RecordValues(i=?, s=?, b=?, bs={ ?, ?, ?, ?, ?, ?, ?, ? }, c=?, li=?, base=?, d=?)" ) - assert interm_cl.has_direct_super_class(interm_cl.direct_super_classes[0]) + assert interm_cl.has_direct_super_class(interm_cl.get_direct_super_classes()[0]) assert interm_cl.has_direct_super_class(base_cl) - assert base_cl.is_anonymous is False - assert base_cl.is_class is True - assert base_cl.is_multi_class is False + assert base_cl.is_anonymous() is False + assert base_cl.is_class() is True + assert base_cl.is_multi_class() is False assert interm_cl.is_sub_class_of(base_cl) assert not interm_cl.is_sub_class_of(variab_cl) @@ -88,20 +91,20 @@ def test_record(json_record_keeper): def test_record_val_classes(json_record_keeper): - variab_cl = json_record_keeper.classes["Variables"] + variab_cl = json_record_keeper.get_classes()["Variables"] assert variab_cl.get_value("i") i_val = variab_cl.get_value("i") - assert i_val.name == "i" - assert i_val.name_init_as_string == "i" - assert i_val.print_type == "int" - assert i_val.record_keeper is json_record_keeper - assert i_val.is_nonconcrete_ok is False - assert i_val.is_template_arg is False - assert i_val.is_used is False + assert i_val.get_name() == "i" + assert i_val.get_name_init_as_string() == "i" + assert i_val.get_print_type() == "int" + assert i_val.get_record_keeper() is json_record_keeper + assert i_val.is_nonconcrete_ok() is False + assert i_val.is_template_arg() is False + assert i_val.is_used() is False def test_record_val_defs(json_record_keeper): - var_prim_def = json_record_keeper.defs["VarPrim"] + var_prim_def = json_record_keeper.get_defs()["VarPrim"] assert var_prim_def.get_value_as_int("i") == 3 assert var_prim_def.get_value_as_int("enormous_pos") == 9123456789123456789 assert var_prim_def.get_value_as_int("enormous_neg") == -9123456789123456789 @@ -112,31 +115,31 @@ def test_record_val_defs(json_record_keeper): def test_init(json_record_keeper): - variab_cl = json_record_keeper.classes["Variables"] + variab_cl = json_record_keeper.get_classes()["Variables"] assert variab_cl.get_value("i") - assert variab_cl.get_value("i").value - i_val_init = variab_cl.get_value("i").value + assert variab_cl.get_value("i").get_value() + i_val_init = variab_cl.get_value("i").get_value() assert str(i_val_init) == "?" - assert i_val_init.as_string == "?" + assert i_val_init.get_as_string() == "?" assert i_val_init.is_complete() is False assert i_val_init.is_concrete() is True def test_record_rec_ty(json_record_keeper): - base_cl = json_record_keeper.classes["Base"] - interm_cl = json_record_keeper.classes["Intermediate"] - deriv_cl = json_record_keeper.classes["Derived"] + base_cl = json_record_keeper.get_classes()["Base"] + interm_cl = json_record_keeper.get_classes()["Intermediate"] + deriv_cl = json_record_keeper.get_classes()["Derived"] - assert not base_cl.type.classes - assert interm_cl.type.classes - assert deriv_cl.type.classes - assert len(interm_cl.type.classes) == 1 - assert len(deriv_cl.type.classes) == 1 - assert interm_cl.type.classes[0].name == "Base" - assert deriv_cl.type.classes[0].name == "Intermediate" + assert not base_cl.get_type().get_classes() + assert interm_cl.get_type().get_classes() + assert deriv_cl.get_type().get_classes() + assert len(interm_cl.get_type().get_classes()) == 1 + assert len(deriv_cl.get_type().get_classes()) == 1 + assert interm_cl.get_type().get_classes()[0].get_name() == "Base" + assert deriv_cl.get_type().get_classes()[0].get_name() == "Intermediate" - assert interm_cl.type.is_sub_class_of(base_cl) - assert deriv_cl.type.is_sub_class_of(interm_cl) + assert interm_cl.get_type().is_sub_class_of(base_cl) + assert deriv_cl.get_type().is_sub_class_of(interm_cl) @pytest.fixture(scope="function") @@ -148,76 +151,81 @@ def record_keeper_test_dialect(): def test_init_complex(record_keeper_test_dialect): - op = record_keeper_test_dialect.defs["Test_TypesOp"] - assert str(op.values.opName) == "types" - assert str(op.values.cppNamespace) == "test" - assert str(op.values.opDocGroup) == "?" - assert str(op.values.results) == "(outs)" - assert str(op.values.regions) == "(region)" - assert str(op.values.successors) == "(successor)" - assert str(op.values.builders) == "?" - assert bool(op.values.skipDefaultBuilders.value) is False - assert str(op.values.assemblyFormat) == "?" - assert bool(op.values.hasCustomAssemblyFormat.value) is False - assert bool(op.values.hasVerifier.value) is False - assert bool(op.values.hasRegionVerifier.value) is False - assert bool(op.values.hasCanonicalizer.value) is False - assert bool(op.values.hasCanonicalizeMethod.value) is False - assert bool(op.values.hasFolder.value) is False - assert bool(op.values.useCustomPropertiesEncoding.value) is False - assert len(op.values.traits.value) == 0 - assert str(op.values.extraClassDeclaration) == "?" - assert str(op.values.extraClassDefinition) == "?" + op = record_keeper_test_dialect.get_defs()["Test_TypesOp"] + assert str(op.get_values().opName) == "types" + assert str(op.get_values().cppNamespace) == "test" + assert str(op.get_values().opDocGroup) == "?" + assert str(op.get_values().results) == "(outs)" + assert str(op.get_values().regions) == "(region)" + assert str(op.get_values().successors) == "(successor)" + assert str(op.get_values().builders) == "?" + assert bool(op.get_values().skipDefaultBuilders.get_value()) is False + assert str(op.get_values().assemblyFormat) == "?" + assert bool(op.get_values().hasCustomAssemblyFormat.get_value()) is False + assert bool(op.get_values().hasVerifier.get_value()) is False + assert bool(op.get_values().hasRegionVerifier.get_value()) is False + assert bool(op.get_values().hasCanonicalizer.get_value()) is False + assert bool(op.get_values().hasCanonicalizeMethod.get_value()) is False + assert bool(op.get_values().hasFolder.get_value()) is False + assert bool(op.get_values().useCustomPropertiesEncoding.get_value()) is False + assert len(op.get_values().traits.get_value()) == 0 + assert str(op.get_values().extraClassDeclaration) == "?" + assert str(op.get_values().extraClassDefinition) == "?" assert ( - repr(op.values) + repr(op.get_values()) == "RecordValues(opDialect=Test_Dialect, opName=types, cppNamespace=test, summary=, description=, opDocGroup=?, arguments=(ins I32:$a, SI64:$b, UI8:$c, Index:$d, F32:$e, NoneType:$f, anonymous_347), results=(outs), regions=(region), successors=(successor), builders=?, skipDefaultBuilders=0, assemblyFormat=?, hasCustomAssemblyFormat=0, hasVerifier=0, hasRegionVerifier=0, hasCanonicalizer=0, hasCanonicalizeMethod=0, hasFolder=0, useCustomPropertiesEncoding=0, traits=[], extraClassDeclaration=?, extraClassDefinition=?)" ) - arguments = op.values.arguments - assert arguments.value.get_arg_name_str(0) == "a" - assert arguments.value.get_arg_name_str(1) == "b" - assert arguments.value.get_arg_name_str(2) == "c" - assert arguments.value.get_arg_name_str(3) == "d" - assert arguments.value.get_arg_name_str(4) == "e" - assert arguments.value.get_arg_name_str(5) == "f" - - assert str(arguments.value[0]) == "I32" - assert str(arguments.value[1]) == "SI64" - assert str(arguments.value[2]) == "UI8" - assert str(arguments.value[3]) == "Index" - assert str(arguments.value[4]) == "F32" - assert str(arguments.value[5]) == "NoneType" - - attr = record_keeper_test_dialect.defs["Test_TestAttr"] - assert str(attr.values.predicate) == "anonymous_334" - assert str(attr.values.storageType) == "test::TestAttr" - assert str(attr.values.returnType) == "test::TestAttr" + arguments = op.get_values().arguments + assert arguments.get_value().get_arg_name_str(0) == "a" + assert arguments.get_value().get_arg_name_str(1) == "b" + assert arguments.get_value().get_arg_name_str(2) == "c" + assert arguments.get_value().get_arg_name_str(3) == "d" + assert arguments.get_value().get_arg_name_str(4) == "e" + assert arguments.get_value().get_arg_name_str(5) == "f" + + assert str(arguments.get_value()[0]) == "I32" + assert str(arguments.get_value()[1]) == "SI64" + assert str(arguments.get_value()[2]) == "UI8" + assert str(arguments.get_value()[3]) == "Index" + assert str(arguments.get_value()[4]) == "F32" + assert str(arguments.get_value()[5]) == "NoneType" + + attr = record_keeper_test_dialect.get_defs()["Test_TestAttr"] + assert str(attr.get_values().predicate) == "anonymous_334" + assert str(attr.get_values().storageType) == "test::TestAttr" + assert str(attr.get_values().returnType) == "test::TestAttr" assert ( - str(attr.values.convertFromStorage.value) + str(attr.get_values().convertFromStorage.get_value()) == "::llvm::cast($_self)" ) - assert str(attr.values.constBuilderCall) == "?" - assert str(attr.values.defaultValue) == "?" - assert str(attr.values.valueType) == "?" - assert bool(attr.values.isOptional.value) is False - assert str(attr.values.baseAttr) == "?" - assert str(attr.values.cppNamespace) == "test" - assert str(attr.values.dialect) == "Test_Dialect" - assert str(attr.values.cppBaseClassName.value) == "::mlir::Attribute" - assert str(attr.values.storageClass) == "TestAttrStorage" - assert str(attr.values.storageNamespace) == "detail" - assert bool(attr.values.genStorageClass.value) is True - assert bool(attr.values.hasStorageCustomConstructor.value) is False - assert str(attr.values.parameters) == "(ins)" - assert str(attr.values.builders) == "?" - assert len(attr.values.traits.value) == 0 - assert str(attr.values.mnemonic) == "test" - assert str(attr.values.assemblyFormat) == "?" - assert bool(attr.values.hasCustomAssemblyFormat.value) is False - assert bool(attr.values.genAccessors.value) is True - assert bool(attr.values.skipDefaultBuilders.value) is False - assert bool(attr.values.genVerifyDecl.value) is False - assert str(attr.values.cppClassName) == "TestAttr" - assert str(attr.values.cppType) == "test::TestAttr" - assert str(attr.values.attrName) == "test.test" + assert str(attr.get_values().constBuilderCall) == "?" + assert str(attr.get_values().defaultValue) == "?" + assert str(attr.get_values().valueType) == "?" + assert bool(attr.get_values().isOptional.get_value()) is False + assert str(attr.get_values().baseAttr) == "?" + assert str(attr.get_values().cppNamespace) == "test" + assert str(attr.get_values().dialect) == "Test_Dialect" + assert str(attr.get_values().cppBaseClassName.get_value()) == "::mlir::Attribute" + assert str(attr.get_values().storageClass) == "TestAttrStorage" + assert str(attr.get_values().storageNamespace) == "detail" + assert bool(attr.get_values().genStorageClass.get_value()) is True + assert bool(attr.get_values().hasStorageCustomConstructor.get_value()) is False + assert str(attr.get_values().parameters) == "(ins)" + assert str(attr.get_values().builders) == "?" + assert len(attr.get_values().traits.get_value()) == 0 + assert str(attr.get_values().mnemonic) == "test" + assert str(attr.get_values().assemblyFormat) == "?" + assert bool(attr.get_values().hasCustomAssemblyFormat.get_value()) is False + assert bool(attr.get_values().genAccessors.get_value()) is True + assert bool(attr.get_values().skipDefaultBuilders.get_value()) is False + assert bool(attr.get_values().genVerifyDecl.get_value()) is False + assert str(attr.get_values().cppClassName) == "TestAttr" + assert str(attr.get_values().cppType) == "test::TestAttr" + assert str(attr.get_values().attrName) == "test.test" + + +def test_mlir_tblgen(record_keeper_test_dialect): + for op in get_requested_op_definitions(record_keeper_test_dialect): + op.dump()