Skip to content

Commit

Permalink
[Refactor] refactor exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
oojahooo committed Apr 25, 2024
1 parent 835be3c commit 3648789
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions src/patch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,47 +71,32 @@ let match_one_by_one ?(db = false) z3env bt_dir donee_dir target_alarm donee_ast
L.info "Try matching with %s..." cand_donor;
let donor_dir = if db then Filename.concat bt_dir cand_donor else out_dir in
let buggy_maps = Maps.create_maps () in
if not (Sys.file_exists (Filename.concat donor_dir "buggy_numeral.map")) then (
L.warn "No numeral map for %s" cand_donor;
())
else
let buggy_ic =
Filename.concat donor_dir "buggy_numeral.map" |> In_channel.create
in
Maps.load_numeral_map buggy_ic buggy_maps.numeral_map;
List.fold_until ~init:()
~f:(fun _ i ->
try
match_once z3env cand_donor donor_dir buggy_maps donee_dir
target_alarm donee_ast out_dir i
with e ->
L.warn "%s" (Exn.to_string e);
Stop ())
[ 0; 1 ] ~finish:ignore
let buggy_ic =
Filename.concat donor_dir "buggy_numeral.map" |> In_channel.create
in
Maps.load_numeral_map buggy_ic buggy_maps.numeral_map;
List.fold_until ~init:()
~f:(fun _ i ->
match_once z3env cand_donor donor_dir buggy_maps donee_dir target_alarm
donee_ast out_dir i)
[ 0; 1 ] ~finish:ignore

let match_one_alarm ?(db = false) z3env donee_dir donee_ast out_dir db_dir
target_alarm =
L.info "Target Alarm: %s" target_alarm;
if String.equal target_alarm "Alarm.map" then ()
else
let bug_type = Utils.find_bug_type donee_dir target_alarm in
if db then
let bt_dir = Filename.concat db_dir bug_type in
Sys_unix.ls_dir bt_dir
|> List.iter
~f:
(match_one_by_one ~db z3env bt_dir donee_dir target_alarm donee_ast
out_dir)
else
match_one_by_one ~db z3env "" donee_dir target_alarm donee_ast out_dir ""
let bug_type = Utils.find_bug_type donee_dir target_alarm in
if db then
let bt_dir = Filename.concat db_dir bug_type in
Sys_unix.ls_dir bt_dir
|> List.iter
~f:
(match_one_by_one ~db z3env bt_dir donee_dir target_alarm donee_ast
out_dir)
else match_one_by_one ~db z3env "" donee_dir target_alarm donee_ast out_dir ""

let run ?(db = false) z3env inline_funcs db_dir donee_dir out_dir =
let donee_ast = Parser.parse_ast donee_dir inline_funcs in
Sys.readdir (Filename.concat donee_dir "sparrow-out/taint/datalog")
|> Array.iter
~f:
(try match_one_alarm ~db z3env donee_dir donee_ast out_dir db_dir
with e ->
fun _ ->
L.warn "%s" (Exn.to_string e);
())
Sys_unix.ls_dir (Filename.concat donee_dir "sparrow-out/taint/datalog")
|> List.iter ~f:(fun ta ->
try match_one_alarm ~db z3env donee_dir donee_ast out_dir db_dir ta
with e -> L.warn "%s" (Exn.to_string e))

0 comments on commit 3648789

Please sign in to comment.