Example #1
0
        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));
        }
Example #2
0
 /// <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;
     }
 }
Example #3
0
        /// <summary>
        /// Gets the numeric value of the Argument either by parsing it as an integer
        /// (in case of a Constant), or by looking up the value in the Symbol table.
        /// 
        /// If the symbol cannot be found, an Error is filed.
        /// </summary>
        /// <param name="assembler">A reference to the Assembler object holding Symbol table</param>
        /// <param name="value">A integer representing the argument's numeric value</param>
        /// <returns>A value indicating if the look up has been successful</returns>
        public bool LookUpValue(Assembler assembler, out int value)
        {
            switch (Type)
            {
                case ArgumentType.Constant:
                    value = int.Parse(Text);
                    break;
                case ArgumentType.SymbolConstant:
                case ArgumentType.Direct:
                case ArgumentType.Indirect:
                    try
                    {
                        value = assembler.Symbols[Text];
                    }
                    catch (Exception)
                    {
                        Error e = new Error();
                        e.ID = 7;
                        e.Description = string.Format(Messages.E0007, Text);
                        e.Line = ParentInstruction.Line;
                        e.Column = Column;
                        ParentInstruction.Error = e;

                        value = 0;
                        return false;
                    }
                    break;
                default:
                    value = 0;
                    break;
            }
            return true;
        }
Example #4
0
 public Analyzer(Assembler assembler)
 {
     Assembler = assembler;
 }
Example #5
0
        /// <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));
                }
            }
        }
Example #6
0
        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));
        }
Example #7
0
 public Analyzer(Assembler assembler)
 {
     Assembler = assembler;
 }