From ffcc04864b13eec2da410f63a3e8c1be9e856b42 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <jahier@imag.fr> Date: Wed, 26 Nov 2008 11:22:27 +0100 Subject: [PATCH] Add two top-level options: "--lustre-v4" and "--expand-enums". --- src/global.ml | 5 +++-- src/ident.ml | 7 ++++--- src/licDump.ml | 34 ++++++++++++++++++++++++++++++---- src/main.ml | 15 ++++++++++++++- src/test/test.res.exp | 3 +++ 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/global.ml b/src/global.ml index 004fab07..6b067ab1 100644 --- a/src/global.ml +++ b/src/global.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 21/11/2008 (at 17:16) by Erwan Jahier> *) +(** Time-stamp: <modified the 26/11/2008 (at 11:00) by Erwan Jahier> *) (** Some global variables. @@ -17,7 +17,8 @@ let compile_all_items = ref false let run_unit_test = ref false let one_op_per_equation = ref true let inline_iterator = ref false - +let lv4 = ref false +let expand_enums = ref false (* the output channel *) let oc = ref Pervasives.stdout diff --git a/src/ident.ml b/src/ident.ml index b43b9535..7a72d5e4 100644 --- a/src/ident.ml +++ b/src/ident.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 24/11/2008 (at 17:09) by Erwan Jahier> *) +(** Time-stamp: <modified the 26/11/2008 (at 11:18) by Erwan Jahier> *) (* J'ai appele ca symbol (mais ca remplace le ident) : c'est juste une couche qui garantit l'unicite en memoire @@ -66,7 +66,8 @@ let (pack_name_to_string : pack_name -> string) = let (string_of_long : long -> string) = - fun (pn, id) -> pn ^"::"^ id + fun (pn, id) -> + if !Global.lv4 then pn ^"__"^ id else pn ^"::"^ id let (long_to_string : long -> string) = string_of_long @@ -114,7 +115,7 @@ let (long_of_string : string -> long) = let string_of_idref i = ( match i.id_pack with - Some p -> p^"::"^i.id_id + Some p -> if !Global.lv4 then (p^"__"^i.id_id) else (p^"::"^i.id_id) | None -> i.id_id ) diff --git a/src/licDump.ml b/src/licDump.ml index 6b2a665a..4d726e6d 100644 --- a/src/licDump.ml +++ b/src/licDump.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 26/11/2008 (at 09:57) by Erwan Jahier> *) +(** Time-stamp: <modified the 26/11/2008 (at 11:15) by Erwan Jahier> *) open Printf open Lxm @@ -32,6 +32,7 @@ let (poly_op_find : Lxm.t -> tab_elt option) = let last_poly_var = ref Int_type_eff +(******************************************************************************) (** Un-nesting iterator calls. The idea is the following: each time a nested iterator call @@ -62,6 +63,17 @@ let create_alias_name long = ^ "_" ^ (Ident.string_of_long long)) + +let (get_rank : 'a -> 'a list -> int) = + fun x l -> + let rec aux i l = + match l with + | [] -> assert false + | y::l -> if x = y then i else aux (i+1) l + in + aux 1 l +let _ = assert (get_rank 5 [1;3;5] = 3) + (******************************************************************************) (* prefix used to prefix user type name in order to avoid name clashed with the alias type name that are generated by the compiler. *) @@ -74,7 +86,13 @@ let rec string_of_const_eff = | Int_const_eff i -> sprintf "%d" i | Real_const_eff r -> r | Extern_const_eff (s,t,vopt) -> (long s) ^ (string_of_const_eff_opt vopt) - | Enum_const_eff (s,t) -> (long s) + | Enum_const_eff (s,t) -> + if !Global.expand_enums then + match t with + | Enum_type_eff(_,l) -> string_of_int (get_rank s l) + | _ -> assert false + else + (long s) | Struct_const_eff (fl, t) -> ( let string_of_field = function (id, veff) -> @@ -115,6 +133,7 @@ and string_def_of_type_eff = function | External_type_eff i -> long i | Enum_type_eff (i, sl) -> assert (sl <>[]); + if !Global.expand_enums then "int" else let f sep acc s = acc ^ sep ^ (long s) in (List.fold_left (f ", ") (f "" "enum {" (List.hd sl)) (List.tl sl)) ^ "}" | Array_type_eff (ty, sz) -> sprintf "%s^%d" (string_of_type_eff ty) sz @@ -389,7 +408,10 @@ and (string_of_by_pos_op_eff: Eff.by_pos_op srcflagged -> Eff.val_exp list -> st | ARROW, [ve1; ve2] -> (string_of_val_exp_eff ve1) ^ " -> " ^ (string_of_val_exp_eff ve2) | FBY, [ve1; ve2] -> - (string_of_val_exp_eff ve1) ^ " fby " ^ (string_of_val_exp_eff ve2) + if !Global.lv4 then + (string_of_val_exp_eff ve1) ^ " -> pre " ^ (string_of_val_exp_eff ve2) + else + (string_of_val_exp_eff ve1) ^ " fby " ^ (string_of_val_exp_eff ve2) | WHEN clk, vel -> (tuple vel) ^ " when " ^ (string_of_clock_exp clk) | CURRENT,_ -> "current " ^ (tuple vel) | TUPLE,_ -> (tuple vel) @@ -543,9 +565,13 @@ and (const_decl: Ident.long -> Eff.const -> string) = let begin_str = ("const " ^ (long tname)) in let end_str = (string_of_const_eff ceff) ^ ";\n" in (match ceff with - | Enum_const_eff _ -> "" + | Enum_const_eff _ -> + if !Global.expand_enums then + (begin_str ^ " = " ^ end_str) + else (* do not print those const, because there were introduced by the compiler *) + "" | Extern_const_eff _ -> begin_str ^ ":" ^ (string_of_type_eff (Eff.type_of_const ceff)) ^ ";\n" | Struct_const_eff _ diff --git a/src/main.ml b/src/main.ml index 01c0a1e6..87104305 100644 --- a/src/main.ml +++ b/src/main.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 19/11/2008 (at 15:45) by Erwan Jahier> *) +(** Time-stamp: <modified the 26/11/2008 (at 11:16) by Erwan Jahier> *) (** Here follows a description of the different modules used by this lus2lic compiler. @@ -105,6 +105,19 @@ let rec arg_list = [ ( "--inline-iterators", Arg.Unit (fun _ -> Global.inline_iterator := true), "\tInline iterators" ); + ( "--expand-enums", Arg.Unit + (fun _ -> Global.expand_enums := true), + "\tTranslate enums into integers" + ); + + ( "--lustre-v4", Arg.Unit + (fun _ -> Global.lv4 := true;Global.inline_iterator := true;Global.expand_enums := true), + "\tGenerate Lustre V4 compatible Lustre (experimental)" + ); + ( "-lv4", Arg.Unit + (fun _ -> Global.lv4 := true;Global.inline_iterator := true;Global.expand_enums := true), + "\tGenerate Lustre V4 compatible Lustre (experimental)" + ); ("-h", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)), "" ); ("-help", Arg.Unit (fun _ -> (Arg.usage arg_list usage_msg; exit 0)),"" ); diff --git a/src/test/test.res.exp b/src/test/test.res.exp index 2e6032f9..3b285e1d 100644 --- a/src/test/test.res.exp +++ b/src/test/test.res.exp @@ -14,6 +14,9 @@ usage: lus2lic [options] <lustre files> | lus2lic -help -vl <int> Set verbose level --keep-nested-calls Keep nested calls --inline-iterators Inline iterators + --expand-enums Translate enums into integers + --lustre-v4 Generate Lustre V4 compatible Lustre (experimental) + -lv4 Generate Lustre V4 compatible Lustre (experimental) -h -help --help Display this list of options -- GitLab