summaryrefslogtreecommitdiff
path: root/sched/main.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-04 22:05:57 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-04 22:05:57 +0100
commitcebd07b64f1f537c5ecf00ec21ff4b7c4032f0a3 (patch)
tree9d2048313fe3ad4c92865c8f0236bed24e64449b /sched/main.ml
parentf253f98136def21b5e50c5922246e2ddfe315442 (diff)
downloadSystDigit-Projet-cebd07b64f1f537c5ecf00ec21ff4b7c4032f0a3.tar.gz
SystDigit-Projet-cebd07b64f1f537c5ecf00ec21ff4b7c4032f0a3.zip
Added stub C simulator (defined dumb-down syntax for netlists).
Diffstat (limited to 'sched/main.ml')
-rw-r--r--sched/main.ml50
1 files changed, 50 insertions, 0 deletions
diff --git a/sched/main.ml b/sched/main.ml
new file mode 100644
index 0000000..988d1ec
--- /dev/null
+++ b/sched/main.ml
@@ -0,0 +1,50 @@
+let simulate = ref false
+let number_steps = ref (-1)
+let sim_path = ref "./netlist_simulator.byte"
+let dumb_down = ref false
+
+let compile filename =
+ try
+ let p = Netlist.read_file filename in
+ let out_name = (Filename.chop_suffix filename ".net") ^ "_sch.net" in
+ let dumb_out_name = (Filename.chop_suffix filename ".net") ^ ".dumb" in
+ let q = ref p in
+
+ begin try
+ q := Scheduler.schedule p
+ with
+ | Scheduler.Combinational_cycle ->
+ Format.eprintf "The netlist has a combinatory cycle.@.";
+ exit 2;
+ end;
+
+ let out = open_out out_name in
+ Netlist_printer.print_program out !q;
+ close_out out;
+ let dumb_out = open_out dumb_out_name in
+ Netlist_printer.print_dumb_program dumb_out !q;
+ close_out dumb_out;
+
+ if !simulate then (
+ let simulator =
+ if !number_steps = -1 then
+ !sim_path
+ else
+ !sim_path ^ " -n " ^ (string_of_int !number_steps)
+ in
+ ignore (Unix.system (simulator^" "^(if !dumb_down then dumb_out_name else out_name)))
+ )
+ with
+ | Netlist.Parse_error s -> Format.eprintf "An error accurred: %s@." s; exit 2
+
+let main () =
+ Arg.parse
+ ["-s", Arg.Set simulate, "Launch the simulator";
+ "-sim", Arg.Set_string sim_path, "Path to the circuit simulator";
+ "-d", Arg.Set dumb_down, "Pass the dumbed-down netlist to the simulator (for the C simulator)";
+ "-n", Arg.Set_int number_steps, "Number of steps to simulate"]
+ compile
+ ""
+;;
+
+main ()