private static Ast.smv_module CreateClockModule(string name)
        {
            List <Tuple <string, Tuple <Int64, Int64> > > vars;
            List <Tuple <string, Ast.types> >             varwithtpyes;
            List <string>      parameters = new List <string>();
            List <Ast.section> sections   = new List <Ast.section>();

            // Variable section
            vars         = ClockVars();
            varwithtpyes = ConvertRngTupleToTypes(vars);
            Ast.section varsec = Ast.section.NewVar(FSharpInteropExtensions.ToFSharplist <Tuple <string, Ast.types> >(varwithtpyes));
            //Assignment section
            Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > > getsections = ClockAssigns(vars);

            Ast.section assignsec = getsections.Item1;
            sections.Add(varsec); sections.Add(assignsec);
            //Create Module
            Ast.smv_module clockmodl = new Ast.smv_module(name,
                                                          FSharpInteropExtensions.ToFSharplist <string>(parameters),
                                                          FSharpInteropExtensions.ToFSharplist <Ast.section>(sections));
            _iassigns[clockmodl] = getsections.Item2.Item1;
            _nassigns[clockmodl] = getsections.Item2.Item2;
            _params[clockmodl]   = parameters;
            _init[clockmodl]     = new List <Ast.expr>();
            _mvars[clockmodl]    = new List <Tuple <string, Tuple <string, List <List <string> > > > >();
            _rvars[clockmodl]    = vars;
            _svars[clockmodl]    = new List <Tuple <string, List <string> > >();
            _trans[clockmodl]    = new List <Ast.expr>();

            return(clockmodl);
        }
        private static Ast.smv_module CreateTimeModule(string name)
        {
            List <Tuple <string, Tuple <Int64, Int64> > > vars;
            List <Tuple <string, Ast.types> >             varwithtpyes;

            Ast.expr           init;
            Ast.expr           transrel;
            Ast.expr           resetident = Ast.expr.NewIdent("reset");
            List <string>      parameters = new List <string>();
            List <Ast.section> secs       = new List <Ast.section>();

            //
            vars         = TimerVars();
            varwithtpyes = ConvertRngTupleToTypes(vars);
            init         = TimerInit(vars);
            transrel     = TimerTransitions(vars, resetident);
            Debug.Assert(transrel != null);
            // Create sections
            Ast.section trans  = Ast.section.NewTrans(transrel);
            Ast.section inits  = Ast.section.NewInit(init);
            Ast.section varbls = Ast.section.NewVar(FSharpInteropExtensions.ToFSharplist <Tuple <string, Ast.types> >(varwithtpyes));
            // Dirty conversions
            Microsoft.FSharp.Collections.FSharpList <Ast.section> sections = FSharpInteropExtensions.ToFSharplist <Ast.section>(secs);
            Microsoft.FSharp.Collections.FSharpList <string>      pars     = FSharpInteropExtensions.ToFSharplist <string>(parameters);
            // Create module
            Ast.smv_module timermodule = new Ast.smv_module(name, pars, sections);
            //Fill memory representation
            //Trans
            List <Ast.expr> transrels = new List <Ast.expr>();

            transrels.Add(transrel);
            _trans.Add(timermodule, transrels);
            //init
            List <Ast.expr> initials = new List <Ast.expr>();

            initials.Add(init);
            _init.Add(timermodule, initials);
            //params
            _params.Add(timermodule, parameters);
            //vars
            _rvars.Add(timermodule, vars);
            //_mvars
            _mvars.Add(timermodule, new List <Tuple <string, Tuple <string, List <List <string> > > > >());
            //_svars
            _svars.Add(timermodule, new List <Tuple <string, List <string> > >());
            //iassigns
            _iassigns.Add(timermodule, new List <Tuple <string, Ast.expr> >());
            //nassigns
            _nassigns.Add(timermodule, new List <Tuple <string, Ast.expr> >());
            return(timermodule);
        }
        private static Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > > ClockAssigns(List <Tuple <string, Tuple <Int64, Int64> > > variables)
        {
            List <Tuple <string, Ast.expr> > stringexprlstinit = new List <Tuple <string, Ast.expr> >();
            List <Tuple <string, Ast.expr> > stringexprlstnext = new List <Tuple <string, Ast.expr> >();

            Ast.expr clockindent = Ast.expr.NewInt(_clockbound);

            Ast.expr timerident    = Ast.expr.NewIdent("time");
            Ast.expr inctimerident = Ast.expr.NewAdd(timerident, Ast.expr.NewInt(1));
            Ast.expr truident      = Ast.expr.NewIdent("TRUE");
            Ast.expr zeroident     = Ast.expr.NewInt(0);
            Ast.expr guard         = Ast.expr.NewLt(timerident, Ast.expr.NewInt(_clockbound));
            // init
            Ast.assign initident = Ast.assign.NewInitAssign("time", zeroident);
            // next
            List <Tuple <Ast.expr, Ast.expr> > caseslst = new List <Tuple <Ast.expr, Ast.expr> >();
            Tuple <Ast.expr, Ast.expr>         guardcs  = new Tuple <Ast.expr, Ast.expr>(guard, inctimerident);

            caseslst.Add(guardcs);
            stringexprlstinit.Add(new Tuple <string, Ast.expr>("time", zeroident));

            Tuple <Ast.expr, Ast.expr> trucs = new Tuple <Ast.expr, Ast.expr>(truident, timerident);

            caseslst.Add(trucs);
            Ast.expr   caseident = Ast.expr.NewCases(FSharpInteropExtensions.ToFSharplist <Tuple <Ast.expr, Ast.expr> >(caseslst));
            Ast.assign nextident = Ast.assign.NewNextAssign("time", caseident);
            stringexprlstnext.Add(new Tuple <string, Ast.expr>("time", caseident));

            List <Ast.assign> assignlst = new List <Ast.assign>();

            assignlst.Add(initident);
            assignlst.Add(nextident);
            Ast.section assignsec = Ast.section.NewAssigns(FSharpInteropExtensions.ToFSharplist <Ast.assign>(assignlst));

            Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > > sectionwithmemoryvalues =
                new Tuple <Ast.section, Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > > >
                    (assignsec, new Tuple <List <Tuple <string, Ast.expr> >, List <Tuple <string, Ast.expr> > >(stringexprlstinit, stringexprlstnext));

            return(sectionwithmemoryvalues);
        }
        private static List <Ast.smv_module> GenSmvModlsFromMem()
        {
            List <Ast.smv_module> astmodules = new List <Ast.smv_module>();

            foreach (var modl in _modules)
            {
                List <Ast.section> sections           = new List <Ast.section>();
                List <Tuple <string, Ast.types> > vrs = new List <Tuple <string, Ast.types> >();
                //svars
                List <Tuple <string, Ast.types> > svars = ConvertSetTupleToTypes(_svars[modl]);
                foreach (var v in svars)
                {
                    vrs.Add(v);
                }
                // Ast.section svarsec = Ast.section.NewVar(FSharpInteropExtensions.ToFSharplist<Tuple<string, Ast.types>> (svars));
                //rvars
                List <Tuple <string, Ast.types> > rvars = ConvertRngTupleToTypes(_rvars[modl]);
                foreach (var v in rvars)
                {
                    vrs.Add(v);
                }
                //mvars
                List <Tuple <string, Ast.types> > mvars = ConvertModlTupleToTypes(_mvars[modl]);
                foreach (var v in mvars)
                {
                    vrs.Add(v);
                }
                Ast.section varsec = Ast.section.NewVar(FSharpInteropExtensions.ToFSharplist <Tuple <string, Ast.types> >(vrs));
                sections.Add(varsec);
                //init
                foreach (var init in _init[modl])
                {
                    sections.Add(Ast.section.NewInit(init));
                }
                //trans
                foreach (var trans in _trans[modl])
                {
                    sections.Add(Ast.section.NewTrans(trans));
                }

                List <Ast.assign> assigns = new List <Ast.assign>();
                using (var e1 = _iassigns[modl].GetEnumerator())
                {
                    while (e1.MoveNext())
                    {
                        var        iassign = e1.Current;
                        Ast.assign iasgn   = Ast.assign.NewInitAssign(iassign.Item1, iassign.Item2);
                        assigns.Add(iasgn);
                    }
                }

                //assigns Bug is here
                using (var e2 = _nassigns[modl].GetEnumerator())
                {
                    while (e2.MoveNext())
                    {
                        var        nassign = e2.Current;
                        Ast.assign nasgn   = Ast.assign.NewNextAssign(nassign.Item1, nassign.Item2);
                        assigns.Add(nasgn);
                    }
                }

                /*
                 * foreach (var iassign in _iassigns[modl])
                 * {
                 *  Ast.assign asgn = Ast.assign.NewInitAssign(iassign.Item1, iassign.Item2);
                 *  assigns.Add(asgn);
                 * }
                 * foreach (var nassign in _nassigns[modl])
                 * {
                 *  Ast.assign asgn = Ast.assign.NewNextAssign(nassign.Item1, nassign.Item2);
                 *  assigns.Add(asgn);
                 * }*/
                if (assigns.Count > 0)
                {
                    sections.Add(Ast.section.NewAssigns(FSharpInteropExtensions.ToFSharplist <Ast.assign>(assigns)));
                }
                Ast.smv_module asyncboundedmodl = new Ast.smv_module(modl.name, FSharpInteropExtensions.ToFSharplist <string>(_params[modl]) /*modl.parameters*/, FSharpInteropExtensions.ToFSharplist <Ast.section>(sections));
                astmodules.Add(asyncboundedmodl);
            }
            return(astmodules);
        }