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