xref: /llvm-project/mlir/examples/toy/Ch2/include/toy/MLIRGen.h (revision 8f66ab1c2e00ca3e94dbdd2e435fbf0fe28bbee9)
1 //===- MLIRGen.h - MLIR Generation from a Toy AST -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares a simple interface to perform IR generation targeting MLIR
10 // from a Module AST for the Toy language.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef TOY_MLIRGEN_H
15 #define TOY_MLIRGEN_H
16 
17 #include <memory>
18 
19 namespace mlir {
20 class MLIRContext;
21 template <typename OpTy>
22 class OwningOpRef;
23 class ModuleOp;
24 } // namespace mlir
25 
26 namespace toy {
27 class ModuleAST;
28 
29 /// Emit IR for the given Toy moduleAST, returns a newly created MLIR module
30 /// or nullptr on failure.
31 mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context,
32                                           ModuleAST &moduleAST);
33 } // namespace toy
34 
35 #endif // TOY_MLIRGEN_H
36