mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add _handle_typed_constant_return
This commit is contained in:
@ -2,6 +2,7 @@ import logging
|
||||
import ast
|
||||
|
||||
from llvmlite import ir
|
||||
from pythonbpf.type_deducer import ctypes_to_ir
|
||||
|
||||
logger: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
@ -21,6 +22,23 @@ def _handle_none_return(builder) -> bool:
|
||||
return True
|
||||
|
||||
|
||||
def _handle_typed_constant_return(call_type, return_value, builder, ret_type) -> bool:
|
||||
"""Handle typed constant return like: return c_int64(42)"""
|
||||
|
||||
# call_type = stmt.value.func.id
|
||||
expected_type = ctypes_to_ir(call_type)
|
||||
|
||||
if expected_type != ret_type:
|
||||
raise ValueError(
|
||||
f"Return type mismatch: expected {ret_type}, got {expected_type}"
|
||||
)
|
||||
|
||||
# return_value = stmt.value.args[0].value
|
||||
builder.ret(ir.Constant(ret_type, return_value))
|
||||
logger.debug(f"Generated typed constant return: {call_type}({return_value})")
|
||||
return True
|
||||
|
||||
|
||||
def _handle_xdp_return(stmt: ast.Return, builder, ret_type) -> bool:
|
||||
"""Handle XDP returns"""
|
||||
if not isinstance(stmt.value, ast.Name):
|
||||
|
||||
Reference in New Issue
Block a user