Normalize raw AST operator and flag information into the structured semantic
records used by later analysis and codegen.
Functions:
normalize_flags
normalize_flags(
node: AST,
*,
lhs_type: DataType | None = None,
rhs_type: DataType | None = None,
) -> SemanticFlags
Source code in packages/irx/src/irx/analysis/normalization.py
20
21
22
23
24
25
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 | @typechecked
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)
promoted_type = common_numeric_type(lhs_type, rhs_type)
unsigned = (
bool(explicit_unsigned)
if explicit_unsigned is not None
else (
is_integer_type(promoted_type) and is_unsigned_type(promoted_type)
)
or (
promoted_type is None
and (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 packages/irx/src/irx/analysis/normalization.py
60
61
62
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
88
89
90
91 | @typechecked
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(),
)
|