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.

autogen.cpp 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * \file imperative/tablegen/autogen.cpp
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. */
  11. #include "./targets/cpp_class.h"
  12. #include "./targets/macros.h"
  13. #include "./targets/pybind11.h"
  14. #include "./targets/python_c_extension.h"
  15. using llvm::raw_ostream;
  16. using llvm::RecordKeeper;
  17. enum ActionType { None, CppHeader, CppBody, Pybind, CPython, EnumListMacro };
  18. // NOLINTNEXTLINE
  19. llvm::cl::opt<ActionType> action(
  20. llvm::cl::desc("Action to perform:"),
  21. llvm::cl::values(
  22. clEnumValN(CppHeader, "gen-cpp-header", "Generate operator cpp header"),
  23. clEnumValN(CppBody, "gen-cpp-body", "Generate operator cpp body"),
  24. clEnumValN(
  25. Pybind, "gen-python-binding",
  26. "Generate pybind11 python bindings"),
  27. clEnumValN(
  28. CPython, "gen-python-c-extension",
  29. "Generate python c extensions"),
  30. clEnumValN(
  31. EnumListMacro, "gen-enum-list-macro",
  32. "Generate enum param list macro")));
  33. using namespace mlir::tblgen;
  34. int main(int argc, char** argv) {
  35. llvm::InitLLVM y(argc, argv);
  36. llvm::cl::ParseCommandLineOptions(argc, argv);
  37. if (action == ActionType::CppHeader) {
  38. return TableGenMain(argv[0], &gen_op_def_c_header);
  39. }
  40. if (action == ActionType::CppBody) {
  41. return TableGenMain(argv[0], &gen_op_def_c_body);
  42. }
  43. if (action == ActionType::Pybind) {
  44. return TableGenMain(argv[0], &gen_op_def_pybind11);
  45. }
  46. if (action == ActionType::CPython) {
  47. return TableGenMain(argv[0], &gen_op_def_python_c_extension);
  48. }
  49. if (action == ActionType::EnumListMacro) {
  50. return TableGenMain(argv[0], &gen_enum_param_list_macro);
  51. }
  52. return -1;
  53. }