4 #include <unordered_map>
6 #include "tir/Constant.h"
7 #include "tir/Context.h"
8 #include "utils/Generator.h"
29 auto* buf = ctx_.alloc().allocate_bytes(
sizeof(Function),
alignof(Function));
30 auto* func =
new(buf) Function{ctx_,
this, type, name};
31 globals_.emplace(name, func);
44 auto* buf = ctx_.alloc().allocate_bytes(
sizeof(GlobalVariable),
45 alignof(GlobalVariable));
46 auto* gv =
new(buf) GlobalVariable{ctx_, type};
47 globals_.emplace(name, gv);
58 auto it = globals_.find(std::string{name});
59 if(it == globals_.end())
return nullptr;
61 return dyn_cast<Function>(go);
71 auto it = globals_.find(std::string{name});
72 if(it == globals_.end())
return nullptr;
74 return dyn_cast<GlobalVariable>(go);
78 std::ostream& print(std::ostream& os)
const;
83 for(
auto& [name, func] : globals_) {
84 if(
auto* f = dyn_cast<Function>(func))
co_yield f;
90 for(
auto& [name, go] : globals_)
co_yield go;
96 for(
auto& [name, go] : globals_)
co_yield std::pair{name, go};
100 auto&
ctx() {
return ctx_; }
104 for(
auto& [name, go] : globals_) {
105 if(
auto* gv = dyn_cast<GlobalVariable>(go))
co_yield gv;
114 Function* builtinException() {
return findFunction("__exception"); }
118 std::pmr::unordered_map<std::string, GlobalObject*> globals_;