2020-05-05 08:48:02 +08:00
|
|
|
//===- BasicPyDialect.h - Basic Python --------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-06-10 10:22:24 +08:00
|
|
|
#ifndef NPCOMP_DIALECT_BASICPY_IR_BASICPY_DIALECT_H
|
|
|
|
#define NPCOMP_DIALECT_BASICPY_IR_BASICPY_DIALECT_H
|
2020-05-05 08:48:02 +08:00
|
|
|
|
2020-05-06 09:16:01 +08:00
|
|
|
#include "mlir/IR/Attributes.h"
|
2020-05-05 08:48:02 +08:00
|
|
|
#include "mlir/IR/Dialect.h"
|
2020-05-06 09:16:01 +08:00
|
|
|
#include "mlir/IR/Types.h"
|
2020-07-05 07:40:02 +08:00
|
|
|
#include "npcomp/Typing/Analysis/CPA/Interfaces.h"
|
2020-05-05 08:48:02 +08:00
|
|
|
|
|
|
|
namespace mlir {
|
|
|
|
namespace NPCOMP {
|
|
|
|
namespace Basicpy {
|
|
|
|
|
2020-05-06 09:16:01 +08:00
|
|
|
namespace detail {
|
|
|
|
struct SlotObjectTypeStorage;
|
|
|
|
} // namespace detail
|
|
|
|
|
2020-06-08 06:15:19 +08:00
|
|
|
/// Python 'bool' type (can contain values True or False, corresponding to
|
|
|
|
/// i1 constants of 0 or 1).
|
2020-07-03 02:24:05 +08:00
|
|
|
class BoolType : public Type::TypeBase<BoolType, Type, TypeStorage> {
|
2020-06-08 06:15:19 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-08-28 06:09:10 +08:00
|
|
|
static BoolType get(MLIRContext *context) { return Base::get(context); }
|
2020-06-08 06:15:19 +08:00
|
|
|
};
|
|
|
|
|
2020-06-08 07:00:29 +08:00
|
|
|
/// The type of the Python `bytes` values.
|
2020-07-03 02:24:05 +08:00
|
|
|
class BytesType : public Type::TypeBase<BytesType, Type, TypeStorage> {
|
2020-06-08 07:00:29 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-08-28 06:09:10 +08:00
|
|
|
static BytesType get(MLIRContext *context) { return Base::get(context); }
|
2020-06-08 07:00:29 +08:00
|
|
|
};
|
|
|
|
|
2020-10-17 08:38:07 +08:00
|
|
|
/// Python 'dict' type.
|
|
|
|
class DictType : public Type::TypeBase<DictType, Type, TypeStorage> {
|
|
|
|
public:
|
|
|
|
using Base::Base;
|
|
|
|
static DictType get(MLIRContext *context) { return Base::get(context); }
|
|
|
|
};
|
|
|
|
|
2020-05-06 09:16:01 +08:00
|
|
|
/// The type of the Python `Ellipsis` value.
|
2020-07-03 02:24:05 +08:00
|
|
|
class EllipsisType : public Type::TypeBase<EllipsisType, Type, TypeStorage> {
|
2020-05-06 09:16:01 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-08-28 06:09:10 +08:00
|
|
|
static EllipsisType get(MLIRContext *context) { return Base::get(context); }
|
2020-05-06 09:16:01 +08:00
|
|
|
};
|
|
|
|
|
2020-10-17 08:38:07 +08:00
|
|
|
/// Python 'list' type.
|
|
|
|
class ListType : public Type::TypeBase<ListType, Type, TypeStorage> {
|
|
|
|
public:
|
|
|
|
using Base::Base;
|
|
|
|
static ListType get(MLIRContext *context) { return Base::get(context); }
|
|
|
|
};
|
|
|
|
|
2020-06-08 06:46:28 +08:00
|
|
|
/// The type of the Python `None` value.
|
2020-07-03 02:24:05 +08:00
|
|
|
class NoneType : public Type::TypeBase<NoneType, Type, TypeStorage> {
|
2020-06-08 06:46:28 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-08-28 06:09:10 +08:00
|
|
|
static NoneType get(MLIRContext *context) { return Base::get(context); }
|
2020-06-08 06:46:28 +08:00
|
|
|
};
|
|
|
|
|
2020-05-06 09:16:01 +08:00
|
|
|
class SlotObjectType : public Type::TypeBase<SlotObjectType, Type,
|
|
|
|
detail::SlotObjectTypeStorage> {
|
|
|
|
public:
|
|
|
|
using Base::Base;
|
|
|
|
static SlotObjectType get(StringAttr className, ArrayRef<Type> slotTypes);
|
|
|
|
StringAttr getClassName();
|
|
|
|
unsigned getSlotCount();
|
|
|
|
ArrayRef<Type> getSlotTypes();
|
2020-05-09 07:04:58 +08:00
|
|
|
|
|
|
|
// Shorthand to check whether the SlotObject is of a given className and
|
|
|
|
// arity.
|
2020-06-04 11:37:09 +08:00
|
|
|
bool isOfClassArity(StringRef className, unsigned arity) {
|
2020-05-09 07:04:58 +08:00
|
|
|
return getClassName().getValue() == className && getSlotCount() == arity;
|
|
|
|
}
|
2020-05-06 09:16:01 +08:00
|
|
|
};
|
|
|
|
|
2020-06-08 06:46:28 +08:00
|
|
|
/// The type of the Python `str` values.
|
2020-07-03 02:24:05 +08:00
|
|
|
class StrType : public Type::TypeBase<StrType, Type, TypeStorage> {
|
2020-06-08 06:46:28 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-08-28 06:09:10 +08:00
|
|
|
static StrType get(MLIRContext *context) { return Base::get(context); }
|
2020-06-08 06:46:28 +08:00
|
|
|
};
|
|
|
|
|
2020-10-17 08:38:07 +08:00
|
|
|
/// Python 'tuple' type.
|
|
|
|
class TupleType : public Type::TypeBase<TupleType, Type, TypeStorage> {
|
|
|
|
public:
|
|
|
|
using Base::Base;
|
|
|
|
static TupleType get(MLIRContext *context) { return Base::get(context); }
|
|
|
|
};
|
|
|
|
|
2020-06-08 06:46:28 +08:00
|
|
|
/// An unknown type that could be any supported python type.
|
2020-07-04 09:16:34 +08:00
|
|
|
class UnknownType : public Type::TypeBase<UnknownType, Type, TypeStorage,
|
|
|
|
NPCOMPTypingTypeMapInterface::Trait> {
|
2020-06-08 06:46:28 +08:00
|
|
|
public:
|
|
|
|
using Base::Base;
|
2020-08-28 06:09:10 +08:00
|
|
|
static UnknownType get(MLIRContext *context) { return Base::get(context); }
|
2020-07-03 04:56:27 +08:00
|
|
|
|
2020-07-04 04:29:52 +08:00
|
|
|
Typing::CPA::TypeNode *mapToCPAType(Typing::CPA::Context &context);
|
2020-06-08 06:46:28 +08:00
|
|
|
};
|
|
|
|
|
2020-05-05 08:48:02 +08:00
|
|
|
} // namespace Basicpy
|
|
|
|
} // namespace NPCOMP
|
|
|
|
} // namespace mlir
|
|
|
|
|
2020-09-17 06:52:15 +08:00
|
|
|
#include "npcomp/Dialect/Basicpy/IR/BasicpyOpsDialect.h.inc"
|
|
|
|
|
2020-06-10 10:22:24 +08:00
|
|
|
#endif // NPCOMP_DIALECT_BASICPY_IR_BASICPY_DIALECT_H
|