From c2d4209f85f46cc91163bc47cc43db252c94acf6 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Thu, 19 Feb 2026 18:51:48 -0500 Subject: [willow]: more cleanup, tests (#12) --- willow/lib/IR/Instructions.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 willow/lib/IR/Instructions.cpp (limited to 'willow/lib/IR/Instructions.cpp') diff --git a/willow/lib/IR/Instructions.cpp b/willow/lib/IR/Instructions.cpp new file mode 100644 index 0000000..15e6786 --- /dev/null +++ b/willow/lib/IR/Instructions.cpp @@ -0,0 +1,64 @@ +#include + +namespace willow { + +UnaryInst::UnaryInst(Opcode op, Type type, Value *value, + std::optional loc) + : Instruction(op, type, loc) { + addOperand(value); +} + +BinaryInst::BinaryInst(Opcode op, Type type, Value *lhs, Value *rhs, + std::optional loc) + : Instruction(op, type, loc) { + addOperand(lhs); + addOperand(rhs); +} + +BrInst::BrInst(Type type, Value *condition, BasicBlock *true_target, + BasicBlock *false_target, std::optional loc) + : Instruction(Opcode::Br, type, loc) { + addOperand(condition); + addOperand(true_target); + addOperand(false_target); +} + +Value *BrInst::getCondition() { return getOperand(0); } + +const Value *BrInst::getCondition() const { return getOperand(0); } + +BasicBlock *BrInst::getTrueTarget() { + return static_cast(getOperand(1)); +} + +const BasicBlock *BrInst::getTrueTarget() const { + return static_cast(getOperand(1)); +} + +BasicBlock *BrInst::getFalseTarget() { + return static_cast(getOperand(2)); +} + +const BasicBlock *BrInst::getFalseTarget() const { + return static_cast(getOperand(2)); +} + +RetInst::RetInst(Type voidty, std::optional loc) + : Instruction(Opcode::Ret, voidty, loc) {} + +RetInst::RetInst(Type voidty, Value *val, std::optional loc) + : Instruction(Opcode::Ret, voidty, loc) { + addOperand(val); +} + +PhiInst::PhiInst(Type type, + std::initializer_list> args, + std::optional loc) + : Instruction(Opcode::Phi, type, loc) { + for (auto [bb, v] : args) { + addOperand(static_cast(bb)); + addOperand(v); + } +} + +} // namespace willow -- cgit v1.2.3