|
6 | 6 | from pythonbpf.helper import HelperHandlerRegistry |
7 | 7 | from pythonbpf.vmlinux_parser.dependency_node import Field |
8 | 8 | from .expr import VmlinuxHandlerRegistry |
9 | | -from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes, IntTy, signedness |
| 9 | +from pythonbpf.type_deducer import ctypes_to_ir, is_ctypes, IntTy, signedness, byte_size |
10 | 10 | from pythonbpf.expr.type_inference import infer_int_type |
11 | 11 | from pythonbpf.maps import BPFMapType |
12 | 12 |
|
@@ -115,7 +115,7 @@ def _allocate_for_call(builder, var_name, rval, local_sym_tab, compilation_conte |
115 | 115 | # slot of that width; the value is converted into it at the store. |
116 | 116 | ir_type = ctypes_to_ir(call_type) |
117 | 117 | var = builder.alloca(ir_type, name=var_name) |
118 | | - var.align = ir_type.width // 8 |
| 118 | + var.align = byte_size(ir_type) |
119 | 119 | local_sym_tab[var_name] = LocalSymbol(var, ir_type) |
120 | 120 | logger.info(f"Pre-allocated {var_name} as {call_type}") |
121 | 121 |
|
@@ -472,7 +472,7 @@ def _allocate_for_attribute( |
472 | 472 | tmp_name = f"{struct_var}_{field_name}_tmp" |
473 | 473 | tmp_ir_type = ir.IntType(field_size_bits) |
474 | 474 | tmp_var = builder.alloca(tmp_ir_type, name=tmp_name) |
475 | | - tmp_var.align = tmp_ir_type.width // 8 |
| 475 | + tmp_var.align = byte_size(tmp_ir_type) |
476 | 476 | local_sym_tab[tmp_name] = LocalSymbol(tmp_var, tmp_ir_type) |
477 | 477 | logger.info( |
478 | 478 | f"Pre-allocated temp {tmp_name} (i{field_size_bits}) for vmlinux field read {vmlinux_struct_name}.{field_name}" |
@@ -527,8 +527,8 @@ def _allocate_with_type(builder, var_name, ir_type): |
527 | 527 | def _get_alignment(ir_type): |
528 | 528 | """Get appropriate alignment for IR type.""" |
529 | 529 | if isinstance(ir_type, ir.IntType): |
530 | | - return ir_type.width // 8 |
| 530 | + return byte_size(ir_type) |
531 | 531 | elif isinstance(ir_type, ir.ArrayType) and isinstance(ir_type.element, ir.IntType): |
532 | | - return ir_type.element.width // 8 |
| 532 | + return byte_size(ir_type.element) |
533 | 533 | else: |
534 | 534 | return 8 # Default: pointer size |
0 commit comments