diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-19 18:51:48 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-19 18:51:48 -0500 |
| commit | c2d4209f85f46cc91163bc47cc43db252c94acf6 (patch) | |
| tree | 8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/Instructions.cpp | |
| parent | d11fbc8268f5775ad783f8570478daad4a9e81cf (diff) | |
| download | compiler-c2d4209f85f46cc91163bc47cc43db252c94acf6.tar.gz | |
[willow]: more cleanup, tests (#12)
Diffstat (limited to 'willow/lib/IR/Instructions.cpp')
| -rw-r--r-- | willow/lib/IR/Instructions.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
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 <willow/IR/Instructions.h> + +namespace willow { + +UnaryInst::UnaryInst(Opcode op, Type type, Value *value, + std::optional<Location> loc) + : Instruction(op, type, loc) { + addOperand(value); +} + +BinaryInst::BinaryInst(Opcode op, Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) + : Instruction(op, type, loc) { + addOperand(lhs); + addOperand(rhs); +} + +BrInst::BrInst(Type type, Value *condition, BasicBlock *true_target, + BasicBlock *false_target, std::optional<Location> 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<BasicBlock *>(getOperand(1)); +} + +const BasicBlock *BrInst::getTrueTarget() const { + return static_cast<const BasicBlock *>(getOperand(1)); +} + +BasicBlock *BrInst::getFalseTarget() { + return static_cast<BasicBlock *>(getOperand(2)); +} + +const BasicBlock *BrInst::getFalseTarget() const { + return static_cast<const BasicBlock *>(getOperand(2)); +} + +RetInst::RetInst(Type voidty, std::optional<Location> loc) + : Instruction(Opcode::Ret, voidty, loc) {} + +RetInst::RetInst(Type voidty, Value *val, std::optional<Location> loc) + : Instruction(Opcode::Ret, voidty, loc) { + addOperand(val); +} + +PhiInst::PhiInst(Type type, + std::initializer_list<std::pair<BasicBlock *, Value *>> args, + std::optional<Location> loc) + : Instruction(Opcode::Phi, type, loc) { + for (auto [bb, v] : args) { + addOperand(static_cast<Value *>(bb)); + addOperand(v); + } +} + +} // namespace willow |