feat(furlang): introduce phi instruction

Refs: #2
This commit is contained in:
2026-06-12 09:43:42 +02:00
parent c1b65838b0
commit 3f6fcc56ff
@@ -6,6 +6,8 @@
#include <cstdint> #include <cstdint>
#include <optional> #include <optional>
#include <ostream> #include <ostream>
#include <utility>
#include <vector>
namespace furlang { namespace furlang {
namespace ir { namespace ir {
@@ -21,6 +23,7 @@ enum class instruction_t {
Branch, /**< Branch */ Branch, /**< Branch */
BranchCond, /**< Conditional branch */ BranchCond, /**< Conditional branch */
Return, /**< Return */ Return, /**< Return */
Phi, /**< Phi function */
}; };
/** /**
@@ -458,6 +461,57 @@ protected:
} }
}; };
/**
* @brief Phi instruction
*
* Used to implement the phi node in the SSA graph.
*/
class phi_instruction final : public instruction {
public:
phi_instruction(std::vector<std::pair<operand, block_index>>&& labels)
: m_labels(std::move(labels)) {}
~phi_instruction() override = default;
/**
* @brief Move constructor.
*/
phi_instruction(phi_instruction&&) noexcept = default;
/**
* @brief Move constructor.
*/
phi_instruction& operator=(phi_instruction&&) noexcept = default;
phi_instruction(const phi_instruction&) = delete;
phi_instruction& operator=(const phi_instruction&) = delete;
public:
/**
* @brief Returns this instruction's type.
*
* @return instruction_t::Phi.
*/
instruction_t type() const override { return instruction_t::Phi; }
/**
* @brief Returns this instruction's labels.
*
* @return The labels.
*/
const std::vector<std::pair<operand, block_index>>& labels() const { return m_labels; }
private:
std::vector<std::pair<operand, block_index>> m_labels;
protected:
std::ostream& print(std::ostream& os) const override {
os << "phi";
for (const auto& pair : m_labels) {
os << ' ' << pair.second << ": " << pair.first;
}
return os;
}
};
} // namespace ir } // namespace ir
} // namespace furlang } // namespace furlang