From 5ed4bea4b1d829728fc9e18e5651bab7c67318d6 Mon Sep 17 00:00:00 2001
From: Guillaume Emile <emile.guillaume@etu.univ-grenoble-alpes.fr>
Date: Mon, 18 Jul 2022 15:23:22 +0200
Subject: [PATCH] add central demon (need to be tested) + add random unsafe
 node (need to be test)

---
 lib/Random/lustre_consts.c     |   4 +
 lib/Random/lustre_consts.h     |   4 +
 lib/Random/lustre_types.h      |  16 ++++
 lib/Random/random.exec         | Bin 0 -> 17864 bytes
 lib/Random/random.sh           |   4 +
 lib/Random/random.sh~          |   4 +
 lib/Random/utils_random.c      |  13 +++
 lib/Random/utils_random.h      |  24 ++++++
 lib/Random/utils_random_ext.c  |   6 ++
 lib/Random/utils_random_ext.c~ |   5 ++
 lib/Random/utils_random_ext.h  |   1 +
 lib/Random/utils_random_loop.c | 151 +++++++++++++++++++++++++++++++++
 lib/sas.lus                    |  29 +++++++
 lib/use_random.lus             |   2 +
 lib/utils.lus                  |  10 ++-
 15 files changed, 272 insertions(+), 1 deletion(-)
 create mode 100644 lib/Random/lustre_consts.c
 create mode 100644 lib/Random/lustre_consts.h
 create mode 100644 lib/Random/lustre_types.h
 create mode 100755 lib/Random/random.exec
 create mode 100644 lib/Random/random.sh
 create mode 100644 lib/Random/random.sh~
 create mode 100644 lib/Random/utils_random.c
 create mode 100644 lib/Random/utils_random.h
 create mode 100644 lib/Random/utils_random_ext.c
 create mode 100644 lib/Random/utils_random_ext.c~
 create mode 100644 lib/Random/utils_random_ext.h
 create mode 100644 lib/Random/utils_random_loop.c
 create mode 100644 lib/use_random.lus

