/// <summary> /// Keeps the debug assertion operation. /// </summary> protected override void Implement( IRContext context, Method.Builder methodBuilder, BasicBlock.Builder builder, DebugAssertOperation debugAssert) { }
/// <summary> /// Maps internal debug assertions to <see cref="AssertFailed(string, string, /// int, string, int)"/> method calls. /// </summary> protected override void Implement( IRContext context, Method.Builder methodBuilder, BasicBlock.Builder builder, DebugAssertOperation debugAssert) { var location = debugAssert.Location; // Create a call to the debug-implementation wrapper while taking the // current source location into account var nextBlock = builder.SplitBlock(debugAssert); var innerBlock = methodBuilder.CreateBasicBlock( location, nameof(AssertFailed)); builder.CreateIfBranch( location, debugAssert.Condition, nextBlock, innerBlock); // Create a call to the assert implementation var innerBuilder = methodBuilder[innerBlock]; var assertFailed = innerBuilder.CreateCall( location, context.Declare(AssertFailedMethod, out var _)); // Move the debug assertion to this block var sourceMessage = debugAssert.Message.ResolveAs <StringValue>(); var message = innerBuilder.CreatePrimitiveValue( location, sourceMessage.String, sourceMessage.Encoding); assertFailed.Add(message); // Append source location information var debugLocation = debugAssert.GetLocationInfo(); assertFailed.Add( innerBuilder.CreatePrimitiveValue(location, debugLocation.FileName)); assertFailed.Add( innerBuilder.CreatePrimitiveValue(location, debugLocation.Line)); assertFailed.Add( innerBuilder.CreatePrimitiveValue(location, debugLocation.Method)); assertFailed.Add( innerBuilder.CreatePrimitiveValue(location, 1)); // Finish the actual assertion call and branch assertFailed.Seal(); innerBuilder.CreateBranch(location, nextBlock); // Remove the debug assertion value debugAssert.Replace(builder.CreateUndefined()); }
/// <summary> /// Specializes debug operations via the instance method /// <see cref="Specialize(in RewriterContext, IRContext, DebugAssertOperation)"/> /// of the parent <paramref name="data"/> instance. /// </summary> private static void Specialize( RewriterContext context, SpecializerData data, DebugAssertOperation value) { if (data.EnableAssertions) { data.Specializer.Specialize(context, data.Context, value); } else { context.Remove(value); } }
/// <summary cref="IValueVisitor.Visit(DebugAssertOperation)"/> public void Visit(DebugAssertOperation debug) => CodeGenerator.GenerateCode(debug);
/// <summary> /// Specializes debug output operations (if any). Note that this default /// implementation removes the output operations from the current program. /// </summary> /// <param name="context">The parent IR context.</param> /// <param name="methodBuilder">The parent method builder.</param> /// <param name="builder">The current block builder.</param> /// <param name="debugAssert">The debug assert operation.</param> protected virtual void Implement( IRContext context, Method.Builder methodBuilder, BasicBlock.Builder builder, DebugAssertOperation debugAssert) => builder.Remove(debugAssert);
/// <summary cref="IBackendCodeGenerator.GenerateCode(DebugAssertOperation)"/> public void GenerateCode(DebugAssertOperation debug) => // Invalid debug node -> should have been removed debug.Assert(false);