2021-06-08 22:03:12 +01:00
|
|
|
/* -*- C++ -*-
|
2021-10-12 20:51:03 +01:00
|
|
|
* Serene Programming Language
|
2021-06-08 22:03:12 +01:00
|
|
|
*
|
2022-01-27 11:44:44 +00:00
|
|
|
* Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
2021-06-08 22:03:12 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 2.
|
2021-06-08 22:03:12 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2021-06-08 22:03:12 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-06-08 22:03:12 +01:00
|
|
|
*/
|
|
|
|
#include "serene/slir/dialect.h"
|
|
|
|
|
2021-08-28 18:01:48 +01:00
|
|
|
#include "serene/slir/dialect.cpp.inc"
|
2021-06-08 22:03:12 +01:00
|
|
|
|
2021-09-28 17:11:50 +01:00
|
|
|
#include <mlir/IR/Builders.h>
|
|
|
|
#include <mlir/IR/BuiltinTypes.h>
|
2022-01-18 19:45:30 +00:00
|
|
|
#include <mlir/IR/Dialect.h>
|
|
|
|
#include <mlir/IR/DialectImplementation.h>
|
|
|
|
#include <mlir/IR/MLIRContext.h>
|
2021-09-28 17:11:50 +01:00
|
|
|
|
2021-06-08 22:03:12 +01:00
|
|
|
namespace serene {
|
|
|
|
namespace slir {
|
|
|
|
|
|
|
|
/// Dialect initialization, the instance will be owned by the context. This is
|
|
|
|
/// the point of registration of types and operations for the dialect.
|
|
|
|
void SereneDialect::initialize() {
|
|
|
|
addOperations<
|
|
|
|
#define GET_OP_LIST
|
|
|
|
#include "serene/slir/ops.cpp.inc"
|
|
|
|
>();
|
2022-01-18 19:45:30 +00:00
|
|
|
addTypes<
|
|
|
|
#define GET_TYPEDEF_LIST
|
|
|
|
#include "serene/slir/types.cpp.inc"
|
|
|
|
>();
|
2021-06-08 22:03:12 +01:00
|
|
|
}
|
|
|
|
|
2022-01-18 19:45:30 +00:00
|
|
|
// static SymbolType parseSymbolType(mlir::MLIRContext &ctx,
|
|
|
|
// mlir::AsmParser &parser) {
|
|
|
|
// llvm::SMLoc loc = parser.getCurrentLocation();
|
|
|
|
// if (parser.parseLess()) {
|
|
|
|
// return SymbolType();
|
|
|
|
// }
|
|
|
|
// std::string fqsym;
|
|
|
|
// if(parser.parseString(&fqsym)) {
|
|
|
|
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
|
|
|
|
// /// Parses a type appearing inside another LLVM dialect-compatible type. This
|
|
|
|
// /// will try to parse any type in full form (including types with the `!llvm`
|
|
|
|
// /// prefix), and on failure fall back to parsing the short-hand version of
|
|
|
|
// the
|
|
|
|
// /// LLVM dialect types without the `!llvm` prefix.
|
|
|
|
// static mlir::Type dispatchParse(mlir::AsmParser &parser, bool allowAny =
|
|
|
|
// true) {
|
|
|
|
// llvm::SMLoc keyLoc = parser.getCurrentLocation();
|
|
|
|
|
|
|
|
// // Try parsing any MLIR type.
|
|
|
|
// mlir::Type type;
|
|
|
|
// mlir::OptionalParseResult result = parser.parseOptionalType(type);
|
|
|
|
|
|
|
|
// if (result.hasValue()) {
|
|
|
|
// if (failed(result.getValue())) {
|
|
|
|
// return nullptr;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!allowAny) {
|
|
|
|
// parser.emitError(keyLoc) << "unexpected type, expected keyword";
|
|
|
|
// return nullptr;
|
|
|
|
// }
|
|
|
|
// return type;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// // If no type found, fallback to the shorthand form.
|
|
|
|
// llvm::StringRef key;
|
|
|
|
|
|
|
|
// if (failed(parser.parseKeyword(&key))) {
|
|
|
|
// return mlir::Type();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// mlir::MLIRContext *ctx = parser.getContext();
|
|
|
|
// return mlir::StringSwitch<mlir::function_ref<mlir::Type()>>(key)
|
|
|
|
// .Case("symbol", [&] { return parseSymbolType(ctx, parser); })
|
|
|
|
// .Default([&] {
|
|
|
|
// parser.emitError(keyLoc) << "unknown LLVM type: " << key;
|
|
|
|
// return mlir::Type();
|
|
|
|
// })();
|
|
|
|
// }
|
|
|
|
// //.Case("struct", [&] { return parseStructType(parser); })
|
|
|
|
// /// Parse an instance of a type registered to the dialect.
|
|
|
|
// mlir::Type SereneDialect::parseType(mlir::DialectAsmParser &parser) const {
|
|
|
|
// llvm::SMLoc loc = parser.getCurrentLocation();
|
|
|
|
// mlir::Type type = dispatchParse(parser, /*allowAny=*/false);
|
|
|
|
// if (!type) {
|
|
|
|
// return type;
|
|
|
|
// }
|
|
|
|
// if (!isCompatibleOuterType(type)) {
|
|
|
|
// parser.emitError(loc) << "unexpected type, expected keyword";
|
|
|
|
// return nullptr;
|
|
|
|
// }
|
|
|
|
// return type;
|
|
|
|
// };
|
|
|
|
|
|
|
|
// // /// Print an instance of a type registered to the dialect.
|
|
|
|
// void SereneDialect::printType(
|
|
|
|
// mlir::Type type, mlir::DialectAsmPrinter &printer) const override{};
|
|
|
|
|
2021-06-08 22:03:12 +01:00
|
|
|
} // namespace slir
|
|
|
|
} // namespace serene
|
2022-01-18 19:45:30 +00:00
|
|
|
#define GET_TYPEDEF_CLASSES
|
|
|
|
#include "serene/slir/types.cpp.inc"
|
2021-06-08 22:03:12 +01:00
|
|
|
|
|
|
|
#define GET_OP_CLASSES
|
|
|
|
#include "serene/slir/ops.cpp.inc"
|