MCPcopy Index your code
hub / github.com/RustPython/RustPython / build_function

Method build_function

crates/jit/src/lib.rs:57–114  ·  view source on GitHub ↗
(
        &mut self,
        bytecode: &bytecode::CodeObject<C>,
        args: &[JitType],
        ret: Option<JitType>,
    )

Source from the content-addressed store, hash-verified

55 }
56
57 fn build_function<C: bytecode::Constant>(
58 &mut self,
59 bytecode: &bytecode::CodeObject<C>,
60 args: &[JitType],
61 ret: Option<JitType>,
62 ) -> Result<(FuncId, JitSig), JitCompileError> {
63 for arg in args {
64 self.ctx
65 .func
66 .signature
67 .params
68 .push(AbiParam::new(arg.to_cranelift()));
69 }
70
71 if ret.is_some() {
72 self.ctx
73 .func
74 .signature
75 .returns
76 .push(AbiParam::new(ret.clone().unwrap().to_cranelift()));
77 }
78
79 let id = self.module.declare_function(
80 &format!("jit_{}", bytecode.obj_name.as_ref()),
81 Linkage::Export,
82 &self.ctx.func.signature,
83 )?;
84
85 let func_ref = self.module.declare_func_in_func(id, &mut self.ctx.func);
86
87 let mut builder = FunctionBuilder::new(&mut self.ctx.func, &mut self.builder_context);
88 let entry_block = builder.create_block();
89 builder.append_block_params_for_function_params(entry_block);
90 builder.switch_to_block(entry_block);
91
92 let sig = {
93 let mut compiler = FunctionCompiler::new(
94 &mut builder,
95 bytecode.varnames.len(),
96 args,
97 ret,
98 entry_block,
99 );
100
101 compiler.compile(func_ref, bytecode)?;
102
103 compiler.sig
104 };
105
106 builder.seal_all_blocks();
107 builder.finalize();
108
109 self.module.define_function(id, &mut self.ctx)?;
110
111 self.module.clear_context(&mut self.ctx);
112
113 Ok((id, sig))
114 }

Callers 1

compileFunction · 0.45

Calls 9

newFunction · 0.85
to_craneliftMethod · 0.80
switch_to_blockMethod · 0.80
pushMethod · 0.45
unwrapMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45
compileMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected