10template<
class Value,
class Type,
class BB,
class Child>
13 constexpr const Child& child()
const {
return *
static_cast<const Child*
>(
this); }
14 constexpr Child& child() {
return *
static_cast<Child*
>(
this); }
17 Value emit_(
const Def* def) {
19 auto& bb =
lam2bb_[place->mut()->template as<Lam>()];
20 return child().emit_bb(bb, def);
24 fe::Tab
tab = fe::Tab::spaces();
40 assert(child().is_valid(res));
47 if (
auto i =
locals_.find(def); i !=
locals_.end())
return i->second;
49 auto val = emit_(def);
54 if (!
root()->is_set()) {
55 child().emit_imported(
root());
63 if (
auto lam = mut->isa<
Lam>())
lam2bb_.try_emplace(lam, BB());
68 auto fct = child().prepare();
73 for (
auto mut : muts) {
74 if (
auto lam = mut->isa<
Lam>()) {
77 child().emit_epilogue(lam);
83 assert_unused(
lam2bb_.size() == old_size &&
"really make sure we didn't trigger a rehash");
DefMap< std::string > locals_
Value emit(const Def *def)
Recursively emits code.
virtual bool direct_style()
std::ostream & ostream() const
Emitter(World &world, std::string name, std::ostream &ostream, bool schedule=false)
Value emit_unsafe(const Def *def)
As above but returning !child().is_valid(value) is permitted.
DefMap< std::string > globals_
DefMap< std::string > types_
void visit(const Nest &nest) override
static const Lam * isa_basicblock(const Def *d)
const Nest & nest() const
NestPhase(World &world, std::string name, bool elide_empty, bool schedule=false)
Builds a nesting tree for all mutables/binders.
static Schedule schedule(const Nest &)
std::string_view name() const
The World represents the whole program and manages creation of MimIR nodes (Defs).
GIDMap< const Def *, To > DefMap
GIDMap< Lam *, To > LamMap