Ejemplo n.º 1
0
        private FSMGraph GenerateGraph()
        {
            //FOR DETAILED EXPLANATION please see SimpleGraph example project
            var dataGraph = new FSMGraph();

            foreach (FSM_State state in fsmStates)
            {
                var dataVertex = new DataVertex(state.name, state.whenStmentTxt);
                dataGraph.AddVertex(dataVertex);
            }
            var vlist = dataGraph.Vertices.ToList();

            for (int i = 0; i < vlist.Count; i++)
            {
                FSM_State stateDst = fsmStates[i];
                for (int j = 0; j < vlist.Count; j++)
                {
                    FSM_State stateSrc = fsmStates[j];
                    if (stateSrc.next_states.ContainsKey(stateDst))
                    {
                        var dataEdge = new DataEdge(vlist[j], vlist[i])
                        {
                            Condition = stateSrc.next_states[stateDst]
                        };
                        dataGraph.AddEdge(dataEdge);
                    }
                }
            }
            return(dataGraph);
        }
Ejemplo n.º 2
0
        private FSMGraph GenerateGraph()
        {
            //FOR DETAILED EXPLANATION please see SimpleGraph example project
            var dataGraph = new FSMGraph();

            foreach (FSM_State state in fsmStates)
            {
                var dataVertex = new DataVertex(state.name);
                dataGraph.AddVertex(dataVertex);
            }
            var vlist = dataGraph.Vertices.ToList();

            for (int i = 0; i < vlist.Count; i++)
            {
                FSM_State stateDst = fsmStates[i];
                for (int j = 0; j < vlist.Count; j++)
                {
                    FSM_State stateSrc = fsmStates[j];
                    if (stateSrc.next_states.ContainsKey(stateDst.name))
                    {
                        var dataEdge = new DataEdge(vlist[j], vlist[i])
                        {
                            Text = string.Format("{0} -> {1}", vlist[j], vlist[i])
                        };
                        dataGraph.AddEdge(dataEdge);
                    }
                }
            }
            //Then create two edges optionaly defining Text property to show who are connected
            //var dataEdge = new DataEdge(vlist[0], vlist[1]) { Text = string.Format("{0} -> {1}", vlist[0], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            //dataEdge = new DataEdge(vlist[2], vlist[0]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[0]) };
            //dataGraph.AddEdge(dataEdge);


            //dataEdge = new DataEdge(vlist[1], vlist[2]) { Text = string.Format("{0} -> {1}", vlist[2], vlist[1]) };
            //dataGraph.AddEdge(dataEdge);
            return(dataGraph);
        }
Ejemplo n.º 3
0
        public static List <FSM_State> vhdlParseStatesTransitions(List <FSM_State> fsmStates, string[] linesOfCode, string fsmCurrStateVar, string fsmNextStateVar)
        {
            //Find the case statement corresponding to the FSM defined by fsmCurrStateVar
            for (int i = lineOfCloseEnum; i < linesOfCode.Length; i++)
            {
                string line = linesOfCode[i];
                if (CaseForFSMExists(line, fsmCurrStateVar))
                {
                    fsmCaseStartLine = i;
                }
                else if (EndCaseForFSMExists(line) && fsmCaseStartLine != -1)
                {
                    fsmCaseEndLine = i;
                    break;
                }
            }
            //Concate the text corresponding to the FSM defined by fsmCurrStateVar
            if (fsmCaseStartLine != -1 && fsmCaseEndLine != -1)
            {
                for (int i = fsmCaseStartLine; i <= fsmCaseEndLine; i++)
                {
                    caseStatementStr += linesOfCode[i];
                }
                //Find the starting & ending lines numbers of each WHEN text foreach STATE in fsmStates
                FSM_State tempState = null, prevState = null;
                for (int i = fsmCaseStartLine; i <= fsmCaseEndLine; i++)
                {
                    string line = linesOfCode[i].Replace("\t", String.Empty).Replace("\n", String.Empty);

                    if ((tempState = GetStateBelongsToWhen(line, fsmStates)) != null)
                    {
                        tempState.whenStmentStartLine = i;
                        if (prevState != null)
                        {
                            prevState.whenStmentEndLine = i;
                        }
                        prevState = tempState;
                    }
                    else if (EndCaseForFSMExists(line) && prevState != null)
                    {
                        prevState.whenStmentEndLine = i;
                    }
                }
                //Concate the WHEN text foreach STATE foreach state in fsmStates
                for (int ii = 0; ii < fsmStates.Count; ii++)
                {
                    FSM_State     state = fsmStates[ii];
                    StringBuilder sb    = new StringBuilder();
                    if (state.whenStmentStartLine != -1 && state.whenStmentEndLine != -1)
                    {
                        for (int i = state.whenStmentStartLine; i < state.whenStmentEndLine; i++)
                        {
                            string line = RemoveLeadingMultiTabs(linesOfCode[i]);
                            sb.AppendLine(line);
                        }
                        state.whenStmentTxt = sb.ToString().Replace("\t", "  ");
                        Utils.WriteLogFile(Utils.logType.Debug, "State: " + state.name + " ", state.whenStmentTxt.Replace("\t", " "));
                    }
                    else
                    {
                        Utils.WriteLogFile(Utils.logType.Debug, "State: " + state.name + " doesn't have a WHEN statement");
                    }
                }
                //TODO: Find transitions to next states foreach state in fsmStates
                foreach (FSM_State state in fsmStates)
                {
                    int startIfLine = -1, endIfLine = -1, startElseLine = -1;
                    int ifsCount = 0;
                    for (int i = state.whenStmentStartLine; i < state.whenStmentEndLine; i++)
                    {
                        string line = linesOfCode[i].Replace("\t", String.Empty).Replace("\n", String.Empty);
                        if (ifsCount == 0 && line.IndexOf(fsmNextStateVar) != -1) //transition found outside of Condition
                        {
                            FSM_State next_state = GetStateForTransition(line, fsmStates, fsmNextStateVar);
                            if (next_state != null)
                            {
                                state.next_states.Add(next_state, "always");
                            }
                            else
                            {
                                Utils.WriteLogFile(logType.Error, "line #" + (i + 1) + ": " + line + " has an unknown next state");
                            }
                        }
                        else if (i > startIfLine && (i < startElseLine || startElseLine == -1) && line.IndexOf(fsmNextStateVar) != -1)
                        {
                            FSM_State next_state = GetStateForTransition(line, fsmStates, fsmNextStateVar);
                            if (next_state != null)
                            {
                                try
                                {
                                    state.next_states.Add(next_state, KeepOnlyConditionText(linesOfCode[startIfLine]));
                                }
                                catch (Exception ex)
                                {
                                    Utils.WriteLogFile(logType.Error, "line #" + (i + 1) + ": " + line + " could not add state transition" + state.name + "->" + next_state.name);
                                }
                            }
                            else
                            {
                                Utils.WriteLogFile(Utils.logType.Error, "line #" + (i + 1) + ": " + line + " has an unknown next state");
                            }
                        }
                        else if (i > startElseLine && line.IndexOf(fsmNextStateVar) != -1)
                        {
                            FSM_State next_state = GetStateForTransition(line, fsmStates, fsmNextStateVar);
                            if (next_state != null)
                            {
                                try
                                {
                                    state.next_states.Add(next_state, "not(" + KeepOnlyConditionText(linesOfCode[startIfLine]) + ")");
                                }
                                catch (Exception ex)
                                {
                                    Utils.WriteLogFile(logType.Error, "line #" + (i + 1) + ": " + line + " could not add state transition" + state.name + "->" + next_state.name);
                                }
                            }
                            else
                            {
                                Utils.WriteLogFile(logType.Error, "line #" + (i + 1) + ": " + line + " has an unknown next state");
                            }
                        }
                        if (IsIfStatement(line))
                        {
                            startIfLine = i;
                            ifsCount++;
                        }
                        else if (IsElseIfStatement(line))
                        {
                            startIfLine = i;
                        }
                        else if (IsElseStatement(line))
                        {
                            startElseLine = i;
                        }
                        else if (IsEndIfStatement(line))
                        {
                            ifsCount--;
                        }
                    }
                }
            }
            else
            {
                WriteLogFile(logType.Debug, "Case statement could not be found for variable", fsmCurrStateVar);
            }

            return(fsmStates);
        }
