Skip to content

Commit 1870ce0

Browse files
committed
Replace ctx.assign with Assign event
1 parent 13b922a commit 1870ce0

File tree

9 files changed

+20
-66
lines changed

9 files changed

+20
-66
lines changed

src/analyses/arinc.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ struct
337337
let assign_id exp id =
338338
match exp with
339339
(* call assign for all analyses (we only need base)! *)
340-
| AddrOf lval -> ctx.assign ~name:"base" lval (mkAddrOf @@ var id)
340+
| AddrOf lval -> ctx.emit (Assign {lval; exp = mkAddrOf @@ var id})
341341
(* TODO not needed for the given code, but we could use Queries.MayPointTo exp in this case *)
342342
| _ -> failwith @@ "Could not assign id. Expected &id. Found "^sprint d_exp exp
343343
in

src/analyses/extract_arinc.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ struct
272272
let assign_id exp id =
273273
if M.tracing then M.trace "extract_arinc" "assign_id %a %s\n" d_exp exp id.vname;
274274
match exp with
275-
| AddrOf lval -> ctx.assign ~name:"base" lval (mkAddrOf @@ var id)
275+
| AddrOf lval -> ctx.emit (Assign {lval; exp = mkAddrOf @@ var id})
276276
| _ -> failwith @@ "Could not assign id. Expected &id. Found "^sprint d_exp exp
277277
in
278278
(* evaluates an argument and returns a list of possible values for that argument. *)

src/analyses/extract_osek.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ struct
265265
let assign_id exp id =
266266
if M.tracing then M.trace "extract_osek" "assign_id %a %s\n" d_exp exp id.vname;
267267
match exp with
268-
| AddrOf lval -> ctx.assign ~name:"base" lval (mkAddrOf @@ var id)
268+
| AddrOf lval -> ctx.emit (Assign {lval; exp = mkAddrOf @@ var id})
269269
| _ -> failwith @@ "Could not assign id. Expected &id. Found "^sprint d_exp exp
270270
in
271271
(* evaluates an argument and returns a list of possible values for that argument. *)

src/analyses/mCP.ml

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ struct
113113
) x
114114

115115
let should_join x y =
116+
(* TODO: GobList.for_all3 *)
116117
let rec zip3 lst1 lst2 lst3 = match lst1,lst2,lst3 with
117118
| [],_, _ -> []
118119
| _,[], _ -> []
@@ -175,26 +176,6 @@ struct
175176
in
176177
iter (uncurry side_one) @@ group_assoc_eq V.equal xs
177178

