Skip to content

normalization

Functions:

normalize_flags

normalize_flags(
    node: AST,
    *,
    lhs_type: DataType | None = None,
    rhs_type: DataType | None = None,
) -> SemanticFlags
Source code in src/irx/analysis/normalization.py
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
def normalize_flags(
    node: astx.AST,
    *,
    lhs_type: astx.DataType | None = None,
    rhs_type: astx.DataType | None = None,
) -> SemanticFlags:
    """
    title: Normalize semantic flags from the raw AST node.
    parameters:
      node:
        type: astx.AST
      lhs_type:
        type: astx.DataType | None
      rhs_type:
        type: astx.DataType | None
    returns:
      type: SemanticFlags
    """
    explicit_unsigned = getattr(node, "unsigned", None)
    unsigned = (
        bool(explicit_unsigned)
        if explicit_unsigned is not None
        else is_unsigned_type(lhs_type) or is_unsigned_type(rhs_type)
    )
    return SemanticFlags(
        unsigned=unsigned,
        fast_math=bool(getattr(node, "fast_math", False)),
        fma=bool(getattr(node, "fma", False)),
        fma_rhs=getattr(node, "fma_rhs", None),
    )

normalize_operator

normalize_operator(
    op_code: str,
    *,
    result_type: DataType | None,
    lhs_type: DataType | None = None,
    rhs_type: DataType | None = None,
    flags: SemanticFlags | None = None,
) -> ResolvedOperator
Source code in src/irx/analysis/normalization.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def normalize_operator(
    op_code: str,
    *,
    result_type: astx.DataType | None,
    lhs_type: astx.DataType | None = None,
    rhs_type: astx.DataType | None = None,
    flags: SemanticFlags | None = None,
) -> ResolvedOperator:
    """
    title: Create a normalized operator record.
    parameters:
      op_code:
        type: str
      result_type:
        type: astx.DataType | None
      lhs_type:
        type: astx.DataType | None
      rhs_type:
        type: astx.DataType | None
      flags:
        type: SemanticFlags | None
    returns:
      type: ResolvedOperator
    """
    return ResolvedOperator(
        op_code=op_code,
        result_type=result_type,
        lhs_type=lhs_type,
        rhs_type=rhs_type,
        flags=flags or SemanticFlags(),
    )