diff --git a/README.org b/README.org index 0f6bb23132825917389203238da6ae30934e93b3..fab82ce4a84bf151c4189ffaba989e0f2f68c000 100644 --- a/README.org +++ b/README.org @@ -40,9 +40,9 @@ install everything, and 'make test' ougth to exit with a 0 return code. #+BEGIN_SRC sh -opam install lutils extlib git clone https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/lustre-v6/lustre-v6.git cd lustre-v6 +opam install --deps-only ./lustre-v6.opam make make install make test diff --git a/lib/soc2c.ml b/lib/soc2c.ml index 7667dea97ba723b2098f408f6b7e69fa565bb61a..489847faf2345957894e89d21a3c71396fed0bce 100644 --- a/lib/soc2c.ml +++ b/lib/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 19/07/2022 (at 16:05) by Erwan Jahier> *) +(* Time-stamp: <modified the 22/07/2022 (at 11:12) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -685,6 +685,10 @@ let (gen_loop_file : string -> LicPrg.t -> Soc.t -> string -> let outputs_io = SocVar.expand_profile true false outputs in let inputs_exp = SocVar.expand_profile true true inputs in let outputs_exp= SocVar.expand_profile true true outputs in + let c_outputs_t = String.concat "," (List.map (fun (id,t) -> Soc2cUtil.type_to_string t id) outputs_io) in + let outputs_list = String.concat "," (List.map (fun (id,_) -> id ) outputs_io) in + let inputs_fmt = List.map (fun (_,t) -> type_to_format_string t) inputs_io in + let outputs_fmt = List.map (fun (_,t) -> type_to_format_string t) outputs_io in Lv6util.entete main_oc "/*" "*/"; Lv6util.entete readinput_oc_c "/*" "*/"; @@ -821,8 +825,43 @@ void _put_string(char* n, char* _V){ } "^(Soc2cExtern.gen_getters fn licprg soc)^" /* Output procedures **********************/ -"^ (gen_memoryless_ctx stbl) +"^ (gen_memoryless_ctx stbl) ^ " + +/* I/O functions for the main loop **********************/ +void get_inputs ("^ + (if SocUtils.is_memory_less soc then "" else ctx^"_type* ctx, ")^ + (String.concat "," + (List.map + (fun (id,t) -> + match t with + | Array (_, _) -> Soc2cUtil.type_to_string t id + | _ -> Soc2cUtil.type_to_string t ("* "^id) ) + inputs) + )^"){\n" ); + + List.iter + (fun (id,t) -> + let t = type_to_string_rif t in + let clk = "" in (* XXX finish me: get the clock if id using soc.clock_profile + and set this string to something like "if (clk_id)" + *) + let str = + let ctx_opt = if SocUtils.is_memory_less soc then "" else "ctx," in + if io_transmit_mode () = Lv6MainArgs.Stack + then Printf.sprintf " %s %s = _get_%s(%s\"%s\");\n" clk (pointer_of_ident id) t ctx_opt id + else Printf.sprintf " %s ctx->%s = _get_%s(%s\"%s\");\n" clk id t ctx_opt id + in + putc_ri str + ) + inputs_exp; + putc_ri ("}\n"); + putc_ri ("void print_outputs ("^c_outputs_t^"){ + printf(\"" ^ (String.concat " " outputs_fmt)^ "\\n\"," ^ outputs_list^ "); +} + +"); + puth_ri (" #include <stdlib.h> #include <stdio.h> @@ -855,50 +894,29 @@ void _put_string(char*, char*); /* Print a promt ? ************************/ static int ISATTY; "); + puth_ri (" +/* I/O functions for the main loop **********************/ +void get_inputs ("^ + (if SocUtils.is_memory_less soc then "" else ctx^"_type*, ")^ + (String.concat "," + (List.map + (fun (_id,t) -> + match t with + | Array (_, _) -> Soc2cUtil.type_to_string t "" + | _ -> Soc2cUtil.type_to_string t ("*") ) + inputs) + )^");\n"); + let c_outputs_profile = String.concat "," (List.map (fun (_,t) -> Soc2cUtil.type_to_string t "") outputs_io) in + puth_ri ("void print_outputs ("^c_outputs_profile^");\n"); + puth_ri "/* I/O functions end **********************/\n"; let to_rif_decl (n,t) = ("\\\""^n^"\\\":" ^(type_to_string_rif t)) in let inputs_t = List.map to_rif_decl inputs_io in let outputs_t = List.map to_rif_decl outputs_io in let inputs_decl = Printf.sprintf "#inputs %s" (String.concat " " inputs_t) in let outputs_decl = Printf.sprintf "#outputs %s" (String.concat " " outputs_t) in - let inputs_fmt = List.map (fun (_,t) -> type_to_format_string t) inputs_io in - let outputs_fmt = List.map (fun (_,t) -> type_to_format_string t) outputs_io in - let c_outputs_t = String.concat "," (List.map (fun (id,t) -> Soc2cUtil.type_to_string t id) outputs_io) in - let outputs_list = String.concat "," (List.map (fun (id,_) -> id ) outputs_io) in putc (" #include \""^base0 ^"_loop_io.h\"\ - -void get_inputs ("^ - (if SocUtils.is_memory_less soc then "" else ctx^"_type* ctx, ")^ - (String.concat "," - (List.map - (fun (id,t) -> - match t with - | Array (_, _) -> Soc2cUtil.type_to_string t id - | _ -> Soc2cUtil.type_to_string t ("* "^id) ) - inputs) - )^ - "){\n"); - List.iter - (fun (id,t) -> - let t = type_to_string_rif t in - let clk = "" in (* XXX finish me: get the clock if id using soc.clock_profile - and set this string to something like "if (clk_id)" - *) - let str = - let ctx_opt = if SocUtils.is_memory_less soc then "" else "ctx," in - if io_transmit_mode () = Lv6MainArgs.Stack - then Printf.sprintf " %s %s = _get_%s(%s\"%s\");\n" clk (pointer_of_ident id) t ctx_opt id - else Printf.sprintf " %s ctx->%s = _get_%s(%s\"%s\");\n" clk id t ctx_opt id - in - putc str - ) - inputs_exp; - putc ("}\n"); - putc ("void print_outputs ("^c_outputs_t^"){ - printf(\"" ^ (String.concat " " outputs_fmt)^ "\\n\"," ^ outputs_list^ "); -} - "); putc (" @@ -1036,8 +1054,8 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) = string_of_soc_key msoc else Filename.basename ( - try Filename.chop_extension args.Lv6MainArgs.outfile - with Invalid_argument _ -> args.Lv6MainArgs.outfile) + try Filename.chop_extension args.Lv6MainArgs.outfile + with Invalid_argument _ -> args.Lv6MainArgs.outfile) in let base = Filename.concat dir base0 in let hfile0 = base0 ^ ".h" in @@ -1062,7 +1080,7 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) = let const_def_h, const_def_c = constdef licprg in let assign_ext_types_list = (Soc2cGenAssign.gen_used_types socs) in let main_soc = SocUtils.find_no_exc msoc stbl in - (* Generate ext files if necessary *) + (* Generate ext files if necessary *) let needs_cfile, needs_hfile = Soc2cExtern.gen_files main_soc stbl licprg ext_cfile ext_hfile hfile in @@ -1086,57 +1104,61 @@ typedef float _float; #define _true 1 #endif // end of _SOC2C_PREDEF_TYPES"); - let putc s = output_string occ s in - let cfmt fmt = Printf.kprintf (fun t -> output_string occ t) fmt in - let puth s = output_string och s in - Lv6util.entete och "/*" "*/"; + let putc s = output_string occ s in + let cfmt fmt = Printf.kprintf (fun t -> output_string occ t) fmt in + let puth s = output_string och s in + Lv6util.entete och "/*" "*/"; - puth "\n#include <stdio.h>"; - puth "\n#include <stdlib.h>"; - puth "\n#include <string.h>\n"; - puth "#include \"lustre_consts.h\""; - output_string och (" + puth "\n#include <stdio.h>"; + puth "\n#include <stdlib.h>"; + puth "\n#include <string.h>\n"; + puth "#include \"lustre_consts.h\""; + output_string och (" // User typedef #ifndef _"^base0^"_TYPES #define _"^base0^"_TYPES\n"); - - output_string och (user_typedef licprg); flush och; - - if needs_hfile || args.Lv6MainArgs.ext_types then ( - puth (Printf.sprintf "\n#ifndef _%s_H_FILE\n" base0); - puth (Printf.sprintf "#include \"%s\"\n" ext_hfile0); - puth (Printf.sprintf "#define _%s_H_FILE\n" base0); - puth (Printf.sprintf "#endif // _%s_H_FILE\n\n" base0); - ); - try + + output_string och (user_typedef licprg); flush och; + + if needs_hfile || args.Lv6MainArgs.ext_types then ( + puth (Printf.sprintf "\n#ifndef _%s_H_FILE\n" base0); + puth (Printf.sprintf "#include \"%s\"\n" ext_hfile0); + puth (Printf.sprintf "#define _%s_H_FILE\n" base0); + puth (Printf.sprintf "#endif // _%s_H_FILE\n\n" base0); + ); + try Lv6util.entete occ "/*" "*/" ; + let gen_loop_files () = + gen_loop_file loopfile licprg main_soc base ocl ocl_readinput_c ocl_readinput_h stbl + in if Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then () else if Lv6MainArgs.global_opt.Lv6MainArgs.multi_core then ( - Soc2yaml.f msoc stbl base + Soc2yaml.f msoc stbl base; + gen_loop_files () ) else if Lv6MainArgs.global_opt.Lv6MainArgs.gen_wcet then ( gen_loop_file4ogensim main_soc base ocl stbl; gen_main_wcet_file main_soc base stbl ) else - gen_loop_file loopfile licprg main_soc base ocl ocl_readinput_c ocl_readinput_h stbl; + gen_loop_files (); putc (Printf.sprintf "#include \"%s\"\n" hfile0); -(* putc (Soc2cExtern.cpy_declaration licprg); *) + (* putc (Soc2cExtern.cpy_declaration licprg); *) putc (Soc2cExtern.const_declaration licprg); let cfiles_acc = - if io_transmit_mode () = Lv6MainArgs.Heap then ( - if socs = [] then [] else ( - putc "/////////////////////////////////////////////////\n"; - putc "//// Static allocation of memoryless soc ctx\n"; - let cfiles_acc = List.fold_left (soc2c 1 och occ stbl msoc) cfiles_acc socs in - putc "/////////////////////////////////////////////////\n"; - cfiles_acc - ); - ) else cfiles_acc + if io_transmit_mode () = Lv6MainArgs.Heap then ( + if socs = [] then [] else ( + putc "/////////////////////////////////////////////////\n"; + putc "//// Static allocation of memoryless soc ctx\n"; + let cfiles_acc = List.fold_left (soc2c 1 och occ stbl msoc) cfiles_acc socs in + putc "/////////////////////////////////////////////////\n"; + cfiles_acc + ); + ) else cfiles_acc in output_string och (typedef_all licprg stbl main_soc); - + putc "//// Defining step functions\n"; let cfiles_acc = List.fold_left (soc2c 2 och occ stbl msoc) cfiles_acc socs in @@ -1147,7 +1169,7 @@ typedef float _float; let outputs_exp2= SocVar.expand_profile true false outputs in let name = get_base_name main_soc.key in if Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then ( - cfmt "///////// dro stuff + cfmt "///////// dro stuff /* droconf.h begins */ /* @@ -1179,15 +1201,15 @@ void ( *init )(); }; /* droconf.h ends */ "; - cfmt "static %s_ctx_type %s_ctx;\n" name name; - cfmt "//dro requires : int ( *step )(); + cfmt "static %s_ctx_type %s_ctx;\n" name name; + cfmt "//dro requires : int ( *step )(); static int ze_step(){ - %s_step(& %s_ctx); - return 0; +%s_step(& %s_ctx); +return 0; } //dro requires : void ( *reset )(); static void ze_reset(){ - %s +%s } #define DRO_REAL(X) ((sizeof(_real)==4)? \"float\" : (sizeof(_real)==8)? \"double\" : \"unknown\") @@ -1197,21 +1219,21 @@ static void ze_reset(){ struct dro_var_t dro_intab[] = { " - name name - (if SocUtils.is_memory_less main_soc then "" else - Printf.sprintf "%s_ctx_reset(& %s_ctx);" name name); - let line2str (id, t) (id2, _t) = - let t = (type_to_string_rif t) in - let cap_t = String.uppercase_ascii t in - Printf.sprintf " {\"%s\", DRO_%s(%s), (void*)&%s_ctx.%s}" id2 cap_t t name id - in - putc (String.concat ",\n" (List.map2 line2str inputs_exp inputs_exp2)); - cfmt "\n}; + name name + (if SocUtils.is_memory_less main_soc then "" else + Printf.sprintf "%s_ctx_reset(& %s_ctx);" name name); + let line2str (id, t) (id2, _t) = + let t = (type_to_string_rif t) in + let cap_t = String.uppercase_ascii t in + Printf.sprintf " {\"%s\", DRO_%s(%s), (void*)&%s_ctx.%s}" id2 cap_t t name id + in + putc (String.concat ",\n" (List.map2 line2str inputs_exp inputs_exp2)); + cfmt "\n}; /* dro: output pointers table */ struct dro_var_t dro_outab[] = { "; - putc (String.concat ",\n" (List.map2 line2str outputs_exp outputs_exp2)); - cfmt "\n}; + putc (String.concat ",\n" (List.map2 line2str outputs_exp outputs_exp2)); + cfmt "\n}; /* dro: dynamic linking infos table */ struct dro_desc_t DRO_DESC_NAME = { DROVERSION, /* expected dro version */ @@ -1223,17 +1245,17 @@ struct dro_desc_t DRO_DESC_NAME = { ze_reset /* init proc = reset proc */ }; " name (List.length inputs_exp) (List.length outputs_exp); - ); (* end dro stuff *) - + ); (* end dro stuff *) + puth "/////////////////////////////////////////////////\n"; if assign_ext_types_list <> [] then ( output_string och "\n// Defining array and extern types assignments \n"; if Lv6MainArgs.global_opt.Lv6MainArgs.gen_wcet then List.iter (fun t -> output_string och (Soc2cGenAssign.f_forloop t)) - assign_ext_types_list + assign_ext_types_list else List.iter (fun t -> output_string och (Soc2cGenAssign.f t)) - assign_ext_types_list + assign_ext_types_list ); output_string och ("#endif // end of _"^base0^"_TYPES\n"); @@ -1247,7 +1269,7 @@ struct dro_desc_t DRO_DESC_NAME = { flush consts_h_oc; close_out consts_h_oc; flush consts_c_oc; close_out consts_c_oc; if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then - Printf.eprintf "W: %s has been generated.\n" loopfile; + Printf.eprintf "W: %s has been generated.\n" loopfile; Printf.eprintf "W: %s has been generated.\n" hfile; Printf.eprintf "W: %s has been generated.\n" cfile; flush stderr; @@ -1277,7 +1299,7 @@ struct dro_desc_t DRO_DESC_NAME = { Printf.sprintf "if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi %s -o %s \\\n\t%s %s %s" gcc execfile cfiles cflags main_files, Printf.sprintf "%s -o %s \\\n\t%s %s %s" - gcc ogensim_exe cfiles cflags ogensim_main_file + gcc ogensim_exe cfiles cflags ogensim_main_file in let main_step = (string_of_soc_key msoc)^"_step" in let gcc = if Lv6MainArgs.global_opt.Lv6MainArgs.gen_wcet then @@ -1330,10 +1352,10 @@ if [ \"$otawa\" = \"true\" ] then # ZZZ otawa won't work with programs that use division because of orange (!?) # Let's compile the c files for otawa\n" ^ - gcc ^ " > \\\n\t$n_n.owcet.log 2>&1 &&\n\n"^ - "$ORANGE $cfile ${n_n}_step -o $n_n.ffx > $n_n.orange.log 2>&1 &&\n" ^ + gcc ^ " > \\\n\t$n_n.owcet.log 2>&1 &&\n\n"^ + "$ORANGE $cfile ${n_n}_step -o $n_n.ffx > $n_n.orange.log 2>&1 &&\n" ^ -" + " IDIR=`readlink -f fixffx` IDIR=`dirname \"$IDIR\"` ARM_LOOPLOC=\"$IDIR/arm.looploc\" @@ -1341,29 +1363,29 @@ ARM_LOOPLOC=\"$IDIR/arm.looploc\" $mkff -x $execfile > $n_n.ff $fixffx $ARM_LOOPLOC -i $n_n.ff > $n_n.fixed.ffx # Let's run otawa (owcet.arm)\n" ^ - "$OTAWA $execfile $main_step -f $n_n.fixed.ffx -f $n_n.ffx --add-prop otawa::ilp::OUTPUT_PATH=$main_step.lp \\\n\t>"^ - "$n_n.owcet.arm.log 2>&1 && \n"^ - "grep WCET $n_n.owcet.arm.log | cut -d \"=\" -f 2 > "^ - "$n.wcet &&\n\n" ^ - "WCET=`cat $n.wcet` \n\n" ^ - "# Let's compile the c files for ogensim \n" ^ - " + "$OTAWA $execfile $main_step -f $n_n.fixed.ffx -f $n_n.ffx --add-prop otawa::ilp::OUTPUT_PATH=$main_step.lp \\\n\t>"^ + "$n_n.owcet.arm.log 2>&1 && \n"^ + "grep WCET $n_n.owcet.arm.log | cut -d \"=\" -f 2 > "^ + "$n.wcet &&\n\n" ^ + "WCET=`cat $n.wcet` \n\n" ^ + "# Let's compile the c files for ogensim \n" ^ + " fi if [ \"$ogensim\" = \"true\" ] then # Now let's run ogensim \n(" ^ - gcc_ogensim ^ " >>$n_n.owcet.log 2>&1 &&\n"^ - "$LUSTREV6 "^(String.concat " " args.Lv6MainArgs.infiles)^" -n $n"^ - " -interface > $n.io &&\n"^ - "$LUSTREV6 "^(String.concat " " args.Lv6MainArgs.infiles)^" -n $n --gen-autotest &&\n\n"^ - "# Now let's run ogensim \n" ^ - "($OGENSIM "^ogensim_exe^" -ul 1 \\\n\t-e $main_step"^ - " -cl $n.cycles -lp $freeport \\\n\t-iol $n.io > $n_n"^ - ".ogensim.log 2>&1&) && \n\nsleep 1 &&\n"^ - "($rdbg -lurette -l 1000 -o "^node^".rif \\\n\t \ - --sut-socket \"127.0.0.1:$freeport\" \\\n\t \ - --env-stdio \"$lutin -boot -rif _${n}_env.lut -n ${n}_env\" || true)) &&\n\n"^ - "$getstat $n.cycles $WCET > $n.stat + gcc_ogensim ^ " >>$n_n.owcet.log 2>&1 &&\n"^ + "$LUSTREV6 "^(String.concat " " args.Lv6MainArgs.infiles)^" -n $n"^ + " -interface > $n.io &&\n"^ + "$LUSTREV6 "^(String.concat " " args.Lv6MainArgs.infiles)^" -n $n --gen-autotest &&\n\n"^ + "# Now let's run ogensim \n" ^ + "($OGENSIM "^ogensim_exe^" -ul 1 \\\n\t-e $main_step"^ + " -cl $n.cycles -lp $freeport \\\n\t-iol $n.io > $n_n"^ + ".ogensim.log 2>&1&) && \n\nsleep 1 &&\n"^ + "($rdbg -lurette -l 1000 -o "^node^".rif \\\n\t \ + --sut-socket \"127.0.0.1:$freeport\" \\\n\t \ + --env-stdio \"$lutin -boot -rif _${n}_env.lut -n ${n}_env\" || true)) &&\n\n"^ + "$getstat $n.cycles $WCET > $n.stat fi if [ \"$xpdf\" = \"true\" ] then @@ -1375,7 +1397,7 @@ fi in output_string ocsh (gcc^"\n\n"); flush ocsh; - + close_out types_h_oc; close_out ocsh; let call_script = Printf.sprintf "sh %s.sh" (Filename.concat dir node) in @@ -1394,17 +1416,17 @@ fi ) else print_string ("you can compile those files calling: "^call_script^"\n"); flush stdout - with - | Delete_C_files -> - close_out types_h_oc; - close_out occ; - close_out och; - if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then close_out ocl; - if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then close_out ocl_readinput_c; - if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then close_out ocl_readinput_h; - if Sys.file_exists hfile then Sys.remove hfile; - if Sys.file_exists cfile then Sys.remove cfile; - if Sys.file_exists ext_cfile then Sys.remove ext_cfile; - if Sys.file_exists ext_hfile then Sys.remove ext_hfile; - if Sys.file_exists loopfile then Sys.remove loopfile; - exit 2 + with + | Delete_C_files -> + close_out types_h_oc; + close_out occ; + close_out och; + if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then close_out ocl; + if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then close_out ocl_readinput_c; + if not Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then close_out ocl_readinput_h; + if Sys.file_exists hfile then Sys.remove hfile; + if Sys.file_exists cfile then Sys.remove cfile; + if Sys.file_exists ext_cfile then Sys.remove ext_cfile; + if Sys.file_exists ext_hfile then Sys.remove ext_hfile; + if Sys.file_exists loopfile then Sys.remove loopfile; + exit 2