Exemple #1
0
 private void ColorInValid()
 {
     foreach (DataGridViewRow row in dataGridView1.Rows)
     {
         int index = (int)row.Cells["Index"].Value;
         //MessageBox.Show(index + ", " + Ports.Count);
         PortEntry port = Ports[index];
         bool      isComment = port.GetIsComment(), isValid = port.GetValid();
         foreach (DataGridViewCell cell in row.Cells)
         {
             if (isComment)
             {
                 cell.Style.BackColor = Color.LimeGreen;
             }
             else if (!isValid)
             {
                 cell.Style.BackColor = Color.Red;
             }
             else
             {
                 cell.Style.BackColor = Color.White;
             }
         }
     }
 }
Exemple #2
0
        /* Check the a port can be added to the chart */
        private bool InputValidation(PortEntry entry)
        {
            if (entry.GetName()[0] >= '0' && entry.GetName()[0] <= '9')
            {
                MessageBox.Show("Port name can't begin with a digit");
                return(false);
            }
            int index = -1;

            for (int i = 0; i < Ports.Count; i++)
            {
                if (Ports[i].GetName().Equals(entry.GetName()))
                {
                    index = i;
                }
            }
            if (index != -1)
            {
                MessageBox.Show("Port " + entry.GetName() + " is already in the list");
                return(false);
            }

            // check sequintial here
            return(true);
        }
Exemple #3
0
 private void AddEntryToTable(PortEntry entry, bool open = false)
 {
     entry.SetIndex(Ports.Count);
     Ports.Add(entry);
     if (!open)
     {
         UpdateDataBase();
     }
 }
        public static bool ValidEntry(PortEntry entry)
        {
            if (entry.GetIsComment())
            {
                return(true);
            }
            bool b = true;

            if (!entry.IsValidData_size())
            {
                entry.SetReason("The port " + entry.GetName() + " has invalid data size: " + entry.GetData_size());
                entry.SetValid(false);
                b = false;
            }
            if (!entry.IsValidMemorySection())
            {
                entry.SetReason("The port " + entry.GetName() + " has invalid memory section: " + entry.GetMemory_section());
                entry.SetValid(false);
                b = false;
            }
            if (!entry.IsValidPriority())
            {
                entry.SetReason("The port " + entry.GetName() + " has Priority out of range [0, 99]");
                entry.SetValid(false);
                b = false;
            }
            if (!entry.IsValidR_W())
            {
                entry.SetReason("The port " + entry.GetName() + " has R_W different from 'R' or 'W': " + entry.GetR_W());
                entry.SetValid(false);
                b = false;
            }
            if (!entry.IsValidAnableEmerge())
            {
                entry.SetReason("The port " + entry.GetName() + " has anable emerge different from 'N' or 'Y': " + entry.GetAnable_emerge());
                entry.SetValid(false);
                b = false;
            }
            if (!entry.IsValidBank())
            {
                entry.SetReason("The port " + entry.GetName() + " has bank different from 'A' or 'B': " + entry.GetBank());
                entry.SetValid(false);
                b = false;
            }
            return(b);
        }
Exemple #5
0
        private bool CheckDup(PortEntry new_entry)
        {
            string name_new = new_entry.GetName();

            foreach (PortEntry item in Ports)
            {
                if (item.GetIsComment() || item == new_entry)
                {
                    continue;
                }
                if (item.GetName().Equals(name_new))
                {
                    new_entry.SetReason("Name " + name_new + " is already in the list");
                    new_entry.SetValid(false);
                    return(false);
                }
            }
            return(true);
        }
