From dc44269befd884f2e80129d89556aad0f66ad829 Mon Sep 17 00:00:00 2001
From: Erwan Jahier <jahier@imag.fr>
Date: Fri, 9 Sep 2016 10:24:07 +0200
Subject: [PATCH] -2c: override the enum mode when generating C code as the
 default (AsEnum) generates unvalid C code.

---
 _oasis             |  2 +-
 src/lv6MainArgs.ml | 33 ++++++++++++++++++++-------------
 src/lv6version.ml  |  4 ++--
 3 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/_oasis b/_oasis
index a04aa0a9..9f427388 100644
--- a/_oasis
+++ b/_oasis
@@ -1,6 +1,6 @@
 OASISFormat: 0.4
 Name:        lustre-v6
-Version:     1.660
+Version:     1.661
 Synopsis:    The Lustre V6 Verimag compiler
 Description: This package contains:
    (1) lus2lic: the (current) name of the compiler (and interpreter via -exec).
diff --git a/src/lv6MainArgs.ml b/src/lv6MainArgs.ml
index 5183ccbf..c4efb2e7 100644
--- a/src/lv6MainArgs.ml
+++ b/src/lv6MainArgs.ml
@@ -1,4 +1,4 @@
-(* Time-stamp: <modified the 05/09/2016 (at 10:28) by Erwan Jahier> *)
+(* Time-stamp: <modified the 05/09/2016 (at 11:02) 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,
@@ -247,6 +247,14 @@ let set_ec_options opt =
   opt.expand_nodes <- true;
   ()
 
+let set_c_options opt =
+  opt.gen_c <- true;
+  (match global_opt.expand_enums with
+   | AsEnum -> global_opt.expand_enums <- AsInt;
+   (* only override the default in this case *)
+   | AsInt | AsConst | AsBool -> ());
+  ()
+    
 (*** USER OPTIONS TAB **)
 let mkoptab (opt:t) : unit = (
     mkopt opt
@@ -270,15 +278,12 @@ let mkoptab (opt:t) : unit = (
     ;
     mkopt opt
       ["-2c";"--to-c"]
-      (Arg.Unit (fun _ -> 
-                 opt.gen_c <- true;
-                 global_opt.expand_enums <- AsInt;
-      ))
+      (Arg.Unit (fun _ -> set_c_options opt))
       ["generate C code"]
     ;
     mkopt opt ~doc_level:Basic
       ["-cc"; "--compile-generated-c"]
-      (Arg.Unit (fun i -> opt.gen_c <- true; opt.launch_cc <- true))
+      (Arg.Unit (fun i -> set_c_options opt; opt.launch_cc <- true))
       ["Try to compile the generated C files (force -2c)"]
     ;
     mkopt opt
@@ -392,12 +397,12 @@ let mkoptab (opt:t) : unit = (
     ;
     mkopt opt ~doc_level:Advanced
       ["-2cil";"--2c-inline-loop"]
-      (Arg.Unit (fun i -> global_opt.soc2c_inline_loops <- true; opt.gen_c <- true))
+      (Arg.Unit (fun i -> global_opt.soc2c_inline_loops <- true; set_c_options opt))
       ["inline loops (that come from array iterators)"]
     ;
     mkopt opt ~doc_level:Advanced
       ["-2cgc";"--2c-global-ctx"]
-      (Arg.Unit (fun i -> global_opt.soc2c_global_ctx <- true; opt.gen_c <- true))
+      (Arg.Unit (fun i -> global_opt.soc2c_global_ctx <- true; set_c_options opt))
       ["node context allocated as global variable (no \"new_ctx\" method)"]
     ;
 
@@ -454,24 +459,26 @@ let mkoptab (opt:t) : unit = (
 
     mkopt opt ~doc_level:Advanced
       ["-2cw7";"--2c-wcet"]
-      (Arg.Unit (fun i -> opt.gen_c <- true; opt.gen_wcet <- true; 
-                          global_opt.soc2c_global_ctx <- true))
+      (Arg.Unit (fun i ->
+                 set_c_options opt;
+                 opt.gen_wcet <- true;
+                 global_opt.soc2c_global_ctx <- true))
       ["generates a main file for computing the wcet (force -2c -2cgc)"]
     ;
 
     mkopt opt ~doc_level:Dev
       ["-2cs";"--2c-stack"]
-      (Arg.Unit (fun i -> opt.gen_c <- true; global_opt.io_transmit_mode <- Stack))
+      (Arg.Unit (fun i -> set_c_options opt; global_opt.io_transmit_mode <- Stack))
       ["Soc I/O are transmitted as params of the step functions (force -2c)"]
     ;
     mkopt opt ~doc_level:Dev
       ["-2ch";"--2c-heap"]
-      (Arg.Unit (fun i -> opt.gen_c <- true; global_opt.io_transmit_mode <- Heap))
+      (Arg.Unit (fun i -> set_c_options opt; global_opt.io_transmit_mode <- Heap))
       ["Soc I/O are transmitted via a ctx structure in the heap (force -2c)"]
     ;
     mkopt opt ~doc_level:Dev
       ["-2chs";"--2c-heap-and-stack"]
-      (Arg.Unit (fun i -> opt.gen_c <- true; global_opt.io_transmit_mode <- HeapStack))
+      (Arg.Unit (fun i -> set_c_options opt; global_opt.io_transmit_mode <- HeapStack))
       ["I/O of memoryless soc are transmitted via the stack, and the heap otherwise (force -2c)"]
     ;
 
diff --git a/src/lv6version.ml b/src/lv6version.ml
index 0e019745..a8e0b2dd 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 = "660"
-let sha_1 = "9c822b3b5e15c279cb863183108cc3a9598abae4"
+let commit = "661"
+let sha_1 = "4508ea9fa98a3e651c3c3039d1525255d50ef17b"
 let str = (branch ^ "." ^ commit ^ " (" ^ sha_1 ^ ")")
 let maintainer = "jahier@imag.fr"
-- 
GitLab