diff --git a/src/lic2soc.ml b/src/lic2soc.ml index 2047902f046f9e5ec42927d3ecf6c2015b13aad4..5f5d4a269aca20362a05393ffa47134d0fcb408d 100644 --- a/src/lic2soc.ml +++ b/src/lic2soc.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 13/06/2014 (at 16:28) by Erwan Jahier> *) +(** Time-stamp: <modified the 20/06/2014 (at 08:14) by Erwan Jahier> *) open Lxm open Lic @@ -524,7 +524,10 @@ let rec (actions_of_expression_acc: Lxm.t -> Soc.tbl -> let init = val_exp_to_filter ctx.prg (List.hd val_exp_list) in if by_pos_op_flg.it = Lic.FBY then (sk_name, sk_prof, Soc.MemInit init), Some init - else + else if by_pos_op_flg.it = Lic.ARROW then + let init = Soc.Const("_true", Data.Bool) in + (sk_name, sk_prof, Soc.MemInit init), Some init + else sk, None in try Soc.SocMap.find sk soc_tbl @@ -692,7 +695,7 @@ let rec f: (LicPrg.t -> Lic.node_key -> Soc.key * Soc.tbl) = | Undef_soc (sk,lxm,pos_op, types, fby_init_opt) -> ( let soc = SocPredef.soc_interface_of_pos_op lxm pos_op types fby_init_opt in - if ( sk)<>( soc.key) then ( + if (sk<>soc.key) then ( print_string ("Soc key mismatch :\n\t" ^ (SocUtils.string_of_soc_key sk) ^ "\n<>\n\t" ^ (SocUtils.string_of_soc_key soc.key) ^ "\n"); diff --git a/src/soc2c.ml b/src/soc2c.ml index e29dd574e09dfe7393cb644b2a4c8024f3922a67..64007404ca87cf2cecd6b07599f610b7ad929117 100644 --- a/src/soc2c.ml +++ b/src/soc2c.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 19/06/2014 (at 11:33) by Erwan Jahier> *) +(* Time-stamp: <modified the 20/06/2014 (at 08:33) by Erwan Jahier> *) (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *) @@ -175,6 +175,11 @@ let (step2c : Soc.tbl -> 'a soc_pp -> Soc.step_method -> unit) = ); sp.cput (sprintf "\n} // End of %s\n\n" sname) +let (gen_instance_init_call : 'a soc_pp -> Soc.instance -> unit) = + fun sp (id,key) -> + let ctx_name = get_ctx_name key in + sp.cfmt "\n %s_reset(&ctx->%s);" ctx_name (id2s id) + let (soc2c: int -> out_channel -> out_channel -> Soc.tbl -> Soc.t -> unit) = fun pass hfile cfile stbl soc -> let hfmt fmt = Printf.kprintf (fun t -> output_string hfile t) fmt in @@ -194,18 +199,29 @@ let (soc2c: int -> out_channel -> out_channel -> Soc.tbl -> Soc.t -> unit) = if is_memory_less soc then hfmt "%s %s;\n" ctx_name_type ctx_name; ) else ( if is_memory_less soc then () else ( + cfmt "// Memory initialisation for %s\n" ctx_name; + hfmt "void %s_reset(%s_type* ctx);\n" ctx_name ctx_name; + cfmt "void %s_reset(%s_type* ctx){" ctx_name ctx_name; + (* Call the reset_ctx functions of the soc instances *) + List.iter (gen_instance_init_call sp) soc.instances; + (match soc.key with + (* set the parameter fields that have a default value (arrow,fby) *) + | (_,_,MemInit (ve)) -> cfmt "\n ctx->_memory = %s;" (string_of_var_expr soc ve) + | _ -> () + ); + cfmt " +} +"; cfmt "// Memory allocation for %s\n" ctx_name; hfmt "%s_type* %s_new_ctx();\n" ctx_name ctx_name; cfmt "%s_type* %s_new_ctx(){" ctx_name ctx_name; cfmt " %s_type* ctx = (%s_type*)calloc(1, sizeof(%s_type)); // ctx->client_data = cdata; - // %s_reset(ctx); + %s_reset(ctx); return ctx; } " ctx_name ctx_name ctx_name ctx_name) ; - - cfmt "// Step function(s) for %s\n" ctx_name; List.iter (step2c stbl sp) soc.step; () @@ -265,13 +281,7 @@ let (typedef_of_soc : Soc.t -> string) = in let str = str ^ (if soc.instances <> [] then " /*INSTANCES*/\n" else "") in let string_of_instance (id,sk) = - let (sk_id,tl,init_opt) = sk in - let init = match init_opt with - | Soc.Nomore -> "" - | Soc.Slic(_,_,_) -> assert false (* fixme *) - | Soc.MemInit(ve) -> Printf.sprintf " = %s" (string_of_var_expr soc ve) - in - Printf.sprintf " %s_type %s%s;\n" (get_ctx_name sk) (id2s id) init + Printf.sprintf " %s_type %s;\n" (get_ctx_name sk) (id2s id) in let str = List.fold_left (fun acc inst -> acc^(string_of_instance inst)) str soc.instances in let str = Printf.sprintf "%s} %s;\n\n" str ctx_name_type in @@ -408,7 +418,7 @@ _boolean _get_bool(char* n){ do { if(ISATTY) { if((s != 1)||(r == -1)) printf(\"\a\"); - printf(\"%s (1,t,T/0,f,F) ? \", n); + // printf(\"%s (1,t,T/0,f,F) ? \", n); } if(scanf(\"%s\", b)==EOF) exit(0); if (*b == 'q') exit(0); diff --git a/src/socPredef.ml b/src/socPredef.ml index 978c8728fec2a2ab820ddeea74d160d78f3a16f3..3a98d81411c24972551c90e843ffe804c0e1ef37 100644 --- a/src/socPredef.ml +++ b/src/socPredef.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 19/06/2014 (at 11:43) by Erwan Jahier> *) +(* Time-stamp: <modified the 20/06/2014 (at 08:07) by Erwan Jahier> *) (** Synchronous Object Code for Predefined operators. *) @@ -515,7 +515,9 @@ let (soc_interface_of_pos_op: instanciate_soc soc concrete_type | Lic.ARROW, _, _ -> let concrete_type = List.nth types 0 in - let soc = of_soc_key (("Lustre::arrow"), types@[concrete_type], Nomore) in + let soc = of_soc_key (("Lustre::arrow"), types@[concrete_type], + MemInit(Const("_true", Data.Bool))) + in let soc = instanciate_soc soc concrete_type in soc | Lic.HAT i,_, _ -> diff --git a/test/lus2lic.sum b/test/lus2lic.sum index 816ded5ed9cf0dd43e2c4d7f90b2563bc6bbfd98..7a9deea9e357482d1ff44726418bfe212077a864 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,4 +1,4 @@ -Test Run By jahier on Thu Jun 19 15:25:21 2014 +Test Run By jahier on Fri Jun 20 08:29:19 2014 Native configuration is i686-pc-linux-gnu === lus2lic tests === @@ -1483,5 +1483,5 @@ XPASS: Test bad programs (semantics): lus2lic {-o /tmp/bug.lic should_fail/seman # of unexpected failures 149 # of unexpected successes 21 # of expected failures 37 -testcase ./lus2lic.tests/non-reg.exp completed in 137 seconds +testcase ./lus2lic.tests/non-reg.exp completed in 128 seconds testcase ./lus2lic.tests/progression.exp completed in 0 seconds diff --git a/test/lus2lic.time b/test/lus2lic.time index 484c0604947af1f4c1096adbdd0d5f5fd97e24b4..ada103c1e49c1a76264bb6377f90ea233bea7409 100644 --- a/test/lus2lic.time +++ b/test/lus2lic.time @@ -1,2 +1,2 @@ -testcase ./lus2lic.tests/non-reg.exp completed in 137 seconds +testcase ./lus2lic.tests/non-reg.exp completed in 128 seconds testcase ./lus2lic.tests/progression.exp completed in 0 seconds diff --git a/test/should_work/modes3x2_v3.lus b/test/should_work/modes3x2_v3.lus index b60407518c745e0d4cf1776830187c68fcbf139a..a7b9505cc042dab226bbd58d94704f458af8d2bc 100644 --- a/test/should_work/modes3x2_v3.lus +++ b/test/should_work/modes3x2_v3.lus @@ -41,11 +41,13 @@ let else (0 -> pre z); tel -node modes3x2_v3(x:data; on_off, toggle: bool) returns (res: data); -var +node modes3x2_v3(x:data; on_off, toggle: bool) returns (res: data; +--); +--var y, z : data; sby : bool; nom : bool; +); let -- assert #(on_off, toggle); @@ -59,3 +61,8 @@ let nom = (on_off = (false -> pre sby)); res = y + z; tel + +node xxx(on_off: bool) returns (sby : bool); +let + sby = (true -> pre on_off); +tel