예제 #1
0
            public string TranslateCompositeFB(FBType fbType)
            {
                string         smvModule          = "";
                ExecutionModel executionModel     = _executionModels.FirstOrDefault(em => em.FBTypeName == fbType.Name);
                var            events             = _storage.Events.Where(ev => ev.FBType == fbType.Name);
                var            variables          = _storage.Variables.Where(ev => ev.FBType == fbType.Name);
                var            instances          = _storage.Instances.Where(inst => inst.FBType == fbType.Name);
                var            withConnections    = _storage.WithConnections.Where(conn => conn.FBType == fbType.Name);
                var            connections        = _storage.Connections.Where(conn => conn.FBType == fbType.Name);
                var            instanceParameters = _storage.InstanceParameters.Where(p => p.FBType == fbType.Name);

                IDispatcher dispatcher = executionModel.Dispatcher;

                //smvModule += _moduleHeader(events, variables, fbType.Name) + "\n";
                smvModule += FbSmvCommon.SmvModuleDeclaration(events, variables, fbType.Name);
                smvModule += CompositeFbSmv.FbInstances(instances, _storage.Events, _storage.Variables, connections, _settings) + "\n";
                smvModule += CompositeFbSmv.InternalBuffersDeclaration(instances, connections, _storage.Events, _storage.Variables) + "\n";
                smvModule += Smv.Assign;
                smvModule += CompositeFbSmv.InternalBuffersInitialization(instances, connections, _storage.Events, _storage.Variables, instanceParameters) + "\n";

                if (_settings.UseProcesses)
                {
                    smvModule += CompositeFbSmv.NonConnectedInstanceOutputEvents(_storage.Events, instances, connections);
                    smvModule += CompositeFbSmv.ComponentDataOutputNextStatements(_storage.Variables, instances);
                }
                //smvModule += _moduleVariablesInitBlock(variables) + "\n";
                //smvModule += _inputVariablesSampleComposite(variables, withConnections) + "\n";
                smvModule += CompositeFbSmv.NonConnectedEventInputs(connections, _storage.Events, instances, _showMessage);
                smvModule += CompositeFbSmv.NonConnectedInputs(connections, _storage.Variables, instances);
                smvModule += CompositeFbSmv.InternalDataConnections(connections, withConnections, _storage.Variables, instances) + "\n";
                smvModule += CompositeFbSmv.ComponentEventOutputs(connections, _settings.UseProcesses) + "\n";
                //smvModule += _eventInputsResetRules(events) + "\n";
                smvModule += "\n-- ---DISPATCHER--- --\n";
                smvModule += "-- *************** --\n";
                smvModule += dispatcher.GetSmvCode(_settings.UseProcesses) + "\n";

                smvModule += CompositeFbSmv.InternalEventConnections(connections, _settings.UseProcesses) + "\n";
                smvModule += CompositeFbSmv.InputEventsResetRules(events, _settings.UseProcesses);
                smvModule += FbSmvCommon.DefineExistsInputEvent(events) + "\n";
                smvModule += CompositeFbSmv.DefineOmega(connections) + "\n";
                smvModule += CompositeFbSmv.DefinePhi(instances, _storage.Events) + "\n"; //phi variable for timed models

                smvModule += FbSmvCommon.ModuleFooter(_settings) + "\n";
                //smvModule += Smv.AlphaBetaRules;

                return(smvModule);
            }
예제 #2
0
            public string GenerateMain()
            {
                string mainModule     = "";
                FBType topLevelFbType = _storage.Types.FirstOrDefault(fbType => fbType.IsRoot);

                if (topLevelFbType == null)
                {
                    throw new ArgumentNullException("Can't find root FB type");
                }

                List <FBInstance>        instanceList       = new List <FBInstance>();
                List <Connection>        connections        = new List <Connection>();
                List <InstanceParameter> instanceParameters = new List <InstanceParameter>();
                FBInstance instance = new FBInstance(topLevelFbType.Name + "_inst", topLevelFbType.Name, "Top-level FB instance", "main");

                instanceList.Add(instance);

                mainModule += String.Format(Smv.ModuleDef, "main", "");
                mainModule += CompositeFbSmv.FbInstances(instanceList, _storage.Events, _storage.Variables, connections, _settings) + "\n";
                mainModule += CompositeFbSmv.InternalBuffersDeclaration(instanceList, connections, _storage.Events, _storage.Variables) + "\n";
                if (_settings.GenerateDummyProperty)
                {
                    mainModule += String.Format(Smv.VarDeclarationBlock, "false_var", Smv.DataTypes.BoolType);
                }
                mainModule += Smv.Assign;
                if (_settings.GenerateDummyProperty)
                {
                    mainModule += String.Format(Smv.VarInitializationBlock, "false_var", Smv.False);
                    mainModule += String.Format(Smv.NextVarAssignment, "false_var", Smv.False);
                }
                mainModule += CompositeFbSmv.InternalBuffersInitialization(instanceList, connections, _storage.Events, _storage.Variables, instanceParameters, true) + "\n";

                mainModule += String.Format(Smv.VarInitializationBlock, instance.Name + "_" + Smv.Alpha, Smv.True);
                mainModule += String.Format(Smv.VarInitializationBlock, instance.Name + "_" + Smv.Beta, Smv.False);


                //Main module next blocks
                //**********************
                foreach (Variable variable in _storage.Variables.Where(v => v.FBType == topLevelFbType.Name && v.Direction == Direction.Input && !v.IsConstant))
                {
                    string smvVariable = instance.Name + "_" + variable.Name;
                    if (variable.ArraySize == 0)
                    {
                        mainModule += String.Format(Smv.NextVarAssignment, smvVariable, smvVariable);
                    }
                    else
                    {
                        for (int i = 0; i < variable.ArraySize; i++)
                        {
                            mainModule += String.Format(Smv.NextVarAssignment, smvVariable + Smv.ArrayIndex(i), smvVariable + Smv.ArrayIndex(i));
                        }
                    }
                }
                foreach (Event ev in _storage.Events.Where(ev => ev.FBType == topLevelFbType.Name))
                {
                    string smvVariable = instance.Name + "_" + ev.Name;
                    string nextRule    = "";
                    if (ev.Direction == Direction.Output)
                    {
                        nextRule = instance.Name + "." + "event_" + ev.Name + "_set : " + Smv.True + ";\n";
                    }
                    else
                    {
                        nextRule = instance.Name + "." + "event_" + ev.Name + "_reset : " + Smv.False + ";\n";
                    }
                    mainModule += String.Format(Smv.NextCaseBlock, smvVariable, nextRule);
                }

                string alphaRule = "\t" + instance.Name + "_" + Smv.Beta + " : " + Smv.True + ";\n" +
                                   "\t" + instance.Name + ".alpha_reset : " + Smv.False + ";\n";
                string betaRule = "\t" + instance.Name + "_" + Smv.Beta + " : " + Smv.False + ";\n" +
                                  "\t" + instance.Name + ".beta_set : " + Smv.True + ";\n";

                mainModule += String.Format(Smv.NextCaseBlock, instance.Name + "_" + Smv.Alpha, alphaRule);
                mainModule += String.Format(Smv.NextCaseBlock, instance.Name + "_" + Smv.Beta, betaRule);
                //**********************

                //mainModule += FbSmvCommon.ModuleFooter(_settings) + "\n";

                if (_settings.GenerateDummyProperty)
                {
                    mainModule += "\nLTLSPEC F false_var=TRUE";
                }

                return(mainModule);
            }