#include "ir/IR.h" #include namespace ir { Context::~Context() = default; ConstantInt* Context::GetConstInt(int v) { auto it = const_ints_.find(v); if (it != const_ints_.end()) { return it->second.get(); } auto inserted = const_ints_.emplace( v, std::make_unique(Type::GetInt32Type(), v)); return inserted.first->second.get(); } ConstantI1* Context::GetConstBool(bool v) { auto it = const_bools_.find(v); if (it != const_bools_.end()) { return it->second.get(); } auto inserted = const_bools_.emplace( v, std::make_unique(Type::GetInt1Type(), v)); return inserted.first->second.get(); } std::string Context::NextTemp() { std::ostringstream oss; oss << "%t" << ++temp_index_; return oss.str(); } std::string Context::NextBlockName(const std::string& prefix) { std::ostringstream oss; oss << prefix << "." << ++block_index_; return oss.str(); } } // namespace ir