mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Move convert_to_bool to type_normalization
This commit is contained in:
@ -5,7 +5,7 @@ import logging
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes
|
from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes
|
||||||
from .type_normalization import normalize_types
|
from .type_normalization import normalize_types, convert_to_bool
|
||||||
|
|
||||||
logger: Logger = logging.getLogger(__name__)
|
logger: Logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -197,16 +197,6 @@ def _handle_compare(
|
|||||||
return _handle_comparator(func, builder, cond.ops[0], lhs, rhs)
|
return _handle_comparator(func, builder, cond.ops[0], lhs, rhs)
|
||||||
|
|
||||||
|
|
||||||
def convert_to_bool(builder, val):
|
|
||||||
if val.type == ir.IntType(1):
|
|
||||||
return val
|
|
||||||
if isinstance(val.type, ir.PointerType):
|
|
||||||
zero = ir.Constant(val.type, None)
|
|
||||||
else:
|
|
||||||
zero = ir.Constant(val.type, 0)
|
|
||||||
return builder.icmp_signed("!=", val, zero)
|
|
||||||
|
|
||||||
|
|
||||||
def _handle_unary_op(
|
def _handle_unary_op(
|
||||||
func,
|
func,
|
||||||
module,
|
module,
|
||||||
|
|||||||
@ -84,3 +84,14 @@ def normalize_types(func, builder, lhs, rhs):
|
|||||||
elif rhs_depth < lhs_depth:
|
elif rhs_depth < lhs_depth:
|
||||||
lhs = _deref_to_depth(func, builder, lhs, lhs_depth - rhs_depth)
|
lhs = _deref_to_depth(func, builder, lhs, lhs_depth - rhs_depth)
|
||||||
return normalize_types(func, builder, lhs, rhs)
|
return normalize_types(func, builder, lhs, rhs)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_to_bool(builder, val):
|
||||||
|
"""Convert a value to boolean."""
|
||||||
|
if val.type == ir.IntType(1):
|
||||||
|
return val
|
||||||
|
if isinstance(val.type, ir.PointerType):
|
||||||
|
zero = ir.Constant(val.type, None)
|
||||||
|
else:
|
||||||
|
zero = ir.Constant(val.type, 0)
|
||||||
|
return builder.icmp_signed("!=", val, zero)
|
||||||
|
|||||||
Reference in New Issue
Block a user