Generate the FuncIR for a function. This takes the basic blocks and function info of a particular function and returns the IR. If the function is nested, also returns the register containing the instance of the corresponding callable class.
(
builder: IRBuilder,
args: list[Register],
blocks: list[BasicBlock],
sig: FuncSignature,
fn_info: FuncInfo,
cdef: ClassDef | None,
is_singledispatch_main_func: bool = False,
)
| 326 | |
| 327 | |
| 328 | def gen_func_ir( |
| 329 | builder: IRBuilder, |
| 330 | args: list[Register], |
| 331 | blocks: list[BasicBlock], |
| 332 | sig: FuncSignature, |
| 333 | fn_info: FuncInfo, |
| 334 | cdef: ClassDef | None, |
| 335 | is_singledispatch_main_func: bool = False, |
| 336 | ) -> tuple[FuncIR, Value | None]: |
| 337 | """Generate the FuncIR for a function. |
| 338 | |
| 339 | This takes the basic blocks and function info of a particular |
| 340 | function and returns the IR. If the function is nested, |
| 341 | also returns the register containing the instance of the |
| 342 | corresponding callable class. |
| 343 | """ |
| 344 | func_reg: Value | None = None |
| 345 | if fn_info.is_nested or fn_info.in_non_ext: |
| 346 | func_ir = add_call_to_callable_class(builder, args, blocks, sig, fn_info) |
| 347 | add_get_to_callable_class(builder, fn_info) |
| 348 | func_reg = instantiate_callable_class(builder, fn_info) |
| 349 | else: |
| 350 | fitem = fn_info.fitem |
| 351 | assert isinstance(fitem, FuncDef), fitem |
| 352 | func_decl = builder.mapper.func_to_decl[fitem] |
| 353 | if cdef and fn_info.name == FAST_PREFIX + func_decl.name: |
| 354 | # Special-cased version of a method has a separate FuncDecl, use that one. |
| 355 | func_decl = builder.mapper.type_to_ir[cdef.info].method_decls[fn_info.name] |
| 356 | if fn_info.is_decorated or is_singledispatch_main_func: |
| 357 | class_name = None if cdef is None else cdef.name |
| 358 | func_decl = FuncDecl( |
| 359 | fn_info.name, |
| 360 | class_name, |
| 361 | builder.module_name, |
| 362 | sig, |
| 363 | func_decl.kind, |
| 364 | is_prop_getter=func_decl.is_prop_getter, |
| 365 | is_prop_setter=func_decl.is_prop_setter, |
| 366 | is_generator=func_decl.is_generator, |
| 367 | is_coroutine=func_decl.is_coroutine, |
| 368 | implicit=func_decl.implicit, |
| 369 | internal=func_decl.internal, |
| 370 | ) |
| 371 | func_ir = FuncIR(func_decl, args, blocks, fitem.line, traceback_name=fitem.name) |
| 372 | else: |
| 373 | func_ir = FuncIR(func_decl, args, blocks, fitem.line, traceback_name=fitem.name) |
| 374 | return (func_ir, func_reg) |
| 375 | |
| 376 | |
| 377 | def generate_getattr_wrapper(builder: IRBuilder, cdef: ClassDef, getattr: FuncDef) -> None: |
no test coverage detected
searching dependent graphs…