summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-21 13:41:47 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2016-03-21 13:41:47 -0400
commite004f1dd48527bf6e46a5c3a72ee4d1ff8c1d18e (patch)
tree8fed543e8d9906bb32424fb4ecbc39db64929fbb
parent3b6dc136a5db16c98643ec4bdfc2a2cc2cd267c1 (diff)
downloadroux-e004f1dd48527bf6e46a5c3a72ee4d1ff8c1d18e.tar.gz
wrap up abi.ml with a main function
-rw-r--r--lisc/tools/abi.ml52
1 files changed, 40 insertions, 12 deletions
diff --git a/lisc/tools/abi.ml b/lisc/tools/abi.ml
index 814bc79..7810e41 100644
--- a/lisc/tools/abi.ml
+++ b/lisc/tools/abi.ml
@@ -130,12 +130,6 @@ module Gen = struct
end
-module type OUT = sig
- val extension: string
- val comment: out_channel -> string -> unit
- val caller: out_channel -> testa -> testa list -> unit
- val callee: out_channel -> testa -> testa list -> unit
-end
(* Code generation for C *)
module OutC = struct
@@ -477,13 +471,47 @@ module OutIL = struct
end
+
+module type OUT = sig
+ val extension: string
+ val comment: out_channel -> string -> unit
+ val caller: out_channel -> testa -> testa list -> unit
+ val callee: out_channel -> testa -> testa list -> unit
+end
+
let _ =
- let module O = OutIL in
- let seed = Gen.init None in
+ let usage code =
+ Printf.eprintf "usage: abi.ml [-s SEED] DIR {c,ssa} {c,ssa}\n";
+ exit code in
+
+ let outmod = function
+ | "c" -> (module OutC : OUT)
+ | "ssa" -> (module OutIL: OUT)
+ | _ -> usage 1 in
+
+ let seed, dir, mcaller, mcallee =
+ match Sys.argv with
+ | [| _; "-s"; seed; dir; caller; callee |] ->
+ let seed =
+ try Some (int_of_string seed) with
+ Failure _ -> usage 1 in
+ seed, dir, outmod caller, outmod callee
+ | [| _; dir; caller; callee |] ->
+ None, dir, outmod caller, outmod callee
+ | [| _; "-h" |] ->
+ usage 0
+ | _ ->
+ usage 1 in
+
+ let seed = Gen.init seed in
let tret = Gen.test () in
let targs = Gen.tests () in
- let oc = stdout in
- O.comment oc (Printf.sprintf "seed %d" seed);
- O.caller oc tret targs;
- O.callee oc tret targs;
+ let module OCaller = (val mcaller : OUT) in
+ let module OCallee = (val mcallee : OUT) in
+ let ocaller = open_out (dir ^ "/caller" ^ OCaller.extension) in
+ let ocallee = open_out (dir ^ "/callee" ^ OCallee.extension) in
+ OCaller.comment ocaller (Printf.sprintf "seed %d" seed);
+ OCallee.comment ocallee (Printf.sprintf "seed %d" seed);
+ OCaller.caller ocaller tret targs;
+ OCallee.callee ocallee tret targs;
()