MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
phase.cpp
Go to the documentation of this file.
1#include "mim/phase/phase.h"
2
3namespace mim {
4
5void Phase::run() {
6 world().verify().ILOG("=== {}: start ===", name());
7 start();
8 world().verify().ILOG("=== {}: done ===", name());
9}
10
12 for (auto def : world().annexes()) rewrite(def);
13 for (auto mut : world().copy_externals()) mut->transfer_external(rewrite(mut)->as_mut());
14}
15
17 for (bool todo = true; todo;) {
18 todo = false;
19 todo |= analyze();
20 }
21
23}
24
26 auto new_world = world().inherit();
27 Rewriter rewriter(new_world);
28
29 for (const auto& [f, def] : world().flags2annex()) new_world.register_annex(f, rewriter.rewrite(def));
30 for (auto mut : world().externals()) {
31 auto new_mut = rewriter.rewrite(mut)->as_mut();
32 new_mut->make_external();
33 }
34
35 swap(world(), new_world);
36}
37
39 for (auto& phase : phases()) phase->run();
40}
41
42} // namespace mim
void start() override
Actual entry.
Definition phase.cpp:25
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
Definition def.h:440
void start() override
Actual entry.
Definition phase.cpp:16
virtual bool analyze()=0
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
Definition phase.cpp:5
std::string_view name() const
Definition phase.h:28
virtual void start()=0
Actual entry.
World & world()
Definition phase.h:27
void start() override
Actual entry.
Definition phase.cpp:38
const auto & phases() const
Definition phase.h:126
World & world()
Definition phase.h:62
void start() override
Actual entry.
Definition phase.cpp:11
Recurseivly rewrites part of a program into the provided World.
Definition rewrite.h:9
virtual Ref rewrite(Ref)
Definition rewrite.cpp:9
World inherit()
Inherits the state into the new World.
Definition world.h:72
World & verify()
Verifies that all externals() and annexes() are Def::is_closed(), if MIM_ENABLE_CHECKS.
Definition world.cpp:563
Definition ast.h:14