//===- MLIRGen.cpp - MLIR Generation from a Toy AST -----------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements a simple IR generation targeting MLIR from a Module AST // for the Toy language. // //===----------------------------------------------------------------------===// #include "toy/MLIRGen.h" #include "mlir/IR/Block.h" #include "mlir/IR/Diagnostics.h" #include "mlir/IR/Value.h" #include "toy/AST.h" #include "toy/Dialect.h" #include "mlir/IR/Builders.h" #include "mlir/IR/BuiltinOps.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/IR/MLIRContext.h" #include "mlir/IR/Verifier.h" #include "toy/Lexer.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/ScopedHashTable.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include <cassert> #include <cstdint> #include <functional> #include <numeric> #include <optional> #include <vector> usingnamespacemlir::toy; usingnamespacetoy; ArrayRef; cast; dyn_cast; isa; ScopedHashTableScope; SmallVector; StringRef; Twine; namespace { /// Implementation of a simple MLIR emission from the Toy AST. /// /// This will emit operations that are specific to the Toy language, preserving /// the semantics of the language and (hopefully) allow to perform accurate /// analysis and transformation based on these high level semantics. class MLIRGenImpl { … }; } // namespace namespace toy { // The public API for codegen. mlir::OwningOpRef<mlir::ModuleOp> mlirGen(mlir::MLIRContext &context, ModuleAST &moduleAST) { … } } // namespace toy