forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
// 保存函数列表并提供模块级上下文访问。
|
|
|
|
#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<Type> ret_type) {
|
|
auto func_ty = Type::GetFunctionType(std::move(ret_type), {});
|
|
functions_.push_back(std::make_unique<Function>(name, std::move(func_ty)));
|
|
return functions_.back().get();
|
|
}
|
|
|
|
Function* Module::CreateFunctionWithType(const std::string& name,
|
|
std::shared_ptr<Type> func_type) {
|
|
functions_.push_back(
|
|
std::make_unique<Function>(name, std::move(func_type), false));
|
|
return functions_.back().get();
|
|
}
|
|
|
|
Function* Module::CreateFunctionDecl(const std::string& name,
|
|
std::shared_ptr<Type> func_type) {
|
|
functions_.push_back(
|
|
std::make_unique<Function>(name, std::move(func_type), true));
|
|
return functions_.back().get();
|
|
}
|
|
|
|
GlobalVariable* Module::CreateGlobalVariable(const std::string& name,
|
|
std::shared_ptr<Type> value_type,
|
|
ConstantValue* init, bool is_const) {
|
|
globals_.push_back(std::make_unique<GlobalVariable>(
|
|
std::move(value_type), name, init, is_const));
|
|
return globals_.back().get();
|
|
}
|
|
|
|
const std::vector<std::unique_ptr<Function>>& Module::GetFunctions() const {
|
|
return functions_;
|
|
}
|
|
|
|
const std::vector<std::unique_ptr<GlobalVariable>>& Module::GetGlobals() const {
|
|
return globals_;
|
|
}
|
|
|
|
} // namespace ir
|