Esempio n. 1
0
        public void CompileFile(string SourceFileName, string TargetFileName, string TargetDirectory, string SignatureFile, bool GenerateExecutable, bool GenerateStackFrames, int ForthStackSize, int ReturnStackSize)
        {
            // Compilation start
            SignalCompilationStart();

            try
            {
                // Parsing
                SignalParsingStart(SourceFileName);
                ForthParser parser      = new ForthParser(SourceFileName);
                var         SourceAtoms = parser.GetForthAtoms();
                SignalParsingEnd();

                // Syntactic analysis
                SignalSyntacticAnalysisStart();
                ForthSyntacticAnalyzer analyzer = new ForthSyntacticAnalyzer(SourceAtoms);
                _MetaData = analyzer.GetMetaData();
                SignalSyntacticAnalysisEnd();

                // Code generation
                SignalCodeGenerationStart();
                ForthCodeGenerator generator = new ForthCodeGenerator(MetaData, TargetFileName, TargetDirectory, SignatureFile, GenerateExecutable, GenerateStackFrames, ForthStackSize, ReturnStackSize);
                generator.DoGenerateCode();
                SignalCodeGenerationEnd();

                // Compilation end
                SignalCompilationEnd();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        string LibraryName;                     // Name of the library to be created

        public ForthCompiler(string SourceFileName, string TargetFileName, string TargetDirectory, bool bQuiet, bool bClock, bool bExe, bool bCheckStack, int iForthStackSize, int iReturnStackSize, bool bMap)
        {
            // Initialize start time
            DateTime dtStart = DateTime.Now;
            TimeSpan ts1, ts2, ts3;


            // Parse the source file
            if (!bQuiet)
            {
                Console.Write("Parsing file...\t\t  ");
            }
            ForthParser fp = new ForthParser(SourceFileName);

            ts1 = (DateTime.Now - dtStart);
            if (!bQuiet)
            {
                if (bClock)
                {
                    Console.WriteLine("Done in {0} ms", ts1.Milliseconds);
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            SourceAtoms = fp.SourceAtoms;
            // Perform a syntactic analysis of the source atoms
            if (!bQuiet)
            {
                Console.Write("Analyzing source atoms... ");
            }
            ForthSyntacticAnalyzer fsa = new ForthSyntacticAnalyzer(SourceAtoms);

            ts2 = (DateTime.Now - dtStart);
            if (!bQuiet)
            {
                if (bClock)
                {
                    Console.WriteLine("Done in {0} ms", ts2.Milliseconds);
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            fsa.GetMetaData(out LibraryName, out GlobalConstants, out GlobalVariables, out LocalVariables, out Words, out ExternalWords);
            // Generate code
            if (!bQuiet)
            {
                Console.Write("Generating code...\t  ");
            }
            ForthCodeGenerator fcg = new ForthCodeGenerator(TargetFileName, TargetDirectory, LibraryName, GlobalConstants, GlobalVariables, LocalVariables, Words, ExternalWords, bExe, bCheckStack, iForthStackSize, iReturnStackSize);

            fcg.DoGenerateCode();
            ts3 = (DateTime.Now - dtStart);
            if (!bQuiet)
            {
                if (bClock)
                {
                    Console.WriteLine("Done in {0} ms", ts3.Milliseconds);
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            if (!bQuiet)
            {
                if (bClock)
                {
                    Console.WriteLine("Total compiling time:\t  {0} ms", ts1.Milliseconds + ts2.Milliseconds + ts3.Milliseconds);
                }
                Console.WriteLine();
                if (GlobalConstants.Count > 0)
                {
                    Console.WriteLine("Constants:\t\t{0}", GlobalConstants.Count);
                }
                if (GlobalVariables.Count > 0)
                {
                    Console.WriteLine("Global variables:\t{0}", GlobalVariables.Count);
                }
                if (LocalVariables.Count > 0)
                {
                    Console.WriteLine("Local variables:\t{0}", LocalVariables.Count);
                }
                if (Words.Count > 0)
                {
                    Console.WriteLine("Words:\t\t\t{0}", Words.Count);
                }
                if (ExternalWords.Count > 0)
                {
                    Console.WriteLine("External words:\t\t{0}", ExternalWords.Count);
                }
                Console.WriteLine();
            }
            // Display detailed map data (/MAP option)
            if (bMap && !bQuiet)
            {
                DisplayMapInformation();
            }
        }