25 Rewriter(std::unique_ptr<World>&& ptr);
29 void reset(std::unique_ptr<World>&& ptr);
63 for (
const auto& old2new :
old2news_ | std::views::reverse)
64 if (
auto i = old2new.find(old_def); i != old2new.end())
return i->second;
78#define CODE_IMM(N) virtual const Def* rewrite_imm_##N(const N*);
79#define CODE_MUT(N) virtual const Def* rewrite_mut_##N(N*);
91 swap(rw1.old2news_, rw2.old2news_);
95 template<
class D = Def>
97 return curr_mut_ ? curr_mut_->template isa<D>() :
nullptr;
101 std::unique_ptr<World> ptr_;
103 Def* curr_mut_ =
nullptr;
109 auto enter(
Def* new_mut) {
return fe::Restore(curr_mut_, new_mut); }
128 vars_.emplace_back(
Vars(var));
148 swap(vrw1.vars_, vrw2.vars_);
152 bool has_intersection(
const Def* old_def) {
154 for (
const auto& vars : vars_ | std::views::reverse)
159 fe::Vector<Vars> vars_;
172 const Def*
map(
const Def* old_def,
const Def* new_def)
final;
189 const Def* get(
const Def* old_def) {
191 if (
auto i = old2new.find(old_def); i != old2new.end())
return i->second;
bool has_free_vars_in(Vars) const
Same as vars.has_intersection(free_vars()).
friend void swap(Rewriter &rw1, Rewriter &rw2) noexcept
virtual const Def * rewrite_imm_Seq(const Seq *seq)
virtual const Def * rewrite_mut_Seq(Seq *seq)
virtual const Def * rewrite_mut(Def *)
virtual const Def * rewrite_stub(Def *, Def *)
virtual const Def * map(const Def *old_def, const Def *new_def)
const Def * map_root(const Def *old_def, const Def *new_def)
Like map() but records into the root map, so the entry outlives the current push()/pop() scope.
void reset(std::unique_ptr< World > &&ptr)
std::deque< Def2Def > old2news_
virtual const Def * rewrite_imm(const Def *)
Rewriter(std::unique_ptr< World > &&ptr)
virtual const Def * rewrite(const Def *)
auto enter(Def *new_mut)
Updates curr_mut() to new_mut and restores it at the end of the scope.
virtual const Def * lookup(const Def *old_def)
Lookup old_def by searching in reverse through the stack of maps.
VarRewriter & add(const Var *var, const Def *arg)
const Def * rewrite_mut(Def *) final
VarRewriter(World &world)
friend void swap(VarRewriter &vrw1, VarRewriter &vrw2) noexcept
const Def * rewrite(const Def *) final
VarRewriter(const Var *var, const Def *arg)
A variable introduced by a binder (mutable).
The World represents the whole program and manages creation of MimIR nodes (Defs).
const Def * rewire_mut(Def *)
friend void swap(Zonker &z1, Zonker &z2) noexcept
const Def * lookup(const Def *old_def) final
Lookup old_def by searching in reverse through the stack of maps.
const Def * rewrite(const Def *) final
const Def * map(const Def *old_def, const Def *new_def) final
const Def * rewrite_mut(Def *mut) final
DefMap< const Def * > Def2Def
fe::View< const Def * > Defs
fe::Vector< const Def * > DefVec
fe::Patricia< const Var, DefKey >::Set Vars