diff --git a/src/lv6MainArgs.ml b/src/lv6MainArgs.ml
index 27ddab4ab5d0f2c7ff4f4c6b01c3806c2b1c4e7e..9bdb880608c36139bdb74af41211dea5025cf141 100644
--- a/src/lv6MainArgs.ml
+++ b/src/lv6MainArgs.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 18/03/2015 (at 16:58) by Erwan Jahier> *)
+(* Time-stamp: <modified the 20/03/2015 (at 14:40) 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,
@@ -38,6 +38,7 @@ type t = {
   mutable tlex :  bool;
   mutable exec :  bool;
   mutable gen_c :  bool;
+  mutable gen_wcet :  bool;
   mutable rif  :  bool;
   mutable gen_ocaml :  bool;
   mutable launch_cc :  bool;
@@ -103,6 +104,7 @@ let (make_opt : unit -> t) =
       tlex =  false;
       exec =  false;
       gen_c =  false;
+      gen_wcet =  false;
       rif  =  false;
       gen_ocaml =  false;
       precision = None;
@@ -372,6 +374,12 @@ let mkoptab (opt:t) : unit = (
       ["Try to compile the generated C files (forces -2c)"]
     ;
 
+    mkopt opt ~hide:true
+      ["--2c-wcet";"-2cw7"]
+      (Arg.Unit (fun i -> opt.gen_c <- true; opt.gen_wcet <- true))
+      ["generates a main file for computing wcet. (forces -2c)"]
+    ;
+
     mkopt opt ~hide:true
       ["--2c-stack";"-2cs"]
       (Arg.Unit (fun i -> opt.gen_c <- true; global_opt.io_transmit_mode <- Stack))
diff --git a/src/lv6MainArgs.mli b/src/lv6MainArgs.mli
index 1d9e2c11fbe220b12d768fe85dc9de11f5acab58..84d74fd2ee84e4ae9cd1685e1f2d78af413aea34 100644
--- a/src/lv6MainArgs.mli
+++ b/src/lv6MainArgs.mli
@@ -40,6 +40,7 @@ type t = {
   mutable tlex :  bool;
   mutable exec :  bool;
   mutable gen_c :  bool;
+  mutable gen_wcet :  bool;
   mutable rif :  bool;
   mutable gen_ocaml :  bool;
   mutable launch_cc :  bool;
diff --git a/src/soc2c.ml b/src/soc2c.ml
index a321e9be53d76a2d8070c36e09600b85562c9048..bd73dc6f4efca6c5dc28e352d44f59ec60a926d4 100644
--- a/src/soc2c.ml
+++ b/src/soc2c.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 20/03/2015 (at 11:14) by Erwan Jahier> *)
+(* Time-stamp: <modified the 20/03/2015 (at 15:48) by Erwan Jahier> *)
 
 
 (* let put (os: out_channel) (fmt:('a, unit, string, unit) format4) : 'a = *)
@@ -349,6 +349,64 @@ let (gen_memoryless_ctx : Soc.tbl -> string) =
 let io_transmit_mode () = Lv6MainArgs.global_opt.Lv6MainArgs.io_transmit_mode
       
 (****************************************************************************)
+let (gen_main_wcet_file : Soc.t -> string -> Soc.tbl -> unit) =
+  fun soc base stbl -> 
+    let mainfile = base^"_main.c" in
+    let oc = open_out mainfile 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
+    let (n,_,_) = soc.key in
+    let n = id2s n in
+    let inputs,outputs = soc.profile in
+    let inputs_io  = SocVar.expand_profile true false inputs  in
+    let outputs_io = SocVar.expand_profile true false outputs in
+    let inputs_exp = SocVar.expand_profile true true  inputs  in
+    let outputs_exp= SocVar.expand_profile true true  outputs in
+    Lv6util.entete oc "/*" "*/";
+    putc  ("
+#include <stdlib.h>
+#include \""^base ^".h\" 
+ 
+int main(){" ^ (
+      match io_transmit_mode () with
+        | Lv6MainArgs.Stack ->
+          let to_c_decl (n,t) = ((Soc2cUtil.data_type_to_c t n)^ ";\n  ") in
+          let inputs_t  = List.map to_c_decl inputs in
+          let outputs_t = List.map to_c_decl outputs in
+          let inputs_decl = Printf.sprintf "\n  %s" (String.concat "" inputs_t) in
+          let outputs_decl = Printf.sprintf "%s" (String.concat "" outputs_t) in
+          let ctx_decl = if SocUtils.is_memory_less soc then "" else 
+              ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);\n\n"
+          in
+          inputs_decl ^ outputs_decl ^ ctx_decl
+        | Lv6MainArgs.Heap -> ("
+          /* Context allocation */
+  " ^ (if SocUtils.is_memory_less soc then ctx^"_type* ctx = &"^ctx^";\n"
+    else ctx^"_type* ctx = "^ ctx^"_new_ctx(NULL);")
+        )
+        | Lv6MainArgs.HeapStack -> ("
+          /* Context allocation */
+  " ^ (if SocUtils.is_memory_less soc then ctx^""
+    else ctx^"_type* ctx ;\n"^ ctx^"_reset(ctx);")
+        )
+    ));
+    let inputs_fmt  = List.map (fun (_,t) -> type_to_format_string t) inputs_io in
+    let outputs_fmt = List.map (fun (_,t) -> type_to_format_string t) outputs_io in
+    if io_transmit_mode () = Lv6MainArgs.Stack 
+    then
+      let i =  fst (List.split inputs) in
+      let o = List.map (fun (n,t) -> match t with Data.Array(_,_) -> n | _ ->"&"^n) outputs in
+      let io = String.concat "," (i@o) in
+      let io = if SocUtils.is_memory_less soc then io else if io = "" then "ctx" else io^",ctx" in
+      putc ("  " ^ step^"("^io^");
+  return 0; 
+}
+");
+    close_out oc
+
+
 let (gen_loop_file : Soc.t -> out_channel -> Soc.tbl -> unit) =
   fun soc oc stbl -> 
     let base = (string_of_soc_key soc.key) in
@@ -555,7 +613,7 @@ int main(){
 
 (****************************************************************************)
 (* The entry point for lus2lic --to-c *)
-           let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
+let (f : Lv6MainArgs.t -> Soc.key -> Soc.tbl -> LicPrg.t -> unit) =
   fun args msoc stbl licprg -> 
     let socs = Soc.SocMap.bindings stbl in
     let socs = snd (List.split socs) in 
@@ -589,7 +647,8 @@ int main(){
       Lv6util.entete occ "/*" "*/" ;
       Lv6util.entete och "/*" "*/";
       gen_loop_file main_soc ocl stbl;
-      
+      if args.Lv6MainArgs.gen_wcet then gen_main_wcet_file main_soc base stbl;
+
       output_string och "
 #include <stdlib.h>
 #include <string.h>