Add a simple_simul compiler option
This commit is contained in:
parent
8d77b7434b
commit
215b602383
|
@ -295,10 +295,13 @@ let main_def_of_class_def cd =
|
||||||
@ [Csexpr funcall]
|
@ [Csexpr funcall]
|
||||||
@ printf_calls
|
@ printf_calls
|
||||||
@
|
@
|
||||||
(if !Compiler_options.hepts_simulation
|
(if !Compiler_options.hepts_simulation || !Compiler_options.simple_simul
|
||||||
then []
|
then []
|
||||||
else [Csexpr (Cfun_call ("puts", [Cconst (Cstrlit "")]))])
|
else [Csexpr (Cfun_call ("puts", [Cconst (Cstrlit "")]))])
|
||||||
@ [Csexpr (Cfun_call ("fflush", [Cvar "stdout"]))] in
|
@ (if !Compiler_options.simple_simul
|
||||||
|
then []
|
||||||
|
else [Csexpr (Cfun_call ("fflush", [Cvar "stdout"]))])
|
||||||
|
in
|
||||||
|
|
||||||
(* Do not forget to initialize memory via reset if needed. *)
|
(* Do not forget to initialize memory via reset if needed. *)
|
||||||
let rst_i =
|
let rst_i =
|
||||||
|
@ -312,45 +315,62 @@ let main_def_of_class_def cd =
|
||||||
(** [main_skel var_list prologue body] generates a C main() function using the
|
(** [main_skel var_list prologue body] generates a C main() function using the
|
||||||
variable list [var_list], prologue [prologue] and loop body [body]. *)
|
variable list [var_list], prologue [prologue] and loop body [body]. *)
|
||||||
let main_skel var_list prologue body =
|
let main_skel var_list prologue body =
|
||||||
|
let args = if !Compiler_options.simple_simul then
|
||||||
|
[]
|
||||||
|
else
|
||||||
|
[("argc", Cty_int); ("argv", Cty_ptr (Cty_ptr Cty_char))]
|
||||||
|
in
|
||||||
|
let cvars = if !Compiler_options.simple_simul then
|
||||||
|
var_list
|
||||||
|
else
|
||||||
|
(step_counter, Cty_int) :: (max_step, Cty_int) :: var_list
|
||||||
|
in
|
||||||
|
let body_block = if !Compiler_options.simple_simul then
|
||||||
|
prologue
|
||||||
|
@ [
|
||||||
|
Cwhile (mk_int 1, body);
|
||||||
|
Creturn (mk_int 0)
|
||||||
|
]
|
||||||
|
else
|
||||||
|
[
|
||||||
|
(*
|
||||||
|
step_count = 0;
|
||||||
|
max_step = 0;
|
||||||
|
if (argc == 2)
|
||||||
|
max_step = atoi(argv[1]);
|
||||||
|
*)
|
||||||
|
Caffect (CLvar step_counter, mk_int 0);
|
||||||
|
Caffect (CLvar max_step, mk_int 0);
|
||||||
|
Cif (Cbop ("==", Cvar "argc", mk_int 2),
|
||||||
|
[Caffect (CLvar max_step,
|
||||||
|
Cfun_call ("atoi",
|
||||||
|
[Carray (Cvar "argv",
|
||||||
|
mk_int 1)]))], []);
|
||||||
|
]
|
||||||
|
@ prologue
|
||||||
|
(* while (!max_step || step_c < max_step) *)
|
||||||
|
@ [
|
||||||
|
Cwhile (Cbop ("||",
|
||||||
|
Cuop ("!", Cvar max_step),
|
||||||
|
Cbop ("<",
|
||||||
|
Cvar step_counter,
|
||||||
|
Cvar max_step)),
|
||||||
|
(* step_counter = step_counter + 1; *)
|
||||||
|
Caffect (CLvar step_counter,
|
||||||
|
Cbop ("+",
|
||||||
|
Cvar step_counter,
|
||||||
|
mk_int 1))
|
||||||
|
:: body);
|
||||||
|
Creturn (mk_int 0)
|
||||||
|
]
|
||||||
|
in
|
||||||
Cfundef {
|
Cfundef {
|
||||||
C.f_name = "main";
|
C.f_name = "main";
|
||||||
f_retty = Cty_int;
|
f_retty = Cty_int;
|
||||||
f_args = [("argc", Cty_int); ("argv", Cty_ptr (Cty_ptr Cty_char))];
|
f_args = args;
|
||||||
f_body = {
|
f_body = {
|
||||||
var_decls = vardecl_of_cvars
|
var_decls = vardecl_of_cvars cvars;
|
||||||
((step_counter, Cty_int) :: (max_step, Cty_int) :: var_list);
|
block_body = body_block
|
||||||
block_body =
|
|
||||||
[
|
|
||||||
(*
|
|
||||||
step_count = 0;
|
|
||||||
max_step = 0;
|
|
||||||
if (argc == 2)
|
|
||||||
max_step = atoi(argv[1]);
|
|
||||||
*)
|
|
||||||
Caffect (CLvar step_counter, mk_int 0);
|
|
||||||
Caffect (CLvar max_step, mk_int 0);
|
|
||||||
Cif (Cbop ("==", Cvar "argc", mk_int 2),
|
|
||||||
[Caffect (CLvar max_step,
|
|
||||||
Cfun_call ("atoi",
|
|
||||||
[Carray (Cvar "argv",
|
|
||||||
mk_int 1)]))], []);
|
|
||||||
]
|
|
||||||
@ prologue
|
|
||||||
(* while (!max_step || step_c < max_step) *)
|
|
||||||
@ [
|
|
||||||
Cwhile (Cbop ("||",
|
|
||||||
Cuop ("!", Cvar max_step),
|
|
||||||
Cbop ("<",
|
|
||||||
Cvar step_counter,
|
|
||||||
Cvar max_step)),
|
|
||||||
(* step_counter = step_counter + 1; *)
|
|
||||||
Caffect (CLvar step_counter,
|
|
||||||
Cbop ("+",
|
|
||||||
Cvar step_counter,
|
|
||||||
mk_int 1))
|
|
||||||
:: body);
|
|
||||||
Creturn (mk_int 0);
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,8 @@ let hepts_simulation = ref false
|
||||||
|
|
||||||
let create_object_file = ref false
|
let create_object_file = ref false
|
||||||
|
|
||||||
|
let simple_simul = ref true
|
||||||
|
|
||||||
let boolean = ref false
|
let boolean = ref false
|
||||||
|
|
||||||
let nosink = ref false
|
let nosink = ref false
|
||||||
|
|
Loading…
Reference in New Issue