summaryrefslogtreecommitdiff
path: root/tools/libdol2asm/data/translation_unit.py
blob: 61ada2952679a01d6be014db4aa6ea9d07b3aca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

from typing import Dict
from dataclasses import dataclass, field
from .section import *

@dataclass
class TranslationUnit:
    name: str  # without the .o extension
    sections: Dict[str, Section] = field(default_factory=dict, repr=False)
    generate: bool = True
    special: str = None


    @property
    def is_empty(self):
        if len(self.sections) == 0:
            return True
        symbol_count = sum([
            sum([
                symbol.has_body
                for symbol in section.symbols
            ])
            for section in self.sections.values()
        ])
        if symbol_count == 0:
            return True
        return False

    def source_path(self, library):
        return library.source_path.joinpath(f"{self.name}.cpp")

    def include_path(self, library):
        return library.include_path.joinpath(f"{self.name}.h")

    def object_path(self, library):
        return library.source_path.joinpath(f"{self.name}.o")

    def asm_function_path(self, library):
        return library.asm_function_path.joinpath(self.name)

    def add_section(self, section: Section):
        self.sections[section.name] = section