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); }
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); }
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); }