public void Compile(Project proj)
        {
            ProjectFile = proj;
            //Make sure the build directory exists and create it if needed
            if (!Directory.Exists(proj.Buildfolder))
                Directory.CreateDirectory(proj.Buildfolder);
            if (!Directory.Exists(proj.OutputFolder))
                Directory.CreateDirectory(proj.OutputFolder);

            //Prepare some stuff needed for preprocessing
            Dictionary<string, PPDefine> defines = new Dictionary<string, PPDefine>();
            foreach (var it in flagDefines)
                defines.Add(it.Name, it);
            List<preprocessFile_IfDefModes> ifdefs = new List<preprocessFile_IfDefModes>();
            List<PostProcessFile> ppFiles = new List<PostProcessFile>();
            //do the preprocessing
            preprocessFile(ifdefs, defines, proj, proj.Mainfile, proj.Mainfile.Substring(proj.Mainfile.LastIndexOf('\\') + 1), ppFiles);
            var ppMainFile = ppFiles[0];

            if (outputFolderCleanup)
            {
                Logger.Instance.log(Logger.LogLevel.VERBOSE, "Cleaning up output dir");
                cleanupRecursive(proj.OutputFolder);
            }

            int errCount = 0;
            //Check the syntax of all files in ppFiles
            foreach(var it in ppFiles)
            {
                //if (!noPrintOut)
                //{
                //    var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
                //    it.resetPosition();
                //    it.FileStream.WriteTo(stream);
                //    stream.Flush();
                //    stream.Close();
                //}
                Scanner scanner = new Scanner(it.FileStream);
                Base baseObject = new Base();
                Parser p = new Parser(scanner);
                Parser.UsedFiles = new List<string>();
                p.BaseObject = baseObject;
                p.Parse();
                if (p.errors.count > 0)
                {
                    errCount += p.errors.count;
                    Logger.Instance.log(Logger.LogLevel.ERROR, "In file '" + it.Name + "'");
                }
                if (printOutMode > 0)
                {
                    if (printOutMode == 1 && it == ppMainFile)
                    {
                        var stream = File.Create(proj.Buildfolder + it.Name + ".objF");
                        it.resetPosition();
                        it.FullFileStream.WriteTo(stream);
                        stream.Flush();
                        stream.Close();
                    }
                    if (printOutMode >= 2)
                    {
                        var stream = File.Create(proj.Buildfolder + it.Name + ".obj");
                        it.resetPosition();
                        it.FileStream.WriteTo(stream);
                        stream.Flush();
                        stream.Close();
                        if (printOutMode >= 3)
                        {
                            var stream2 = File.Create(proj.Buildfolder + it.Name + ".objF");
                            it.resetPosition();
                            it.FullFileStream.WriteTo(stream2);
                            stream2.Flush();
                            stream2.Close();
                        }
                        else if(it == ppMainFile)
                        {
                            var stream2 = File.Create(proj.Buildfolder + it.Name + ".objF");
                            it.resetPosition();
                            it.FullFileStream.WriteTo(stream2);
                            stream2.Flush();
                            stream2.Close();
                        }
                    }
                }
                it.resetPosition();
            }
            if(errCount > 0)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Translating!");
                return;
            }

            //process the actual file

            Base oosTreeBase = new Base();
            NamespaceResolver.BaseClass = oosTreeBase;
            Parser parser = new Parser(new Scanner(ppMainFile.FullFileStream));
            Parser.UsedFiles = new List<string>();
            parser.BaseObject = oosTreeBase;
            parser.Parse();
            errCount = parser.errors.count + parser.BaseObject.finalize();
            if (errCount > 0)
            {
                Logger.Instance.log(Logger.LogLevel.ERROR, "Errors found (" + errCount + "), cannot continue with Comnpiling!");
                return;
            }
            SqfConfigFile configFile = new SqfConfigFile(configFileName);
            oosTreeBase.writeOut(null, configFile);
            configFile.writeOut(proj.OutputFolder);
        }
