/// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler" /> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="basicBlocks">The basic blocks.</param>
        /// <param name="threadID">The thread identifier.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, MosaMethod method, BasicBlocks basicBlocks, int threadID)
        {
            Compiler = compiler;
            Method = method;
            Type = method.DeclaringType;
            Scheduler = compiler.CompilationScheduler;
            Architecture = compiler.Architecture;
            TypeSystem = compiler.TypeSystem;
            TypeLayout = compiler.TypeLayout;
            Trace = compiler.CompilerTrace;
            Linker = compiler.Linker;
            BasicBlocks = basicBlocks ?? new BasicBlocks();
            Pipeline = new CompilerPipeline();
            StackLayout = new StackLayout(Architecture, method.Signature.Parameters.Count + (method.HasThis || method.HasExplicitThis ? 1 : 0));
            VirtualRegisters = new VirtualRegisters(Architecture);
            LocalVariables = emptyOperandList;
            ThreadID = threadID;
            DominanceAnalysis = new Dominance(Compiler.CompilerOptions.DominanceAnalysisFactory, BasicBlocks);
            PluggedMethod = compiler.PlugSystem.GetPlugMethod(Method);
            stop = false;

            MethodData = compiler.CompilerData.GetCompilerMethodData(Method);
            MethodData.Counters.Clear();

            EvaluateParameterOperands();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="VirtualRegisterLayout"/> class.
 /// </summary>
 /// <param name="architecture">The architecture.</param>
 /// <param name="stackLayout">The stack layout.</param>
 public VirtualRegisterLayout(IArchitecture architecture, StackLayout stackLayout)
 {
     this.architecture = architecture;
     this.stackLayout = stackLayout;
 }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            if (pipeline == null)
                throw new ObjectDisposedException(@"MethodCompilerBase");

            foreach (IMethodCompilerStage mcs in pipeline)
            {
                IDisposable d = mcs as IDisposable;
                if (d != null)
                    d.Dispose();
            }

            pipeline = null;
            architecture = null;
            linker = null;
            method = null;
            type = null;
            instructionSet = null;
            basicBlocks = null;
            stackLayout = null;
            locals = null;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="compiler">The assembly compiler.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="instructionSet">The instruction set.</param>
        protected BaseMethodCompiler(BaseCompiler compiler, RuntimeMethod method, InstructionSet instructionSet)
        {
            this.compiler = compiler;
            this.method = method;
            this.type = method.DeclaringType;
            this.compilationScheduler = compiler.Scheduler;
            this.moduleTypeSystem = method.Module;
            this.architecture = compiler.Architecture;
            this.typeSystem = compiler.TypeSystem;
            this.typeLayout = Compiler.TypeLayout;
            this.internalTrace = Compiler.InternalTrace;
            this.linker = compiler.Linker;

            this.basicBlocks = new BasicBlocks();

            this.instructionSet = instructionSet ?? new InstructionSet(256);

            this.pipeline = new CompilerPipeline();

            this.stackLayout = new StackLayout(architecture, method.Parameters.Count + (method.Signature.HasThis || method.Signature.HasExplicitThis ? 1 : 0));

            this.virtualRegisterLayout = new VirtualRegisterLayout(architecture, stackLayout);

            EvaluateParameterOperands();

            this.stopMethodCompiler = false;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseMethodCompiler"/> class.
        /// </summary>
        /// <param name="assemblyCompiler">The assembly compiler.</param>
        /// <param name="type">The type, which owns the method to compile.</param>
        /// <param name="method">The method to compile by this instance.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <param name="compilationScheduler">The compilation scheduler.</param>
        protected BaseMethodCompiler(AssemblyCompiler assemblyCompiler, RuntimeType type, RuntimeMethod method, InstructionSet instructionSet, ICompilationSchedulerStage compilationScheduler)
        {
            if (compilationScheduler == null)
                throw new ArgumentNullException(@"compilationScheduler");

            this.assemblyCompiler = assemblyCompiler;
            this.method = method;
            this.type = type;
            this.compilationScheduler = compilationScheduler;
            this.moduleTypeSystem = method.Module;

            this.architecture = assemblyCompiler.Architecture;
            this.typeSystem = assemblyCompiler.TypeSystem;
            this.typeLayout = AssemblyCompiler.TypeLayout;
            this.internalTrace = AssemblyCompiler.InternalTrace;

            this.linker = assemblyCompiler.Pipeline.FindFirst<IAssemblyLinker>();
            this.plugSystem = assemblyCompiler.Pipeline.FindFirst<IPlugSystem>();

            this.parameters = new List<Operand>(new Operand[method.Parameters.Count]);
            this.basicBlocks = new BasicBlocks();

            this.instructionSet = instructionSet ?? new InstructionSet(256);

            this.pipeline = new CompilerPipeline();

            this.stackLayout = new StackLayout(architecture, method.Parameters.Count + (method.Signature.HasThis || method.Signature.HasExplicitThis ? 1 : 0));

            this.virtualRegisterLayout = new VirtualRegisterLayout(architecture, stackLayout);

            EvaluateParameterOperands();
        }