Files
nudt-compiler-cpp/src/ir/Function.cpp
2026-03-11 22:08:27 +08:00

32 lines
769 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// IR Function
// - 保存参数列表、基本块列表
// - 记录函数属性/元信息(按需要扩展)
#include "ir/IR.h"
namespace ir {
Function::Function(std::string name, std::shared_ptr<Type> ret_type)
: Value(std::move(ret_type), std::move(name)) {
entry_ = CreateBlock("entry");
}
BasicBlock* Function::CreateBlock(const std::string& name) {
auto block = std::make_unique<BasicBlock>(name);
auto* ptr = block.get();
blocks_.push_back(std::move(block));
if (!entry_) {
entry_ = ptr;
}
return ptr;
}
BasicBlock* Function::entry() { return entry_; }
const BasicBlock* Function::entry() const { return entry_; }
const std::vector<std::unique_ptr<BasicBlock>>& Function::blocks() const {
return blocks_;
}
} // namespace ir