diff options
Diffstat (limited to 'willow/lib/IR/IRBuilder.cpp')
| -rw-r--r-- | willow/lib/IR/IRBuilder.cpp | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/willow/lib/IR/IRBuilder.cpp b/willow/lib/IR/IRBuilder.cpp new file mode 100644 index 0000000..62e7a98 --- /dev/null +++ b/willow/lib/IR/IRBuilder.cpp @@ -0,0 +1,210 @@ +#include <willow/IR/IRBuilder.h> + +namespace willow { + +AddInst *IRBuilder::BuildAdd(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new AddInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +MulInst *IRBuilder::BuildMul(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new MulInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +SubInst *IRBuilder::BuildSub(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new SubInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +DivInst *IRBuilder::BuildDiv(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new DivInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +ModInst *IRBuilder::BuildMod(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new ModInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +ShlInst *IRBuilder::BuildShl(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new ShlInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +ShrInst *IRBuilder::BuildShr(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new ShrInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +AshlInst *IRBuilder::BuildAshl(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new AshlInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +AshrInst *IRBuilder::BuildAshr(Type type, Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new AshrInst{type, lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +EqInst *IRBuilder::BuildEq(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new EqInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +LtInst *IRBuilder::BuildLt(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new LtInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +GtInst *IRBuilder::BuildGt(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new GtInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +LeInst *IRBuilder::BuildLe(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new LeInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +GeInst *IRBuilder::BuildGe(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new GeInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +AndInst *IRBuilder::BuildAnd(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new AndInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +OrInst *IRBuilder::BuildOr(Value *lhs, Value *rhs, + std::optional<Location> loc) { + auto *inst = new OrInst{ctx.types().IntType(1), lhs, rhs, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +NotInst *IRBuilder::BuildNot(Value *val, std::optional<Location> loc) { + auto *inst = new NotInst{ctx.types().IntType(1), val, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +JmpInst *IRBuilder::BuildJmp(BasicBlock *dst, std::optional<Location> loc) { + + auto *inst = new JmpInst{ctx.types().VoidType(), dst, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +BrInst *IRBuilder::BuildBr(Value *predicate, BasicBlock *truedst, + BasicBlock *falsedst, std::optional<Location> loc) { + auto *inst = + new BrInst{ctx.types().VoidType(), predicate, truedst, falsedst, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +RetInst *IRBuilder::BuildRet(Value *val, std::optional<Location> loc) { + auto *inst = new RetInst{ctx.types().VoidType(), val, loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} +RetInst *IRBuilder::BuildRet(std::optional<Location> loc) { + auto *inst = new RetInst{ctx.types().VoidType(), loc}; + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +PhiInst *IRBuilder::BuildPhi( + Type ty, std::initializer_list<std::pair<BasicBlock *, Value *>> args, + std::optional<Location> loc) { + auto *inst = new PhiInst(ty, args, loc); + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +AllocaInst *IRBuilder::BuildAlloca(Type ty, std::optional<Location> loc) { + Type pty = ctx.types().PtrType(ty); + auto *inst = new AllocaInst(pty, loc); + insert_point->insertAfter(*inst); + insert_point++; + + return inst; +} + +}; // namespace willow |