Пример #1
0
        /// <summary>
        /// Preprocesses the specified ASM library.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Loops over all the ASM blocks, removing empty ones, checking plug paths and 
        /// preprocessing non-empty blocks.
        /// </para>
        /// </remarks>
        /// <param name="TheLibrary">The library to preprocess.</param>
        /// <returns>Always CompileResult.OK. In all other cases, exceptions are thrown.</returns>
        public static CompileResult Preprocess(ASMLibrary TheLibrary)
        {
            CompileResult result = CompileResult.OK;

            if (TheLibrary.ASMPreprocessed)
            {
                return result;
            }
            TheLibrary.ASMPreprocessed = true;

            for (int i = 0; i < TheLibrary.ASMBlocks.Count; i++)
            {
                ASMBlock aBlock = TheLibrary.ASMBlocks[i];
                if (aBlock.Plugged)
                {
                    if (string.IsNullOrWhiteSpace(aBlock.PlugPath))
                    {
                        TheLibrary.ASMBlocks.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
                else
                {
                    if (aBlock.ASMOps.Count == 0)
                    {
                        TheLibrary.ASMBlocks.RemoveAt(i);
                        i--;
                        continue;
                    }
                    Preprocess(aBlock);
                }
            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// Preprocesses the specified ASM library.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Loops over all the ASM blocks, removing empty ones, checking plug paths and
        /// preprocessing non-empty blocks.
        /// </para>
        /// </remarks>
        /// <param name="TheLibrary">The library to preprocess.</param>
        /// <returns>Always CompileResult.OK. In all other cases, exceptions are thrown.</returns>
        public static CompileResult Preprocess(ASMLibrary TheLibrary)
        {
            CompileResult result = CompileResult.OK;

            if (TheLibrary.ASMPreprocessed)
            {
                return(result);
            }
            TheLibrary.ASMPreprocessed = true;

            for (int i = 0; i < TheLibrary.ASMBlocks.Count; i++)
            {
                ASMBlock aBlock = TheLibrary.ASMBlocks[i];
                if (aBlock.Plugged)
                {
                    if (string.IsNullOrWhiteSpace(aBlock.PlugPath))
                    {
                        TheLibrary.ASMBlocks.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
                else
                {
                    if (aBlock.ASMOps.Count == 0)
                    {
                        TheLibrary.ASMBlocks.RemoveAt(i);
                        i--;
                        continue;
                    }
                    Preprocess(aBlock);
                }
            }

            return(result);
        }
Пример #3
0
 /// <summary>
 /// Executes the ASM Processor for the specified library.
 /// </summary>
 /// <param name="TheLibrary">The library to execute the processor on.</param>
 /// <returns>The return value from the ASMProcessor.Process method.</returns>
 private static CompileResult ExecuteASMProcessor(ASMLibrary TheLibrary)
 {
     return(ASMProcessor.Process(TheLibrary));
 }
Пример #4
0
        /// <summary>
        /// Processes the given ASM library.
        /// </summary>
        /// <param name="TheLibrary">The library to process.</param>
        /// <returns>Always CompileResult.OK. In all other cases, exceptions are thrown.</returns>
        public static CompileResult Process(ASMLibrary TheLibrary)
        {
            CompileResult result = CompileResult.OK;

            if (TheLibrary.ASMProcessed)
            {
                return result;
            }
            TheLibrary.ASMProcessed = true;
            
            int MaxConcurrentCompilerProcesses = Environment.ProcessorCount;
            List<List<ASMBlock>> CompilerLabourDivision = new List<List<ASMBlock>>();
            for (int i = 0; i < MaxConcurrentCompilerProcesses; i++)
            {
                CompilerLabourDivision.Add(new List<ASMBlock>());
            }

            int num = 0;
            foreach (ASMBlock aBlock in TheLibrary.ASMBlocks)
            {
                ProcessBlock(aBlock);

                if (aBlock.ASMOutputFilePath != null)
                {
                    CompilerLabourDivision[num % MaxConcurrentCompilerProcesses].Add(aBlock);
                    num++;
                }
            }

            TheLibrary.ASMBlocks.RemoveAll(x => x.ASMOutputFilePath == null);

#if COMPILER_ASYNC
            List<bool> Completed = new List<bool>();
            for (int i = 0; i < MaxConcurrentCompilerProcesses; i++)
            {
                Completed.Add(false);
                ExecuteAssemblyCodeCompilerAsync(CompilerLabourDivision[i],
                    delegate(object state)
                    {
                        Completed[(int)state] = true;
                    },
                    i);
            }

            for (int i = 0; i < MaxConcurrentCompilerProcesses; i++)
            {
                while (!Completed[i])
                {
                    System.Threading.Thread.Sleep(100);
                }
            }
#else

            for (int i = 0; i < MaxConcurrentCompilerProcesses; i++)
            {
                ExecuteAssemblyCodeCompilerSync(CompilerLabourDivision[i]);
            }

#endif

            return result;
        }
Пример #5
0
 /// <summary>
 /// Executes the ASM Processor for the specified library.
 /// </summary>
 /// <param name="TheLibrary">The library to execute the processor on.</param>
 /// <returns>The return value from the ASMProcessor.Process method.</returns>
 private static CompileResult ExecuteASMProcessor(ASMLibrary TheLibrary)
 {
     return ASMProcessor.Process(TheLibrary);
 }