Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Virtual eXecuter Assembler by Claus Andersen");
            Console.WriteLine("Version: 1.0 - March 3rd 2008");

            Dictionary <string, List <string> > options = CommandLineParser.Run(args);

            if (options.ContainsKey("f") == false)
            {
                throw new Exception("No input file specified");
            }
            if (options["f"].Count == 0)
            {
                throw new Exception("No input file specified");
            }
            if (options["f"].Count > 1)
            {
                throw new Exception("Only one input file is accepted");
            }

            string fullFileName             = options["f"][0];
            string fileName                 = Path.GetFileName(fullFileName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullFileName);
            string fileDirectory            = Path.GetDirectoryName(fullFileName);

            Assembler assembler = new Assembler();

            try
            {
                Part part = assembler.Assemble(fullFileName);

                part.Save(fileDirectory + "/" + fileNameWithoutExtension + ".part");

                if (options.ContainsKey("l"))
                {
                    part.GenerateListFile(fileDirectory + "/" + fileNameWithoutExtension + ".list");
                }

                if (options.ContainsKey("m"))
                {
                    part.GenerateMapFile(fileDirectory + "/" + fileNameWithoutExtension + ".map");
                }
            }
            catch (Exception ex)
            {
                if (options.ContainsKey("@"))
                {
                    Console.WriteLine(ex.Message + "\n\n" + ex.StackTrace);
                }
                else
                {
                    Console.WriteLine(ex.Message);
                }
            }

            if (options.ContainsKey("!"))
            {
                Console.WriteLine("Press any key to continue");
                Console.ReadKey();
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Virtual eXecuter Assembler by Claus Andersen");
            Console.WriteLine("Version: 0.10 - June 14th 2008");
            Console.WriteLine("");

            try
            {
                List <string> sourceFiles;
                string        outputDirectory           = Directory.GetCurrentDirectory();
                bool          generatePreprocessorFiles = false;
                bool          generateMapFiles          = false;
                bool          generateListFiles         = false;

                #region Parse command line
                Dictionary <string, List <string> > options = CommandLineParser.Run(args);

                if (options == null || options.Count == 0 || options.ContainsKey("default") == false || options["default"].Count == 0)
                {
                    Help();
                    Quit();
                    return;
                }

                sourceFiles = options["default"];

                if (options.ContainsKey("o") && options["o"] != null && options["o"].Count == 1)
                {
                    outputDirectory = options["o"][0];
                    Directory.CreateDirectory(outputDirectory);
                }

                if (options.ContainsKey("p"))
                {
                    generatePreprocessorFiles = true;
                }

                if (options.ContainsKey("m"))
                {
                    generateMapFiles = true;
                }

                if (options.ContainsKey("l"))
                {
                    generateListFiles = true;
                }

                if (sourceFiles == null || sourceFiles.Count == 0)
                {
                    Help();
                    Quit();
                    return;
                }

                if (options.ContainsKey("w"))
                {
                    waitWhenExiting = true;
                }
                #endregion

                foreach (string sourceFile in sourceFiles)
                {
                    string sourceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(sourceFile);
                    string sourceFileDirectory            = Path.GetFullPath(sourceFile).Remove(sourceFile.LastIndexOf("\\"));
                    string partFile         = outputDirectory + "\\" + sourceFileNameWithoutExtension + ".part";
                    string preprocessorFile = outputDirectory + "\\" + sourceFileNameWithoutExtension + ".pre";
                    string mapFile          = outputDirectory + "\\" + sourceFileNameWithoutExtension + ".map";
                    string listFile         = outputDirectory + "\\" + sourceFileNameWithoutExtension + ".list";

                    StreamReader sourceFileReader       = new StreamReader(sourceFile);
                    FileStream   partFileWriter         = File.Create(partFile);
                    StreamWriter preprocessorFileWriter = new StreamWriter(preprocessorFile);
                    preprocessorFileWriter.AutoFlush = true;
                    StreamWriter mapFileWriter = new StreamWriter(mapFile);
                    mapFileWriter.AutoFlush = true;
                    StreamWriter listFileWriter = new StreamWriter(listFile);
                    listFileWriter.AutoFlush = true;

                    Preprocessor pre = new Preprocessor();

                    StreamReader preprocessorReader = pre.Run(sourceFileReader, sourceFileDirectory);

                    /*
                     *                                      if (generateListFiles)
                     *                                      {
                     *                                              Informer.Instance.SetListFile(listFileName);
                     *                                      }
                     *
                     *                                      if (mapFileName != "")
                     *                                      {
                     *                                              Informer.Instance.SetMapFile(mapFileName);
                     *                                      }
                     */

                    Assembler asm = new Assembler();

                    asm.FindLabels(preprocessorReader);
                    asm.GenerateCode(preprocessorReader);
                    XmlSerializer serializer = new XmlSerializer(typeof(Assembler));
                    serializer.Serialize(partFileWriter, asm);

                    //					asm.GenerateExecutable(outputFile);


                    sourceFileReader.Close();
                    partFileWriter.Close();
                    preprocessorFileWriter.Close();
                    mapFileWriter.Close();
                    listFileWriter.Close();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
            Quit();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Virtual eXecuter Assembler by Claus Andersen");
            Console.WriteLine("Version: 0.03 - June 22nd 2008");
            Console.WriteLine("");

            try
            {
                #region Parse command line
                Dictionary <string, List <string> > options = CommandLineParser.Run(args);

                if (options == null || options.Count == 0)
                {
                    Help();
                    Quit();
                    return;
                }

                if (options.ContainsKey("default"))
                {
                    sourceFileName = options["default"][0];
                    if (File.Exists(sourceFileName) == false)
                    {
                        Console.WriteLine("The specified source file does not exist");
                        Quit();
                        return;
                    }
                    outputFileName = Path.ChangeExtension(sourceFileName, ".vxx");
                }

                if (options.ContainsKey("o"))
                {
                    outputFileName = options["o"][0];
                }

                if (options.ContainsKey("l"))
                {
                    if (options["l"].Count == 0)
                    {
                        listFileName = Path.ChangeExtension(sourceFileName, ".lst");
                    }
                    else if (options["l"].Count == 1)
                    {
                        listFileName = options["l"][0];
                    }
                    else
                    {
                        Console.WriteLine("More than one list file was specified");
                    }
                }

                if (options.ContainsKey("m"))
                {
                    if (options["m"].Count == 0)
                    {
                        mapFileName = Path.ChangeExtension(sourceFileName, ".map");
                    }
                    else if (options["m"].Count == 1)
                    {
                        mapFileName = options["m"][0];
                    }
                    else
                    {
                        Console.WriteLine("More than one map file was specified");
                    }
                }

                if (sourceFileName == "")
                {
                    Help();
                    Quit();
                    return;
                }

                if (options.ContainsKey("w"))
                {
                    waitWhenExiting = true;
                }
                #endregion

                outputFile = File.Create(outputFileName);

                if (listFileName != "")
                {
                    Informer.Instance.SetListFile(listFileName);
                }

                if (mapFileName != "")
                {
                    Informer.Instance.SetMapFile(mapFileName);
                }

                Assembler asm = new Assembler();

                StreamReader preprocessedSourceFile = asm.Preprocessor(sourceFileName);

                asm.FindLabels(preprocessedSourceFile);
                asm.GenerateCode(preprocessedSourceFile);
                asm.GenerateExecutable(outputFile);

                preprocessedSourceFile.Close();
                outputFile.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: " + ex.Message);
            }
            Quit();
        }