private void UpdateTable(RegisterEntry entry) { TreeGridNode node; string group = entry.GetGroup(); object[] ent = entry.GetTableEntry(); bool b, isField = entry.GetRegType() == RegisterEntry.type_field.FIELD; treeGridView1.Rows.AddRange(); foreach (TreeGridNode group_node in treeGridView1.Nodes) { if (group_node.Cells["Registers"].Value.ToString().Equals(group)) { if (!isField) { node = group_node.Nodes.Add(ent); group_node.Expand(); } else { TreeGridNode tmp = null; group_node.Expand(); foreach (TreeGridNode reg in group_node.Nodes) { b = reg.GetIsExpanded(); reg.Expand(); if ((int)reg.Cells["IndexColumn"].Value == entry.GetIndex()) { tmp = reg; break; } else if (!b) { reg.Collapse(); } } if (tmp != null) { node = tmp.Nodes.Add(ent); //group_node.Expand(); tmp.Expand(); } break; } } } }
private void AddEntryToTable(RegisterEntry entry, bool open = false) { bool isField = entry.GetRegType() == RegisterEntry.type_field.FIELD; if (isField) { RegList[entry.GetIndex()].AddField(entry); } else { entry.SetIndex(RegList.Count); // only outer index RegList.Add(entry); } if (!open) { UpdateDataBase(); } UpdateTable(entry); }
private void TreeGridView1_SelectionChanged(object sender, EventArgs e) { RegisterEntry re = null; foreach (TreeGridNode item in treeGridView1.SelectedRows) { try { re = RegList[(int)item.Cells["IndexColumn"].Value]; int index = (int)item.Cells["SecondaryIndexColumn"].Value; if (index != -1) { re = re.GetFields()[index]; //MessageBox.Show(re.GetIndex().ToString() + ", " + index); } else { //MessageBox.Show(re.GetIndex().ToString()); } break; } catch (NullReferenceException) { //do nothing for groups return; } } if (re != null) { RegNameText.Text = re.GetName(); CommentText.Text = re.GetComment(); InitText.Text = re.GetInit(); int index = LSBOpts.FindStringExact(re.GetLSB().ToString()); if (index == -1) { index = 0; } LSBOpts.SelectedIndex = index; index = LSBOpts.FindStringExact(re.GetLSB().ToString()); if (index == -1) { index = 0; } LSBOpts.SelectedIndex = index; index = MSBOpts.FindStringExact(re.GetMSB().ToString()); if (index == -1) { index = 31; } MSBOpts.SelectedIndex = index; index = MAISOpts.FindStringExact(re.GetMAIS().ToString()); if (index == -1) { index = 0; } MAISOpts.SelectedIndex = index; index = TypeOpts.FindStringExact(re.GetRegType().ToString()); if (index == -1) { index = 0; } TypeOpts.SelectedIndex = index; index = FPGAOpts.FindStringExact(re.GetFPGA().ToString()); if (index == -1) { index = 0; } FPGAOpts.SelectedIndex = index; RegGroupOpts.SelectedIndex = RegGroupOpts.FindStringExact(re.GetGroup()); if (re.GetIsComment()) { ErrorMessage.Text = ""; } else if (!re.GetValid()) { ErrorMessage.Text = re.GetReason(); } else { ErrorMessage.Text = ""; } } }
/* Check the a register can be added to the chart */ private bool InputValidation(RegisterEntry entry) { if (entry.GetName()[0] >= '0' && entry.GetName()[0] <= '9') { MessageBox.Show("Register name can't begin with a digit"); return(false); } if (entry.GetRegType() != RegisterEntry.type_field.FIELD) { int index = -1; for (int i = 0; i < RegList.Count; i++) { if (RegList[i].GetName().Equals(entry.GetName())) { index = i; } } if (index != -1) { MessageBox.Show("Register " + entry.GetName() + " (" + RegList[index].GetAddress() + ") is already in the list"); return(false); } int addr = FindAddress(); if (addr == -1) { MessageBox.Show("Unable to add register " + entry.GetName() + ", no free slot in memory"); return(false); } entry.SetAddress(addr); } else { if (RegList.Count == 0) { MessageBox.Show("There are no registers in the list"); return(false); } int addr = -1, index = -1; RegisterEntry item; using (ChooseAddressPrompt prompt = new ChooseAddressPrompt(RegList.ToArray())) { if (prompt.ShowDialog() == DialogResult.OK) { addr = prompt.Chosen_address; index = prompt.Index; item = RegList[prompt.Index]; } else { return(false); } } List <RegisterEntry> fields = item.GetFields(); foreach (RegisterEntry field in fields) { if (field.GetName().Equals(entry.GetName())) { MessageBox.Show("Field " + entry.GetName() + " (" + item.GetAddress() + ") is already in the list of " + item.GetName()); return(false); } } entry.SetAddress(addr); entry.SetIndex(index); } if (!entry.IsValidLsbMsb()) { MessageBox.Show("Can't insert register " + entry.GetName() + " with LSB greater than MSB"); return(false); } return(true); }
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]); while (j < lines_correct.Length && lines_correct[j].Equals("")) { j++; } // Finished current state if (lines_correct[j].Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0")) { j = j + 2; run_state++; } if (run_state == (int)Cmp_mod.Reg_names || run_state == (int)Cmp_mod.Reg_entrys) { int k; string curr_group = "JACKSHIT", prev_group; for (k = i + 1; k < lines.Length && !lines_correct[j - 1].Equals(lines[k]); k++) { // Save Groups Match result = Regex.Match(lines[k], pattern); if (result.Success) { prev_group = curr_group; curr_group = Regex.Split(lines[k], pattern)[1]; RegisterEntry entry = RegisterEntry.RegEntryParse(curr_group, prev_group, lines[k + 1].Equals(lines_correct[j - 1])); if (entry != null) { entry.SetIsComment(true); if (entry.GetRegType() == RegisterEntry.type_field.FIELD) { int address = entry.GetAddress(); RegisterEntry re = FindAtAdress(address); if (re != null) { re.AddField(entry); } } else { Registers.Add(entry); } curr_group = prev_group; } else if (!Groups.Contains(curr_group) && (curr_group == "" || curr_group[curr_group.Length - 1] != ',')) { Groups.Add(curr_group); } } // Save Names else if (run_state == (int)Cmp_mod.Reg_names) { if (!IsValidRegName(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.Reg_entrys) { RegisterEntry entry = RegisterEntry.RegEntryParse(lines[k], curr_group, lines[k + 1].Equals(lines_correct[j - 1])); if (entry != null) { //MessageBox.Show(entry.GetName() + " " + entry.GetName().Length.ToString()); string type = entry.GetRegType().ToString(); if (type.Equals("FIELD") || type.Equals("field")) { int address = entry.GetAddress(); RegisterEntry re = FindAtAdress(address); if (re != null) { re.AddField(entry); } else { MessageBox.Show("COMPILATION 2: Address " + address + " doesn't exist (" + (k + 1) + ")"); Console.WriteLine("COMPILATION 2: Address " + address + " doesn't exist (" + (k + 1) + ")" + "\nFinishing compilation..."); return(false); } } else { Registers.Add(entry); } } else { MessageBox.Show("COMPILATION 3: Parsing error at line " + (k + 1)); Console.WriteLine("COMPILATION 3: Parsing error at line " + (k + 1) + "\nFinishing compilation..."); return(false); } } } run_state++; i = k; } else { lines[i] = RemoveComment(lines[i]); while (i < lines.Length && lines[i].Equals("")) { i++; } if (!lines_correct[j].Equals(lines[i])) { MessageBox.Show("COMPILATION 4: Invalid file\n" + lines[i] + "\n" + lines_correct[j]); Console.WriteLine("COMPILATION 4: 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); }