178-
let do_assigns ctx assigns (xs:(int * Obj.t) list) =
179-
if List.is_empty assigns then xs (* nothing to do *)
180-
else
181-
let spec_assign n d : Obj.t =
182-
(* spec of current analysis *)
183-
let (module S:MCPSpec) = spec n in
184-
let assign_one d (lval, exp, name, ctx) =
185-
match name with
186-
| Some x when x <> find_spec_name n -> obj d (* do nothing if current spec name is filtered out *)
187-
| _ ->
188-
let ctx' = {(obj ctx) with local = obj d} in
189-
S.assign ctx' lval exp
190-
in
191-
let get_lval (lval, exp, name, ctx) = lval in
192-
(* group by assigns on the same lval -> only those must be joined *)
193-
List.group (compareBy get_lval) assigns
194-
|> List.fold_left (fun d xs -> List.map (assign_one d) xs |> List.reduce S.D.join |> repr) d
195-
in
196-
List.map (fun (n,d) -> n, spec_assign n d) xs
197-
198179
let rec do_splits ctx pv (xs:(int * (Obj.t * Events.t list)) list) =
199180
let split_one n (d,emits) =
200181
let nv = assoc_replace (n,d) pv in
@@ -218,25 +199,25 @@ struct
218199
let do_emit ctx = function
219200
| Events.SplitBranch (exp, tv) ->
220201
ctx_with_local ctx (branch ctx exp tv)
202+
| Events.Assign {lval; exp} ->
203+
ctx_with_local ctx (assign ctx lval exp)
221204
| e ->
222205
let spawns = ref [] in
223206
let splits = ref [] in
224207
let sides = ref [] in (* why do we need to collect these instead of calling ctx.sideg directly? *)
225-
let assigns = ref [] in
226208
let emits = ref [] in
227209
let ctx'' = outer_ctx "do_emits" ~spawns ~sides ~emits ctx in
228210
let octx'' = outer_ctx "do_emits" ~spawns ~sides ~emits octx in
229211
let f post_all (n,(module S:MCPSpec),(d,od)) =
230-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "do_emits" ~splits ~assigns ~post_all ctx'' n d in
231-
let octx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "do_emits" ~splits ~assigns ~post_all octx'' n d in
212+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "do_emits" ~splits ~post_all ctx'' n d in
213+
let octx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "do_emits" ~splits ~post_all octx'' n d in
232214
n, repr @@ S.event ctx' e octx'
233215
in
234216
let d, q = map_deadcode f @@ spec_list2 ctx.local octx.local in
235217
if M.tracing then M.tracel "event" "%a\n before: %a\n after:%a\n" Events.pretty e D.pretty ctx.local D.pretty d;
236218
do_sideg ctx !sides;
237219
do_spawns ctx !spawns;
238220
do_splits ctx d !splits;
239-
let d = do_assigns ctx !assigns d in
240221
let d = do_emits ctx !emits d in
241222
if q then raise Deadcode else ctx_with_local ctx d
242223
in
@@ -247,18 +228,16 @@ struct
247228
let spawns = ref [] in
248229
let splits = ref [] in
249230
let sides = ref [] in (* why do we need to collect these instead of calling ctx.sideg directly? *)
250-
let assigns = ref [] in
251231
let emits = ref [] in
252232
let ctx'' = outer_ctx "branch" ~spawns ~sides ~emits ctx in
253233
let f post_all (n,(module S:MCPSpec),d) =
254-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "branch" ~splits ~assigns ~post_all ctx'' n d in
234+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "branch" ~splits ~post_all ctx'' n d in
255235
n, repr @@ S.branch ctx' e tv
256236
in
257237
let d, q = map_deadcode f @@ spec_list ctx.local in
258238
do_sideg ctx !sides;
259239
do_spawns ctx !spawns;
260240
do_splits ctx d !splits;
261-
let d = do_assigns ctx !assigns d in
262241
let d = do_emits ctx !emits d in
263242
if q then raise Deadcode else d
264243

@@ -343,7 +322,7 @@ struct
343322
}
344323

