MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / FunctionCompiler

Method FunctionCompiler

lib/llvm/compiler.cpp:544–581  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

542
543public:
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()) {

Callers

nothing calls this directly

Calls 11

toLLVMTypeFunction · 0.85
toLLVMConstantZeroFunction · 0.85
positionAtEndMethod · 0.80
createLoadMethod · 0.80
getFirstParamMethod · 0.80
createAllocaMethod · 0.80
createStoreMethod · 0.80
getInt64Method · 0.80
getNextParamMethod · 0.80
createFunction · 0.50
getTypeMethod · 0.45

Tested by

no test coverage detected