diff --git a/lib/Random/lustre_consts.c b/lib/Random/lustre_consts.c
new file mode 100644
index 00000000..bc36e0d3
--- /dev/null
+++ b/lib/Random/lustre_consts.c
@@ -0,0 +1,4 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+#include "lustre_consts.h"
\ No newline at end of file
diff --git a/lib/Random/lustre_consts.h b/lib/Random/lustre_consts.h
new file mode 100644
index 00000000..0c80098e
--- /dev/null
+++ b/lib/Random/lustre_consts.h
@@ -0,0 +1,4 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+#include "lustre_types.h"
\ No newline at end of file
diff --git a/lib/Random/lustre_types.h b/lib/Random/lustre_types.h
new file mode 100644
index 00000000..d9385f1c
--- /dev/null
+++ b/lib/Random/lustre_types.h
@@ -0,0 +1,16 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+
+#ifndef _SOC2C_PREDEF_TYPES
+#define _SOC2C_PREDEF_TYPES
+typedef int _boolean;
+typedef int _integer;
+typedef char* _string;
+typedef double _real;
+typedef double _double;
+typedef float _float;
+#define _false 0
+#define _true 1
+#endif
+// end of _SOC2C_PREDEF_TYPES
\ No newline at end of file
diff --git a/lib/Random/random.exec b/lib/Random/random.exec
new file mode 100755
index 0000000000000000000000000000000000000000..7b1d5ae64a2428c32e49038e36a4253f2c56db0d
GIT binary patch
literal 17864
zcmeHPeQ*@VmG6}h5*V)p7)LSqSR;sq6D<-kUyfyVkp!ch_%N1;odd=z?Mhll(yn)B
z9f3^(CF8JB6jMo@_*^9AbE<qKRjIO5iA^O=f<p}FRL%vtm~eM-qVw6wD*iYb<FkCh
z?EPMMztPOFo4fnxs;+KZwe$M@-bZ)8>6z*2p4MmEIyRR1e1cQCxJ3{*S)-7U78tka
z3`j_<6<6T+7vfqm6Z{N`DS1c{NLA`DbJHq~mxGesQ7!k<MOu$3*N`aL6-!mR0H#8>
zgX}8ENb_FWtnHYx+%7Lb#z+BqwCQPT2oh7L9mOWsAjKlr?52<Db|2G}?T972DQ!2U
z?U;^Jg^-wXJSish`<eFVrLAOy#FTU?ZF|*<QvPUwxXbAg1q-HZcPs3up8ws%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*|4)HepLwP)!loKOw&!_^N$gIb
z#CnRG<{AGN2&nI|J->(Y|A82%#vyV4WIK-I!;p~*+w(lgxfNuEZ&nnsk8IEMkB~U+
zMM$eQDw@<R6SiaeHUv)lWJqZywY_)dgzebhd&m&R_2=>T=e2zeD{AVszXY7h*Xp)5
z+h1=ZDnq)IoYd1rr2Lq6cuW^a&!Lav$K~_=cNQ?NyEN2?<T{o4dykOIWnFr$^QcHs
NbF<Q@^cZ+p@t^US**O3J

literal 0
HcmV?d00001

diff --git a/lib/Random/random.sh b/lib/Random/random.sh
new file mode 100644
index 00000000..07a6da31
--- /dev/null
+++ b/lib/Random/random.sh
@@ -0,0 +1,4 @@
+if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi
+$C_COMPILER -o random.exec \
+	Random/utils_random_ext.c Random/lustre_consts.c Random/utils_random.c  Random/utils_random_loop.c
+
diff --git a/lib/Random/random.sh~ b/lib/Random/random.sh~
new file mode 100644
index 00000000..07a6da31
--- /dev/null
+++ b/lib/Random/random.sh~
@@ -0,0 +1,4 @@
+if [ -z ${C_COMPILER} ]; then C_COMPILER=gcc; fi
+$C_COMPILER -o random.exec \
+	Random/utils_random_ext.c Random/lustre_consts.c Random/utils_random.c  Random/utils_random_loop.c
+
diff --git a/lib/Random/utils_random.c b/lib/Random/utils_random.c
new file mode 100644
index 00000000..5d2b57e7
--- /dev/null
+++ b/lib/Random/utils_random.c
@@ -0,0 +1,13 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+#include "utils_random.h"
+//// Defining step functions
+// Step function(s) for utils_c_rand_ctx
+// Step function(s) for utils_random_ctx
+void utils_random_step(_integer x,_integer *res){
+
+  utils_c_rand_step(x,res); 
+
+} // End of utils_random_step
+
diff --git a/lib/Random/utils_random.h b/lib/Random/utils_random.h
new file mode 100644
index 00000000..91093483
--- /dev/null
+++ b/lib/Random/utils_random.h
@@ -0,0 +1,24 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "lustre_consts.h"
+
+// User typedef 
+#ifndef _utils_random_TYPES
+#define _utils_random_TYPES
+// Memoryless soc ctx typedef 
+// Memoryfull soc ctx typedef 
+#endif // end of  _utils_random_TYPES
+
+#ifndef _utils_random_H_FILE
+#include "utils_random_ext.h"
+#define _utils_random_H_FILE
+#endif // _utils_random_H_FILE
+
+void utils_random_step(_integer ,_integer *);
+
+/////////////////////////////////////////////////
diff --git a/lib/Random/utils_random_ext.c b/lib/Random/utils_random_ext.c
new file mode 100644
index 00000000..83e091f8
--- /dev/null
+++ b/lib/Random/utils_random_ext.c
@@ -0,0 +1,6 @@
+#include "utils_random.h"
+#include <assert.h>
+void utils_c_rand_step(_integer x,_integer *res){
+  assert (0 < x );
+  *res = (rand() % x);
+}
diff --git a/lib/Random/utils_random_ext.c~ b/lib/Random/utils_random_ext.c~
new file mode 100644
index 00000000..482555db
--- /dev/null
+++ b/lib/Random/utils_random_ext.c~
@@ -0,0 +1,5 @@
+#include "utils_random.h"
+void utils_c_rand_step(_integer x,_integer *res){
+  assert (0 < x );
+  *res = (rand() % x);
+}
diff --git a/lib/Random/utils_random_ext.h b/lib/Random/utils_random_ext.h
new file mode 100644
index 00000000..80c5463d
--- /dev/null
+++ b/lib/Random/utils_random_ext.h
@@ -0,0 +1 @@
+void utils_c_rand_step(_integer ,_integer *);
diff --git a/lib/Random/utils_random_loop.c b/lib/Random/utils_random_loop.c
new file mode 100644
index 00000000..4aac425f
--- /dev/null
+++ b/lib/Random/utils_random_loop.c
@@ -0,0 +1,151 @@
+/* This file was generated by lv6 version v6.106.1. */
+/*  lv6 utils.lus -n random -2c -exec -dir Random */
+/* on PC-Travail the 18/07/2022 at 15:00:26 */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "utils_random.h" 
+/* Print a promt ? ************************/
+static int ISATTY;
+/* MACROS DEFINITIONS ****************/
+#ifndef TT
+#define TT "1"
+#endif
+#ifndef FF
+#define FF "0"
+#endif
+#ifndef BB
+#define BB "bottom"
+#endif
+#ifdef CKCHECK
+/* set this macro for testing output clocks */
+#endif
+
+void _read_pragma(char b[]) {
+
+   if (!strcmp(b,"#quit")) exit(0);
+   if (!strcmp(b,"#q")) exit(0);
+}
+char* _get_string(char* n){
+   static char b[10] = "dummy";
+   return b;
+}
+/* Standard Input procedures **************/
+_boolean _get_bool(char* n){
+   char b[512];
+   char c;
+   _boolean r = 0;
+   int s = 1;
+   do {
+      if(ISATTY) {
+         if((s != 1)||(r == -1)) printf("\a");
+         // printf("%s (1,t,T/0,f,F) ? ", n);
+      }
+      if(scanf("%s", b)==EOF) exit(0);
+      r = -1;
+      c=b[0];
+      if(c == 'q') exit(0);
+      if(c == '#') _read_pragma(b);
+      if((c == '0') || (c == 'f') || (c == 'F')) r = 0;
+      if((c == '1') || (c == 't') || (c == 'T')) r = 1;
+   } while((s != 1) || (r == -1));
+   return r;
+}
+_integer _get_int(char* n){
+   char b[512];
+   _integer r;
+   int s = 1;
+   do {
+      if(ISATTY) {
+         if(s != 1) printf("\a");
+         //printf("%s (integer) ? ", n);
+      }
+      if(scanf("%s", b)==EOF) exit(0);
+      if(*b == 'q') exit(0);
+      if(*b == '#') {
+         _read_pragma(b);
+      } else {
+        s = sscanf(b, "%d", &r);
+      }
+   } while(s != 1);
+   return r;
+}
+#define REALFORMAT ((sizeof(_real)==8)?"%lf":"%f")
+_real _get_real(char* n){
+   char b[512];
+   _real r;
+   int s = 1;
+   do {
+      if(ISATTY) {
+         if(s != 1) printf("\a");
+         //printf("%s (real) ? ", n);
+      }
+      if(scanf("%s", b)==EOF) exit(0);
+      if(*b == 'q') exit(0);
+      if(*b == '#') {
+         _read_pragma(b);
+      } else {
+         s = sscanf(b, REALFORMAT, &r);
+      }
+   } while(s != 1);
+   return r;
+}
+/* Standard Output procedures **************/
+void _put_bottom(char* n){
+   if(ISATTY) printf("%s = ", n);
+   printf("%s ", BB);
+   if(ISATTY) printf("\n");
+}
+void _put_bool(char* n, _boolean _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%s ", (_V)? TT : FF);
+   if(ISATTY) printf("\n");
+}
+void _put_int(char* n, _integer _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%d ", _V);
+   if(ISATTY) printf("\n");
+}
+void _put_real(char* n, _real _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%f ", _V);
+   if(ISATTY) printf("\n");
+}
+void _put_string(char* n, char* _V){
+   if(ISATTY) printf("%s = ", n);
+   printf("%s ", _V);
+   if(ISATTY) printf("\n");
+}
+
+/* Output procedures **********************/
+#ifdef CKCHECK
+void %s_BOT_n(void* cdata){
+   _put_bottom("n");
+}
+#endif
+
+/* Main procedure *************************/
+int main(){
+  int _s = 0;
+  _integer x;
+  _integer res;
+  
+  printf("#inputs \"x\":int\n");
+  printf("#outputs \"res\":int\n");
+
+  /* Main loop */
+  ISATTY = isatty(0);
+  while(1){
+    if (ISATTY) printf("#step %d \n", _s+1);
+    else if(_s) printf("\n");
+    fflush(stdout);
+    ++_s;
+    x = _get_int("x");
+    utils_random_step(x,&res);
+    // printf("%d #outs %d\n",x,res);
+    printf("%d\n",res);
+  }
+  return 1;
+   
+}
diff --git a/lib/sas.lus b/lib/sas.lus
index 2451a5be..ffa29ac8 100644
--- a/lib/sas.lus
+++ b/lib/sas.lus
@@ -37,6 +37,10 @@ let
       and (silent<<an,pn>>(enab) or boolred<<1,pn,pn>>(map<<boolany<<an>>, pn>>(acti)));
 tel;
 
+(*function distributed<<const an:int; const pn:int>>(enab : bool^an^pn)
+returns (acti : bool^an^pn);
+var
+  nb_enab,rng:int;*)
 -- Exactly one node is activated.
 node daemon_is_central<<const an:int; const pn:int>>(acti, enab : bool^an^pn)
 returns (y : bool);
@@ -46,6 +50,31 @@ let
 
 tel;
 
+function make_activ_tab<<const an:int>>(ain:int; elem:bool^an)
+returns(aout:int; res:bool^an);
+var
+  elem_is_true:bool;
+let
+  elem_is_true = boolany<<an>>(elem);
+  res= if elem_is_true and (ain=0) then elem else false^an;
+  aout = if elem_is_true then ain-1 else ain;
+tel;
+
+function if_true_add_1<<const an:int>>(ain: int; elem: bool^an)
+returns(aout : int);
+let
+  aout= if boolany<<an>>(elem) then ain+1 else ain; 
+tel;
+
+unsafe function central<<const an:int; const pn:int>>(enab : bool^an^pn)
+returns (acti : bool^an^pn);
+var
+  nb_enab,rng,temp:int;
+let
+  nb_enab = red<<if_true_add_1<<an>>,pn>>(0,enab);
+  rng = random(nb_enab);
+  temp,acti = fillred<<make_activ_tab<<an>>,pn>>(rng,enab);
+tel; 
 
 -- No two neighboring nodes are active at once.
 node daemon_is_locally_central<<const an:int; const pn:int>>(
diff --git a/lib/use_random.lus b/lib/use_random.lus
new file mode 100644
index 00000000..975f3669
--- /dev/null
+++ b/lib/use_random.lus
@@ -0,0 +1,2 @@
+--Make a random function for Lustre by using C function:
+unsafe extern function c_rand(x:int) returns (res:int);
\ No newline at end of file
diff --git a/lib/utils.lus b/lib/utils.lus
index 4d16cbb3..1568d3a7 100644
--- a/lib/utils.lus
+++ b/lib/utils.lus
@@ -1,3 +1,11 @@
+include "use_random.lus"
+
+--Random (unsafe extern function):
+unsafe function random(x:int) returns (res:int);
+let
+  res = c_rand(x);
+tel
+
 -- Generates an array of indexes: [0, 1, ..., N-1]
 function range<<const N:int>>(_ : bool) returns (r : int^N);
 let
@@ -80,4 +88,4 @@ function weight (e:neigh)
 returns(res : int);
 let
   res = e.weight;
-tel;
+tel;
\ No newline at end of file
-- 
GitLab