Skip to content

Commit 0a65717

Browse files
committed
Move convert_to_bool to type_normalization
1 parent e62557b commit 0a65717

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pythonbpf/expr/expr_pass.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Dict
66

77
from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes
8-
from .type_normalization import normalize_types
8+
from .type_normalization import normalize_types, convert_to_bool
99

1010
logger: Logger = logging.getLogger(__name__)
1111

@@ -197,16 +197,6 @@ def _handle_compare(
197197
return _handle_comparator(func, builder, cond.ops[0], lhs, rhs)
198198

199199

200-
def convert_to_bool(builder, val):
201-
if val.type == ir.IntType(1):
202-
return val
203-
if isinstance(val.type, ir.PointerType):
204-
zero = ir.Constant(val.type, None)
205-
else:
206-
zero = ir.Constant(val.type, 0)
207-
return builder.icmp_signed("!=", val, zero)
208-
209-
210200
def _handle_unary_op(
211201
func,
212202
module,

pythonbpf/expr/type_normalization.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,14 @@ def normalize_types(func, builder, lhs, rhs):
8484
elif rhs_depth < lhs_depth:
8585
lhs = _deref_to_depth(func, builder, lhs, lhs_depth - rhs_depth)
8686
return normalize_types(func, builder, lhs, rhs)
87+
88+
89+
def convert_to_bool(builder, val):
90+
"""Convert a value to boolean."""
91+
if val.type == ir.IntType(1):
92+
return val
93+
if isinstance(val.type, ir.PointerType):
94+
zero = ir.Constant(val.type, None)
95+
else:
96+
zero = ir.Constant(val.type, 0)
97+
return builder.icmp_signed("!=", val, zero)

0 commit comments

Comments
 (0)