Example #2
0
        static void Main(string[] args)
        {
            StreamReader istr = new StreamReader(Console.OpenStandardInput(), Console.InputEncoding);
            StreamWriter ostr = new StreamWriter(System.Console.OpenStandardOutput(), Console.OutputEncoding);

            if (args.Count() < 2)
            {
                Help();
                return;
            }

            bool low_opt = false, hight_opt = false;
            int index_in = 2, index_out = 3;

            switch (args[1])
            {
                case "-low":
                    low_opt = true;
                    break;
                case "-hight":
                    hight_opt = true;
                    break;
                case "-low-hight":
                    low_opt = hight_opt = true;
                    break;
                default:
                    index_in = 1;
                    index_out = 2;
                    break;
            }

            istr = new StreamReader(args[index_in]);
            if (index_out < args.Count())
            {
                ostr = new StreamWriter(args[index_out]);
            }

            Scaner scaner = null;
            Parser parser = null;
            Fasm.CodeGen codegen = null;
            switch (args[0])
            {
                case "-l":
                    scaner = new Scaner(istr);
                    Token t = null;
                    while (t == null || t.type != Token.Type.EOF)
                    {
                        try
                        {
                            t = scaner.Read();
                            Console.WriteLine(t.ToString());
                        }
                        catch (Scaner.Exception e)
                        {
                            ostr.WriteLine(e.Message);
                        }
                    }
                    break;
                case "-p":
                    parser = new Parser(new Scaner(istr));
                    parser.Parse();
                    parser.PrintTree(ostr);
                    ostr.WriteLine(parser.logger.ToString());
                    break;
                case "-c":
                    parser = new Parser(new Scaner(istr));
                    parser.Parse();
                    if (!parser.logger.isEmpty())
                    {
                        ostr.WriteLine(parser.logger.ToString());
                        break;
                    }
                    codegen = new Fasm.CodeGen(parser.tstack);
                    codegen.Generate(ostr);
                    break;
                case "-cexe":
                    parser = new Parser(new Scaner(istr));
                    parser.Parse();
                    if (!parser.logger.isEmpty())
                    {
                        ostr.WriteLine(parser.logger.ToString());
                        break;
                    }
                    codegen = new Fasm.CodeGen(parser.tstack);
                    codegen.Generate(ostr);
                    ostr.Flush();
                    ostr.Close();
                    if (index_out < args.Count())
                    {
                        Process.Start(new ProcessStartInfo
                        {
                            FileName = "C:/fasm/fasm.exe",
                            WindowStyle = ProcessWindowStyle.Hidden,
                            Arguments = string.Format("{0} {1}", args[index_out], args[index_out])
                        });
                    }
                    break;
                default:
                    Help();
                    return;
            }

            istr.Close();
            ostr.Close();
        }
 public void CheckSyntax(string filepath)
 {
     Scanner scanner = new Scanner(filepath);
     Parser parser = new Parser(scanner);
     parser.Parse();
 }
Example #4
0
        static void Main(string[] args)
        {
            StreamReader istr = new StreamReader(Console.OpenStandardInput(), Console.InputEncoding);
            StreamWriter ostr = new StreamWriter(System.Console.OpenStandardOutput(), Console.OutputEncoding);

            if (args.Count() < 2)
            {
                Help();
                return;
            }

            bool low_opt = false, hight_opt = false;
            int  index_in = 2, index_out = 3;

            switch (args[1])
            {
            case "-low":
                low_opt = true;
                break;

            case "-hight":
                hight_opt = true;
                break;

            case "-low-hight":
                low_opt = hight_opt = true;
                break;

            default:
                index_in  = 1;
                index_out = 2;
                break;
            }

            istr = new StreamReader(args[index_in]);
            if (index_out < args.Count())
            {
                ostr = new StreamWriter(args[index_out]);
            }

            Scaner scaner = null;
            Parser parser = null;

            Fasm.CodeGen codegen = null;
            switch (args[0])
            {
            case "-l":
                scaner = new Scaner(istr);
                Token t = null;
                while (t == null || t.type != Token.Type.EOF)
                {
                    try
                    {
                        t = scaner.Read();
                        Console.WriteLine(t.ToString());
                    }
                    catch (Scaner.Exception e)
                    {
                        ostr.WriteLine(e.Message);
                    }
                }
                break;

            case "-p":
                parser = new Parser(new Scaner(istr));
                parser.Parse();
                parser.PrintTree(ostr);
                ostr.WriteLine(parser.logger.ToString());
                break;

            case "-c":
                parser = new Parser(new Scaner(istr));
                parser.Parse();
                if (!parser.logger.isEmpty())
                {
                    ostr.WriteLine(parser.logger.ToString());
                    break;
                }
                codegen = new Fasm.CodeGen(parser.tstack);
                codegen.Generate(ostr);
                break;

            case "-cexe":
                parser = new Parser(new Scaner(istr));
                parser.Parse();
                if (!parser.logger.isEmpty())
                {
                    ostr.WriteLine(parser.logger.ToString());
                    break;
                }
                codegen = new Fasm.CodeGen(parser.tstack);
                codegen.Generate(ostr);
                ostr.Flush();
                ostr.Close();
                if (index_out < args.Count())
                {
                    Process.Start(new ProcessStartInfo
                    {
                        FileName    = "C:/fasm/fasm.exe",
                        WindowStyle = ProcessWindowStyle.Hidden,
                        Arguments   = string.Format("{0} {1}", args[index_out], args[index_out])
                    });
                }
                break;

            default:
                Help();
                return;
            }

            istr.Close();
            ostr.Close();
        }