// 保存函数列表并提供模块级上下文访问。 #include "ir/IR.h" namespace ir { Context& Module::GetContext() { return context_; } const Context& Module::GetContext() const { return context_; } Function* Module::CreateFunction(const std::string& name, std::shared_ptr ret_type) { auto func_ty = Type::GetFunctionType(std::move(ret_type), {}); functions_.push_back(std::make_unique(name, std::move(func_ty))); return functions_.back().get(); } Function* Module::CreateFunctionWithType(const std::string& name, std::shared_ptr func_type) { functions_.push_back( std::make_unique(name, std::move(func_type), false)); return functions_.back().get(); } Function* Module::CreateFunctionDecl(const std::string& name, std::shared_ptr func_type) { functions_.push_back( std::make_unique(name, std::move(func_type), true)); return functions_.back().get(); } GlobalVariable* Module::CreateGlobalVariable(const std::string& name, std::shared_ptr value_type, ConstantValue* init, bool is_const) { globals_.push_back(std::make_unique( std::move(value_type), name, init, is_const)); return globals_.back().get(); } const std::vector>& Module::GetFunctions() const { return functions_; } const std::vector>& Module::GetGlobals() const { return globals_; } } // namespace ir