Add Python extension IR structs

pull/335/head
A. R. Shajii 2023-02-09 11:11:51 -05:00
parent c08a2d7d17
commit 252f8c2c0d
2 changed files with 124 additions and 0 deletions

View File

@ -181,6 +181,7 @@ set(CODON_HPPFILES
codon/cir/llvm/llvm.h
codon/cir/llvm/optimize.h
codon/cir/module.h
codon/cir/pyextension.h
codon/cir/cir.h
codon/cir/transform/cleanup/canonical.h
codon/cir/transform/cleanup/dead_code.h

View File

@ -0,0 +1,123 @@
// Copyright (C) 2022-2023 Exaloop Inc. <https://exaloop.io>
#pragma once
#include <string>
#include <vector>
#include "codon/cir/func.h"
#include "codon/cir/types/types.h"
namespace codon {
namespace ir {
struct PyFunction {
enum Type { TOPLEVEL, METHOD, CLASS, STATIC };
std::string name;
std::string doc;
Func *func = nullptr;
Type type = Type::TOPLEVEL;
};
struct PyMember {
enum Type {
SHORT,
INT,
LONG,
FLOAT,
DOUBLE,
STRING,
OBJECT,
OBJECT_EX,
CHAR,
BYTE,
UBYTE,
UINT,
USHORT,
ULONG,
BOOL,
LONGLONG,
ULONGLONG,
PYSSIZET
};
std::string name;
std::string doc;
Type type = Type::SHORT;
bool readonly = false;
};
struct PyGetSet {
std::string name;
std::string doc;
Func *get = nullptr;
Func *set = nullptr;
};
struct PyType {
std::string name;
std::string doc;
types::Type *type = nullptr;
PyType *base = nullptr;
Func *repr = nullptr;
Func *add = nullptr;
Func *iadd = nullptr;
Func *sub = nullptr;
Func *isub = nullptr;
Func *mul = nullptr;
Func *imul = nullptr;
Func *mod = nullptr;
Func *imod = nullptr;
Func *divmod = nullptr;
Func *pow = nullptr;
Func *ipow = nullptr;
Func *neg = nullptr;
Func *pos = nullptr;
Func *abs = nullptr;
Func *bool_ = nullptr;
Func *invert = nullptr;
Func *lshift = nullptr;
Func *ilshift = nullptr;
Func *rshift = nullptr;
Func *irshift = nullptr;
Func *and_ = nullptr;
Func *iand = nullptr;
Func *xor_ = nullptr;
Func *ixor = nullptr;
Func *or_ = nullptr;
Func *ior = nullptr;
Func *int_ = nullptr;
Func *float_ = nullptr;
Func *floordiv = nullptr;
Func *ifloordiv = nullptr;
Func *truediv = nullptr;
Func *itruediv = nullptr;
Func *index = nullptr;
Func *matmul = nullptr;
Func *imatmul = nullptr;
Func *len = nullptr;
Func *getitem = nullptr;
Func *setitem = nullptr;
Func *contains = nullptr;
Func *hash = nullptr;
Func *call = nullptr;
Func *str = nullptr;
Func *cmp = nullptr;
Func *iter = nullptr;
Func *del = nullptr;
Func *new_ = nullptr;
Func *init = nullptr;
std::vector<PyFunction> methods;
std::vector<PyMember> members;
std::vector<PyGetSet> getset;
};
struct PyModule {
std::string name;
std::string doc;
std::vector<PyFunction> functions;
std::vector<PyType> types;
};
} // namespace ir
} // namespace codon