Skip to content

Commit

Permalink
fixes the order of arguments in the callsites plugin (#939)
Browse files Browse the repository at this point in the history
* adds an order for subroutine arguments

* ocp-indented

* removed upper bound for llvm version

* added a comment

* used an easier way to compare intents

* updated comments
  • Loading branch information
gitoleg authored Apr 1, 2019
1 parent d9277ca commit 651003f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions plugins/callsites/callsites_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ let add_def intent blk def =
then Term.prepend def_t blk def
else Term.append def_t blk def

let defs_of_args call intent args : def term seq =
Seq.filter_map args ~f:(fun arg ->
let defs_of_args call intent args =
List.filter_map args ~f:(fun arg ->
require (intent_matches arg intent) >>= fun () ->
def_of_arg arg >>| transfer_attrs call)

Expand All @@ -54,14 +54,21 @@ let target intent sub blk call =
| _ -> None
else Some blk

(* Note, that output arguments will be inserted in the reverse order, so
we sort all of them in a natural way to get the following order: In Both Out *)
let enum_args t =
let compare x y =
Option.compare compare_intent (Arg.intent x) (Arg.intent y) in
Term.enum arg_t t |> Seq.to_list |> List.stable_sort ~compare

let insert_defs prog sub =
let blk_with_def intent blk jmp sub : blk term option =
call_of_jmp jmp >>= fun caller ->
callee caller prog >>= fun callee ->
target intent sub blk caller >>| fun blk ->
Term.enum arg_t callee |>
enum_args callee |>
defs_of_args jmp intent |>
Seq.fold ~init:blk ~f:(add_def intent) in
List.fold ~init:blk ~f:(add_def intent) in
let insert intent blk jmp sub =
Option.value_map (blk_with_def intent blk jmp sub)
~default:sub ~f:(Term.update blk_t sub) in
Expand Down

0 comments on commit 651003f

Please sign in to comment.