|
4 | 4 | import logging |
5 | 5 | from typing import Dict |
6 | 6 |
|
7 | | -from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes, IntTy, signedness |
| 7 | +from pythonbpf.type_deducer import ( |
| 8 | + ctypes_to_ir, |
| 9 | + is_ctypes, |
| 10 | + IntTy, |
| 11 | + int_literal_type, |
| 12 | + signedness, |
| 13 | +) |
8 | 14 | from .call_registry import CallHandlerRegistry |
9 | 15 | from .ir_ops import deref_to_depth, access_struct_field |
10 | 16 | from .operators import apply_binop, usual_arithmetic_conversions, UNARY_OPS, BOOL_OPS |
@@ -54,8 +60,7 @@ def _handle_name_expr( |
54 | 60 | def _int_literal(v: int): |
55 | 61 | """An integer literal: a 64-bit constant with C's literal rank as its |
56 | 62 | descriptor, `int` if the value fits and `long long` otherwise.""" |
57 | | - lit_ty = IntTy(32, True) if -(1 << 31) <= v < (1 << 31) else IntTy(64, True) |
58 | | - return ir.Constant(ir.IntType(64), v), lit_ty |
| 63 | + return ir.Constant(ir.IntType(64), v), int_literal_type(v) |
59 | 64 |
|
60 | 65 |
|
61 | 66 | def _handle_constant_expr(compilation_context, builder, expr: ast.Constant): |
@@ -221,8 +226,7 @@ def get_typed_operand(func, compilation_context, operand, builder, local_sym_tab |
221 | 226 | else: |
222 | 227 | vmlinux_result = VmlinuxHandlerRegistry.handle_name(operand.id) |
223 | 228 | if vmlinux_result is not None: |
224 | | - val, _ = vmlinux_result |
225 | | - return val, IntTy(64, True) |
| 229 | + return vmlinux_result # (i64 constant, its C rank) |
226 | 230 | elif isinstance(operand, ast.Constant): |
227 | 231 | if isinstance(operand.value, (int, bool)): |
228 | 232 | v = int(operand.value) |
|
0 commit comments