/// <summary> /// Starts a code-generation phase. /// </summary> /// <param name="context">The target IR context.</param> /// <returns>The created code-generation phase.</returns> public CodeGenerationPhase BeginCodeGeneration(IRContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var newPhase = new CodeGenerationPhase(this, context, context.Verifier); if (Interlocked.CompareExchange( ref codeGenerationPhase, newPhase, null) != null) { throw new InvalidOperationException(); } driverNotifier.Reset(); return(newPhase); }
/// <summary> /// Finishes the current code-generation phase. /// </summary> /// <param name="phase">The current phase.</param> internal void FinishCodeGeneration(CodeGenerationPhase phase) { Debug.Assert(phase != null, "Invalid phase"); Debug.WriteLineIf( !phase.HadWorkToDo, "This code generation phase had nothing to do"); if (phase.HadWorkToDo) { driverNotifier.Wait(); } if (Interlocked.CompareExchange( ref codeGenerationPhase, null, phase) != phase) { throw new InvalidOperationException(); } }