Commit 60401655 authored by erwan's avatar erwan
Browse files

New: add a -dir option

parent 3b76b067
(* Time-stamp: <modified the 02/07/2021 (at 10:48) by Erwan Jahier> *)
(* Time-stamp: <modified the 05/07/2021 (at 10:34) by Erwan Jahier> *)
(*
Le manager d'argument adapt de celui de lutin, plus joli
N.B. solution un peu batarde : les options sont stockes, comme avant, dans Global,
......@@ -48,6 +48,7 @@ type t = {
}
(* Those are really too boring to be functionnal (used in all over the places) *)
type global_opt = {
mutable dir : string;
mutable gen_c_inline_predef : bool;
mutable lv4 : bool;
mutable kcg : bool;
......@@ -73,6 +74,7 @@ type global_opt = {
}
let (global_opt:global_opt) =
{
dir = "";
gen_c_inline_predef = true;
gen_autotest = false;
lv4 = false;
......@@ -279,6 +281,10 @@ let mkoptab (opt:t) : unit = (
(Arg.String(function x -> opt.outfile <- x))
["Set the output file name"]
;
mkopt opt ["-dir";"--directory"] ~arg:" <string>"
(Arg.String(function x -> global_opt.dir <- x))
["Set the directory into which output files are generated"]
;
mkopt opt
["-exec"]
(Arg.Unit (fun _ ->
......
(* Time-stamp: <modified the 02/07/2021 (at 10:11) by Erwan Jahier> *)
(* Time-stamp: <modified the 05/07/2021 (at 10:29) by Erwan Jahier> *)
type enum_mode =
AsInt (* translate enums into int (for rif-friendlyness *)
......@@ -53,6 +53,7 @@ type t = {
(* Those are really too boring to be functionnal (used in all over the places) *)
type global_opt = {
mutable dir : string;
mutable gen_c_inline_predef : bool;
mutable lv4 : bool;
mutable kcg : bool;
......
(* Time-stamp: <modified the 05/07/2021 (at 10:23) by Erwan Jahier> *)
(* Time-stamp: <modified the 05/07/2021 (at 10:56) by Erwan Jahier> *)
(* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
......@@ -242,9 +242,13 @@ let (soc2c : int -> out_channel -> out_channel -> Soc.tbl -> Soc.key ->
Printf.kprintf (fun t -> output_string cfile t) "static %s %s;\n" ctx_name_type ctx_name;
cfiles_acc
) else (
let base = string_of_soc_key soc.key in
let dir = Lv6MainArgs.global_opt.Lv6MainArgs.dir in
let base0 = (string_of_soc_key soc.key) in
let base = Filename.concat dir base0 in
let cfile,hfile,cfiles_acc =
if one_file() || msoc_key = soc.key then cfile, hfile, cfiles_acc else
let _cfile0 = (base0^".c") in
let hfile0 = (base0^".h") in
let cfile = (base^".c") in
let hfile = (base^".h") in
let cfile_oc = open_out cfile in
......@@ -252,11 +256,11 @@ let (soc2c : int -> out_channel -> out_channel -> Soc.tbl -> Soc.key ->
(*open_out (base^".h"), *)
Lv6util.entete cfile_oc "/*" "*/" ;
Lv6util.entete hfile_oc "/*" "*/" ;
Printf.fprintf cfile_oc "#include \"%s\"\n" hfile;
Printf.fprintf cfile_oc "#include \"%s\"\n" hfile0;
Printf.fprintf hfile_oc "#include \"lustre_types.h\"\n";
Printf.fprintf hfile_oc "#include \"lustre_consts.h\"\n";
Printf.fprintf hfile_oc "#ifndef _%s_H_FILE \n" base;
Printf.fprintf hfile_oc "#define _%s_H_FILE \n" base;
Printf.fprintf hfile_oc "#ifndef _%s_H_FILE \n" base0;
Printf.fprintf hfile_oc "#define _%s_H_FILE \n" base0;
flush cfile_oc;
flush hfile_oc;
cfile_oc, hfile_oc,
......@@ -591,7 +595,8 @@ let gen_main_loop_body inputs outputs soc ctx =
(****************************************************************************)
let (gen_main_wcet_file : Soc.t -> string -> Soc.tbl -> unit) =
fun soc base _stbl ->
fun soc base _stbl ->
let base0 = Filename.basename base in
let mainfile = base^"_main.c" in
let oc = open_out mainfile in
......@@ -602,7 +607,7 @@ let (gen_main_wcet_file : Soc.t -> string -> Soc.tbl -> unit) =
Lv6util.entete oc "/*" "*/";
putc ("
#include <stdlib.h>
#include \""^base ^".h\"
#include \""^base0 ^".h\"
int main(){" ^ (gen_main_loop_body inputs outputs soc ctx));
(match io_transmit_mode () with
| Lv6MainArgs.Stack ->
......@@ -630,7 +635,8 @@ int main(){" ^ (gen_main_loop_body inputs outputs soc ctx));
let (gen_loop_file : string -> LicPrg.t -> Soc.t -> string -> out_channel -> Soc.tbl
-> unit) =
fun fn licprg soc base oc stbl ->
fun fn licprg soc base oc stbl ->
let base0 = Filename.basename base in
let putc s = output_string oc s in
let ctx = get_ctx_name soc.key in
let step = Soc2cDep.step_name soc.key "step" in
......@@ -645,7 +651,7 @@ let (gen_loop_file : string -> LicPrg.t -> Soc.t -> string -> out_channel -> Soc
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include \""^base ^".h\"
#include \""^base0 ^".h\"
/* Print a promt ? ************************/
static int ISATTY;
/* MACROS DEFINITIONS ****************/
......@@ -953,7 +959,8 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
let socs = snd (List.split socs) in
(* XXX que fait-on pour les soc predef ? *)
(* let _, socs = List.partition is_predef socs in *)
let base =
let dir = Lv6MainArgs.global_opt.Lv6MainArgs.dir in
let base0 =
if args.Lv6MainArgs.outfile = "" then
string_of_soc_key msoc
else
......@@ -961,9 +968,12 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
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
let hfile = base ^ ".h" in
let cfile = base ^ ".c" in
let ext_cfile = Printf.sprintf "%s_ext.c" base in
let ext_hfile0 = Printf.sprintf "%s_ext.h" base0 in
let ext_hfile = Printf.sprintf "%s_ext.h" base in
let loopfile = base^"_loop.c" in
let occ = open_out cfile in
......@@ -972,10 +982,10 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
if Lv6MainArgs.global_opt.Lv6MainArgs.soc2c_dro then stdout else
open_out loopfile
in
let types_h_oc = open_out "lustre_types.h" in
let consts_h_oc = open_out "lustre_consts.h" in
let consts_c_oc = open_out "lustre_consts.c" in
let cfiles_acc = ["lustre_consts.c"; cfile] in
let types_h_oc = open_out (Filename.concat dir "lustre_types.h") in
let consts_h_oc = open_out (Filename.concat dir "lustre_consts.h") in
let consts_c_oc = open_out (Filename.concat dir "lustre_consts.c") in
let cfiles_acc = [Filename.concat dir "lustre_consts.c"; cfile] in
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
......@@ -1004,13 +1014,13 @@ typedef float _float;
#endif
// end of _SOC2C_PREDEF_TYPES
// User typedef
#ifndef _"^base^"_TYPES
#define _"^base^"_TYPES\n");
#ifndef _"^base0^"_TYPES
#define _"^base0^"_TYPES\n");
output_string types_h_oc (user_typedef licprg);
output_string types_h_oc ("#endif // enf of _"^base^"_TYPES
"
^ (typedef_all licprg stbl main_soc )
^ (if needs_hfile then "#include \""^ base ^"_ext.h\"" else ""));
^ (if needs_hfile then "#include \""^ base0 ^"_ext.h\"" else ""));
try
let putc s = output_string occ s in
......@@ -1034,11 +1044,11 @@ typedef float _float;
";
if needs_hfile then puth (Printf.sprintf "#include \"%s\"\n" ext_hfile);
puth (Printf.sprintf "#ifndef _%s_H_FILE\n" base);
puth (Printf.sprintf "#define _%s_H_FILE\n" base);
if needs_hfile then puth (Printf.sprintf "#include \"%s\"\n" ext_hfile0);
puth (Printf.sprintf "#ifndef _%s_H_FILE\n" base0);
puth (Printf.sprintf "#define _%s_H_FILE\n" base0);
putc (Printf.sprintf "#include \"%s\"\n" hfile);
putc (Printf.sprintf "#include \"%s\"\n" hfile0);
(* putc (Soc2cExtern.cpy_declaration licprg); *)
putc (Soc2cExtern.const_declaration licprg);
let cfiles_acc =
......@@ -1169,7 +1179,7 @@ struct dro_desc_t DRO_DESC_NAME = {
else args.Lv6MainArgs.outfile
in
let cflags = try Sys.getenv "CFLAGS" with Not_found -> "" in
let ocsh = open_out (node ^".sh") in
let ocsh = open_out (Filename.concat dir (node ^".sh")) in
let main_file, ogensim_main_file, gcc =
if Lv6MainArgs.global_opt.Lv6MainArgs.gen_wcet then
base^"_main.c",base^"_loop.c","$gcc --specs=linux.specs -g"
......@@ -1287,7 +1297,7 @@ fi
flush ocsh;
close_out types_h_oc;
close_out ocsh;
let call_script = "sh "^node^".sh" in
let call_script = Printf.sprintf "sh %s.sh" (Filename.concat dir node) in
let call_exec = "./"^node^".exec" in
if args.Lv6MainArgs.launch_cc then (
print_string ("sys call: '"^call_script^"'\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment