/* Insert register to the table */ private void InsertButton_Click(object sender, EventArgs e) { if (RegNameText.Text.Equals("")) { MessageBox.Show("Invalid register name: Empty name"); InitFields(); return; } RegisterEntry entry; if (InitText.Text.Equals("")) { ErrorMessage.Text = "Init field is empty, resort to default (0)"; entry = new RegisterEntry(RegNameText.Text, -1, MAISOpts.Text, LSBOpts.Text, MSBOpts.Text, TypeOpts.Text, FPGAOpts.Text, "0", CommentText.Text, RegGroupOpts.Text); } else { ErrorMessage.Text = "Register named " + RegNameText.Text + " was added"; entry = new RegisterEntry(RegNameText.Text, -1, MAISOpts.Text, LSBOpts.Text, MSBOpts.Text, TypeOpts.Text, FPGAOpts.Text, InitText.Text, CommentText.Text, RegGroupOpts.Text); } if (!InputValidation(entry)) { return; } AddEntryToTable(entry); InitFields(); }
private bool CheckDup(RegisterEntry new_entry) { int addr_new = new_entry.GetAddress(); string name_new = new_entry.GetName(); foreach (RegisterEntry item in RegList) { if (item.GetIsComment() || item == new_entry) { continue; } if (item.GetName().Equals(name_new)) { new_entry.SetReason("Name " + name_new + " is already in the list at address " + item.GetAddress().ToString()); new_entry.SetValid(false); return(false); } if (item.GetAddress() == addr_new) { new_entry.SetReason("Address " + addr_new + " is already in the list at register " + item.GetName()); new_entry.SetValid(false); return(false); } } return(true); }
private void ColorNode(TreeGridNode node) { int index = (int)node.Cells["IndexColumn"].Value, indexSec = (int)node.Cells["SecondaryIndexColumn"].Value; RegisterEntry entry = RegList[index]; //MessageBox.Show(entry.GetName() + ": [" + index + ", " + indexSec + "]"); if (indexSec != -1) { entry = entry.GetFields()[indexSec]; } for (int i = 0; i < treeGridView1.ColumnCount; i++) { if (entry.GetIsComment()) { node.Cells[i].Style.BackColor = Color.LimeGreen; } else if (!entry.GetValid()) { node.Cells[i].Style.BackColor = Color.Red; } else { node.Cells[i].Style.BackColor = Color.White; } } }
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); }
public static bool ValidEntry(RegisterEntry entry) { if (entry.GetIsComment()) { return(true); } bool b = true; if (!entry.IsValidAddress()) { entry.SetReason("The register " + entry.GetName() + " has invalid address: " + entry.GetAddress()); entry.SetValid(false); b = false; } if (!entry.IsValidMAIS()) { entry.SetReason("The register " + entry.GetName() + " has invalid MAIS field: " + entry.GetMAIS()); entry.SetValid(false); b = false; } if (!entry.IsValidLSB()) { entry.SetReason("The register " + entry.GetName() + "(" + entry.GetAddress() + ") has LSB out of range [0, 32)"); entry.SetValid(false); b = false; } if (!entry.IsValidLSB()) { entry.SetReason("The register " + entry.GetName() + "(" + entry.GetAddress() + ") has MSB out of range [0, 32)"); entry.SetValid(false); b = false; } if (!entry.IsValidLsbMsb()) { entry.SetReason("The register " + entry.GetName() + "(" + entry.GetAddress() + ") has MSB < LSB"); entry.SetValid(false); b = false; } return(b); }
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 = ""; } } }
private void SaveButton_Click(object sender, EventArgs e) { if (PathToFile.Text.Equals("")) { SaveAsButton_Click(sender, e); return; } StreamReader file; try { file = new StreamReader("mycorrect.txt"); string line; string res = ""; string title = Path.GetFileNameWithoutExtension(PathToFile.Text); string date = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss"); string introDec = "Original path: " + PathToFile.Text + "</br>The following is a documentation for " + title + ". The table " + "contains the registers created using the GUI."; //MessageBox.Show(Path.GetFileNameWithoutExtension(PathToFile.Text)); string doc = "<html><head><title>" + title + " Documentation" + "</title>"; doc += "<style>table, th, td { border: 1px solid black; } th, td {padding: 5px; text-align: center;}" + "</style></head><body>"; doc += "<h1><font face = 'arial'><u>Documentation For " + title + "</h1></u>"; doc += date; doc += "<h2>" + date + "<br/>" + introDec + "</h2>"; doc += "<table style='width: 100 %'>"; doc += "<tr><th>Name</th><th>Group</th><th>Address</th><th>Mais</th><th>LSB</th><th>MSB</th><th>TYPE</th><th>FPGA</th><th>Init</th><th>Comment</th></tr>"; TreeGridNode last_node = null; for (int i = treeGridView1.Nodes.Count - 1; i >= 0; i--) { TreeGridNode last_group = treeGridView1.Nodes[i]; if (last_group.HasChildren) { last_node = last_group.Nodes[last_group.Nodes.Count - 1]; if (last_node.HasChildren) { last_node = last_node.Nodes[last_node.Nodes.Count - 1]; } break; } } RegisterEntry last = RegList[(int)last_node.Cells["IndexColumn"].Value]; int k = (int)last_node.Cells["SecondaryIndexColumn"].Value; if (k != -1) { last = last.GetFields()[k]; //MessageBox.Show() } while ((line = file.ReadLine()) != null) { if (line.Length == 0) { res += "\n"; continue; } //System.Console.WriteLine(line); if ('#' == line[0]) { continue; } if (line.Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0")) { break; } res += line + "\n"; } string prop = "", names = ""; foreach (string group in RegGroupOpts.Items) { names += "\t\t -- " + group + "\n"; prop += "\t\t -- " + group + "\n"; foreach (RegisterEntry l in RegList) { if (l.GetGroup().Equals(group)) { List <RegisterEntry> fields = l.GetFields(); names += l.toName(); prop += l.ToEntry(l == last); doc += l.ToXMLstring(); foreach (RegisterEntry f in fields) { names += f.toName(); prop += f.ToEntry(f == last); doc += f.ToXMLstring(); } } } } doc += "</table></font></body></html>"; res += names; while ((line = file.ReadLine()) != null) { //System.Console.WriteLine(line); if (line.Length == 0) { res += "\n"; continue; } if ('#' == line[0]) { continue; } if (line.Equals("0o0o0o0o0o0o0o0o0o0o0o0o0o00o0o0o0o0o0o00o0o0o0o0o0")) { break; } res += line + '\n'; } res += prop; while ((line = file.ReadLine()) != null) { //System.Console.WriteLine(line); if (line.Length == 0) { res += "\n"; continue; } if ('#' == line[0]) { continue; } res += line + '\n'; } file.Close(); try { File.WriteAllText(PathToFile.Text, res); //MessageBox.Show(Path.GetDirectoryName(PathToFile.Text) + "\\" + title + "_doc.txt"); File.WriteAllText(Path.GetDirectoryName(PathToFile.Text) + "\\" + title + "_doc.html", doc); saved = true; ErrorMessage.Text = "File Saved!"; } catch { MessageBox.Show("Invalid Path to File"); } } catch (IOException t) { MessageBox.Show("ArgumentException " + t.ToString()); } }
/* Edit a register */ private void Load_Click(object sender, EventArgs e) { RegisterEntry re = null; TreeGridNode node = 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]; } node = item; break; } catch (NullReferenceException) { //do nothing for groups return; } } if (re == null) { MessageBox.Show("Please select a register in order to edit"); return; } string name = RegNameText.Text; if (!re.GetName().Equals(name)) { MessageBox.Show("You can't edit a register's name"); RegNameText.Text = re.GetName(); return; } string mais = MAISOpts.Text; string lsb = LSBOpts.Text; string msb = MSBOpts.Text; string type = TypeOpts.Text; string fpga = FPGAOpts.Text; string init = InitText.Text; string comment = CommentText.Text; string group = RegGroupOpts.Text; RegisterEntry entry; int i = re.GetIndex(), j = re.GetSecondaryIndex(); if (i == -1) { MessageBox.Show("No such register " + name); InitFields(); return; } entry = RegList[i]; if (j != -1) { entry = entry.GetFields()[j]; } if (entry.GetIsComment()) { MessageBox.Show("This register is a comment and can't be edited"); //InitFields(); return; } Enum.TryParse(type, out RegisterEntry.type_field t); RegisterEntry.type_field s = entry.GetRegType(); if ((s == RegisterEntry.type_field.FIELD && t != RegisterEntry.type_field.FIELD) || s != RegisterEntry.type_field.FIELD && t == RegisterEntry.type_field.FIELD) { MessageBox.Show("Can't edit a field or create one using Load"); TypeOpts.SelectedIndex = (int)s; return; } if (!RegisterEntry.IsValidLsbMsb(msb, lsb)) { MessageBox.Show("Can't edit an entry to have LSB > MSB"); //InitFields(); return; } Enum.TryParse(fpga, out RegisterEntry.fpga_field r); entry.EditRegister(mais, lsb, msb, t, r, init, comment, group); OpenValidation(); UpdateDataBase(); EditCell(node, entry.GetTableEntry()); }
/* 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); }
public void AddField(RegisterEntry Field) { Field.SetGroup(Group); Field.SetSecondaryIndex(Fields.Count); Fields.Add(Field); }