2020-05-05 08:48:02 +08:00
|
|
|
//===- BasicPyDialect.td - Basic python dialect ------------*- tablegen -*-===//
|
|
|
|
//
|
|
|
|
// This file is licensed 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT
|
|
|
|
#define NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT
|
|
|
|
|
|
|
|
include "mlir/IR/OpBase.td"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dialect definition
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
def Basicpy_Dialect : Dialect {
|
|
|
|
let name = "basicpy";
|
|
|
|
let summary = "Basic Python dialect";
|
|
|
|
let description = [{
|
|
|
|
Core types and ops
|
|
|
|
}];
|
|
|
|
let cppNamespace = "Basicpy";
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Op templates
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
class Basicpy_Op<string mnemonic, list<OpTrait> traits = []> :
|
|
|
|
Op<Basicpy_Dialect, mnemonic, traits> {
|
|
|
|
let parser = [{ return parse$cppClass(parser, &result); }];
|
|
|
|
let printer = [{ return print$cppClass(p, *this); }];
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Dialect types
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-05-06 09:16:01 +08:00
|
|
|
def Basicpy_SlotObjectType : DialectType<Basicpy_Dialect,
|
|
|
|
CPred<"$_self.isa<::mlir::NPCOMP::Basicpy::SlotObjectType>()">,
|
|
|
|
"Slot object"> {
|
|
|
|
let typeDescription = [{
|
|
|
|
Type for built-in objects which have a fixed number of slots and a type
|
|
|
|
name in the system catalog of types. In some ways, this resembles a
|
|
|
|
namedtuple, but it is used for built-in custom objects.
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
def Basicpy_NoneType : DialectType<Basicpy_Dialect,
|
|
|
|
CPred<"$_self.isa<::mlir::NPCOMP::Basicpy::NoneType>()">, "None type">,
|
|
|
|
BuildableType<"$_builder.getType<::mlir::NPCOMP::Basicpy::NoneType>()"> {
|
|
|
|
let typeDescription = [{
|
|
|
|
Type of the Python 'None' value.
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
def Basicpy_EllipsisType : DialectType<Basicpy_Dialect,
|
|
|
|
CPred<"$_self.isa<::mlir::NPCOMP::Basicpy::EllipsisType>()">, "Ellipsis type">,
|
|
|
|
BuildableType<"$_builder.getType<::mlir::NPCOMP::Basicpy::EllipsisType>()"> {
|
|
|
|
let typeDescription = [{
|
|
|
|
Type of the Python 'Ellipsis' value.
|
|
|
|
}];
|
|
|
|
}
|
2020-05-05 08:48:02 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Type predicates
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-05-06 09:16:01 +08:00
|
|
|
def Basicpy_SingletonType : AnyTypeOf<[
|
|
|
|
Basicpy_NoneType,
|
|
|
|
Basicpy_EllipsisType
|
|
|
|
]>;
|
2020-05-05 08:48:02 +08:00
|
|
|
|
2020-05-09 07:04:58 +08:00
|
|
|
// A predicate to determine whether a Type is a SlotObject of a given
|
|
|
|
// className and arity. Does no checking of slot types.
|
|
|
|
class Basicpy_SlotObjectOfClassArity<string className, int arity> :
|
|
|
|
And<[
|
|
|
|
Basicpy_SlotObjectType.predicate,
|
|
|
|
CPred<
|
|
|
|
"$_self.cast<::mlir::NPCOMP::Basicpy::SlotObjectType>().isOfClassArity(\""
|
|
|
|
# className # "\", " # arity # ")">
|
|
|
|
]>;
|
|
|
|
|
|
|
|
// Type representing a 'slice' object, which mirrors the Python built-in
|
|
|
|
// slice class.
|
|
|
|
def Basicpy_SliceSlotObjectType :
|
|
|
|
Type<Basicpy_SlotObjectOfClassArity<"slice", 3>>;
|
|
|
|
|
2020-05-05 08:48:02 +08:00
|
|
|
#endif // NPCOMP_DIALECT_BASICPY_BASICPY_DIALECT
|