diff options
| author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2026-02-03 14:59:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 14:59:53 -0500 |
| commit | add95b14f74e6dbe04a6efe98ff0f20424930b73 (patch) | |
| tree | 13ce413ee4190a4c8f8743c7740aaa8d04353f14 /willow/lib | |
| parent | c5b2905c5a64433f8519531a77d3acc42d881f17 (diff) | |
| download | compiler-add95b14f74e6dbe04a6efe98ff0f20424930b73.tar.gz | |
[willow]: initial frontend work, unit tests (#8)dev/stefan
Diffstat (limited to 'willow/lib')
| -rw-r--r-- | willow/lib/IR/Instruction.cpp | 18 | ||||
| -rw-r--r-- | willow/lib/IR/Value.cpp | 27 |
2 files changed, 43 insertions, 2 deletions
diff --git a/willow/lib/IR/Instruction.cpp b/willow/lib/IR/Instruction.cpp index 587736d..a6e0c9b 100644 --- a/willow/lib/IR/Instruction.cpp +++ b/willow/lib/IR/Instruction.cpp @@ -1,4 +1,5 @@ #include <willow/IR/Instruction.h> +#include <willow/IR/Instructions.h> namespace willow { @@ -33,6 +34,19 @@ bool Instruction::isTerminatorOp(Opcode op) { } } -Successors Instruction::succs(); - +Successors Instruction::succs() { + using enum Opcode; + switch (op) { + case Jmp: { + auto inst = static_cast<JmpInst *>(this); + return Successors{inst->getTarget()}; + } + case Br: { + auto inst = static_cast<BrInst *>(this); + return Successors{inst->getTrueTarget(), inst->getFalseTarget()}; + } + default: + return Successors{}; + } +} }; // namespace willow diff --git a/willow/lib/IR/Value.cpp b/willow/lib/IR/Value.cpp new file mode 100644 index 0000000..13e029f --- /dev/null +++ b/willow/lib/IR/Value.cpp @@ -0,0 +1,27 @@ +#include <willow/IR/Value.h> +#include <willow/IR/Constant.h> +#include <ostream> + +std::ostream &operator<<(std::ostream &os, const willow::Value &v) { + using willow::ValueKind; + auto ty = v.getType(); + if (!v.isVoid()) + os << ty << " "; + + switch (v.getValueKind()) { + case ValueKind::Parameter: + [[fallthrough]]; + case ValueKind::Instruction: { + return os << "%" << v.getName(); + } + case ValueKind::BasicBlock: { + return os << "^" << v.getName(); + } + case ValueKind::Function: { + return os << "@" << v.getName(); + } + case ValueKind::Constant: { + return os << *static_cast<const willow::Constant*>(&v); + } + } +} |