MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
core.cpp
Go to the documentation of this file.
2
3#include <mim/config.h>
4#include <mim/pass.h>
5
6using namespace mim;
7using namespace mim::plug;
8
9extern "C" MIM_EXPORT Plugin mim_get_plugin() { return {"core", MIM_VERSION, core::register_normalizers, nullptr}; }
10
11namespace mim::plug::core {
12
13template<bool up>
14const Sigma* convert(const TBound<up>* b) {
15 auto& w = b->world();
16
17 if constexpr (up) {
18 nat_t align = 0;
19 nat_t size = 0;
20
21 for (auto op : b->ops()) {
22 auto a = Lit::isa(w.call(trait::align, op));
23 auto s = Lit::isa(w.call(trait::size, op));
24 if (!a || !s) return nullptr;
25
26 align = std::max(align, *a);
27 size = std::max(size, *s);
28 }
29
30 assert(size % align == 0);
31 auto arr = w.arr(size / align, w.type_int(align * 8_u64));
32
33 return w.sigma({w.type_idx(b->num_ops()), arr})->template as<Sigma>();
34 } else {
35 return w.sigma(b->ops())->template as<Sigma>();
36 }
37}
38
39#ifndef DOXYGEN
40template const Sigma* convert(const TBound<false>*);
41template const Sigma* convert(const TBound<true>*);
42#endif
43
44} // namespace mim::plug::core
World & world() const noexcept
Definition def.cpp:444
constexpr auto ops() const noexcept
Definition def.h:301
constexpr size_t num_ops() const noexcept
Definition def.h:305
static std::optional< T > isa(const Def *def)
Definition def.h:838
A dependent tuple type.
Definition tuple.h:20
Specific Bound depending on Up.
Definition lattice.h:34
#define MIM_EXPORT
Definition config.h:19
The core Plugin
Definition core.h:8
const Sigma * convert(const TBound< up > *b)
Definition core.cpp:14
const Def * op(trait o, const Def *type)
Definition core.h:35
void register_normalizers(Normalizers &normalizers)
Definition ast.h:14
u64 nat_t
Definition types.h:37
mim::Plugin mim_get_plugin()
#define MIM_VERSION
Definition plugin.h:54
Basic info and registration function pointer to be returned from a specific plugin.
Definition plugin.h:59