/// <summary> /// Builds the current project. /// </summary> /// <param name="binaryPath">A variable to store the path to the generated binary.</param> /// <returns>A value indicating whether the build was successful.</returns> protected internal override bool Build(out string binaryPath) { Project.Save(); Assembler a = new Assembler(); a.LoadFromFile(Project.MainItem.Path); if (a.Process()) { string path = Path.Combine(Path.GetDirectoryName(Project.Path), Path.GetFileNameWithoutExtension(Project.Filename)); a.SaveAsBinary(path + ".bin"); if (Settings.Default.Pico_GenerateHex) a.SaveAsHex(path + ".hex"); if (Settings.Default.Pico_GenerateTxt) a.SaveAsText(path + ".txt"); a.DebugInformation.SaveToFile(path + ".bin.mldbg"); binaryPath = path + ".bin"; return true; } else { // Report errors. Gui.ErrorsPad.ClearItems(); foreach (var error in a.Errors) { string desc = string.Format("E{0:0000}: {1}.", error.ID, error.Description); Gui.ErrorsPad.AddItem(new ListItem(desc, Project.MainItem, error.Line, error.Column)); } Gui.ErrorsPad.ShowOnMainForm(); binaryPath = string.Empty; return false; } }
/// <summary> /// Assembles the current document and updates info editor /// or files an error. /// </summary> private void infoTimer_Tick(object sender, EventArgs e) { infoTimer.Enabled = false; if (!InfoEditor.Visible) return; var gui = Item.Project.Platform.Gui as DebuggablePlatform.DebuggableGuiProvider; var errPad = gui.ErrorsPad; errPad.ClearItems(); var doc = Editor.Document; Assembler a = new Assembler(doc.TextContent); if (a.Process()) { errorPanel.Visible = false; string[] info = new string[doc.TotalNumberOfLines]; foreach (var ins in a.Instructions) { info[ins.Line - 1] = string.Format("{0,5}: {1}", ins.Address, ins.CodeToString()); } var sb = new StringBuilder(); foreach (var s in info) { sb.AppendLine(s); } InfoEditor.Document.TextContent = sb.ToString(); InfoEditor.Document.RequestUpdate(new ICSharpCode.TextEditor.TextAreaUpdate(ICSharpCode.TextEditor.TextAreaUpdateType.WholeTextArea)); AdjustInfoEditorScrollbar(); } else { errorPanel.Visible = true; foreach (var error in a.Errors) { string desc = string.Format("E{0:0000}: {1}.", error.ID, error.Description); errPad.AddItem(new ListItem(desc, Item, error.Line, error.Column)); } } }
static void Main(string[] args) { Greet(); if (args.Length == 0 || args.Length > 3) { Usage(); return; } bool hex = false; bool txt = false; int firstFileIndex = 0; if (args[0].StartsWith("/") || args[0].StartsWith("-")) { firstFileIndex = 1; string ar = args[0].ToLower(); if (ar == "/hex" || ar == "-hex") { hex = true; } else if (ar == "/txt" || ar == "-txt") { txt = true; } else { Usage(); return; } } Assembler a = new Assembler(); try { a.LoadFromFile(args[firstFileIndex]); } catch (Exception) { Console.WriteLine(string.Format("Could not load file '{0}'", args[firstFileIndex])); return; } if (!a.Process()) { Console.WriteLine(string.Format("Could not assemble '{0}'", args[firstFileIndex])); Console.WriteLine(); foreach (Error e in a.Errors) { Console.WriteLine(e.ToString()); } return; } string outFile; if (args.Length == firstFileIndex + 2) // outFile specified in an argument { outFile = args[firstFileIndex + 1]; } else { outFile = args[firstFileIndex].ToLower(); string extension = ".bin"; if (hex) extension = ".hex"; if (txt) extension = ".txt"; outFile = outFile.Replace(".pca", extension); if (outFile == args[firstFileIndex].ToLower()) { outFile += extension; } } try { if (hex) { a.SaveAsHex(outFile); } else if (txt) { a.SaveAsText(outFile); } else // bin { a.SaveAsBinary(outFile); } a.DebugInformation.SaveToFile(outFile + ".mldbg"); } catch (Exception) { Console.WriteLine(string.Format("Could no write file '{0}'", outFile)); return; } Console.WriteLine(string.Format("File '{0}' successfully assembled. Result written to '{1}'", args[firstFileIndex], outFile)); }
static void Main(string[] args) { Greet(); if (args.Length == 0 || args.Length > 3) { Usage(); return; } bool hex = false; bool txt = false; int firstFileIndex = 0; if (args[0].StartsWith("/") || args[0].StartsWith("-")) { firstFileIndex = 1; string ar = args[0].ToLower(); if (ar == "/hex" || ar == "-hex") { hex = true; } else if (ar == "/txt" || ar == "-txt") { txt = true; } else { Usage(); return; } } Assembler a = new Assembler(); try { a.LoadFromFile(args[firstFileIndex]); } catch (Exception) { Console.WriteLine(string.Format("Could not load file '{0}'", args[firstFileIndex])); return; } if (!a.Process()) { Console.WriteLine(string.Format("Could not assemble '{0}'", args[firstFileIndex])); Console.WriteLine(); foreach (Error e in a.Errors) { Console.WriteLine(e.ToString()); } return; } string outFile; if (args.Length == firstFileIndex + 2) // outFile specified in an argument { outFile = args[firstFileIndex + 1]; } else { outFile = args[firstFileIndex].ToLower(); string extension = ".bin"; if (hex) { extension = ".hex"; } if (txt) { extension = ".txt"; } outFile = outFile.Replace(".pca", extension); if (outFile == args[firstFileIndex].ToLower()) { outFile += extension; } } try { if (hex) { a.SaveAsHex(outFile); } else if (txt) { a.SaveAsText(outFile); } else // bin { a.SaveAsBinary(outFile); } a.DebugInformation.SaveToFile(outFile + ".mldbg"); } catch (Exception) { Console.WriteLine(string.Format("Could no write file '{0}'", outFile)); return; } Console.WriteLine(string.Format("File '{0}' successfully assembled. Result written to '{1}'", args[firstFileIndex], outFile)); }