mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add ctypes in eval_expr
This commit is contained in:
@ -1,24 +1,28 @@
|
||||
from llvmlite import ir
|
||||
|
||||
# TODO: THIS IS NOT SUPPOSED TO MATCH STRINGS :skull:
|
||||
mapping = {
|
||||
"c_int8": ir.IntType(8),
|
||||
"c_uint8": ir.IntType(8),
|
||||
"c_int16": ir.IntType(16),
|
||||
"c_uint16": ir.IntType(16),
|
||||
"c_int32": ir.IntType(32),
|
||||
"c_uint32": ir.IntType(32),
|
||||
"c_int64": ir.IntType(64),
|
||||
"c_uint64": ir.IntType(64),
|
||||
"c_float": ir.FloatType(),
|
||||
"c_double": ir.DoubleType(),
|
||||
"c_void_p": ir.IntType(64),
|
||||
# Not so sure about this one
|
||||
"str": ir.PointerType(ir.IntType(8)),
|
||||
}
|
||||
|
||||
|
||||
def ctypes_to_ir(ctype: str):
|
||||
mapping = {
|
||||
"c_int8": ir.IntType(8),
|
||||
"c_uint8": ir.IntType(8),
|
||||
"c_int16": ir.IntType(16),
|
||||
"c_uint16": ir.IntType(16),
|
||||
"c_int32": ir.IntType(32),
|
||||
"c_uint32": ir.IntType(32),
|
||||
"c_int64": ir.IntType(64),
|
||||
"c_uint64": ir.IntType(64),
|
||||
"c_float": ir.FloatType(),
|
||||
"c_double": ir.DoubleType(),
|
||||
"c_void_p": ir.IntType(64),
|
||||
# Not so sure about this one
|
||||
"str": ir.PointerType(ir.IntType(8)),
|
||||
}
|
||||
if ctype in mapping:
|
||||
return mapping[ctype]
|
||||
raise NotImplementedError(f"No mapping for {ctype}")
|
||||
|
||||
|
||||
def is_ctypes(ctype: str) -> bool:
|
||||
return ctype in mapping
|
||||
|
||||
Reference in New Issue
Block a user