#include namespace willow { AddInst *IRBuilder::BuildAdd(Type type, Value *lhs, Value *rhs, std::optional 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 loc) { auto *inst = new RetInst{ctx.types().VoidType(), val, loc}; insert_point->insertAfter(*inst); insert_point++; return inst; } RetInst *IRBuilder::BuildRet(std::optional 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> args, std::optional loc) { auto *inst = new PhiInst(ty, args, loc); insert_point->insertAfter(*inst); insert_point++; return inst; } AllocaInst *IRBuilder::BuildAlloca(Type ty, std::optional loc) { Type pty = ctx.types().PtrType(ty); auto *inst = new AllocaInst(pty, loc); insert_point->insertAfter(*inst); insert_point++; return inst; } }; // namespace willow