| 542 | |
| 543 | public: |
| 544 | FunctionCompiler(LLVM::Compiler::CompileContext &Context, |
| 545 | LLVM::FunctionCallee F, Span<const ValType> Locals, |
| 546 | bool Interruptible, bool InstructionCounting, |
| 547 | bool GasMeasuring) noexcept |
| 548 | : Context(Context), LLContext(Context.LLContext), |
| 549 | Interruptible(Interruptible), F(F), Builder(LLContext) { |
| 550 | if (F.Fn) { |
| 551 | Builder.positionAtEnd(LLVM::BasicBlock::create(LLContext, F.Fn, "entry")); |
| 552 | ExecCtx = Builder.createLoad(Context.ExecCtxTy, F.Fn.getFirstParam()); |
| 553 | |
| 554 | if (InstructionCounting) { |
| 555 | LocalInstrCount = Builder.createAlloca(Context.Int64Ty); |
| 556 | Builder.createStore(LLContext.getInt64(0), LocalInstrCount); |
| 557 | } |
| 558 | |
| 559 | if (GasMeasuring) { |
| 560 | LocalGas = Builder.createAlloca(Context.Int64Ty); |
| 561 | Builder.createStore(LLContext.getInt64(0), LocalGas); |
| 562 | } |
| 563 | |
| 564 | for (LLVM::Value Arg = F.Fn.getFirstParam().getNextParam(); Arg; |
| 565 | Arg = Arg.getNextParam()) { |
| 566 | LLVM::Type Ty = Arg.getType(); |
| 567 | LLVM::Value ArgPtr = Builder.createAlloca(Ty); |
| 568 | Builder.createStore(Arg, ArgPtr); |
| 569 | Local.emplace_back(Ty, ArgPtr); |
| 570 | } |
| 571 | |
| 572 | for (const auto &Type : Locals) { |
| 573 | LLVM::Type Ty = toLLVMType(LLContext, Type); |
| 574 | LLVM::Value ArgPtr = Builder.createAlloca(Ty); |
| 575 | Builder.createStore( |
| 576 | toLLVMConstantZero(LLContext, Type, Context.CompositeTypes), |
| 577 | ArgPtr); |
| 578 | Local.emplace_back(Ty, ArgPtr); |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | LLVM::BasicBlock getTrapBB(ErrCode::Value Error) noexcept { |
| 584 | if (auto Iter = TrapBB.find(Error); Iter != TrapBB.end()) { |
nothing calls this directly
no test coverage detected