Getting errors in tablegen generated file

I am getting errors in tablegen generated files when I try to build llvm using ninja. Following are few of theerrors:

In file included from /home/user3/LLVM_MLIR/llvm-project/mlir/lib/Dialect/MyToy/IR/MyToyOps.cpp:13:
tools/mlir/include/mlir/Dialect/MyToy/IR/MyToyOps.cpp.inc:992:18: error: ‘getOperation’ was not declared in this scope; did you mean ‘Operation’?
  992 |   _odsPrinter << getOperation()->getResultTypes();
      |                  ^~~~~~~~~~~~
      |                  Operation

In file included from /home/user3/LLVM_MLIR/llvm-project/mlir/lib/Dialect/MyToy/IR/MyToyOps.cpp:13:
tools/mlir/include/mlir/Dialect/MyToy/IR/MyToyOps.cpp.inc:991:15: error: no match for ‘operator<<’ (operand types are ‘mlir::OpAsmPrinter’ and ‘char’)
  991 |   _odsPrinter << ' ';
      |   ~~~~~~~~~~~ ^~ ~~~
      |   |              |
      |   |              char
      |   mlir::OpAsmPrinter

Why is this happening? Isn’t tablegen supposed to generate correct code?
Kindly help.

You need to include headers such as “mlir/IR/OpImplementation.h” before you include the ODS-generated implementation.

As Alex says, ODS only generates parts but not the whole output (hence more inc.h and inc.cpp files rather than h and cpp). Starting from standalone example (or even with the Toy tutorial) should give a good bootstrap from which to iterate.