Add a simple_simul compiler option

This commit is contained in:
jeltz 2020-12-30 01:10:45 +01:00
parent 8d77b7434b
commit 215b602383
Signed by: jeltz
GPG Key ID: 800882B66C0C3326
2 changed files with 59 additions and 37 deletions

View File

@ -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,14 +315,23 @@ 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 =
Cfundef { let args = if !Compiler_options.simple_simul then
C.f_name = "main"; []
f_retty = Cty_int; else
f_args = [("argc", Cty_int); ("argv", Cty_ptr (Cty_ptr Cty_char))]; [("argc", Cty_int); ("argv", Cty_ptr (Cty_ptr Cty_char))]
f_body = { in
var_decls = vardecl_of_cvars let cvars = if !Compiler_options.simple_simul then
((step_counter, Cty_int) :: (max_step, Cty_int) :: var_list); var_list
block_body = 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; step_count = 0;
@ -349,8 +361,16 @@ let main_skel var_list prologue body =
Cvar step_counter, Cvar step_counter,
mk_int 1)) mk_int 1))
:: body); :: 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
} }
} }

View File

@ -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