feat(furc): introduce function call expression and call instruction

This commit is contained in:
2026-06-28 13:14:46 +02:00
parent 0bcbe1d7d1
commit 7b609f87c9
9 changed files with 220 additions and 6 deletions
@@ -7,6 +7,7 @@
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
@@ -627,6 +628,76 @@ protected:
}
};
/**
* @brief Function call instruction.
*/
class call_instruction final : public instruction {
public:
template <typename NameFwd, typename ArgsFwd>
call_instruction(NameFwd&& name, operand&& dst, ArgsFwd&& args)
: m_name(std::forward<NameFwd>(name)), m_dst(std::move(dst)), m_args(std::forward<ArgsFwd>(args)) {}
~call_instruction() override = default;
call_instruction(call_instruction&&) noexcept = default;
call_instruction& operator=(call_instruction&&) noexcept = default;
call_instruction(const call_instruction&) = delete;
call_instruction& operator=(const call_instruction&) = delete;
public:
/**
* @brief Returns this instruction's type.
*
* @return instruction_t::Call.
*/
instruction_t type() const override { return instruction_t::Call; }
bool has_destination() const override { return true; }
/**
* @brief Returns this instruction's destination register.
*
* @return The register.
*/
operand& destination() override { return m_dst; }
/**
* @brief Returns this instruction's destination register.
*
* @return The register.
*/
const operand& destination() const override { return m_dst; }
std::vector<const operand*> sources() const override {
std::vector<const operand*> srcs;
srcs.reserve(m_args.size());
for (const auto& op : m_args)
srcs.push_back(&op);
return srcs;
}
/**
* @brief Returns this instruction's callee name.
*
* @return The name.
*/
const std::string& name() const { return m_name; }
private:
std::string m_name;
operand m_dst;
std::vector<operand> m_args;
protected:
std::ostream& print(std::ostream& os) const override {
os << "call " << m_name << '(';
bool first = true;
for (const auto& op : m_args) {
if (!first) os << ", ";
first = false;
os << op;
}
return os << ") = " << m_dst;
}
};
} // namespace ir
} // namespace furlang