Exemple #6
0
        /* Insert port to the table */
        private void InsertButton_Click(object sender, EventArgs e)
        {
            if (PortNameText.Text.Equals(""))
            {
                MessageBox.Show("Invalid port name: Empty name");
                InitFields();
                return;
            }

            char Anable_emerge = 'Y';

            if (!EmergencyCheckBox.Checked)
            {
                Anable_emerge = 'N';
            }

            /*Console.WriteLine(PortNameText.Text);
             * Console.WriteLine(ValidCheckBox.Checked.ToString());
             * Console.WriteLine(TypeOpts.SelectedItem.ToString());
             * Console.WriteLine(R_WCombo.SelectedItem.ToString());
             * Console.WriteLine(DataSizeBox.SelectedItem.ToString());
             * Console.WriteLine(BankBox.SelectedItem.ToString());
             * Console.WriteLine(MemorySizeText.Text);
             * Console.WriteLine(numericUpDown2.Value.ToString());
             * Console.WriteLine(RelativeAddressCheckBox.Checked.ToString());
             * Console.WriteLine(numericUpDown1.Value.ToString());
             * Console.WriteLine(Anable_emerge);
             * Console.WriteLine(DebugCheckBox.Checked.ToString());
             * Console.WriteLine(CommentText.Text);*/
            PortEntry entry = new PortEntry(PortNameText.Text, ValidCheckBox.Checked.ToString(), TypeOpts.SelectedItem.ToString(), R_WCombo.SelectedItem.ToString()[0], DataSizeBox.SelectedItem.ToString(),
                                            BankBox.SelectedItem.ToString()[0], MemorySizeText.Text, numericUpDown2.Value.ToString(), RelativeAddressCheckBox.Checked.ToString(), numericUpDown1.Value.ToString(), Anable_emerge, DebugCheckBox.Checked.ToString(), CommentText.Text);

            if (!InputValidation(entry))
            {
                return;
            }
            AddEntryToTable(entry);
            searchBox.Text = "";
            UpdateTable(Ports);
            ErrorMessage.Text = "Message: Port named " + PortNameText.Text + " was added";
            InitFields();
            saved = false;
        }
        public bool IsFileValid()
        {
            // Prepare texts for comparison: remove comments and convert to lower case
            Console.WriteLine("Preparing to compile " + path_to_file);
            string[] lines_correct = File.ReadAllLines(path_to_correct);
            string[] lines         = File.ReadAllLines(path_to_file);
            for (int i = 0; i < lines_correct.Length; i++)
            {
                lines_correct[i] = TrimAndLower(lines_correct[i]);
            }
            for (int i = 0; i < lines.Length; i++)
            {
                lines[i] = TrimAndLower(lines[i]);
            }
            lines_correct = Array.FindAll(lines_correct, IsNotComment).ToArray();
            lines         = Array.FindAll(lines, IsNotComment).ToArray();

            // Init state of comparison
            int run_state = (int)Cmp_mod.Start;
            int j         = 0;

            // Parsing Analysis: Compare
            Console.WriteLine("Compiling...");
            for (int i = 0; i < lines.Length; i++)
            {
                // Skip empty lines
                //lines_correct[j] = RemoveComment(lines_correct[j]);
                bool b1 = string.IsNullOrWhiteSpace(lines_correct[j]);
                bool b2 = Regex.Match(lines_correct[j], @"^[ \t]*--(.*)").Success;
                while (j < lines_correct.Length && (lines_correct[j].Equals("") || b1 || b2))
                {
                    j++;
                    if (j == lines_correct.Length - 1)
                    {
                        break;
                    }
                    b1 = string.IsNullOrWhiteSpace(lines_correct[j]);
                    //b1 = Regex.Match(lines_correct[j], @"^[\r\n]*").Success;
                    b2 = Regex.Match(lines_correct[j], @"^[ \t]*--(.*)").Success;
                }
                // Finished current state
                if (j == lines_correct.Length)
                {
                    break;
                }
                if (lines_correct[j].Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0"))
                {
                    j = j + 2;
                    run_state++;
                }
                else if (lines_correct[j].Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0o"))
                {
                    j = j + 1;
                    run_state++;
                }
                if (run_state == (int)Cmp_mod.Port_names || run_state == (int)Cmp_mod.Port_entrys)
                {
                    int k;
                    for (k = i; k < lines.Length && !lines_correct[j - 1].Equals(lines[k]); k++)
                    {
                        Match result = Regex.Match(lines[k], pattern);
                        if (result.Success)
                        {
                            if (run_state == (int)Cmp_mod.Port_names)
                            {
                                continue;
                            }
                            string    port_str = Regex.Split(lines[k], pattern)[1];
                            PortEntry pe       = PortEntry.PortEntryParse(port_str, lines[k + 1].Equals(lines_correct[j - 1]));
                            if (pe != null)
                            {
                                //MessageBox.Show("Comment port!");
                                pe.SetIsComment(true);
                                Ports.Add(pe);
                                continue;
                            }
                        }
                        // Save Names
                        if (run_state == (int)Cmp_mod.Port_names)
                        {
                            if (!IsValidPortName(lines[k]))
                            {
                                MessageBox.Show("COMPILATION 1: Parsing error at line " + (k + 1));
                                Console.WriteLine("COMPILATION 1: Parsing error at line " + (k + 1) + "\nFinishing compilation....");
                                return(false);
                            }
                        }
                        else if (run_state == (int)Cmp_mod.Port_entrys)
                        {
                            bool      last  = lines[k + 1].Equals(lines_correct[j]);
                            PortEntry entry = PortEntry.PortEntryParse(lines[k], last);
                            if (entry != null)
                            {
                                //MessageBox.Show(entry.GetName() + " " + entry.GetName().Length.ToString());
                                string type = entry.GetPortType().ToString();
                                Ports.Add(entry);
                            }
                            else
                            {
                                b1 = string.IsNullOrWhiteSpace(lines[k]);
                                b2 = Regex.Match(lines[k], @"^[ \t]*--(.*)").Success;
                                if (k < lines.Length && (lines[k].Equals("") || b1 || b2))
                                {
                                    continue;
                                }
                                MessageBox.Show("COMPILATION 2: Parsing error at line " + (k + 1));
                                Console.WriteLine("COMPILATION 2: Parsing error at line " + (k + 1) + "\nFinishing compilation....");
                                return(false);
                            }
                            if (last)
                            {
                                //j--;
                                //k++;
                                break;
                            }
                        }
                    }
                    run_state++;
                    i = k;
                }
                else
                {
                    //lines[i] = RemoveComment(lines[i]);
                    b1 = string.IsNullOrWhiteSpace(lines[i]);
                    b2 = Regex.Match(lines[i], @"^[ \t]*--(.*)").Success;
                    bool b3 = Regex.Match(lines[i], @"^use(.)*").Success || Regex.Match(lines[i], @"^library(.*)").Success;
                    while (i < lines.Length && (lines[i].Equals("") || b1 || b2 || b3))
                    {
                        i++;
                        if (i == lines.Length - 1)
                        {
                            break;
                        }
                        b1 = string.IsNullOrWhiteSpace(lines[i]);
                        b2 = Regex.Match(lines[i], @"^[ \t]*--(.*)").Success;
                        b3 = Regex.Match(lines[i], @"^use(.)*").Success || Regex.Match(lines[i], @"^library(.*)").Success;
                    }
                    if (!lines_correct[j].Equals(lines[i]))
                    {
                        MessageBox.Show("COMPILATION 3: Invalid file\n" + lines[i] + "\n" + lines_correct[j]);
                        Console.WriteLine("COMPILATION 3: Invalid file\n" + lines[i] + "!=" + lines_correct[j] + "\nFinishing compilation....");
                        return(false);
                    }
                    j++;
                }
            }
            Console.WriteLine("Logic analysis...");
            if (!NamesCrossValid())
            {
                return(false);
            }
            ValidRegLogic(); // Sematic Analysis, add everything from here
            Console.WriteLine("Compilation is complete");
            return(true);
        }
Exemple #8
0
        private void DataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            PortEntry pe = null;

            foreach (DataGridViewRow item in dataGridView1.SelectedRows)
            {
                pe = Ports[(int)item.Cells["Index"].Value];
                //MessageBox.Show(item.Cells["Index"].Value.ToString());
                break;
            }
            if (pe != null)
            {
                PortNameText.Text               = pe.GetName();
                CommentText.Text                = pe.GetComment();
                MemorySizeText.Text             = pe.GetMemorySize();
                ValidCheckBox.Checked           = pe.GetValidField();
                RelativeAddressCheckBox.Checked = pe.GetRelative_address();
                EmergencyCheckBox.Checked       = pe.GetAnable_emerge() == 'Y';
                DebugCheckBox.Checked           = pe.GetRead_bk_address();

                int index = R_WCombo.FindStringExact(pe.GetR_W().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                R_WCombo.SelectedIndex = index;
                index = DataSizeBox.FindStringExact(pe.GetData_size().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                DataSizeBox.SelectedIndex = index;
                index = TypeOpts.FindStringExact(pe.GetPortType().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                TypeOpts.SelectedIndex = index;
                index = BankBox.FindStringExact(pe.GetBank().ToString());
                if (index == -1)
                {
                    index = 0;
                }
                BankBox.SelectedIndex = index;
                index = pe.GetPriority();
                if (index >= 100 || index <= 0)
                {
                    index = 99;
                }
                numericUpDown1.Value = index;
                index = pe.GetMemory_section();
                if (index < 0)
                {
                    index = 1;
                }
                numericUpDown2.Value = index;

                if (pe.GetIsComment())
                {
                    ErrorMessage.Text = "Message: ";
                }
                else if (!pe.GetValid())
                {
                    ErrorMessage.Text = "Message: " + pe.GetReason();
                }
                else
                {
                    ErrorMessage.Text = "Message: ";
                }
            }
        }
Exemple #9
0
        private void Load_Click(object sender, EventArgs e)
        {
            PortEntry       pe     = null;
            DataGridViewRow item_f = null;
            int             i      = -1;

            foreach (DataGridViewRow item in dataGridView1.SelectedRows)
            {
                i      = (int)item.Cells["Index"].Value;
                pe     = Ports[i];
                item_f = item;
                break;
            }
            if (pe == null)
            {
                MessageBox.Show("Please select a port in order to edit");
                return;
            }
            string name = PortNameText.Text;

            if (!pe.GetName().Equals(name))
            {
                MessageBox.Show("You can't edit a port's name");
                PortNameText.Text = pe.GetName();
                return;
            }
            string memory_size      = MemorySizeText.Text;
            bool   valid            = ValidCheckBox.Checked;
            char   r_w              = R_WCombo.SelectedItem.ToString()[0];
            bool   relative_address = RelativeAddressCheckBox.Checked;
            char   emergency_enable = 'N';

            if (EmergencyCheckBox.Checked)
            {
                emergency_enable = 'Y';
            }
            bool   debug_enable   = DebugCheckBox.Checked;
            int    priority       = (int)numericUpDown1.Value;
            int    memory_section = (int)numericUpDown2.Value;
            int    data_size      = int.Parse(DataSizeBox.SelectedItem.ToString());
            char   bank           = BankBox.SelectedItem.ToString()[0];
            string comment        = CommentText.Text;
            p_type type           = (p_type)Enum.Parse(typeof(p_type), TypeOpts.Text, true);

            if (i == -1)
            {
                MessageBox.Show("No such port " + name);
                InitFields();
                return;
            }
            if (pe.GetIsComment())
            {
                MessageBox.Show("This port is a comment and can't be edited");
                //InitFields();
                return;
            }
            pe.EditPort(valid, type, r_w, data_size, bank, memory_size, memory_section, relative_address, priority, emergency_enable, debug_enable, comment);
            OpenValidation();
            UpdateDataBase();
            EditCell(item_f, pe.GetTableEntry());
            //MessageBox.Show(pe.ToString());
            saved = false;
        }