| 587 | |
| 588 | |
| 589 | class GroupGenerator: |
| 590 | def __init__( |
| 591 | self, |
| 592 | modules: dict[str, ModuleIR], |
| 593 | source_paths: dict[str, str], |
| 594 | group_name: str | None, |
| 595 | group_map: dict[str, str | None], |
| 596 | names: NameGenerator, |
| 597 | compiler_options: CompilerOptions, |
| 598 | ) -> None: |
| 599 | """Generator for C source for a compilation group. |
| 600 | |
| 601 | The code for a compilation group contains an internal and an |
| 602 | external .h file, and then one .c if not in multi_file mode or |
| 603 | one .c file per module if in multi_file mode. |
| 604 | |
| 605 | Arguments: |
| 606 | modules: (name, ir) pairs for each module in the group |
| 607 | source_paths: Map from module names to source file paths |
| 608 | group_name: The name of the group (or None if this is single-module compilation) |
| 609 | group_map: A map of modules to their group names |
| 610 | names: The name generator for the compilation |
| 611 | compiler_options: Mypyc specific options, including multi_file mode |
| 612 | """ |
| 613 | self.modules = modules |
| 614 | self.source_paths = source_paths |
| 615 | self.context = EmitterContext( |
| 616 | names, compiler_options.strict_traceback_checks, group_name, group_map |
| 617 | ) |
| 618 | self.names = names |
| 619 | # Initializations of globals to simple values that we can't |
| 620 | # do statically because the windows loader is bad. |
| 621 | self.simple_inits: list[tuple[str, str]] = [] |
| 622 | self.group_name = group_name |
| 623 | self.use_shared_lib = group_name is not None |
| 624 | self.compiler_options = compiler_options |
| 625 | self.multi_file = compiler_options.multi_file |
| 626 | # Multi-phase init is needed to enable free-threading. In the future we'll |
| 627 | # probably want to enable it always, but we'll wait until it's stable. |
| 628 | self.multi_phase_init = IS_FREE_THREADED |
| 629 | |
| 630 | @property |
| 631 | def group_suffix(self) -> str: |
| 632 | return "_" + exported_name(self.group_name) if self.group_name else "" |
| 633 | |
| 634 | @property |
| 635 | def short_group_suffix(self) -> str: |
| 636 | return "_" + exported_name(self.group_name.split(".")[-1]) if self.group_name else "" |
| 637 | |
| 638 | def generate_c_for_modules(self) -> list[tuple[str, str]]: |
| 639 | file_contents = [] |
| 640 | multi_file = self.use_shared_lib and self.multi_file |
| 641 | |
| 642 | # Collect all literal refs in IR. |
| 643 | for module in self.modules.values(): |
| 644 | for fn in module.functions: |
| 645 | collect_literals(fn, self.context.literals) |
| 646 |
no outgoing calls
no test coverage detected
searching dependent graphs…