345324
(* Explicitly polymorphic type required here for recursive call in branch. *)
346-
and inner_ctx: type d g c v. string -> ?splits:(int * (Obj.t * Events.t list)) list ref -> ?assigns:(lval * exp * string option * Obj.t) list ref -> ?post_all:(int * Obj.t) list -> (D.t, G.t, C.t, V.t) ctx -> int -> Obj.t -> (d, g, c, v) ctx = fun tfname ?splits ?assigns ?(post_all=[]) ctx n d ->
325+
and inner_ctx: type d g c v. string -> ?splits:(int * (Obj.t * Events.t list)) list ref -> ?post_all:(int * Obj.t) list -> (D.t, G.t, C.t, V.t) ctx -> int -> Obj.t -> (d, g, c, v) ctx = fun tfname ?splits ?(post_all=[]) ctx n d ->
347326
let split = match splits with
348327
| Some splits -> (fun d es -> splits := (n,(repr d,es)) :: !splits)
349328
| None -> (fun _ _ -> failwith ("Cannot \"split\" in " ^ tfname ^ " context."))
@@ -356,16 +335,11 @@ struct
356335
; global = (fun v -> ctx.global (v_of n v) |> g_to n |> obj)
357336
; split
358337
; sideg = (fun v g -> ctx.sideg (v_of n v) (`Lifted (n, repr g)))
359-
; assign = (
360-
match assigns with
361-
| Some assigns -> (fun ?name v e -> assigns := (v,e,name, repr ctx')::!assigns)
362-
| None -> (fun ?name _ -> failwith ("Cannot \"assign\" in " ^ tfname ^ " context."))
363-
)
364338
}
365339
in
366340
ctx'
367341

368-
let assign (ctx:(D.t, G.t, C.t, V.t) ctx) l e =
342+
and assign (ctx:(D.t, G.t, C.t, V.t) ctx) l e =
369343
let spawns = ref [] in
370344
let splits = ref [] in
371345
let sides = ref [] in
@@ -404,113 +378,101 @@ struct
404378
let spawns = ref [] in
405379
let splits = ref [] in
406380
let sides = ref [] in
407-
let assigns = ref [] in
408381
let emits = ref [] in
409382
let ctx'' = outer_ctx "body" ~spawns ~sides ~emits ctx in
410383
let f post_all (n,(module S:MCPSpec),d) =
411-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "body" ~splits ~assigns ~post_all ctx'' n d in
384+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "body" ~splits ~post_all ctx'' n d in
412385
n, repr @@ S.body ctx' f
413386
in
414387
let d, q = map_deadcode f @@ spec_list ctx.local in
415388
do_sideg ctx !sides;
416389
do_spawns ctx !spawns;
417390
do_splits ctx d !splits;
418-
let d = do_assigns ctx !assigns d in
419391
let d = do_emits ctx !emits d in
420392
if q then raise Deadcode else d
421393

422394
let return (ctx:(D.t, G.t, C.t, V.t) ctx) e f =
423395
let spawns = ref [] in
424396
let splits = ref [] in
425397
let sides = ref [] in
426-
let assigns = ref [] in
427398
let emits = ref [] in
428399
let ctx'' = outer_ctx "return" ~spawns ~sides ~emits ctx in
429400
let f post_all (n,(module S:MCPSpec),d) =
430-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "return" ~splits ~assigns ~post_all ctx'' n d in
401+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "return" ~splits ~post_all ctx'' n d in
431402
n, repr @@ S.return ctx' e f
432403
in
433404
let d, q = map_deadcode f @@ spec_list ctx.local in
434405
do_sideg ctx !sides;
435406
do_spawns ctx !spawns;
436407
do_splits ctx d !splits;
437-
let d = do_assigns ctx !assigns d in
438408
let d = do_emits ctx !emits d in
439409
if q then raise Deadcode else d
440410

441411
let intrpt (ctx:(D.t, G.t, C.t, V.t) ctx) =
442412
let spawns = ref [] in
443413
let splits = ref [] in
444414
let sides = ref [] in
445-
let assigns = ref [] in
446415
let emits = ref [] in
447416
let ctx'' = outer_ctx "interpt" ~spawns ~sides ~emits ctx in
448417
let f post_all (n,(module S:MCPSpec),d) =
449-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "interpt" ~splits ~assigns ~post_all ctx'' n d in
418+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "interpt" ~splits ~post_all ctx'' n d in
450419
n, repr @@ S.intrpt ctx'
451420
in
452421
let d, q = map_deadcode f @@ spec_list ctx.local in
453422
do_sideg ctx !sides;
454423
do_spawns ctx !spawns;
455424
do_splits ctx d !splits;
456-
let d = do_assigns ctx !assigns d in
457425
let d = do_emits ctx !emits d in
458426
if q then raise Deadcode else d
459427

460428
let asm (ctx:(D.t, G.t, C.t, V.t) ctx) =
461429
let spawns = ref [] in
462430
let splits = ref [] in
463431
let sides = ref [] in
464-
let assigns = ref [] in
465432
let emits = ref [] in
466433
let ctx'' = outer_ctx "asm" ~spawns ~sides ~emits ctx in
467434
let f post_all (n,(module S:MCPSpec),d) =
468-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "asm" ~splits ~assigns ~post_all ctx'' n d in
435+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "asm" ~splits ~post_all ctx'' n d in
469436
n, repr @@ S.asm ctx'
470437
in
471438
let d, q = map_deadcode f @@ spec_list ctx.local in
472439
do_sideg ctx !sides;
473440
do_spawns ctx !spawns;
474441
do_splits ctx d !splits;
475-
let d = do_assigns ctx !assigns d in
476442
let d = do_emits ctx !emits d in
477443
if q then raise Deadcode else d
478444

479445
let skip (ctx:(D.t, G.t, C.t, V.t) ctx) =
480446
let spawns = ref [] in
481447
let splits = ref [] in
482448
let sides = ref [] in
483-
let assigns = ref [] in
484449
let emits = ref [] in
485450
let ctx'' = outer_ctx "skip" ~spawns ~sides ~emits ctx in
486451
let f post_all (n,(module S:MCPSpec),d) =
487-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "skip" ~splits ~assigns ~post_all ctx'' n d in
452+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "skip" ~splits ~post_all ctx'' n d in
488453
n, repr @@ S.skip ctx'
489454
in
490455
let d, q = map_deadcode f @@ spec_list ctx.local in
491456
do_sideg ctx !sides;
492457
do_spawns ctx !spawns;
493458
do_splits ctx d !splits;
494-
let d = do_assigns ctx !assigns d in
495459
let d = do_emits ctx !emits d in
496460
if q then raise Deadcode else d
497461

498462
let special (ctx:(D.t, G.t, C.t, V.t) ctx) r f a =
499463
let spawns = ref [] in
500464
let splits = ref [] in
501465
let sides = ref [] in
502-
let assigns = ref [] in
503466
let emits = ref [] in
504467
let ctx'' = outer_ctx "special" ~spawns ~sides ~emits ctx in
505468
let f post_all (n,(module S:MCPSpec),d) =
506-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "special" ~splits ~assigns ~post_all ctx'' n d in
469+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "special" ~splits ~post_all ctx'' n d in
507470
n, repr @@ S.special ctx' r f a
508471
in
509472
let d, q = map_deadcode f @@ spec_list ctx.local in
510473
do_sideg ctx !sides;
511474
do_spawns ctx !spawns;
512475
do_splits ctx d !splits;
513-
let d = do_assigns ctx !assigns d in
514476
let d = do_emits ctx !emits d in
515477
if q then raise Deadcode else d
516478

@@ -547,7 +509,6 @@ struct
547509
let combine (ctx:(D.t, G.t, C.t, V.t) ctx) r fe f a fc fd =
548510
let spawns = ref [] in
549511
let sides = ref [] in
550-
let assigns = ref [] in
551512
let emits = ref [] in
552513
let ctx'' = outer_ctx "combine" ~spawns ~sides ~emits ctx in
553514
(* Like spec_list2 but for three lists. Tail recursion like map3_rev would have.
@@ -565,13 +526,12 @@ struct
565526
| _, _, _ -> invalid_arg "MCP.spec_list3_rev_acc"
566527
in
567528
let f post_all (n,(module S:MCPSpec),(d,fc,fd)) =
568-
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "combine" ~assigns ~post_all ctx'' n d in
529+
let ctx' : (S.D.t, S.G.t, S.C.t, S.V.t) ctx = inner_ctx "combine" ~post_all ctx'' n d in
569530
n, repr @@ S.combine ctx' r fe f a (Option.map obj fc) (obj fd)
570531
in
571532
let d, q = map_deadcode f @@ List.rev @@ spec_list3_rev_acc [] ctx.local fc fd in
572533
do_sideg ctx !sides;
573534
do_spawns ctx !spawns;
574-
let d = do_assigns ctx !assigns d in
575535
let d = do_emits ctx !emits d in
576536
if q then raise Deadcode else d
577537

src/domains/events.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type t =
88
| SplitBranch of exp * bool (** Used to simulate old branch-based split. *)
99
| AssignSpawnedThread of lval * ThreadIdDomain.Thread.t (** Assign spawned thread's ID to lval. *)
1010
| Access of {var_opt: CilType.Varinfo.t option; write: bool} (** Access varinfo (unknown if None). *)
11+
| Assign of {lval: CilType.Lval.t; exp: CilType.Exp.t} (** Used to simulate old [ctx.assign]. *)
1112

1213
let pretty () = function
1314
| Lock m -> dprintf "Lock %a" LockDomain.Addr.pretty m
@@ -17,3 +18,4 @@ let pretty () = function
1718
| SplitBranch (exp, tv) -> dprintf "SplitBranch (%a, %B)" d_exp exp tv
1819
| AssignSpawnedThread (lval, tid) -> dprintf "AssignSpawnedThread (%a, %a)" d_lval lval ThreadIdDomain.Thread.pretty tid
1920
| Access {var_opt; write} -> dprintf "Access {var_opt=%a, write=%B}" (docOpt (CilType.Varinfo.pretty ())) var_opt write
21+
| Assign {lval; exp} -> dprintf "Assugn {lval=%a, exp=%a}" CilType.Lval.pretty lval CilType.Exp.pretty exp

src/framework/analyses.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ type ('d,'g,'c,'v) ctx =
315315
; spawn : lval option -> varinfo -> exp list -> unit
316316
; split : 'd -> Events.t list -> unit
317317
; sideg : 'v -> 'g -> unit
318-
; assign : ?name:string -> lval -> exp -> unit
319318
}
320319

321320
exception Ctx_failure of string

src/framework/constraints.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,6 @@ struct
498498
; spawn = spawn
499499
; split = (fun (d:D.t) es -> assert (List.is_empty es); r := d::!r)
500500
; sideg = sideg
501-
; assign = (fun ?name _ -> failwith "Cannot \"assign\" in common context.")
502501
}
503502
and spawn lval f args =
504503
(* TODO: adjust ctx node/edge? *)

src/framework/control.ml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ struct
250250
; spawn = (fun _ -> failwith "Global initializers should never spawn threads. What is going on?")
251251
; split = (fun _ -> failwith "Global initializers trying to split paths.")
252252
; sideg = sideg
253-
; assign = (fun ?name _ -> failwith "Global initializers trying to assign.")
254253
}
255254
in
256255
let edges = CfgTools.getGlobalInits file in
@@ -348,7 +347,6 @@ struct
348347
; spawn = (fun _ -> failwith "Bug1: Using enter_func for toplevel functions with 'otherstate'.")
349348
; split = (fun _ -> failwith "Bug2: Using enter_func for toplevel functions with 'otherstate'.")
350349
; sideg = sideg
351-
; assign = (fun ?name _ -> failwith "Bug4: Using enter_func for toplevel functions with 'otherstate'.")
352350
}
353351
in
354352
let args = List.map (fun x -> MyCFG.unknown_exp) fd.sformals in
@@ -383,7 +381,6 @@ struct
383381
; spawn = (fun _ -> failwith "Bug1: Using enter_func for toplevel functions with 'otherstate'.")
384382
; split = (fun _ -> failwith "Bug2: Using enter_func for toplevel functions with 'otherstate'.")
385383
; sideg = sideg
386-
; assign = (fun ?name _ -> failwith "Bug4: Using enter_func for toplevel functions with 'otherstate'.")
387384
}
388385
in
389386
(* TODO: don't hd *)
@@ -574,7 +571,6 @@ struct
574571
; spawn = (fun v d -> failwith "Cannot \"spawn\" in query context.")
575572
; split = (fun d es -> failwith "Cannot \"split\" in query context.")
576573
; sideg = (fun v g -> failwith "Cannot \"split\" in query context.")
577-
; assign = (fun ?name _ -> failwith "Cannot \"assign\" in query context.")
578574
}
579575
in
580576
Spec.query ctx
@@ -629,7 +625,6 @@ struct
629625
; spawn = (fun v d -> failwith "Cannot \"spawn\" in query context.")
630626
; split = (fun d es -> failwith "Cannot \"split\" in query context.")
631627
; sideg = (fun v g -> failwith "Cannot \"split\" in query context.")
632-
; assign = (fun ?name _ -> failwith "Cannot \"assign\" in query context.")
633628
}
634629
in
635630
Spec.query ctx (WarnGlobal (Obj.repr g))

src/witness/witness.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ struct
309309
; spawn = (fun v d -> failwith "Cannot \"spawn\" in witness context.")
310310
; split = (fun d es -> failwith "Cannot \"split\" in witness context.")
311311
; sideg = (fun v g -> failwith "Cannot \"sideg\" in witness context.")
312-
; assign = (fun ?name _ -> failwith "Cannot \"assign\" in witness context.")
313312
}
314313
in
315314
Spec.query ctx

0 commit comments

Comments
 (0)