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.

emitter.h 791 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include <stdexcept>
  3. #include <unordered_map>
  4. #include "llvm/ADT/StringRef.h"
  5. #include "llvm/Support/raw_ostream.h"
  6. namespace mlir::tblgen {
  7. using llvm::raw_ostream;
  8. struct Environment {
  9. std::unordered_map<unsigned int, std::pair<llvm::StringRef, llvm::StringRef>>
  10. enumAlias;
  11. };
  12. struct EmitterBase {
  13. EmitterBase(raw_ostream& os_) : os(os_) {}
  14. EmitterBase(raw_ostream& os_, Environment& env) : os(os_), env_p(&env) {}
  15. protected:
  16. void newline() { os << "\n"; }
  17. Environment& env() {
  18. if (env_p) {
  19. return *env_p;
  20. }
  21. throw std::runtime_error(
  22. "access global environment via non-environment emitter");
  23. }
  24. raw_ostream& os;
  25. Environment* env_p = nullptr;
  26. };
  27. } // namespace mlir::tblgen