Ejemplo n.º 4
0
        public static List <FSM_State> vhdlParseStatesTransitions(List <FSM_State> fsmStates, string[] linesOfCode, string fsmCurrStateVar, string fsmNextStateVar)
        {
            //Find the case statement corresponding to the FSM defined by fsmCurrStateVar
            for (int i = lineOfCloseEnum; i < linesOfCode.Length; i++)
            {
                string line = linesOfCode[i].Replace("\t", String.Empty).Replace("\n", String.Empty);
                if (CaseForFSMExists(line, fsmCurrStateVar))
                {
                    fsmCaseStartLine = i;
                }
                else if (line.Contains("end case;") && fsmCaseStartLine != -1)
                {
                    fsmCaseEndLine = i;
                    break;
                }
            }
            //Concate the text corresponding to the FSM defined by fsmCurrStateVar
            if (fsmCaseStartLine != -1 && fsmCaseEndLine != -1)
            {
                for (int i = fsmCaseStartLine; i <= fsmCaseEndLine; i++)
                {
                    caseStatementStr += linesOfCode[i];
                }
            }
            //Find the starting & ending lines numbers of each WHEN text foreach STATE in fsmStates
            FSM_State tempState = null, prevState = null;

            if (fsmCaseStartLine != -1 && fsmCaseEndLine != -1)
            {
                for (int i = fsmCaseStartLine; i <= fsmCaseEndLine; i++)
                {
                    string line = linesOfCode[i].Replace("\t", String.Empty).Replace("\n", String.Empty);

                    if ((tempState = GetStateBelongsToWhen(line, fsmStates)) != null)
                    {
                        tempState.whenStmentStartLine = i;
                        if (prevState != null)
                        {
                            prevState.whenStmentEndLine = i;
                        }
                        prevState = tempState;
                    }
                    else if (EndCaseForFSMExists(line) && prevState != null)
                    {
                        prevState.whenStmentEndLine = i;
                    }
                }
                //Concate the WHEN text foreach STATE foreach state in fsmStates
                for (int ii = 0; ii < fsmStates.Count; ii++)
                {
                    FSM_State state = fsmStates[ii];
                    if (state.whenStmentStartLine != -1 && state.whenStmentEndLine != -1)
                    {
                        for (int i = state.whenStmentStartLine; i < state.whenStmentEndLine; i++)
                        {
                            state.whenStmentTxt += linesOfCode[i];
                        }
                    }
                }
                //TODO: Find transitions to next states foreach state in fsmStates
            }
            else
            {
                MessageBox.Show("No FSM case found based on " + fsmCurrStateVar + ".", "VHDL FSM case statement not found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return(fsmStates);
        }