예제 #1
0
        private static bool TryDoFlowScriptCompilation()
        {
            Logger.Info("Compiling FlowScript...");

            // Get format verson
            var version = GetFlowScriptFormatVersion();

            if (version == FormatVersion.Unknown)
            {
                Logger.Error("Invalid FlowScript file format specified");
                return(false);
            }

            // Compile source
            var compiler = new FlowScriptCompiler(version);

            compiler.AddListener(Listener);
            compiler.Encoding = MessageScriptEncoding;
            compiler.EnableProcedureTracing     = FlowScriptEnableProcedureTracing;
            compiler.EnableProcedureCallTracing = FlowScriptEnableProcedureCallTracing;
            compiler.EnableFunctionCallTracing  = FlowScriptEnableFunctionCallTracing;
            compiler.EnableStackCookie          = FlowScriptEnableStackCookie;
            compiler.ProcedureHookMode          = FlowScriptEnableProcedureHook ? ProcedureHookMode.ImportedOnly : ProcedureHookMode.None;

            if (LibraryName != null)
            {
                var library = LibraryLookup.GetLibrary(LibraryName);

                if (library == null)
                {
                    Logger.Error("Invalid library name specified");
                    return(false);
                }

                compiler.Library = library;
            }

            FlowScript flowScript = null;
            var        success    = false;

            using (var file = File.Open(InputFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                try
                {
                    success = compiler.TryCompile(file, out flowScript);
                }
                catch (UnsupportedCharacterException e)
                {
                    Logger.Error($"Character '{e.Character}' not supported by encoding '{e.EncodingName}'");
                }

                if (!success)
                {
                    Logger.Error("One or more errors occured during compilation!");
                    return(false);
                }
            }

            // Write binary
            Logger.Info("Writing binary to file...");
            return(TryPerformAction("An error occured while saving the file.", () => flowScript.ToFile(OutputFilePath)));
        }