Skip to content

env

Environment module

Environment

Environment base class

Parameters:

Name Type Description Default
platform Platform

Platform

required
arch Type[QuokkaArch]

Architecture

required

Attributes:

Name Type Description
platform Platform

Platform

arch Type[QuokkaArch]

Architecture

calling_convention Type[CallingConvention]

Calling convention

Source code in quokka/analysis/env.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class Environment:
    """Environment base class

    Args:
        platform: Platform
        arch: Architecture

    Attributes:
        platform: Platform
        arch: Architecture
        calling_convention: Calling convention

    """

    def __init__(
        self,
        platform: quokka.analysis.Platform,
        arch: Type[quokka.analysis.arch.QuokkaArch],
    ):
        """Constructor"""
        self.platform: quokka.analysis.Platform = platform
        self.arch: Type[quokka.analysis.arch.QuokkaArch] = arch
        self.calling_convention: Type[
            cc.CallingConvention
        ] = get_calling_convention_for_arch_platform(platform, arch)

__init__(platform, arch)

Constructor

Source code in quokka/analysis/env.py
77
78
79
80
81
82
83
84
85
86
87
def __init__(
    self,
    platform: quokka.analysis.Platform,
    arch: Type[quokka.analysis.arch.QuokkaArch],
):
    """Constructor"""
    self.platform: quokka.analysis.Platform = platform
    self.arch: Type[quokka.analysis.arch.QuokkaArch] = arch
    self.calling_convention: Type[
        cc.CallingConvention
    ] = get_calling_convention_for_arch_platform(platform, arch)

Platform

Bases: Enum

Platform enumeration

Source code in quokka/analysis/env.py
90
91
92
93
94
95
96
class Platform(enum.Enum):
    """Platform enumeration"""

    UNKNOWN = enum.auto()
    WINDOWS = enum.auto()
    LINUX = enum.auto()
    APPLE = enum.auto()

get_calling_convention_for_arch_platform(platform, arch)

Retrieve the calling convention used for this couple platform/arch

Parameters:

Name Type Description Default
platform Platform

Used platform

required
arch Type[QuokkaArch]

Used architecture

required

Returns:

Type Description
Type[CallingConvention]

A calling convention

Source code in quokka/analysis/env.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def get_calling_convention_for_arch_platform(
    platform: quokka.analysis.Platform,
    arch: Type[quokka.analysis.QuokkaArch],
) -> Type[cc.CallingConvention]:
    """Retrieve the calling convention used for this couple platform/arch

    Arguments:
        platform: Used platform
        arch: Used architecture

    Returns:
        A calling convention
    """
    mapping = {
        quokka.analysis.Platform.LINUX: {
            ArchX64: cc.SystemVAMD,  # Must be before x86
            ArchX86: cc.CCdecl,
            ArchARM: cc.ARMCC,
            ArchARM64: cc.ARM64CC,
        },
        quokka.analysis.Platform.WINDOWS: {
            ArchX86: cc.Stdcall,
            ArchX64: cc.MicrosoftAMD64,
        },
    }

    platform_mapping = mapping.get(platform)
    if platform_mapping is None:
        return cc.CallingConvention

    for architecture, convention in platform_mapping.items():
        if issubclass(arch, architecture):
            return convention

    return cc.CallingConvention