Skip to content

Commit 15db306

Browse files
committed
Remove unused functions and clean up memory region detection in eBPF C code generation.
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 331505b commit 15db306

File tree

1 file changed

+1
-69
lines changed

1 file changed

+1
-69
lines changed

src/ebpf_c_codegen.ml

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ type enhanced_memory_info = {
4747
(** Variable name to enhanced memory info mapping *)
4848
type memory_info_map = (string, enhanced_memory_info) Hashtbl.t
4949

50-
type bounds_hint = { verified: bool; size_hint: int }
51-
5250
(** Detect memory region type from IR value semantics *)
5351
let detect_memory_region_type ir_val =
5452
match ir_val.value_desc with
@@ -58,11 +56,6 @@ let detect_memory_region_type ir_val =
5856
| IRTempVariable _ -> RegularMemory (* Temporary variables *)
5957
| _ -> RegularMemory
6058

61-
(** Check if IR value represents packet data *)
62-
let is_packet_data_value ir_val =
63-
match detect_memory_region_type ir_val with
64-
| PacketData -> true
65-
| _ -> false
6659

6760
(** Check if IR value represents map-derived data - heuristic approach *)
6861
let is_map_value_parameter ir_val =
@@ -76,12 +69,6 @@ let is_map_value_parameter ir_val =
7669
| _ -> false)
7770
| _ -> false
7871

79-
(** Check if IR value is local stack memory *)
80-
let is_local_stack_value ir_val =
81-
match detect_memory_region_type ir_val with
82-
| LocalStack -> true
83-
| _ -> false
84-
8572
(** Enhanced memory region detection using provided memory info *)
8673
let detect_memory_region_enhanced ?(memory_info_map=None) ir_val =
8774
match memory_info_map with
@@ -103,21 +90,6 @@ let detect_memory_region_enhanced ?(memory_info_map=None) ir_val =
10390
(* Fallback to heuristic detection *)
10491
detect_memory_region_type ir_val
10592

106-
(** Get enhanced bounds information *)
107-
let get_enhanced_bounds_info ?(memory_info_map=None) ir_val =
108-
match memory_info_map with
109-
| Some info_map ->
110-
(match ir_val.value_desc with
111-
| IRVariable var_name ->
112-
(try
113-
let info = Hashtbl.find info_map var_name in
114-
Some { verified = info.bounds_verified; size_hint =
115-
match info.size_hint with Some s -> s | None -> 0 }
116-
with
117-
| Not_found -> None)
118-
| _ -> None)
119-
| None -> None
120-
12193
(** C code generation context *)
12294
type c_context = {
12395
(* Generated C code lines *)
@@ -2393,38 +2365,8 @@ let generate_ringbuf_operation ctx ringbuf_val op =
23932365
(* on_event is userspace-only operation *)
23942366
failwith "Ring buffer on_event() operation is not supported in eBPF programs - it's userspace-only"
23952367

2396-
(** Generate C code for IR instruction *)
2397-
2398-
(** Helper function to convert AST expressions to C code for bpf_loop callbacks *)
2399-
let rec generate_ast_expr_to_c (expr : Ast.expr) counter_var =
2400-
match expr.Ast.expr_desc with
2401-
| Ast.Literal (Ast.IntLit (i, _)) -> Ast.IntegerValue.to_string i
2402-
| Ast.Literal (Ast.BoolLit b) -> if b then "true" else "false"
2403-
| Ast.Identifier name when name = "i" -> counter_var (* Map loop variable to counter *)
2404-
| Ast.Identifier name -> name
2405-
| Ast.BinaryOp (left, op, right) ->
2406-
let left_c = generate_ast_expr_to_c left counter_var in
2407-
let right_c = generate_ast_expr_to_c right counter_var in
2408-
let op_c = match op with
2409-
| Ast.Add -> "+"
2410-
| Ast.Sub -> "-"
2411-
| Ast.Mul -> "*"
2412-
| Ast.Div -> "/"
2413-
| Ast.Mod -> "%"
2414-
| Ast.Eq -> "=="
2415-
| Ast.Ne -> "!="
2416-
| Ast.Lt -> "<"
2417-
| Ast.Le -> "<="
2418-
| Ast.Gt -> ">"
2419-
| Ast.Ge -> ">="
2420-
| Ast.And -> "&&"
2421-
| Ast.Or -> "||"
2422-
in
2423-
sprintf "(%s %s %s)" left_c op_c right_c
2424-
| _ -> "/* complex expr */"
2425-
24262368
(** Generate assignment instruction with optional const keyword *)
2427-
and generate_assignment ctx dest_val expr is_const =
2369+
let generate_assignment ctx dest_val expr is_const =
24282370
let assignment_prefix = if is_const then "const " else "" in
24292371

24302372
(* Check if this is a pinned global variable assignment *)
@@ -3455,16 +3397,6 @@ let generate_c_function ctx ir_func =
34553397
emit_line ctx "}";
34563398
emit_blank_line ctx
34573399

3458-
(** Helper function to compile C code to eBPF object *)
3459-
let compile_c_to_ebpf c_filename obj_filename =
3460-
let cmd = sprintf "clang -target bpf -O2 -g -c %s -o %s" c_filename obj_filename in
3461-
let exit_code = Sys.command cmd in
3462-
if exit_code = 0 then
3463-
Ok obj_filename
3464-
else
3465-
Error (sprintf "Compilation failed with exit code %d" exit_code)
3466-
3467-
34683400
(** Generate ProgArray map for tail calls *)
34693401
let generate_prog_array_map ctx prog_array_size =
34703402
if prog_array_size > 0 then (

0 commit comments

Comments
 (0)