Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Log.writeLine = WriteLine;
#if DEBUG
            Log.level = LogLevel.TRACE;
#else
            Log.level = LogLevel.INFO;
#endif

            if (args == null || args.Length < 1)
            {
                WriteLine(LogLevel.ERROR, msg.get("E0500"));
                return;
            }

            try
            {
                foreach (string arg in args)
                {
                    Compiler.Compiler compiler = new Compiler.Compiler();
                    compiler.Init();
                    byte[] dat = compiler.Start(arg);
                    if (dat != null)
                    {
                        File.WriteAllBytes(compiler.OutFileName, dat);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.FATAL, ex.Message);
                Log.WriteLine(LogLevel.FATAL, ex.StackTrace);
            }
        }
Exemplo n.º 2
0
        public void BPStart(string mainName, string mainPath, List <string> mainText, string moduleLibPath, string outFolderPrefix)
        {
            Status = true;

            string tmpName = mainName;
            var    ind     = mainName.LastIndexOf('.');

            if (ind != -1)
            {
                var ext = mainName.Substring(ind);
                if (ext == ".bp")
                {
                    Data.Project.Type = Enums.ProjectType.BP;
                }
                else if (ext == ".lms")
                {
                    Data.Project.Type = Enums.ProjectType.LMS;
                }

                tmpName = mainName.Substring(0, mainName.LastIndexOf('.'));
            }
            Data.Project.ModuleLibPath = moduleLibPath;
            Data.Project.Path          = mainPath;
            Data.Project.MainName      = mainName;

            _outFolder = outFolderPrefix + Data.Project.MainName.Replace(Extension.BPProgram, "");

            Console.Write("Interpreter start ... ");

            new Preprocessor().Start(tmpName, mainPath, mainText);

            if (Data.Errors.Count > 0)
            {
                Console.Write("\n");
                new ErrorShow().ShowToConsole();
                Status = false;
                return;
            }

            new Utils.Interpreter().Start();
            if (Data.Errors.Count > 0)
            {
                Console.Write("\n");
                new ErrorShow().ShowToConsole();
                Status = false;
                return;
            }

            var file = GetOutFile();

            WriteOutFile(file, outFolderPrefix);
            Console.Write("OK");

            // Компилятор
            Console.Write("\n");
            Console.Write("Compiler start ... ");
            WriteToStream(file, _streamI);
            _streamI.Position = 0;
            var errors = new List <string>();

            _compiler.Start(_streamI, _streamC, errors);
            if (errors.Count > 0)
            {
                Console.Write("\n");
                new ErrorShow().ShowToConsole(errors);
                Status = false;
                return;
            }
            _streamC.Position = 0;
            WriteStreamToFile(_streamC, ".lmsb");
            Console.Write("OK");

            // Ассемблер
            Console.Write("\n");
            Console.Write("Assembler start ... ");
            _streamC.Position = 0;
            _assembler.Start(_streamC, _streamA, errors);
            if (errors.Count > 0)
            {
                Console.Write("\n");
                new ErrorShow().ShowToConsole(errors);
                Status = false;
                return;
            }
            var content = _streamA.ToArray();

            WriteByteToFile(content, ".rbf");
            Console.Write("OK");
            Console.Write("\n");
        }