예제 #1
0
    } // WriteProgramSource

    public static void DumpSymTabAndWriteSrcTxt(String path, String moduleName)
    {
//-----------------------------------|----------------------------------------
        String genMcppFileName = path + moduleName + "_Gen.mcpp";

        if (File.Exists(genMcppFileName))
        {
            File.Delete(genMcppFileName);
        }
        Console.WriteLine("emitting  mcpp to \"" + genMcppFileName + "\" ...");
        FileStream genMcppFs = new FileStream(genMcppFileName, FileMode.Create);

        genMcpp = new StreamWriter(genMcppFs);
        GenSrcText.DumpSymTab();
        GenSrcText.WriteProgramSource();
        genMcpp.Close();
    } // DumpSymTabAndWriteSrcTxt
예제 #2
0
    } // Abort

    private static void CompileFile(String srcFileName)
    {
        try {
            FileStream srcFs = new FileStream(srcFileName, FileMode.Open);
            Lex.src = new StreamReader(srcFs);
        } catch (Exception) {
            Lex.src = null;
        } // try/catch
        if (Lex.src == null)
        {
            Console.WriteLine("*** file \"{0}\" not found", srcFileName);
            return;
        } // if
        Console.WriteLine("parsing           \"" + srcFileName + "\" ...");
        Syn.Parse();
        Lex.src.Close();
        Lex.src = null;
        int    extStart    = srcFileName.LastIndexOf('.');
        String lstFileName = srcFileName.Substring(0, extStart) + ".lst";

        if (Errors.NumOfErrors() > 0)
        {
            Console.WriteLine("{0} error(s) detected,", Errors.NumOfErrors());
            Console.WriteLine("  listing to      \"" + lstFileName + "\"...");
            StreamWriter lst = null;
            try {
                FileStream lstFs = new FileStream(lstFileName, FileMode.Create);
                lst = new StreamWriter(lstFs);
            } catch (Exception) {
                lst = null;
            } // try/catch
            if (lst == null)
            {
                Utils.FatalError(NAME, "CompileFile", "file \"{0}\" not created", lstFileName);
                return;
            } // if
            FileStream srcFs = new FileStream(srcFileName, FileMode.Open);
            Lex.src = new StreamReader(srcFs);
            lst.WriteLine(NAME + " (file: \"{0}\")", srcFileName);
            Errors.GenerateListing(Lex.src, lst, Errors.ListingShape.longListing);
            Lex.src.Close();
            Lex.src = null;
            lst.Close();
            lst = null;
        }
        else
        {
// *** start: not in Main.frm ***

            if (File.Exists(lstFileName))
            {
                File.Delete(lstFileName);
            }

            String moduleName = (String)srcFileName.Clone();
            String path       = String.Empty;

            int lastBackSlashIdx = moduleName.LastIndexOf('\\');
            if (lastBackSlashIdx >= 0)
            {
                path       = moduleName.Substring(0, lastBackSlashIdx + 1);
                moduleName = moduleName.Substring(lastBackSlashIdx + 1);
            } // if

            int periodIdx = moduleName.IndexOf('.');
            if (periodIdx >= 0)
            {
                moduleName = moduleName.Substring(0, periodIdx);
            }

#if GEN_SRC  // symbol table gen. of source text with symbol table dump
            StartTimer();
            GenSrcText.DumpSymTabAndWriteSrcTxt(path, moduleName);
            WriteElapsedTime("GenSrcText");
#endif

#if GEN_CIL_AS_TEXT // CIL generation to il-file and assembling to exe
            StartTimer();
            GenCilAsText.GenerateAssembly(path, moduleName);
            WriteElapsedTime("GenCilAsText");
            VerifyAssembly(path, moduleName);
#endif // GEN_CIL_AS_TEXT

#if GEN_CIL_REF_EMIT // CIL generation with Reflection.Emit
            StartTimer();
            GenCilByRefEmit.GenerateAssembly(path, moduleName);
            WriteElapsedTime("GenCilByReflectionEmit");
            VerifyAssembly(path, moduleName);
#endif

// *** end ***

            Console.WriteLine("compilation completed successfully");
        } // else
        Utils.Modules(Utils.ModuleAction.resetModule);
    }     // CompileFile