|
|
|
@ -295,10 +295,13 @@ let main_def_of_class_def cd =
|
|
|
|
|
@ [Csexpr funcall]
|
|
|
|
|
@ printf_calls
|
|
|
|
|
@
|
|
|
|
|
(if !Compiler_options.hepts_simulation
|
|
|
|
|
(if !Compiler_options.hepts_simulation || !Compiler_options.simple_simul
|
|
|
|
|
then []
|
|
|
|
|
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. *)
|
|
|
|
|
let rst_i =
|
|
|
|
@ -312,14 +315,23 @@ let main_def_of_class_def cd =
|
|
|
|
|
(** [main_skel var_list prologue body] generates a C main() function using the
|
|
|
|
|
variable list [var_list], prologue [prologue] and loop body [body]. *)
|
|
|
|
|
let main_skel var_list prologue body =
|
|
|
|
|
Cfundef {
|
|
|
|
|
C.f_name = "main";
|
|
|
|
|
f_retty = Cty_int;
|
|
|
|
|
f_args = [("argc", Cty_int); ("argv", Cty_ptr (Cty_ptr Cty_char))];
|
|
|
|
|
f_body = {
|
|
|
|
|
var_decls = vardecl_of_cvars
|
|
|
|
|
((step_counter, Cty_int) :: (max_step, Cty_int) :: var_list);
|
|
|
|
|
block_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;
|
|
|
|
@ -349,8 +361,16 @@ let main_skel var_list prologue body =
|
|
|
|
|
Cvar step_counter,
|
|
|
|
|
mk_int 1))
|
|
|
|
|
:: body);
|
|
|
|
|
Creturn (mk_int 0);
|
|
|
|
|
];
|
|
|
|
|
Creturn (mk_int 0)
|
|
|
|
|
]
|
|
|
|
|
in
|
|
|
|
|
Cfundef {
|
|
|
|
|
C.f_name = "main";
|
|
|
|
|
f_retty = Cty_int;
|
|
|
|
|
f_args = args;
|
|
|
|
|
f_body = {
|
|
|
|
|
var_decls = vardecl_of_cvars cvars;
|
|
|
|
|
block_body = body_block
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|