summaryrefslogtreecommitdiff
path: root/willow/lib/IR/Instructions.cpp
diff options
context:
space:
mode:
authorStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:45:44 -0500
committerStefan Weigl-Bosker <stefan@s00.xyz>2026-02-19 18:45:44 -0500
commitaf3d0ad1926eb825f64152cf217fc9a4777f0be3 (patch)
tree8d7f73ce6c3c89863418382d8d553a06c668bbb3 /willow/lib/IR/Instructions.cpp
parentd11fbc8268f5775ad783f8570478daad4a9e81cf (diff)
downloadcompiler-af3d0ad1926eb825f64152cf217fc9a4777f0be3.tar.gz
[willow]: more cleanup, testsmore-tests
Diffstat (limited to 'willow/lib/IR/Instructions.cpp')
-rw-r--r--willow/lib/IR/Instructions.cpp64
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