diff --git a/_oasis b/_oasis index 03ad8c59574d1f80126d3f77c6dd443006fd7bce..f1e9b432b0e7952d88081d978c1d3ce9f5923023 100644 --- a/_oasis +++ b/_oasis @@ -1,6 +1,6 @@ OASISFormat: 0.4 Name: lustre-v6 -Version: 1.700 +Version: 1.701 Synopsis: The Lustre V6 Verimag compiler Description: This package contains: (1) lus2lic: the (current) name of the compiler (and interpreter via -exec). @@ -39,7 +39,7 @@ Executable "lus2lic.dbg" # - from ocamldebug prompt: # cd test # set arg blabla -# dir ~/lus2lic/src ~/lus2lic/ ~/lus2lic/_build/src /home/jahier/.opam/4.02.1+PIC/lib/rdbg-plugin/ +# dir ~/lus2lic/src ~/lus2lic/ ~/lus2lic/_build/src ~/rdbg/src ~/rdbg/_build/src ~/lutils/src ~/lutils/_build/src Library "lustre-v6" @@ -50,5 +50,5 @@ Library "lustre-v6" BuildDepends: str,unix,num,rdbg-plugin (>= 1.51) Install:true XMETAEnable: true - InternalModules: SocExecValue,SocUtils,Lv6util,Lv6version,Lv6errors,Lxm,Lv6MainArgs,Lv6Verbose,Soc,SocPredef,Lv6Id,SocExecDbg,SocExec,SocExecEvalPredef,Lv6Compile,AstTab,AstTabSymbol,AstInstanciateModel,Lv6parserUtils,AstV6,FilenameExtras,LicTab,LicDump,AstPredef,Lic,AstCore,FreshName,IdSolver,EvalConst,LicEvalConst,LicEvalType,UnifyType,Ast2lic,AstV6Dump,EvalClock,UnifyClock,LicEvalClock,EvalType,LicPrg,LicMetaOp,L2lCheckOutputs,Lv6Misc,L2lRmPoly,L2lExpandMetaOp,L2lSplit,L2lExpandNodes,L2lExpandArrays,L2lCheckLoops,L2lCheckMemSafe,L2lOptimIte,Lv6lexer,Lv6parser,AstRecognizePredef,Lic2soc,Action,ActionsDeps,SocVar,TopoSort,SortActions,SortActionsExpe,L2lCheckCKeyWord,L2lCheckKcgKeyWord,L2lWhenOnId,L2lNoWhenNot,L2lRemoveAlias + InternalModules: SocExecValue,SocUtils,Lv6util,Lv6version,Lv6errors,Lxm,Lv6MainArgs,Lv6Verbose,Soc,SocPredef,Lv6Id,SocExecDbg,SocExec,SocExecEvalPredef,Lv6Compile,AstTab,AstTabSymbol,AstInstanciateModel,Lv6parserUtils,AstV6,FilenameExtras,LicTab,LicDump,AstPredef,Lic,AstCore,FreshName,IdSolver,EvalConst,LicEvalConst,LicEvalType,UnifyType,Ast2lic,AstV6Dump,EvalClock,UnifyClock,LicEvalClock,EvalType,LicPrg,LicMetaOp,L2lCheckOutputs,Lv6Misc,L2lRmPoly,L2lExpandMetaOp,L2lSplit,L2lExpandNodes,L2lExpandArrays,L2lCheckLoops,L2lCheckMemSafe,L2lOptimIte,Lv6lexer,Lv6parser,AstRecognizePredef,Lic2soc,Action,ActionsDeps,SocVar,TopoSort,SortActions,SortActionsExpe,L2lCheckCKeyWord,L2lCheckKcgKeyWord,L2lWhenOnId,L2lNoWhenNot,L2lRemoveAlias,L2lExpandEnum # Comment se passer de cette liste à la Prevert ? diff --git a/src/l2lExpandArrays.ml b/src/l2lExpandArrays.ml index 219963b37920e4bf1a9267f6df3a8b567b4b6049..ebfcce5c8bf2f414509375486abee53d7ace4256 100644 --- a/src/l2lExpandArrays.ml +++ b/src/l2lExpandArrays.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 24/11/2016 (at 16:25) by Erwan Jahier> *) +(** Time-stamp: <modified the 04/07/2017 (at 15:23) by Erwan Jahier> *) (* Replace structures and arrays by as many variables as necessary. Since structures can be nested, it migth be a lot of new variables... @@ -217,7 +217,7 @@ let (expand_left : local_ctx -> left -> left list) = in flatten_var_tree vt -let rec unfold i x = if i < 0 then [] else x::(unfold (i-1) x) +let rec unfold i x = if i <= 0 then [] else x::(unfold (i-1) x) let rec (expand_array_types : Lic.type_ list -> Lic.type_ list) = fun tl -> @@ -325,7 +325,8 @@ and (var_trees_of_val_exp : "\n*** during Array expansion: '"^ (Lv6Id.string_of_long idl)^ "': Unknown constant.\n*** Current constants are: "^ (LicPrg.fold_consts - (fun k c acc -> acc^(Printf.sprintf "\n\t%s" (Lic.string_of_const c))) + (fun k c acc -> + acc^(Printf.sprintf "\n\t%s" (Lic.string_of_const c))) lctx.prg "") in @@ -334,7 +335,7 @@ and (var_trees_of_val_exp : | HAT(_) | CONCAT | ARRAY | PREDEF_CALL _ | CALL _ | PRE | ARROW | FBY | CURRENT _ | WHEN _ | TUPLE -> ( - (* Create a new loc var to alias such expressions *) + (* Create a new loc var to alias such expressions *) let acc, nloc = make_new_loc lctx lxm acc ve in acc, gen_var_trees (make_val_exp lxm nloc) "" nloc.var_type_eff ) @@ -359,15 +360,30 @@ and do_const acc lctx lxm const = (acc, L (ve_const)) and (break_tuple : Lxm.t -> left list -> val_exp -> Lic.eq_info srcflagged list) = +(* break + x1, x2 = ve1, ve2; + into + x1 = ve1; + x2 = ve2; + + Note that this work only if the node expansion has already been + done! (otherwise, we would not have the same number of items in the + left and in the rigth part) *) fun lxm left_list ve -> - (* Note that this work only if the node expansion has already - been done! (otherwise, we would not have the same number of - items in the left and in the rigth part) *) let rec aux ve = (* flatten val exp*) match ve.ve_core with - | CallByPosLic ({it= TUPLE}, vel) - | CallByPosLic ({it= CONCAT}, vel) + | CallByPosLic ({it= TUPLE}, vel) + | CallByPosLic ({it= CONCAT}, vel) | CallByPosLic ({it= ARRAY}, vel) -> List.flatten (List.map aux vel) +(* necessary ? + | CallByPosLic ({src=lxm;it= CONST (Array_const_eff(cl,t))}, []) -> + List.map (fun c -> + { ve_core = CallByPosLic ({src=lxm;it= CONST c}, []); + ve_typ = [t]; + ve_clk = [List.hd ve.ve_clk]; + ve_src = [List.hd ve.ve_src] + }) cl + *) | CallByPosLic ({src=lxm;it= HAT(i)}, vel) -> let ve1 = List.hd vel in let ve1l = aux ve1 in @@ -392,22 +408,23 @@ and (break_tuple : Lxm.t -> left list -> val_exp -> Lic.eq_info srcflagged list) [ve] else List.map2 - (fun ve1 ve2 -> - { ve with ve_core = CallByPosLic (binop, [ve1;ve2])}) + (fun ve1 ve2 -> { ve with ve_core = CallByPosLic (binop, [ve1;ve2])}) ve1l ve2l | CallByPosLic ({it= PREDEF_CALL( {src=if_lxm ; it = ("Lustre","if"),[]}); src=lxm}, [cond; ve1; ve2]) -> ( let ve1l, ve2l = aux ve1, aux ve2 in - if (List.length ve1l <> List.length ve2l) then + let l1,l2= List.length ve1l, List.length ve2l in + if (l1 <> l2) then let vel2str vel = (String.concat ", " (List.map LicDump.string_of_val_exp_eff vel)) in - let msg = - "*** error expression " ^ (LicDump.string_of_val_exp_eff ve) ^ - "\n cannot be broken \n" ^(vel2str ve1l) ^ - " should have the same arity as\n"^(vel2str ve2l) ^ "\n" - in + let msg = Printf.sprintf + "error: expression \n %s\n cannot be broken \n %s (%d) + \n should have the same arity as\n%s(%d)" + (LicDump.string_of_val_exp_eff ve) + (vel2str ve1l) l1 (vel2str ve2l) l2 + in raise (Lv6errors.Compile_error(lxm, msg)) else List.map2 @@ -428,8 +445,8 @@ and (break_tuple : Lxm.t -> left list -> val_exp -> Lic.eq_info srcflagged list) else let vel = aux ve in if (List.length vel <> lll) then - (* migth occur for generic nodes, that needs to be compiled, - but that will not be dumped. *) + (* migth occur for generic nodes, that needs to be compiled, + but that will not be dumped. *) [{ src = lxm ; it = (left_list, ve) }] else List.map2 @@ -459,6 +476,20 @@ and expand_val_exp_list lctx acc vel = ) ([],acc) (List.rev vel) + +and (build_and_eq : Lic.node_key srcflagged -> val_exp list -> val_exp list + -> val_exp list) = + fun op vel1 vel2 -> + (* transform [(x1;x2] = [y1;y2] into [x1=y1;x2=y2 ]*) + assert (op.it = (("Lustre","eq"),[]) || op.it = (("Lustre","neq"),[])); + let f ve1 ve2 = + let lxm = op.src in + {ve_core = CallByPosLic({src=lxm;it=PREDEF_CALL(op)},[ve1;ve2]); + ve_typ = [Bool_type_eff]; + ve_clk = ve1.ve_clk; + ve_src = op.src} + in + List.map2 f vel1 vel2 and (expand_val_exp: local_ctx -> acc -> val_exp -> val_exp * acc) = fun lctx acc ve -> match ve.ve_core with @@ -481,6 +512,19 @@ and (expand_val_exp: local_ctx -> acc -> val_exp -> val_exp * acc) = let ve = unfold (i,[]) in TUPLE, acc, ve ) + | PREDEF_CALL { src = lxm; it = (("Lustre",("eq"|"neq")),[]) } -> ( + let PREDEF_CALL(op) = by_pos_op in + let vel,acc = expand_val_exp_list lctx acc vel in + match vel with + | [{ve_core = CallByPosLic ({it = TUPLE}, ve1::ve12::vel1) }; + {ve_core = CallByPosLic ({it = TUPLE}, ve2::ve22::vel2) }] -> + let vel_eq = build_and_eq op (ve1::ve12::vel1) (ve2::ve22::vel2) in + let and_op = PREDEF_CALL {src=lxm;it=(("Lustre","and"),[])} in + and_op, acc, vel_eq + + | [ve1; ve2] -> by_pos_op, acc, vel + | _ -> assert false (* sno *) + ) | CONCAT | PREDEF_CALL _ | CALL _ | PRE | ARROW | FBY | CURRENT _ | WHEN _ | TUPLE | CONST _ -> @@ -501,9 +545,11 @@ and (expand_val_exp: local_ctx -> acc -> val_exp -> val_exp * acc) = TUPLE, acc, flatten_var_tree vt in let newve = CallByPosLic(Lxm.flagit by_pos_op lxm, vel) in + let new_typ = expand_array_types ve.ve_typ in let newve = { ve with ve_core = newve ; - ve_typ = expand_array_types ve.ve_typ; + ve_typ = new_typ; + ve_clk = List.map (fun _ -> List.hd ve.ve_clk) new_typ } in (* if newve.core <> ve.core then ( *) diff --git a/src/l2lExpandEnum.ml b/src/l2lExpandEnum.ml new file mode 100644 index 0000000000000000000000000000000000000000..f680aa584296f8b6633d86cd2ef98aa12bc6cd82 --- /dev/null +++ b/src/l2lExpandEnum.ml @@ -0,0 +1,174 @@ +(* Time-stamp: <modified the 30/06/2017 (at 09:52) by Erwan Jahier> *) + + +open Lxm +open Lic + +let dbg = (Lv6Verbose.get_flag "enumasbool") +let profile_info = Lv6Verbose.profile_info + +type target = I (*int*) | BA (* Boolean array *) + +(* exported *) +let rec (doit : target -> LicPrg.t -> LicPrg.t) = + fun target inprg -> + + let rec (do_var_info : Lic.var_info -> Lic.var_info) = + fun vi -> + { vi with var_type_eff = do_type vi.var_type_eff } + + and (do_left : Lic.left -> Lic.left) = + fun l -> + match l with + | LeftVarLic(vi,lxm) -> LeftVarLic(do_var_info vi,lxm) + | LeftFieldLic(l,id,t) -> LeftFieldLic(do_left l,id, do_type t) + | LeftArrayLic(l,i,t) -> LeftArrayLic(do_left l,i, do_type t) + | LeftSliceLic(l,si,t) -> LeftSliceLic(do_left l,si, do_type t) + + and (do_type :Lic.type_ -> Lic.type_) = + fun t -> + match target, t with + | BA,Enum_type_eff(n,ll) -> Array_type_eff(Bool_type_eff,List.length ll) + | I ,Enum_type_eff(_,_) -> Int_type_eff + | _ ,Bool_type_eff + | _ ,Int_type_eff + | _ ,Real_type_eff + | _ ,External_type_eff _ + | _ ,TypeVar _ -> t + | _ ,Abstract_type_eff(id,t) -> Abstract_type_eff(id, do_type t) + | _ ,Array_type_eff(t,i) -> Array_type_eff(do_type t,i) + | _ ,Struct_type_eff(n,l) -> + let l = List.map (fun (id, (t, opt)) -> (id, (do_type t, opt))) l in + Struct_type_eff(n,l) + + and (do_eq : Lic.eq_info srcflagged -> Lic.eq_info srcflagged ) = + fun { src = lxm_eq ; it = (left_list, ve) } -> + let ve = do_val_exp ve in + let left_list = List.map do_left left_list in + { src = lxm_eq ; it = (left_list, ve) } + + and (do_const : Lic.const -> Lic.const) = + fun c -> + match c with + | Enum_const_eff (s,Enum_type_eff(_,ll)) -> + if target = BA then + let xl = + List.map (fun x -> Bool_const_eff(if x=s then true else false)) ll + in + Array_const_eff(xl,Array_type_eff(Bool_type_eff,List.length ll)) + else + let i = Lv6util.pos_in_list 0 s ll in + Int_const_eff (string_of_int i) + | Enum_const_eff (n,t) -> Enum_const_eff (n,do_type t) + | Abstract_const_eff(id, t, c, b) -> + Abstract_const_eff(id, do_type t, do_const c, b) + | Struct_const_eff(l,t) -> + let l = List.map (fun (id,c) -> id, do_const c) l in + Struct_const_eff(l,do_type t) + + | Array_const_eff(cl,t) -> Array_const_eff(List.map do_const cl, do_type t) + | Tuple_const_eff(cl) -> Tuple_const_eff(List.map do_const cl) + | Extern_const_eff(id,t) -> Extern_const_eff(id, do_type t) + + | Bool_const_eff(_) + | Int_const_eff(_) + | Real_const_eff(_) -> c + + and (do_val_exp: val_exp -> val_exp) = + fun ve -> + let ve_core = + match ve.ve_core with + | Merge(ce,cl) -> ( + let cl = + List.fold_left + (fun (ncl) ({src=lxm;it=c}, ve) -> + let ve = do_val_exp ve in + (({src=lxm;it= (* do_const*) c}, ve)::ncl) + ) + [] cl + in + Merge(ce,cl) + ) + | CallByNameLic(op, fl) -> ( + let fl = List.fold_left (fun (nfl) (id,ve) -> ((id,do_val_exp ve)::nfl)) + ([]) (List.rev fl) + in + CallByNameLic(op, fl) + ) + | CallByPosLic (op, vel) -> ( + let vel = + List.fold_left (fun vel ve -> (do_val_exp ve)::vel) [] (List.rev vel) + in + let ec = Lv6MainArgs.global_opt.Lv6MainArgs.ec in + let op = + { op with + it = match op.it, ec with + | Lic.CONST c,_ -> Lic.CONST (do_const c) + | Lic.CONST_REF idl, true -> ( + match target, LicPrg.find_const inprg idl with + | _, None -> op.it + | BA, Some (Enum_const_eff (s,Enum_type_eff(_,ll))) -> + let xl = + List.map (fun x -> Bool_const_eff(if x=s then true else false)) ll + in + Lic.CONST + (Array_const_eff(xl,Array_type_eff(Bool_type_eff,List.length ll))) + | I, Some (Enum_const_eff (s,Enum_type_eff(_,ll))) -> ( + let i = Lv6util.pos_in_list 0 s ll in + Lic.CONST (Int_const_eff (string_of_int i)) + ) + | _,_ -> op.it + ) + | _,_ -> op.it + } + in + CallByPosLic(op, vel) + ) + in + { ve with + ve_core = ve_core; + ve_typ = List.map do_type ve.ve_typ; + } + + and (do_val_exp_flag:val_exp srcflagged -> val_exp srcflagged) = + fun ve_f -> + let ve = do_val_exp ve_f.it in + { ve_f with it = ve } + + and (do_node : Lic.node_exp -> Lic.node_exp) = + fun n -> + match n.def_eff with + | ExternLic | MetaOpLic | AbstractLic _ -> n + | BodyLic b -> + let eqs = List.map (fun eq -> do_eq eq) b.eqs_eff in + let ass = List.map (fun ve -> do_val_exp_flag ve) b.asserts_eff in + { n with + inlist_eff = List.map do_var_info n.inlist_eff; + outlist_eff = List.map do_var_info n.outlist_eff; + loclist_eff = (match n.loclist_eff with + | None -> None + | Some l -> Some(List.map do_var_info l)); + def_eff = BodyLic{asserts_eff=ass; eqs_eff=eqs}; + } + + in (* back to doit *) + let outprg = LicPrg.empty in + (** types and constants do not change *) + let outprg = + LicPrg.fold_types (fun k t acc -> LicPrg.add_type k (do_type t) acc) + inprg outprg + in + let outprg = + LicPrg.fold_consts (fun k c acc -> LicPrg.add_const k (do_const c) acc) + inprg outprg + in + (** transform nodes *) + let rec (doit_node : Lic.node_key -> Lic.node_exp -> LicPrg.t -> LicPrg.t) = + fun nk ne outprg -> + Lv6Verbose.exe ~flag:dbg (fun() -> Printf.printf "#DBG: L2lExpandEnum '%s'\n" + (Lic.string_of_node_key nk)); + let ne = do_node ne in + LicPrg.add_node nk ne outprg + in + let outprg = LicPrg.fold_nodes doit_node inprg outprg in + outprg diff --git a/src/l2lExpandEnum.mli b/src/l2lExpandEnum.mli new file mode 100644 index 0000000000000000000000000000000000000000..5863700d7eead68edd3d0b53a662c5d0cee2ce2d --- /dev/null +++ b/src/l2lExpandEnum.mli @@ -0,0 +1,14 @@ +(* Time-stamp: <modified the 28/06/2017 (at 16:47) by Erwan Jahier> *) + +(** Transform enums into int, or Bool arrays, depending on the value + of Lv6MainArgs.global_opt.expand_enums + +in ec mode, const_ref are inlined by their definition, as const +definitions such as « const x = 3; » is not supported by ec tools. + +nb : for bool arrays, we use 1-hot encoding to understand what's +going on in the generated code. + + *) +type target = I (*int*) | BA (* Boolean array *) +val doit : target -> LicPrg.t -> LicPrg.t diff --git a/src/l2lSplit.ml b/src/l2lSplit.ml index bbf45c0e43c6b2e22f1df4a39e6e4dd546317bc6..be56b96a68fb56237dcef198898147e1bfbbc9ff 100644 --- a/src/l2lSplit.ml +++ b/src/l2lSplit.ml @@ -16,7 +16,7 @@ let profile_info = Lv6Verbose.profile_info (********************************************************************************) let new_var type_eff clock_eff = - let id = Lv6Id.of_string (FreshName.local_var "v") in + let id = Lv6Id.of_string (FreshName.local_var "split") in let var = { var_name_eff = id; @@ -222,33 +222,7 @@ and (split_val_exp : LicPrg.t -> bool -> bool -> Lic.val_exp -> Lic.val_exp * sp nve, (eql@[eq], vl@nv_l) ) | CallByPosLic({it=Lic.VAR_REF _}, _) -> ve, ([],[]) - | CallByPosLic({src=lxm;it=Lic.CONST_REF idl}, vel) -> - (* expand const ref in -ec -eei mode - Should I rather always inline const? - *) - (try - if not Lv6MainArgs.global_opt.Lv6MainArgs.ec then raise Not_found else - let const = - let c = match LicPrg.find_const lic_prg idl with - Some c -> c | None -> raise Not_found (* meant to catched *) - in - match c with - | (Enum_const_eff (s,Enum_type_eff(_,ll))) -> - (match Lv6MainArgs.global_opt.Lv6MainArgs.expand_enums with - | Lv6MainArgs.AsInt -> - let i = Lv6util.pos_in_list 0 s ll in - (Int_const_eff (string_of_int i)) - | Lv6MainArgs.AsBool - | Lv6MainArgs.AsConst - | Lv6MainArgs.AsEnum -> raise Not_found (* meant to catched *) - ) - | _ -> raise Not_found - in - { ve with - ve_core=CallByPosLic({src=lxm;it=Lic.CONST const}, vel) - }, ([],[]) - with Not_found -> ve, ([],[]) - ) + | CallByPosLic({src=lxm;it=Lic.CONST_REF idl}, vel) -> ve, ([],[]) | CallByPosLic({src=lxm;it=Lic.CONST _}, _) -> if not when_flag then let clk = ve.ve_clk in @@ -335,23 +309,25 @@ and (split_val_exp : LicPrg.t -> bool -> bool -> Lic.val_exp -> Lic.val_exp * sp | _ -> { ve with ve_typ = List.map (fun v -> v.var_type_eff) nv_l; ve_clk = clk_l; - ve_core = CallByPosLic( - Lxm.flagit Lic.TUPLE lxm, - (List.map - (fun nv -> - let nnv = { - ve_core = CallByPosLic - (Lxm.flagit (Lic.VAR_REF (nv.var_name_eff)) lxm, []); - ve_typ = [nv.var_type_eff]; - ve_clk = [snd nv.var_clock_eff]; - ve_src = lxm - } - in - nnv - ) - nv_l - ) - ) + ve_core = + CallByPosLic( + Lxm.flagit Lic.TUPLE lxm, + (List.map + (fun nv -> + let nnv = { + ve_core = CallByPosLic + (Lxm.flagit (Lic.VAR_REF (nv.var_name_eff)) lxm, + []); + ve_typ = [nv.var_type_eff]; + ve_clk = [snd nv.var_clock_eff]; + ve_src = lxm + } + in + nnv + ) + nv_l + ) + ) } in let lpl = List.map (fun nv -> LeftVarLic(nv, lxm)) nv_l in @@ -406,7 +382,12 @@ and split_node (lic_prg:LicPrg.t) (opt:Lv6MainArgs.t) (n: Lic.node_exp) : Lic.no in let neqs = List.map remove_tuple_from_eq neqs in let nb = { eqs_eff = neqs ; asserts_eff = nasserts } in - { n with loclist_eff = Some nv; def_eff = BodyLic nb } + let n = + { n with + loclist_eff = Some nv; + def_eff = BodyLic nb } + in + n in res @@ -430,7 +411,8 @@ let rec doit (opt:Lv6MainArgs.t) (inprg : LicPrg.t) : LicPrg.t = (** TRAITE LES NOEUDS : *) let rec do_node k (ne:Lic.node_exp) = (* On passe en parametre un constructeur de nouvelle variable locale *) - profile_info (Printf.sprintf "#DBG: split equations of '%s'\n" (Lic.string_of_node_key k)); + profile_info (Printf.sprintf "#DBG: split equations of '%s'\n" + (Lic.string_of_node_key k)); let ne' = split_node inprg opt ne in res := LicPrg.add_node k ne' !res in diff --git a/src/l2lSplit.mli b/src/l2lSplit.mli index 43b4a73f2f82246a5a2304e0889375a3dacd0e92..2b8a06ac5469e8169ee7aadfb47933de9bf8c54b 100644 --- a/src/l2lSplit.mli +++ b/src/l2lSplit.mli @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 16/01/2015 (at 10:08) by Erwan Jahier> *) +(* Time-stamp: <modified the 30/06/2017 (at 10:13) by Erwan Jahier> *) (** Split the equations of a node into several ones, in such a way diff --git a/src/lic.ml b/src/lic.ml index cc35b0eb4c06d81a17b42a170024b7c4aa096628..ab7d2016206af10e8edb081f0e32117d909bb413 100644 --- a/src/lic.ml +++ b/src/lic.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 16/01/2017 (at 17:49) by Erwan Jahier> *) +(* Time-stamp: <modified the 30/06/2017 (at 11:28) by Erwan Jahier> *) (** Define the Data Structure representing Compiled programs. By compiled we mean that constant are propagated, packages are @@ -574,7 +574,7 @@ let (type_of_const: const -> type_) = | Abstract_const_eff (s, teff, _v, _is_exported) -> teff | Enum_const_eff (s, teff) -> teff | Struct_const_eff (fl, teff) -> teff - | Array_const_eff (ct, teff) -> Array_type_eff (teff, List.length ct) + | Array_const_eff (ct, teff) -> teff (* Array_type_eff (teff, List.length ct) *) | Tuple_const_eff cl -> (* Utiliser plutot types_of_const (ci dessous) qui traite les tuples *) print_internal_error "Lic.type_of_const" "should not have been called for a tuple"; diff --git a/src/lic2soc.ml b/src/lic2soc.ml index 02595679172eb4b3735e57eb4d11ee2462c1b5a6..79a8773edd32b0e9da91717614b67cbbb21873ac 100644 --- a/src/lic2soc.ml +++ b/src/lic2soc.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 21/06/2017 (at 10:20) by Erwan Jahier> *) +(** Time-stamp: <modified the 03/07/2017 (at 10:31) by Erwan Jahier> *) (* XXX ce module est mal écrit. A reprendre. (R1) *) @@ -648,19 +648,10 @@ let rec (actions_of_expression_acc: Lxm.t -> Soc.tbl -> (sk_name, sk_prof, Soc.Curr(cc)), None | _ -> sk, None in - try Soc.SocMap.find sk soc_tbl - with Not_found -> - Lv6Verbose.exe ~flag:dbg (fun () -> - let l = Soc.SocMap.bindings soc_tbl in - let kl = fst (List.split l) in - let klstr = List.map SocUtils.string_of_soc_key kl in - print_string ("\n********* Cannot find the soc.key " ^ - (SocUtils.string_of_soc_key sk) ^ " in \n\t" ^ - (String.concat "\n\t" klstr)^"\n"); - flush stdout; - ); - raise (Undef_soc (sk, by_pos_op_flg.src, by_pos_op_flg.it, - args_types,fby_init_opt)) + try SocUtils.find by_pos_op_flg.src sk soc_tbl + with Lv6errors.Compile_error(lxm,msg) -> + Lv6Verbose.exe ~flag:dbg (fun () -> print_string msg; flush stdout); + raise (Undef_soc (sk, lxm,by_pos_op_flg.it,args_types,fby_init_opt)) in make_e2a_elt by_pos_op_flg.src clk lpl acc val_exp_list soc ) @@ -755,7 +746,7 @@ let rec f: (LicPrg.t -> Lic.node_key -> Soc.key * Soc.tbl) = | None -> assert false | Some node_def -> (match soc_of_node prog node_def soc_tbl with - | Some(_,soc,soc_tbl) -> SocMap.add sk soc soc_tbl + | Some(_,soc,soc_tbl) -> SocUtils.add sk soc soc_tbl | None -> print_string ("Undefined soc : " ^ (string_of_node_key nk) ^ "\n"); flush stdout; @@ -780,7 +771,7 @@ let rec f: (LicPrg.t -> Lic.node_key -> Soc.key * Soc.tbl) = flush stdout; assert false ); - let soc_tbl = SocMap.add soc.key soc soc_tbl in + let soc_tbl = SocUtils.add soc.key soc soc_tbl in snd (process_node nk soc_tbl) ) | Polymorphic -> diff --git a/src/licDump.ml b/src/licDump.ml index de1180d0adaa0b6969da43ac25ec2141189be428..82dfe6287dad5209374ab4919e8ea6bcb515c6b0 100644 --- a/src/licDump.ml +++ b/src/licDump.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 21/06/2017 (at 15:27) by Erwan Jahier> *) +(* Time-stamp: <modified the 27/06/2017 (at 15:36) by Erwan Jahier> *) open Lv6errors open Printf @@ -182,7 +182,8 @@ and string_of_type_eff = function (match global_opt.Lv6MainArgs.expand_enums with | AsEnum | AsConst -> string_of_ident name | AsInt -> if global_opt.kcg then dump_long name else "int" - | AsBool -> if global_opt.kcg then dump_long name else + | AsBool -> if global_opt.kcg then dump_long name else + (* let get_n x = (* returns the n s.t., 2^(n-1) < x <= 2^n *) assert(x>0); let rec f n acc = @@ -191,6 +192,10 @@ and string_of_type_eff = function f 0 1 in let size = get_n (List.length el) in + *) + (* well, 1-hot encoding is efficient enough and easier + to understand afterwards *) + let size = (List.length el) in ("bool^"^(string_of_int size)) ) | Array_type_eff (ty, sz) -> diff --git a/src/licPrg.ml b/src/licPrg.ml index ed686a034085867c82e57581a328f581eaa22231..11013a317c20ec5aa9f23e5b60031cd5c14d478a 100644 --- a/src/licPrg.ml +++ b/src/licPrg.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 20/06/2017 (at 15:25) by Erwan Jahier> *) +(* Time-stamp: <modified the 28/06/2017 (at 17:21) by Erwan Jahier> *) open Lv6MainArgs module ItemKeyMap = struct @@ -116,18 +116,30 @@ let del_node (k:Lic.node_key) (prg:t) : t = { prg with nodes = NodeKeyMap.remove k prg.nodes } -(* to encode int into bools (for --expand-enums-as-bool) *) -let rec (int_to_bool_array: int -> int -> bool list) = +(* to encode int into bools (for --expand-enums-as-bool) +let rec (int_to_bool_array_hot: int -> int -> bool list) = fun i size -> assert(size >= 0); if size = 0 then [] else let d,r = i / 2, (i mod 2) = 1 in r::(int_to_bool_array d (size-1)) - let _ = assert (int_to_bool_array 1 3 = [true; false; false]); assert (int_to_bool_array 2 3 = [false; true; false]); assert (int_to_bool_array 8 3 = [false; false; false]);; + *) +(* hot 1 encoding *) +let rec (int_to_bool_array: int -> int -> bool list) = + fun i size -> + assert(size >= 0); + if size = 0 then [] else + let x = (i=0) in + x::(int_to_bool_array (i-1) (size-1)) + +let _ = + assert (int_to_bool_array 0 3 = [true; false; false]); + assert (int_to_bool_array 1 3 = [false; true; false]); + assert (int_to_bool_array 2 4 = [false; false; true; false]);; @@ -141,14 +153,16 @@ let to_file (opt: Lv6MainArgs.t) (this:t) (main_node: Lv6Id.idref option) = (* global_opt.Lv6MainArgs.kcg || *) (* Lv6MainArgs.global_opt.Lv6MainArgs.expand_enums = AsEnum) *) (* then *) - output_string opt.Lv6MainArgs.oc (LicDump.type_decl tn te) - (* else *) + output_string opt.Lv6MainArgs.oc (LicDump.type_decl tn te) + (* else *) (* () *) ) this.types ); - (* for generating lv4 or ec compatible code, enum types are + (* const definition + + for generating lv4 or ec compatible code, enum types are translated into an extern type + an extern const per enums. For instance, @@ -213,28 +227,33 @@ let to_file (opt: Lv6MainArgs.t) (this:t) (main_node: Lv6Id.idref option) = const_list; ) | Lv6MainArgs.AsBool -> ( - if global_opt.kcg || global_opt.ec then () else ( - let const_list = to_const_list this.types in - List.iter - (fun l -> - (List.iteri - (fun i (t,elt) -> - let get_n x = (* returns the n s.t., 2^(n-1) < x <= 2^n *) - assert(x>0); - let rec f n acc = if x > acc then f (n+1) (2*acc) else n in - f 0 1 - in - let size = get_n (List.length l) in - let bool_list = int_to_bool_array i size in - let const = Lic.Array_const_eff - (List.map (fun b -> Lic.Bool_const_eff(b)) bool_list, - Lic.Bool_type_eff) - in - output_string opt.Lv6MainArgs.oc (LicDump.const_decl elt const)) - ) - l) - const_list; - ) + if global_opt.kcg || global_opt.ec then () else ( + let const_list = to_const_list this.types in + List.iter + (fun l -> + let size = List.length l in + (* let size = get_n size in *) + (List.iteri + (fun i (t,elt) -> + let bool_list = int_to_bool_array i size in + (* + let get_n x = (* returns the n s.t., 2^(n-1) < x <= 2^n *) + assert(x>0); + let rec f n acc = if x > acc then f (n+1) (2*acc) else n in + f 0 1 + in + let size = get_n (List.length l) in + *) + + let const = Lic.Array_const_eff + (List.map (fun b -> Lic.Bool_const_eff(b)) bool_list, + Lic.Bool_type_eff) + in + output_string opt.Lv6MainArgs.oc (LicDump.const_decl elt const)) + ) + l) + const_list; + ) ) | Lv6MainArgs.AsEnum -> () ); @@ -254,7 +273,7 @@ let to_file (opt: Lv6MainArgs.t) (this:t) (main_node: Lv6Id.idref option) = in output_string opt.Lv6MainArgs.oc (str); flush opt.Lv6MainArgs.oc; - ))) + ))) this.nodes ; (* If no node is set a top-level, the compiler will compile every node. But the diff --git a/src/lus2licRun.ml b/src/lus2licRun.ml index 6a02c6ba51c4dc24fe871a05d6b887ecdfb2049c..70770cb9c58de5e18b16e49a8a26a273c4fd0d60 100644 --- a/src/lus2licRun.ml +++ b/src/lus2licRun.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 22/06/2017 (at 15:52) by Erwan Jahier> *) +(* Time-stamp: <modified the 03/07/2017 (at 10:38) by Erwan Jahier> *) (*----------------------------------------------------------------------- ** Copyright (C) - Verimag. *) @@ -41,7 +41,7 @@ let make argv = exit 1 ) in - let soc = try Soc.SocMap.find sk soc_tbl with Not_found -> assert false in + let soc = SocUtils.find_no_exc sk soc_tbl in let soc_inputs,soc_outputs = soc.profile in let soc_inputs,soc_outputs = if opt.Lv6MainArgs.expand_io_type then diff --git a/src/lustre-v6.mldylib b/src/lustre-v6.mldylib index 543f8c0a9a5d283f343b643d233ff79b4f2558a6..ba6b378928af25b4377912414393e74ebcdb330c 100644 --- a/src/lustre-v6.mldylib +++ b/src/lustre-v6.mldylib @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 0c16d4972282798ddcde58321a6bed10) +# DO NOT EDIT (digest: 0e59a5b102689755b86c5ab8a3414f4f) Lus2licRun SocExecValue SocUtils @@ -66,4 +66,5 @@ L2lCheckKcgKeyWord L2lWhenOnId L2lNoWhenNot L2lRemoveAlias +L2lExpandEnum # OASIS_STOP diff --git a/src/lustre-v6.mllib b/src/lustre-v6.mllib index 543f8c0a9a5d283f343b643d233ff79b4f2558a6..ba6b378928af25b4377912414393e74ebcdb330c 100644 --- a/src/lustre-v6.mllib +++ b/src/lustre-v6.mllib @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 0c16d4972282798ddcde58321a6bed10) +# DO NOT EDIT (digest: 0e59a5b102689755b86c5ab8a3414f4f) Lus2licRun SocExecValue SocUtils @@ -66,4 +66,5 @@ L2lCheckKcgKeyWord L2lWhenOnId L2lNoWhenNot L2lRemoveAlias +L2lExpandEnum # OASIS_STOP diff --git a/src/lv6Compile.ml b/src/lv6Compile.ml index d7b8a9374536d42333ebb0d87fb7252fe2a92252..32078660a04bf98aaafaadc9a56cc77f46919164 100644 --- a/src/lv6Compile.ml +++ b/src/lv6Compile.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 20/06/2017 (at 17:09) by Erwan Jahier> *) +(* Time-stamp: <modified the 04/07/2017 (at 15:55) by Erwan Jahier> *) open Lxm open Lv6errors @@ -10,7 +10,151 @@ let dbg = (Lv6Verbose.get_flag "ast") let profile_info = Lv6Verbose.profile_info -let (doit : Lv6MainArgs.t -> AstV6.pack_or_model list -> Lv6Id.idref option -> LicPrg.t) = +let split opt zelic = + if + Lv6MainArgs.global_opt.Lv6MainArgs.one_op_per_equation + || opt.Lv6MainArgs.expand_nodes (* expand performs no fixpoint, so it will work + only if we have one op per equation...*) + then ( + (* Split des equations (1 eq = 1 op) *) + profile_info "One op per equations...\n"; + L2lSplit.doit opt zelic) + else + zelic + +let expand_nodes opt main_node zelic = + if opt.Lv6MainArgs.expand_node_call <> [] || opt.Lv6MainArgs.expand_nodes then ( + let mn:Lv6Id.idref = + match main_node with + | None -> + (match LicPrg.choose_node zelic with + | None -> assert false + | Some(nk,_) -> Lv6Id.idref_of_long (fst nk) + ) + | Some mn -> mn + in + let ids_to_expand = + List.map Lv6Id.idref_of_string opt.Lv6MainArgs.expand_node_call + in + let long_match_idref (p,n) idref = + (* if no pack is specified, we match them all *) + (Lv6Id.name_of_idref idref = n) + && (match Lv6Id.pack_of_idref idref with + None -> true + | Some p2 -> p = p2) + in + let nodes_to_keep: Lic.node_key list = + LicPrg.fold_nodes + (fun (long,sargs) _ acc -> + if opt.Lv6MainArgs.expand_nodes then + (if long_match_idref long mn then + (long,sargs)::acc + else + acc) + else if + List.exists (long_match_idref long) ids_to_expand + then + acc + else + (long,sargs)::acc + ) + zelic + [] + in + assert (nodes_to_keep <> []); + profile_info ("Expanding the following node calls: " + ^(String.concat "," (List.map Lv6Id.string_of_idref ids_to_expand))^"\n"); + profile_info ("Keeping the following node calls: " + ^(String.concat "," (List.map Lic.string_of_node_key nodes_to_keep))^"\n"); + L2lExpandNodes.doit nodes_to_keep zelic + ) + else + zelic + +(* may introduce arrays, that may need to be expanded, so + this has to be done before expand_arrays *) +let expand_enums opt zelic = + match Lv6MainArgs.global_opt.Lv6MainArgs.expand_enums with + | Lv6MainArgs.AsBool -> L2lExpandEnum.doit L2lExpandEnum.BA zelic + | Lv6MainArgs.AsInt -> L2lExpandEnum.doit L2lExpandEnum.I zelic + | Lv6MainArgs.AsEnum + | Lv6MainArgs.AsConst -> zelic + +let remove_polymorphism opt zelic = +(* élimination polymorphisme surcharge *) + profile_info "Removing polymorphism...\n"; + L2lRmPoly.doit zelic + +let expand_iterators opt zelic = + if not opt.Lv6MainArgs.inline_iterator then zelic else ( + profile_info "Inlining iterators...\n"; + (* to be done before array expansion otherwise they won't be expanded *) + let zelic = L2lExpandMetaOp.doit zelic in + if Lv6MainArgs.global_opt.Lv6MainArgs.kcg && not opt.Lv6MainArgs.inline_iterator + then + L2lExpandMetaOp.doit_boolred zelic + else + zelic + ) + +let optimize_ite opt zelic = + if not opt.Lv6MainArgs.optim_ite then zelic else ( + profile_info "Optimizing if/then/else...\n"; + L2lOptimIte.doit zelic) + +(* Array and struct expansion: to do after polymorphism elimination +and after node expansion *) +let expand_arrays opt zelic = + if not opt.Lv6MainArgs.expand_arrays then zelic else ( + profile_info "Expanding arrays...\n"; + let zelic = L2lExpandArrays.doit zelic in + let zelic = split opt zelic in + zelic + ) + +(* alias des types array XXX fait partir lic2soc en boucle à + cause des soc key qui ne sont plus cohérentes entre elles + (cf commentaire au début du module). Bon, j'enleve, car j'en ai + pas vraiment besoin en plus. + *) +let alias_arrays opt zelic = zelic + (* profile_info "Aliasing arrays...\n"; *) + (* let zelic = L2lAliasType.doit zelic in *) + +let remove_aliases opt zelic = + if opt.Lv6MainArgs.keep_aliases then zelic else L2lRemoveAlias.doit zelic + +let when_on_idents opt zelic = + (* should be done after L2lOptimIte, as it introduces some 'when' *) + if not Lv6MainArgs.global_opt.Lv6MainArgs.when_on_ident then zelic else ( + profile_info "Creating ident on when statements if necessary...\n"; + L2lWhenOnId.doit zelic) +let no_when_not opt zelic = + if not Lv6MainArgs.global_opt.Lv6MainArgs.no_when_not then zelic else ( + profile_info "Replace 'when not' statements by new variables...\n"; + L2lNoWhenNot.doit zelic) + +let check_loops opt zelic = + if Lv6MainArgs.global_opt.Lv6MainArgs.ec then ( + profile_info "Check loops...\n"; + L2lCheckLoops.doit zelic + ) + +let check_decl opt zelic = + profile_info "Check safety and memory declarations...\n"; + if opt.Lv6MainArgs.gen_c then + L2lCheckCKeyWord.doit zelic; + if Lv6MainArgs.global_opt.Lv6MainArgs.kcg then + L2lCheckKcgKeyWord.doit zelic + else + L2lCheckMemSafe.doit zelic + +let check_outputs opt zelic = + profile_info "Check unique outputs...\n"; + L2lCheckOutputs.doit zelic + +let (doit : Lv6MainArgs.t -> AstV6.pack_or_model list -> Lv6Id.idref option -> + LicPrg.t) = fun opt srclist main_node -> (* let t0 = Sys.time() in *) profile_info "Lv6Compile: Start!\n"; @@ -25,7 +169,6 @@ let (doit : Lv6MainArgs.t -> AstV6.pack_or_model list -> Lv6Id.idref option -> L . dans un des packs déclarés "uses", avec priorité dans l'ordre *) - let lic_tab = LicTab.create syntax_tab in Lv6Verbose.exe ~flag:dbg (fun () -> AstTab.dump syntax_tab); @@ -41,132 +184,22 @@ let (doit : Lv6MainArgs.t -> AstV6.pack_or_model list -> Lv6Id.idref option -> L profile_info "Converting to lic_prg...\n"; let zelic = LicTab.to_lic_prg lic_tab in if opt.Lv6MainArgs.print_interface then zelic else ( - profile_info "Check safety and memory declarations...\n"; - if opt.Lv6MainArgs.gen_c then - L2lCheckCKeyWord.doit zelic; - if Lv6MainArgs.global_opt.Lv6MainArgs.kcg then - L2lCheckKcgKeyWord.doit zelic - else - L2lCheckMemSafe.doit zelic; - let zelic = - if not opt.Lv6MainArgs.optim_ite then zelic else ( - profile_info "Optimizing if/then/else...\n"; - L2lOptimIte.doit zelic) - in - let zelic = - (* élimination polymorphisme surcharge *) - profile_info "Removing polymorphism...\n"; - L2lRmPoly.doit zelic - in - let zelic = if not opt.Lv6MainArgs.inline_iterator then zelic else ( - profile_info "Inlining iterators...\n"; - (* to be done before array expansion otherwise they won't be expanded *) - L2lExpandMetaOp.doit zelic - ) - in - let zelic = - if Lv6MainArgs.global_opt.Lv6MainArgs.kcg && not opt.Lv6MainArgs.inline_iterator - then - L2lExpandMetaOp.doit_boolred zelic - else - zelic - in - let zelic = - if - Lv6MainArgs.global_opt.Lv6MainArgs.one_op_per_equation - || opt.Lv6MainArgs.expand_nodes (* expand performs no fixpoint, so it will work - only if we have one op per equation...*) - then ( - (* Split des equations (1 eq = 1 op) *) - profile_info "One op per equations...\n"; - L2lSplit.doit opt zelic) - else - zelic - in - let zelic = - (* should be done after L2lOptimIte, as it introduces some 'when' *) - if not Lv6MainArgs.global_opt.Lv6MainArgs.when_on_ident then zelic else ( - profile_info "Creating ident on when statements if necessary...\n"; - L2lWhenOnId.doit zelic) - in - let zelic = - if opt.Lv6MainArgs.expand_node_call <> [] || opt.Lv6MainArgs.expand_nodes then ( - let mn:Lv6Id.idref = - match main_node with - | None -> - (match LicPrg.choose_node zelic with - | None -> assert false - | Some(nk,_) -> Lv6Id.idref_of_long (fst nk) - ) - | Some mn -> mn - in - let ids_to_expand = - List.map Lv6Id.idref_of_string opt.Lv6MainArgs.expand_node_call - in - let long_match_idref (p,n) idref = - (* if no pack is specified, we match them all *) - (Lv6Id.name_of_idref idref = n) - && (match Lv6Id.pack_of_idref idref with - None -> true - | Some p2 -> p = p2) - in - let nodes_to_keep: Lic.node_key list = - LicPrg.fold_nodes - (fun (long,sargs) _ acc -> - if opt.Lv6MainArgs.expand_nodes then - (if long_match_idref long mn then - (long,sargs)::acc - else - acc) - else if - List.exists (long_match_idref long) ids_to_expand - then - acc - else - (long,sargs)::acc - ) - zelic - [] - in - assert (nodes_to_keep <> []); - profile_info ("Expanding the following node calls: " - ^(String.concat "," (List.map Lv6Id.string_of_idref ids_to_expand))^"\n"); - profile_info ("Keeping the following node calls: " - ^(String.concat "," (List.map Lic.string_of_node_key nodes_to_keep))^"\n"); - L2lExpandNodes.doit nodes_to_keep zelic - ) - else - zelic - in - let zelic = - if not Lv6MainArgs.global_opt.Lv6MainArgs.no_when_not then zelic else ( - profile_info "Replace 'when not' statements by new variables...\n"; - L2lNoWhenNot.doit zelic) - in - (* Array and struct expansion: to do after polymorphism elimination - and after node expansion *) - let zelic = if not opt.Lv6MainArgs.expand_arrays then zelic else ( - profile_info "Expanding arrays...\n"; - L2lExpandArrays.doit zelic) - in - let zelic = - if opt.Lv6MainArgs.keep_aliases then zelic else L2lRemoveAlias.doit zelic - in - (* alias des types array XXX fait partir lic2soc en boucle à - cause des soc key qui ne sont plus cohérentes entre elles - (cf commentaire au début du module). Bon, j'enleve, car j'en ai - pas vraiment besoin en plus. - - profile_info "Aliasing arrays...\n"; - let zelic = L2lAliasType.doit zelic in - *) - (* Currently only works in this mode *) - if Lv6MainArgs.global_opt.Lv6MainArgs.ec then ( - profile_info "Check loops...\n"; - L2lCheckLoops.doit zelic - ); - profile_info "Check unique outputs...\n"; - L2lCheckOutputs.doit zelic; + check_decl opt zelic; + + let zelic = optimize_ite opt zelic in + let zelic = remove_polymorphism opt zelic in + let zelic = expand_iterators opt zelic in (* before expand_arrays *) + let zelic = split opt zelic in (* after expand_iterators *) + let zelic = expand_enums opt zelic in (* before expand_arrays *) + let zelic = when_on_idents opt zelic in (* after optimize_ite *) + let zelic = expand_nodes opt main_node zelic in (* after split *) + let zelic = no_when_not opt zelic in + let zelic = expand_arrays opt zelic in (* after expand_nodes + and remove_polymorphism *) + let zelic = remove_aliases opt zelic in + (* let zelic = alias_arrays opt zelic in *) + check_loops opt zelic; + check_outputs opt zelic; profile_info "Lic Compilation done!\n"; zelic ) diff --git a/src/lv6MainArgs.ml b/src/lv6MainArgs.ml index 5a6985626042a3445698fe9aa9e75a2dd539353f..513ca501c1e41cbbcfd4dd34761d610fec032473 100644 --- a/src/lv6MainArgs.ml +++ b/src/lv6MainArgs.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 19/06/2017 (at 15:01) by Erwan Jahier> *) +(* Time-stamp: <modified the 28/06/2017 (at 16:44) by Erwan Jahier> *) (* Le manager d'argument adapté de celui de lutin, plus joli N.B. solution un peu batarde : les options sont stockées, comme avant, dans Global, @@ -333,18 +333,17 @@ let mkoptab (opt:t) : unit = ( mkopt opt ~doc_level:Advanced ["-ee"; "--expand-enums"] (Arg.Unit (fun _ -> global_opt.expand_enums <- AsConst)) - [" Translate enums using extern types and consts (for lv4 and ec)"] + [" Translate enums using extern types and consts"] ; mkopt opt ~doc_level:Advanced ["-eei"; "--expand-enums-as-int"] (Arg.Unit (fun _ -> global_opt.expand_enums <- AsInt)) - [" Translate enums using integers (to be kind with data plotters)"] + [" Translate enums into integers (to be kind with data plotters)"] ; mkopt opt ~doc_level:Dev ["-eeb"; "--expand-enums-as-bool"] (Arg.Unit (fun _ -> global_opt.expand_enums <- AsBool)) - [" Translate enums using boolean arrays (to be kind with model-checkers)"; - "ZZZ: buggy for arrays and using bools is not necessary for lesar."] + [" Translate enums into boolean arrays (to be kind with model-checkers)"] ; mkopt opt ~doc_level:Advanced ["-esa"; "--expand-structs-and-arrays"] diff --git a/src/lv6version.ml b/src/lv6version.ml index 42d295810be5b7dfd8ec9508a8f762d18d7f3e19..1d738530c8029bbed07a1fe058e4ee4fb0573a01 100644 --- a/src/lv6version.ml +++ b/src/lv6version.ml @@ -1,7 +1,7 @@ (** Automatically generated from Makefile *) let tool = "lus2lic" let branch = "master" -let commit = "700" -let sha_1 = "fd3bc9566365dd3042af3302ecab8e9311e76e2d" +let commit = "701" +let sha_1 = "acc2dbb3a79f2ba9ed0489bd8bff1bfc31846d4b" let str = (branch ^ "." ^ commit ^ " (" ^ sha_1 ^ ")") let maintainer = "jahier@imag.fr" diff --git a/src/main.ml b/src/main.ml index 2f30d2cb0c810cc8baf98dc80ff2876bbe4d9a67..44799a59192979a1692281fd247949eb66e9293c 100644 --- a/src/main.ml +++ b/src/main.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 27/06/2017 (at 14:26) by Erwan Jahier> *) +(* Time-stamp: <modified the 03/07/2017 (at 10:22) by Erwan Jahier> *) open Lv6Verbose open AstV6 @@ -123,12 +123,12 @@ let (gen_autotest_files : LicPrg.t -> Lv6Id.idref option -> Lv6MainArgs.t -> uni (if range_flag then ( match t with | Data.Real -> " real [-10000.0;10000.0]" - | Data.Int -> " int [-10000;10000]" + | Data.Int -> " int [-10000; 10000]" | Data.Enum(_, idl) -> " int [0;"^(string_of_int (List.length idl - 1)) ^"]" | _ -> idref.Lv6Id.id_id ) else idref.Lv6Id.id_id) in - let soc = try Soc.SocMap.find msk zesoc with Not_found -> assert false in + let soc = try SocUtils.find (Lxm.dummy "") msk zesoc with Not_found -> assert false in let invars,outvars=soc.Soc.profile in let invars = SocVar.expand_profile false false invars in let outvars = SocVar.expand_profile true false outvars in diff --git a/src/soc.ml b/src/soc.ml index 0dd0e7b79bbd76dda12f712d35589d9eab125bc8..3e83bca7abe3de949e34874bb3e853eb8e30b796 100644 --- a/src/soc.ml +++ b/src/soc.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 24/11/2016 (at 16:35) by Erwan Jahier> *) +(* Time-stamp: <modified the 03/07/2017 (at 10:15) by Erwan Jahier> *) (** Synchronous Object Component *) @@ -105,8 +105,15 @@ module SocMap = Map.Make( end ) -type tbl = t SocMap.t +(* XXX Faire une table a 2 niveaux d'index: + - le nom + - le type + *) +type tbl = t SocMap.t +(* cf SocUtils *) + + let cpt = ref 0 let (make: key -> instance) = fun sk -> diff --git a/src/soc2c.ml b/src/soc2c.ml index f10272e12e38c1d6d50ca831c89fde7825042ec2..a208bd9c5233b9a72febb608abca85f8a0c263f2 100644 --- a/src/soc2c.ml +++ b/src/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 27/06/2017 (at 11:37) by Erwan Jahier> *) +(* Time-stamp: <modified the 03/07/2017 (at 10:37) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -76,8 +76,8 @@ let (gao2c : Soc.tbl -> 'a soc_pp -> Soc.gao -> unit) = let l = List.map2 (Soc2cDep.gen_assign_var_expr sp.soc) vel_out vel_in in String.concat "" l ) - | Call(vel_out, Method((inst_name,sk),sname), vel_in,_) -> ( - let called_soc = Soc.SocMap.find sk stbl in + | Call(vel_out, Method((inst_name,sk),sname), vel_in,lxm) -> ( + let called_soc = SocUtils.find lxm sk stbl in let _, get_index = Soc2cInstances.to_array (sp.soc).instances in let index = get_index (inst_name,sk) in let step_arg = Printf.sprintf "ctx->%s_tab[%d]" (get_ctx_name sk) index in @@ -87,8 +87,8 @@ let (gao2c : Soc.tbl -> 'a soc_pp -> Soc.gao -> unit) = List.iter (fun ve -> assert(var_expr_is_not_a_slice ve)) vel_out; Soc2cDep.gen_step_call sp.soc called_soc vel_out vel_in ctx sname step_arg ) - | Call(vel_out, Procedure sk, vel_in,_) -> ( - let called_soc = Soc.SocMap.find sk stbl in + | Call(vel_out, Procedure sk, vel_in, lxm) -> ( + let called_soc = SocUtils.find lxm sk stbl in let ctx = get_ctx_name called_soc.key in (try List.iter (fun ve -> assert(var_expr_is_not_a_slice ve)) vel_in; @@ -146,12 +146,12 @@ let (step2c : Soc.tbl -> 'a soc_pp -> Soc.step_method -> unit) = List.iter (gao2c stbl sp) gaol ) | Iterator(it,it_soc_key,s) -> - let it_soc = Soc.SocMap.find it_soc_key stbl in + let it_soc = SocUtils.find sm.lxm it_soc_key stbl in sp.cput (Soc2cDep.get_iterator sp.soc it it_soc s) | Boolred(i,j,k) -> sp.cput (Soc2cDep.get_boolred sp.soc i j k) | Condact(k,el) -> - sp.cput (Soc2cDep.get_condact sp.soc (Soc.SocMap.find k stbl) el) + sp.cput (Soc2cDep.get_condact sp.soc (SocUtils.find sm.lxm k stbl) el) ); sp.cput (sprintf "\n} // End of %s\n\n" sname) ) @@ -896,7 +896,7 @@ let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) = let cfiles_acc = ["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 = Soc.SocMap.find msoc stbl in + let main_soc = SocUtils.find_no_exc msoc stbl in (* Generate ext files if necessary *) let needs_cfile, needs_hfile = Soc2cExtern.gen_files main_soc stbl licprg ext_cfile ext_hfile hfile diff --git a/src/socUtils.ml b/src/socUtils.ml index 653a4176b9a6eb02f370d9b69506a6f254d5e0dd..578c558f06691a8a95154aee7d8cd4283db4e4ce 100644 --- a/src/socUtils.ml +++ b/src/socUtils.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 22/11/2016 (at 14:21) by Erwan Jahier> *) +(** Time-stamp: <modified the 03/07/2017 (at 10:27) by Erwan Jahier> *) open Soc @@ -304,22 +304,24 @@ let output: (bool -> string -> Soc.t list -> unit) = ); flush stdout - - let (find : Lxm.t -> Soc.key -> Soc.tbl -> Soc.t) = - fun lxm sk soc_tbl -> - try SocMap.find sk soc_tbl + fun lxm sk soc_tbl -> + try SocMap.find sk soc_tbl with Not_found -> let str_of_key = string_of_soc_key in let nodes = SocMap.fold (fun sk _ acc -> (str_of_key sk)::acc) soc_tbl [] in let nodes_str = String.concat "\n\t" nodes in let msg = Printf.sprintf - ("Cannot find a soc for the node %s. \n Available nodes are: \n\t%s\n") + ("Cannot find a soc for the node %s. \n Available nodes are: \n\t%s\n") (str_of_key sk) nodes_str in raise (Lv6errors.Compile_error(lxm,msg)) +let (add: key -> t -> tbl -> tbl) = + fun k soc tbl -> + SocMap.add k soc tbl + let (find_no_exc : Soc.key -> Soc.tbl -> Soc.t) = fun sk soc_tbl -> try find (Lxm.dummy "") sk soc_tbl @@ -328,8 +330,6 @@ let (find_no_exc : Soc.key -> Soc.tbl -> Soc.t) = flush stdout; assert false - - let gen_index_list n = let rec aux acc i n = if i<0 then acc else aux (i::acc) (i-1) n diff --git a/src/socUtils.mli b/src/socUtils.mli index 243fb70af9c5ba8ec86d7912c47dba19d0d54395..4b35a4304750c3992608d3a3c705803899d6f003 100644 --- a/src/socUtils.mli +++ b/src/socUtils.mli @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 06/02/2015 (at 16:00) by Erwan Jahier> *) +(** Time-stamp: <modified the 03/07/2017 (at 10:22) by Erwan Jahier> *) (** Donne toute les méthodes d'un composant. *) @@ -42,6 +42,9 @@ val output: bool -> string -> Soc.t list -> unit (* Raise a compile error in not found *) val find : Lxm.t -> Soc.key -> Soc.tbl -> Soc.t +val add: Soc.key -> Soc.t -> Soc.tbl -> Soc.tbl + + (* Raise an internal error if not found *) val find_no_exc : Soc.key -> Soc.tbl -> Soc.t diff --git a/test/lus2lic.sum b/test/lus2lic.sum index 924850242e4a58fd9d97fea513daccfade890690..4182add2431d0c6cb3a2a7970f2f5c80f10cc347 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,5 +1,5 @@ ==> lus2lic0.sum <== -Test Run By jahier on Tue Jun 27 14:29:44 +Test Run By jahier on Tue Jul 4 15:58:04 Native configuration is x86_64-unknown-linux-gnu === lus2lic0 tests === @@ -64,7 +64,7 @@ XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/lecte XFAIL: Test bad programs (assert): test_lus2lic_no_node should_fail/assert/s.lus ==> lus2lic1.sum <== -Test Run By jahier on Tue Jun 27 14:29:45 +Test Run By jahier on Tue Jul 4 15:58:05 Native configuration is x86_64-unknown-linux-gnu === lus2lic1 tests === @@ -256,7 +256,9 @@ PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c ec.lus {} PASS: ./lus2lic {-2c enum0.lus -n enum0} PASS: sh enum0.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c enum0.lus {} -FAIL: Generate c code : ./lus2lic {-2c enum0_lv4.lus -n enum0_lv4} +PASS: ./lus2lic {-2c enum0_lv4.lus -n enum0_lv4} +PASS: sh enum0_lv4.sh +FAIL: Try to compare lus2lic -exec and -2c: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c enum0_lv4.lus {} PASS: ./lus2lic {-2c ex.lus -n ex} PASS: sh ex.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c ex.lus {} @@ -401,7 +403,7 @@ PASS: sh multipar.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c multipar.lus {} ==> lus2lic2.sum <== -Test Run By jahier on Tue Jun 27 14:30:37 +Test Run By jahier on Tue Jul 4 15:59:00 Native configuration is x86_64-unknown-linux-gnu === lus2lic2 tests === @@ -730,9 +732,6 @@ PASS: ./lus2lic {-2c when_tuple.lus -n when_tuple} PASS: ./lus2lic {-2c xx.lus -n xx} PASS: sh xx.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c xx.lus {} -PASS: ./lus2lic {-2c xxx.lus -n xxx} -PASS: sh xxx.sh -PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c xxx.lus {} PASS: ./lus2lic {-2c yyy.lus -n yyy} PASS: sh yyy.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c yyy.lus {} @@ -744,7 +743,7 @@ PASS: sh zzz2.sh PASS: /home/jahier/lus2lic/test/../utils/compare_exec_and_2c zzz2.lus {} ==> lus2lic3.sum <== -Test Run By jahier on Tue Jun 27 14:31:50 +Test Run By jahier on Tue Jul 4 16:00:19 Native configuration is x86_64-unknown-linux-gnu === lus2lic3 tests === @@ -837,7 +836,8 @@ PASS: ./myec2c {-o array_concat2.c array_concat2.ec} PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node array_concat2.lus {} PASS: ./lus2lic {-o array_equals.lic array_equals.lus} PASS: ./lus2lic {-ec -o array_equals.ec array_equals.lus} -FAIL: Try ec2c on the result: ./myec2c {-o array_equals.c array_equals.ec} +PASS: ./myec2c {-o array_equals.c array_equals.ec} +PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node array_equals.lus {} PASS: ./lus2lic {-o arrays.lic arrays.lus} PASS: ./lus2lic {-ec -o arrays.ec arrays.lus} PASS: ./myec2c {-o arrays.c arrays.ec} @@ -1025,7 +1025,8 @@ PASS: ./lus2lic {-ec -o enum0.ec enum0.lus} PASS: ./myec2c {-o enum0.c enum0.ec} PASS: ./lus2lic {-o enum0_lv4.lic enum0_lv4.lus} PASS: ./lus2lic {-ec -o enum0_lv4.ec enum0_lv4.lus} -FAIL: Try ec2c on the result: ./myec2c {-o enum0_lv4.c enum0_lv4.ec} +PASS: ./myec2c {-o enum0_lv4.c enum0_lv4.ec} +PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node enum0_lv4.lus {} PASS: ./lus2lic {-o ex.lic ex.lus} PASS: ./lus2lic {-ec -o ex.ec ex.lus} PASS: ./myec2c {-o ex.c ex.ec} @@ -1252,7 +1253,7 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node multipar.lus {} ==> lus2lic4.sum <== -Test Run By jahier on Tue Jun 27 14:34:05 +Test Run By jahier on Tue Jul 4 16:02:37 Native configuration is x86_64-unknown-linux-gnu === lus2lic4 tests === @@ -1563,7 +1564,8 @@ PASS: ./myec2c {-o struct0.c struct0.ec} PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node struct0.lus {} PASS: ./lus2lic {-o struct_equality.lic struct_equality.lus} PASS: ./lus2lic {-ec -o struct_equality.ec struct_equality.lus} -FAIL: Try ec2c on the result: ./myec2c {-o struct_equality.c struct_equality.ec} +PASS: ./myec2c {-o struct_equality.c struct_equality.ec} +PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node struct_equality.lus {} PASS: ./lus2lic {-o struct_with.lic struct_with.lus} PASS: ./lus2lic {-ec -o struct_with.ec struct_with.lus} PASS: ./myec2c {-o struct_with.c struct_with.ec} @@ -1720,10 +1722,6 @@ PASS: ./lus2lic {-o xx.lic xx.lus} PASS: ./lus2lic {-ec -o xx.ec xx.lus} PASS: ./myec2c {-o xx.c xx.ec} PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node xx.lus {} -PASS: ./lus2lic {-o xxx.lic xxx.lus} -PASS: ./lus2lic {-ec -o xxx.ec xxx.lus} -PASS: ./myec2c {-o xxx.c xxx.ec} -PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node xxx.lus {} PASS: ./lus2lic {-o yyy.lic yyy.lus} PASS: ./lus2lic {-ec -o yyy.ec yyy.lus} PASS: ./myec2c {-o yyy.c yyy.ec} @@ -1747,39 +1745,39 @@ PASS: /home/jahier/lus2lic/test/../utils/test_lus2lic_no_node zzz2.lus {} === lus2lic1 Summary === -# of expected passes 320 +# of expected passes 322 # of unexpected failures 5 ==> lus2lic2.sum <== === lus2lic2 Summary === -# of expected passes 329 +# of expected passes 326 # of unexpected failures 2 ==> lus2lic3.sum <== === lus2lic3 Summary === -# of expected passes 481 -# of unexpected failures 11 +# of expected passes 485 +# of unexpected failures 9 # of unresolved testcases 3 ==> lus2lic4.sum <== === lus2lic4 Summary === -# of expected passes 467 -# of unexpected failures 7 +# of expected passes 465 +# of unexpected failures 6 =============================== -# Total number of failures: 25 -lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 0 seconds -lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 52 seconds -lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 72 seconds -lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 135 seconds -lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 64 seconds +# Total number of failures: 22 +lus2lic0.log:testcase ./lus2lic.tests/test0.exp completed in 1 seconds +lus2lic1.log:testcase ./lus2lic.tests/test1.exp completed in 55 seconds +lus2lic2.log:testcase ./lus2lic.tests/test2.exp completed in 74 seconds +lus2lic3.log:testcase ./lus2lic.tests/test3.exp completed in 137 seconds +lus2lic4.log:testcase ./lus2lic.tests/test4.exp completed in 67 seconds * Ref time: -0.05user 0.02system 5:30.19elapsed 0%CPU (0avgtext+0avgdata 5548maxresident)k -64inputs+0outputs (0major+6187minor)pagefaults 0swaps +0.05user 0.02system 5:39.47elapsed 0%CPU (0avgtext+0avgdata 5644maxresident)k +128inputs+0outputs (0major+6125minor)pagefaults 0swaps * Quick time (-j 4): -0.05user 0.02system 2:39.50elapsed 0%CPU (0avgtext+0avgdata 5672maxresident)k -128inputs+0outputs (0major+6172minor)pagefaults 0swaps +0.04user 0.03system 2:22.63elapsed 0%CPU (0avgtext+0avgdata 5724maxresident)k +160inputs+0outputs (0major+6134minor)pagefaults 0swaps diff --git a/test/should_work/xxx.lus b/test/should_work/xxx.lus deleted file mode 100644 index 66616158769c6e905791bc2ee751f6a8e0d13b27..0000000000000000000000000000000000000000 --- a/test/should_work/xxx.lus +++ /dev/null @@ -1,8 +0,0 @@ - -node xxx ( a : int ) returns ( res : int ); -let --- res = red <<red <<red <<iplus, 2 >>, 2>>, 2>> (0, 1^2^2^2 ); - res = red <<red <<+, 2 >>, 2>> (0, 1^2^2 ); --- res = red <<+, 2>> (0, 1^2 ); - -tel