You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

macros.cpp 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "./macros.h"
  2. #include "../emitter.h"
  3. #include "./cpp_class.h"
  4. namespace mlir::tblgen {
  5. bool gen_enum_param_list_macro(raw_ostream& os, llvm::RecordKeeper& keeper) {
  6. std::vector<std::pair<std::string, std::string>> enums;
  7. std::vector<std::pair<std::string, std::string>> bit_enums;
  8. Environment env;
  9. foreach_operator(keeper, [&](MgbOp& op) {
  10. for (auto&& i : op.getAttributes()) {
  11. if (auto attr = llvm::dyn_cast<MgbEnumAttr>(&i.attr)) {
  12. auto insert = [&](const MgbEnumAttr& attr) {
  13. auto&& item = std::make_pair(
  14. attr.getParentNamespace(), attr.getEnumName());
  15. if (env.enumAlias
  16. .emplace(attr.getBaseRecord()->getID(), std::move(item))
  17. .second) {
  18. if (attr.getEnumCombinedFlag()) {
  19. bit_enums.emplace_back(item);
  20. } else {
  21. enums.emplace_back(item);
  22. }
  23. }
  24. };
  25. if (auto alias = llvm::dyn_cast<MgbAliasAttr>(attr)) {
  26. auto&& aliasBase = alias->getAliasBase();
  27. insert(llvm::cast<MgbEnumAttr>(aliasBase));
  28. } else {
  29. insert(*attr);
  30. }
  31. }
  32. }
  33. });
  34. os << "#define FOR_EACH_ENUM_PARAM(cb)";
  35. for (auto&& i : enums) {
  36. os << formatv(" \\\n cb({0}::{1});", i.first, i.second);
  37. }
  38. os << "\n";
  39. os << "#define FOR_EACH_BIT_COMBINED_ENUM_PARAM(cb)";
  40. for (auto&& i : bit_enums) {
  41. os << formatv(" \\\n cb({0}::{1});", i.first, i.second);
  42. }
  43. os << "\n";
  44. return false;
  45. }
  46. } // namespace mlir::tblgen