diff --git a/src/lic2soc.ml b/src/lic2soc.ml index 70ef99eb5476809d993ee95b4f17029dcd596900..c9abd275a9fa5f89de2b886efc0858efa8072a2e 100644 --- a/src/lic2soc.ml +++ b/src/lic2soc.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 27/03/2013 (at 15:33) by Erwan Jahier> *) +(** Time-stamp: <modified the 29/03/2013 (at 09:54) by Erwan Jahier> *) open Lxm open Lic @@ -388,7 +388,7 @@ let create_instance_from_soc: (ctx -> Soc.t -> ctx * Soc.instance) = let ctx, inst_name = create_new_instance_name c.Soc.key ctx in ctx, (inst_name, c.Soc.key) -(* if the soc has memories, do create an instance *) +(* if the soc has memories (a pre, or node with memory), do create an instance *) let (make_instance : Lxm.t -> Lic.clock -> ctx -> Soc.t -> ctx * Soc.instance option) = fun lxm clk ctx soc -> @@ -396,11 +396,11 @@ let (make_instance : | [] -> ( match soc.Soc.have_mem with | None -> ctx, None - | Some _ -> + | Some _ -> (* pre/fby*) let ctx, m = create_instance_from_soc ctx soc in ctx, Some(m) ) - | _ -> + | _ -> (* the soc has sub-soc with memory *) let ctx, m = create_instance_from_soc ctx soc in ctx, Some(m) @@ -723,20 +723,28 @@ let rec f: (LicPrg.t -> Lic.node_key -> Soc.key * Soc.tbl) = let nsk, soc_tbl = process_node iter_node soc_tbl in let nsoc = SocUtils.find lxm nsk soc_tbl in let nsoc_step = match nsoc.step with [s] -> s - | _ -> assert false + | _ -> assert false (* hmm. Iterating on a pre will not work. XXX fixme ! *) in + let rec make_n_instance ctx acc n = + if n=0 then ctx,acc else + match make_instance lxm Lic.BaseLic ctx nsoc with + | ctx,Some inst -> make_n_instance ctx (inst::acc) (n-1) + | ctx,None -> ctx,[] + in + let c = int_of_string c in + let ctx, instances = make_n_instance ctx [] c in let soc = { - Soc.key = soc_key; - Soc.profile = soc_profile_of_node node; - Soc.instances = nsoc.instances ; (* XXX create n x |nsoc.instances| instances! *) - Soc.step = [ + Soc.key = soc_key; + Soc.profile = soc_profile_of_node node; + Soc.instances = instances ; + Soc.step = [ { - name = "step"; - lxm = nsoc_step.lxm; + name = "step"; + lxm = nsoc_step.lxm; idx_ins = nsoc_step.idx_ins; idx_outs = nsoc_step.idx_outs; - impl = Iterator(snd (fst nk), nsk, int_of_string c); + impl = Iterator(snd (fst nk), nsk, c); } ]; Soc.have_mem = None; diff --git a/src/socExec.ml b/src/socExec.ml index 246a684685bd50a396e920dbbc80b0986c29b736..151e673427571043595729b14f8e775c22e5ddc6 100644 --- a/src/socExec.ml +++ b/src/socExec.ml @@ -1,8 +1,9 @@ -(* Time-stamp: <modified the 29/03/2013 (at 08:55) by Erwan Jahier> *) +(* Time-stamp: <modified the 29/03/2013 (at 10:59) by Erwan Jahier> *) open Soc open SocExecValue +let dbg = Some(Verbose.get_flag "exec") let (assign_expr : ctx -> var_expr -> var_expr -> ctx) = fun ctx ve_in ve_out -> @@ -11,7 +12,6 @@ let (assign_expr : ctx -> var_expr -> var_expr -> ctx) = sadd_partial ctx.s ve_out ctx.cpath v } - (* [array_index i v] returns the var_expr v[i] *) let (array_index : int -> var -> var_expr) = fun i (vn,vt) -> @@ -28,38 +28,30 @@ let rec (soc_step : Soc.step_method -> Soc.tbl -> Soc.t -> SocExecValue.ctx let soc_name,_,_ = soc.key in match step.impl with | Predef -> ( - try SocExecEvalPredef.get soc.key ctx - with Not_found -> (* Not a predef op *) - print_string ("*** Error when executing " ^ soc_name ^ - ". Is it defined in SocExecEvalPredef?\n"); flush stdout; - assert false + try SocExecEvalPredef.get soc.key ctx + with Not_found -> (* Not a predef op *) print_string ( + "*** Int error in "^soc_name^". Is it defined in SocExecEvalPredef?\n"); + flush stdout; assert false ) | Gaol(vl,gaol) -> List.fold_left (do_gao step.lxm soc_tbl) ctx gaol | Iterator("map", node_sk, n) -> let node_soc = SocUtils.find step.lxm node_sk soc_tbl in let node_step = match node_soc.step with [step] -> step | _ -> assert false in - let iter_inputs,iter_outputs = soc.profile in - let node_inputs,node_outputs = node_soc.profile in - let node_step_in_vars = filter_params node_soc node_inputs node_step.idx_ins in - let node_step_out_vars = filter_params node_soc node_outputs node_step.idx_outs in - let path_save = ctx.cpath in - let rctx = ref ctx in + let iter_inputs,iter_outputs = soc.profile in + let rctx = ref ctx in + let (proc_name,_,_) = node_soc.key in + let inst_name = + match soc.instances with + | [] -> Array.make n proc_name + | _ -> Array.of_list (List.map fst soc.instances) + in for i = 0 to n-1 do - let (proc_name,_,_) = node_soc.key in - (* XXX something else has to be done if the node has memories *) - -(* XXX appler do_step *) - rctx := { !rctx with cpath = proc_name::ctx.cpath }; - let args_in : var_expr list = List.map (array_index i) iter_inputs in - let args_out : var_expr list = List.map (array_index i) iter_outputs in - let new_s = substitute_args_and_params args_in node_step_in_vars !rctx in - rctx := { !rctx with s=new_s }; - rctx := soc_step node_step soc_tbl node_soc !rctx; - let s_out = substitute_params_and_args node_step_out_vars args_out !rctx in - rctx := { cpath=path_save; s = s_out }; + rctx := { !rctx with cpath = inst_name.(i)::ctx.cpath }; + let vel_in : var_expr list = List.map (array_index i) iter_inputs in + let vel_out : var_expr list = List.map (array_index i) iter_outputs in + rctx := do_step inst_name.(i) node_step !rctx soc_tbl soc vel_in vel_out; done; - (* 4 DEBUG*) let str = string_of_substs !rctx.s in print_string ("ici3 \n"^str); flush stdout; - !rctx; + !rctx; | Iterator(it, it_soc, n) -> assert false and (do_gao : Lxm.t -> Soc.tbl -> SocExecValue.ctx -> gao -> SocExecValue.ctx) = @@ -118,8 +110,6 @@ and (filter_params : Soc.t -> Soc.var list -> int list -> Soc.var list) = let res = List.map (fun i -> local_nth i el) il in res - - (* expand struct and arrays when communicating with the outside world (a good idea?) *) let rec (expand_profile:Soc.var list -> Soc.var list) = fun vl -> @@ -136,10 +126,7 @@ and expand_var var = match var with res := (vn^"_"^(string_of_int k),vt) :: !res; done; (expand_profile !res) - | (vn,Struct(name,fl)) -> - let res = List.map (fun (fn,t) -> vn^"_"^fn,t ) fl in - expand_profile res - + | (vn,Struct(name,fl)) -> expand_profile (List.map (fun (fn,t) -> vn^"_"^fn,t ) fl) | (vn,Extern id) -> assert false (* finish me! *) | (vn,Alpha _) -> assert false (* should not occur *) @@ -186,7 +173,6 @@ let (unexpand : sl -> Soc.var list -> sl) = | (id,v)::sl, (_,Enum(n,el))::vl -> let s = (id, int_to_enum v el) in aux (s::sl_done) sl vl - | _, (vn, Array(vt,i))::vl -> ( let sl_todo_ref = ref sl_todo in let sl_done_ref = ref [] in @@ -207,7 +193,6 @@ let (unexpand : sl -> Soc.var list -> sl) = let sl_done = (vn, S fl)::sl_done in aux sl_done sl_todo vl - | _, (vn,Extern id)::_ -> assert false (* finish me! *) | _, (vn,Alpha _ )::_ -> assert false (* should not occur *) | [],_::_ -> assert false (* should not occur *) @@ -246,6 +231,7 @@ let rec (loop_step : Soc.tbl -> Soc.t -> SocExecValue.ctx -> int -> out_channel Rif_base.write oc " #outs "; Rif_base.write_outputs oc vntl s; Rif_base.flush oc; + Verbose.exe ~flag:dbg (fun () -> dump_substs ctx.s; flush stdout); loop_step soc_tbl soc ctx (step_nb+1) oc let (f : Soc.tbl -> Soc.key -> unit) = diff --git a/src/socExecValue.ml b/src/socExecValue.ml index 55394df2b7f12f63ece5634eef7010f075e1a0a3..d33a2b419df7f3bef9de7f35de7ffaf93fb5f29e 100644 --- a/src/socExecValue.ml +++ b/src/socExecValue.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 28/03/2013 (at 17:39) by Erwan Jahier> *) +(* Time-stamp: <modified the 29/03/2013 (at 09:57) by Erwan Jahier> *) open Soc @@ -369,28 +369,28 @@ let empty_ctx: ctx = { let rec (create_ctx : Soc.tbl -> Soc.t -> ctx) = fun soc_tbl soc -> let rec (init_soc: Soc.t -> ident list -> substs -> substs) = - fun soc cpath mem -> + fun soc cpath mem -> let mem = match soc.have_mem with - | Some(vt, Some(value)) -> + | Some(vt, Some(value)) -> let name = (SocPredef.get_mem_name soc.key vt)::cpath in let value = get_value empty_ctx value in sadd mem name value - | Some(vt, None) -> + | Some(vt, None) -> let name = (SocPredef.get_mem_name soc.key vt)::cpath in - let value = U in + let value = U in sadd mem name value | None -> mem - in + in List.fold_left (init_instances cpath) mem soc.instances - + and (init_instances: ident list -> substs -> Soc.instance -> substs) = - fun cpath mem (iname, sk) -> + fun cpath mem (iname, sk) -> let soc = SocUtils.find_no_exc sk soc_tbl in init_soc soc (iname::cpath) mem in { - s = init_soc soc [] (Node []); + s = init_soc soc [] (Node []); cpath = []; } diff --git a/test/lus2lic.sum b/test/lus2lic.sum index 0276af029a2b19254b623d4e1d4023f56065dff1..6b4c7e9cebcc236176e08c168c69a4fb6e10de12 100644 --- a/test/lus2lic.sum +++ b/test/lus2lic.sum @@ -1,4 +1,4 @@ -Test Run By jahier on Thu Mar 28 18:08:46 2013 +Test Run By jahier on Fri Mar 29 08:55:59 2013 Native configuration is i686-pc-linux-gnu === lus2lic tests ===