#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(Type type, Value *lhs, Value *rhs, std::optional loc) { auto *inst = new AndInst{type, lhs, rhs, loc}; insert_point->insertAfter(*inst); insert_point++; return inst; } OrInst *IRBuilder::buildOr(Type type, Value *lhs, Value *rhs, std::optional loc) { auto *inst = new OrInst{type, lhs, rhs, loc}; insert_point->insertAfter(*inst); insert_point++; return inst; } NotInst *IRBuilder::buildNot(Type type, Value *val, std::optional loc) { auto *inst = new NotInst{type, 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