コード例 #1
0
        static void DisplayMapInformation(ForthCompiler compiler)
        {
            DisplayLineToConsole(string.Empty);
            DisplayLineToConsole("Summary of compilation objects", ConsoleColor.White);

            // Display global constants
            DisplayLineToConsole(string.Empty);
            DisplayLineToConsole("Global constants:", ConsoleColor.Blue);
            foreach (var fc in compiler.MetaData.GlobalConstants)
            {
                if (fc.Value.GetType() != typeof(string))
                {
                    DisplayLineToConsole(string.Format("{0} = {1}", fc.Name, fc.Value));
                }
                else
                {
                    DisplayLineToConsole(string.Format("{0} = \"{1}\"", fc.Name, fc.Value));
                }
            }

            // Display global variables
            DisplayLineToConsole(string.Empty);
            DisplayLineToConsole("Global variables:", ConsoleColor.Blue);
            foreach (var fv in compiler.MetaData.GlobalVariables)
            {
                DisplayLineToConsole(string.Format("{0} = (Addr:{1}, Size:{2})", fv.Name, fv.Address, fv.Size));
            }

            // Display local variables
            DisplayLineToConsole(string.Empty);
            DisplayLineToConsole("Local variables:", ConsoleColor.Blue);
            foreach (var flv in compiler.MetaData.LocalVariables)
            {
                DisplayLineToConsole(string.Format("{0} = (Addr:{1}, Word:{2})", flv.Name, flv.Address, flv.WordName));
            }

            // Display words
            DisplayLineToConsole(string.Empty);
            DisplayLineToConsole("Words:", ConsoleColor.Blue);
            foreach (var ew in compiler.MetaData.Words)
            {
                DisplayLineToConsole(string.Format("-> {0}", ew.Name));
            }

            // Display external words
            DisplayLineToConsole(string.Empty);
            DisplayLineToConsole("External words:", ConsoleColor.Blue);
            foreach (var ew in compiler.MetaData.ExternalWords)
            {
                DisplayLineToConsole(string.Format("{0} = (Library:{1}, Class:{2}, Method:{3})", ew.Name, ew.Library, ew.Class, ew.Method));
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Initialize default parameter values
            bDisplayLogo = bExe = bCheckStack = true;
            bQuiet       = bClock = bMap = false;
            sOutputFile  = sOutputDir = "";

            // Display usage screen if no parameters are given
            if (args.Length < 1)
            {
                Usage();
                return;
            }

            sInput = args[0];

            // Cycle through command line parameters
            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "/NOLOGO":
                    bDisplayLogo = false;
                    break;

                case "/QUIET":
                    bQuiet = true;
                    break;

                case "/CLOCK":
                    bClock = true;
                    break;

                case "/EXE":
                    bExe = true;
                    break;

                case "/DLL":
                    bExe = false;
                    break;

                case "/NOCHECK":
                    bCheckStack = false;
                    break;

                case "/MAP":
                    bMap = true;
                    break;

                default:
                    if (args[i].ToUpper().StartsWith("/OUTPUT="))
                    {
                        sOutputFile = args[i].Substring(8);
                    }
                    else
                    if (args[i].ToUpper().StartsWith("/FS:"))
                    {
                        try
                        {
                            iForthStackSize = Convert.ToInt32(args[i].Substring(4));
                        }
                        catch (FormatException)
                        {
                            Usage();
                            return;
                        }
                    }
                    else
                    if (args[i].ToUpper().StartsWith("/RS:"))
                    {
                        try
                        {
                            iReturnStackSize = Convert.ToInt32(args[i].Substring(4));
                        }
                        catch (FormatException)
                        {
                            Usage();
                            return;
                        }
                    }
                    else
                    {
                        Usage();
                        return;
                    }
                    break;
                }
            }

            // Process input file
            string inDrive = "", inDir = "", inFile = "", inExt = "";

            FileNameSplit(sInput, out inDrive, out inDir, out inFile, out inExt);
            if (inExt == "")
            {
                sInput = inDrive + inDir + inFile + ".4th";
            }

            // Process parameters
            if (bDisplayLogo)
            {
                DisplayLogo();
            }
            if (sOutputFile == "")
            {
                sOutputFile = inFile + (bExe ? ".exe" : ".dll");
                sOutputDir  = null;
            }
            else
            {
                FileNameSplit(sOutputFile, out inDrive, out inDir, out inFile, out inExt);
                sOutputFile = inFile + inExt;
                sOutputDir  = inDrive + inDir;
                if (sOutputDir == "")
                {
                    sOutputDir = null;
                }
            }

            if (!bQuiet)
            {
                Console.WriteLine("Compiling file '{0}' to '{1}'", sInput, sOutputDir + sOutputFile);
            }

            try
            {
                ForthCompiler fc = new ForthCompiler(sInput, sOutputFile, sOutputDir, bQuiet, bClock, bExe, bCheckStack, iForthStackSize, iReturnStackSize, bMap);
            }
            catch (Exception e)
            {
                Console.WriteLine("\n\rCompiling error: {0}", e.Message);
                if (!bQuiet)
                {
                    Console.WriteLine("Operation failed.");
                }
                return;
            }
            if (!bQuiet)
            {
                Console.WriteLine("Operation completed successfully.");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            // Initialize default parameter values
            DisplayLogo = GenerateExecutable = CheckStack = true;
            QuietMode   = ShowTimings = DisplayMap = false;
            OutputFile  = OutputDirectory = SignatureFile = string.Empty;

            // Display usage screen if no parameters are given
            if (args.Length < 1)
            {
                DisplayUsageToConsole();
                return;
            }

            SourceFile = args[0];

            // Cycle through command line parameters
            for (int i = 1; i < args.Length; i++)
            {
                switch (args[i].ToUpper())
                {
                case "/NOLOGO":
                    DisplayLogo = false;
                    break;

                case "/QUIET":
                    QuietMode = true;
                    break;

                case "/CLOCK":
                    ShowTimings = true;
                    break;

                case "/EXE":
                    GenerateExecutable = true;
                    break;

                case "/DLL":
                    GenerateExecutable = false;
                    break;

                case "/NOCHECK":
                    CheckStack = false;
                    break;

                case "/MAP":
                    DisplayMap = true;
                    break;

                default:
                    if (args[i].ToUpper().StartsWith("/OUTPUT="))
                    {
                        OutputFile = args[i].Substring(8);
                    }
                    else
                    if (args[i].ToUpper().StartsWith("/FS:"))
                    {
                        try
                        {
                            ForthStackSize = Convert.ToInt32(args[i].Substring(4));
                        }
                        catch (FormatException)
                        {
                            DisplayUsageToConsole();
                            return;
                        }
                    }
                    else
                    if (args[i].ToUpper().StartsWith("/RS:"))
                    {
                        try
                        {
                            ReturnStackSize = Convert.ToInt32(args[i].Substring(4));
                        }
                        catch (FormatException)
                        {
                            DisplayUsageToConsole();
                            return;
                        }
                    }
                    else
                    if (args[i].ToUpper().StartsWith("/KEY="))
                    {
                        SignatureFile = args[i].Substring(5);
                    }
                    else
                    {
                        DisplayUsageToConsole();
                        return;
                    }
                    break;
                }
            }

            // Process parameters
            if (DisplayLogo)
            {
                DisplayLogoToConsole();
            }

            #region Input File Processing
            // If the extension for the input file is missing, add it
            if (!Path.HasExtension(SourceFile))
            {
                SourceFile = Path.ChangeExtension(SourceFile, ".4th");
            }
            #endregion

            #region Input File Existence Check
            // Check whether the input file really exists
            if (!File.Exists(SourceFile))
            {
                DisplayLineToConsole(string.Format("\n\rERROR: The file '{0}' could not be found.", SourceFile), ConsoleColor.Red);
                return;
            }
            #endregion

            #region Output File Processing
            // If there is no output file specified, generate a name for it based on the input file
            if (OutputFile == string.Empty)
            {
                OutputFile      = Path.GetFileName(SourceFile);
                OutputFile      = Path.ChangeExtension(OutputFile, GenerateExecutable ? ".exe" : ".dll");
                OutputDirectory = Path.GetDirectoryName(SourceFile);
                if (OutputDirectory == string.Empty)
                {
                    OutputDirectory = ".";
                }
            }
            else
            {
                OutputDirectory = Path.GetDirectoryName(OutputFile);
                if (OutputDirectory == string.Empty)
                {
                    OutputDirectory = null;
                }
                OutputFile = Path.GetFileName(OutputFile);
            }
            #endregion

            ForthCompiler compiler = new ForthCompiler();
            compiler.OnCodeGenerationStart    += new ForthCompiler.CompilerEventHandler(compiler_OnCodeGenerationStart);
            compiler.OnCodeGenerationEnd      += new ForthCompiler.CompilerEventHandler(compiler_OnCodeGenerationEnd);
            compiler.OnCompilationStart       += new ForthCompiler.CompilerEventHandler(compiler_OnCompilationStart);
            compiler.OnCompilationEnd         += new ForthCompiler.CompilerEventHandler(compiler_OnCompilationEnd);
            compiler.OnParsingEnd             += new ForthCompiler.CompilerEventHandler(compiler_OnParsingEnd);
            compiler.OnParsingStart           += new ForthCompiler.CompilerEventHandler(compiler_OnParsingStart);
            compiler.OnSyntacticAnalysisEnd   += new ForthCompiler.CompilerEventHandler(compiler_OnSyntacticAnalysisEnd);
            compiler.OnSyntacticAnalysisStart += new ForthCompiler.CompilerEventHandler(compiler_OnSyntacticAnalysisStart);

            try
            {
                compiler.CompileFile(SourceFile, OutputFile, OutputDirectory, SignatureFile, GenerateExecutable, CheckStack, ForthStackSize, ReturnStackSize);
            }
            catch (Exception e)
            {
                DisplayLineToConsole("\t\tFAILED", ConsoleColor.Red);
                DisplayLineToConsole(string.Format("\n\rCompilation error: {0}", e.Message), ConsoleColor.White);
                return;
            }

            if (DisplayMap)
            {
                DisplayMapInformation(compiler);
            }
        }