Generate IR for a method. If the method takes arguments, you should immediately afterwards call add_argument() for each non-self argument (self is created implicitly). Args: class_ir: Add method to this class name: Short name of the method
(
self,
class_ir: ClassIR,
name: str,
ret_type: RType,
fn_info: FuncInfo | str = "",
self_type: RType | None = None,
internal: bool = False,
)
| 1382 | |
| 1383 | @contextmanager |
| 1384 | def enter_method( |
| 1385 | self, |
| 1386 | class_ir: ClassIR, |
| 1387 | name: str, |
| 1388 | ret_type: RType, |
| 1389 | fn_info: FuncInfo | str = "", |
| 1390 | self_type: RType | None = None, |
| 1391 | internal: bool = False, |
| 1392 | ) -> Iterator[None]: |
| 1393 | """Generate IR for a method. |
| 1394 | |
| 1395 | If the method takes arguments, you should immediately afterwards call |
| 1396 | add_argument() for each non-self argument (self is created implicitly). |
| 1397 | |
| 1398 | Args: |
| 1399 | class_ir: Add method to this class |
| 1400 | name: Short name of the method |
| 1401 | ret_type: Return type of the method |
| 1402 | fn_info: Optionally, additional information about the method |
| 1403 | self_type: If not None, override default type of the implicit 'self' |
| 1404 | argument (by default, derive type from class_ir) |
| 1405 | """ |
| 1406 | self.enter(fn_info, ret_type=ret_type) |
| 1407 | self.function_name_stack.append(name) |
| 1408 | self.class_ir_stack.append(class_ir) |
| 1409 | if self_type is None: |
| 1410 | self_type = RInstance(class_ir) |
| 1411 | self.add_argument(SELF_NAME, self_type) |
| 1412 | try: |
| 1413 | yield |
| 1414 | finally: |
| 1415 | arg_regs, args, blocks, ret_type, fn_info = self.leave() |
| 1416 | sig = FuncSignature(args, ret_type) |
| 1417 | name = self.function_name_stack.pop() |
| 1418 | class_ir = self.class_ir_stack.pop() |
| 1419 | decl = FuncDecl(name, class_ir.name, self.module_name, sig, internal=internal) |
| 1420 | ir = FuncIR(decl, arg_regs, blocks) |
| 1421 | class_ir.methods[name] = ir |
| 1422 | class_ir.method_decls[name] = ir.decl |
| 1423 | self.functions.append(ir) |
| 1424 | |
| 1425 | def add_argument(self, var: str | Var, typ: RType, kind: ArgKind = ARG_POS) -> Register: |
| 1426 | """Declare an argument in the current function. |
no test coverage detected