forked from KPGPMC/furlang
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user