aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2020-09-10 16:20:40 +0200
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2020-09-10 16:20:40 +0200
commit0566b93d9e42ab023eb95a4535af0c3a86b0421c (patch)
tree3767113c0a3486dea006be78cbb8e69ac426d9be
parentd2a72d9218f633e99028d6ac59d19ec1bec81493 (diff)
downloadcompcert-kvx-0566b93d9e42ab023eb95a4535af0c3a86b0421c.tar.gz
compcert-kvx-0566b93d9e42ab023eb95a4535af0c3a86b0421c.zip
use with_destructor
-rw-r--r--kvx/InstructionScheduler.ml45
-rw-r--r--kvx/InstructionScheduler.mli4
2 files changed, 29 insertions, 20 deletions
diff --git a/kvx/InstructionScheduler.ml b/kvx/InstructionScheduler.ml
index 32f394b1..eab0b21a 100644
--- a/kvx/InstructionScheduler.ml
+++ b/kvx/InstructionScheduler.ml
@@ -12,6 +12,16 @@
(* *)
(* *************************************************************)
+let with_destructor dtor stuff f =
+ try let ret = f stuff in
+ dtor stuff;
+ ret
+ with exn -> dtor stuff;
+ raise exn;;
+
+let with_out_channel chan f = with_destructor close_out chan f;;
+let with_in_channel chan f = with_destructor close_in chan f;;
+
(** Schedule instructions on a synchronized pipeline
@author David Monniaux, CNRS, VERIMAG *)
@@ -844,16 +854,15 @@ let pseudo_boolean_solver = ref "pb_solver"
let pseudo_boolean_scheduler pb_type problem =
try
- let filename_in = "problem.opb"
- (* needed only if not using stdout and filename_out = "problem.sol" *) in
- let opb_problem = open_out filename_in in
- let mapper = pseudo_boolean_print_problem opb_problem problem pb_type in
- close_out opb_problem;
-
- let opb_solution = Unix.open_process_in (!pseudo_boolean_solver ^ " " ^ filename_in) in
- let ret = adjust_check_solution mapper (pseudo_boolean_read_solution mapper opb_solution) in
- close_in opb_solution;
- Some ret
+ let filename_in = "problem.opb" in
+ (* needed only if not using stdout and filename_out = "problem.sol" *)
+ let mapper =
+ with_out_channel (open_out filename_in)
+ (fun opb_problem ->
+ pseudo_boolean_print_problem opb_problem problem pb_type) in
+ Some (with_in_channel
+ (Unix.open_process_in (!pseudo_boolean_solver ^ " " ^ filename_in))
+ (fun opb_solution -> adjust_check_solution mapper (pseudo_boolean_read_solution mapper opb_solution)))
with
| Unschedulable -> None;;
@@ -1193,23 +1202,23 @@ let ilp_read_solution mapper channel =
let ilp_solver = ref "ilp_solver"
let problem_nr = ref 0
-
+
let ilp_scheduler pb_type problem =
try
let filename_in = Printf.sprintf "problem%05d.lp" !problem_nr
and filename_out = Printf.sprintf "problem%05d.sol" !problem_nr in
incr problem_nr;
- let opb_problem = open_out filename_in in
- let mapper = ilp_print_problem opb_problem problem pb_type in
- close_out opb_problem;
+ let mapper = with_out_channel (open_out filename_in)
+ (fun opb_problem -> ilp_print_problem opb_problem problem pb_type) in
begin
match Unix.system (!ilp_solver ^ " " ^ filename_in ^ " " ^ filename_out) with
| Unix.WEXITED 0 ->
- let opb_solution = open_in filename_out in
- let ret = adjust_check_solution mapper (ilp_read_solution mapper opb_solution) in
- close_in opb_solution;
- Some ret
+ Some (with_in_channel
+ (open_in filename_out)
+ (fun opb_solution ->
+ adjust_check_solution mapper
+ (ilp_read_solution mapper opb_solution)))
| Unix.WEXITED _ -> failwith "failed to start ilp solver"
| _ -> None
end
diff --git a/kvx/InstructionScheduler.mli b/kvx/InstructionScheduler.mli
index 6d27b30c..85e2a5c6 100644
--- a/kvx/InstructionScheduler.mli
+++ b/kvx/InstructionScheduler.mli
@@ -65,10 +65,10 @@ val list_scheduler : problem -> solution option
(** Schedule the problem using the order of instructions without any reordering *)
val greedy_scheduler : problem -> solution option
-(** Schedule a problem using a scheduler applied in the opposite direction, e.g. for list scheduling from the end instead of the start. *)
+(** Schedule a problem using a scheduler applied in the opposite direction, e.g. for list scheduling from the end instead of the start. BUGGY *)
val schedule_reversed : scheduler -> problem -> int array option
-(** Schedule a problem from the end using a list scheduler. *)
+(** Schedule a problem from the end using a list scheduler. BUGGY *)
val reverse_list_scheduler : problem -> int array option
(** Check that a problem is well-formed.