Skip to content

Commit

Permalink
Extended ILEmitter by adding a new WriteLine instruction for debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rs-mt committed Jan 26, 2023
1 parent ed3f48a commit 872582e
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Src/ILGPU/Backends/IL/ILEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ public interface IILEmitter
/// <param name="labels">The jump targets.</param>
void EmitSwitch(ILLabel[] labels);

/// <summary>
/// Emits code to write something to the console.
/// </summary>
/// <param name="message">The message to write.</param>
void EmitWriteLine(string message);

/// <summary>
/// Finishes the code generation process.
/// </summary>
Expand Down Expand Up @@ -405,6 +411,10 @@ public void EmitSwitch(params ILLabel[] labels)
Generator.Emit(OpCodes.Switch, switchLabels);
}

/// <summary cref="IILEmitter.EmitWriteLine"/>
public void EmitWriteLine(string message) =>
Generator.EmitWriteLine(message);

/// <summary cref="IILEmitter.Finish"/>
public void Finish() { }

Expand Down Expand Up @@ -635,6 +645,10 @@ public void EmitSwitch(params ILLabel[] labels)
}
}

/// <summary cref="IILEmitter.EmitWriteLine"/>
public void EmitWriteLine(string message) =>
Writer.WriteLine($" => Write('{message}')");

/// <summary cref="IILEmitter.Finish"/>
public void Finish()
{
Expand Down Expand Up @@ -717,6 +731,9 @@ public void EmitConstant(double constant) { }
/// <summary cref="IILEmitter.EmitSwitch(ILLabel[])"/>
public void EmitSwitch(params ILLabel[] labels) { }

/// <summary cref="IILEmitter.EmitWriteLine"/>
public void EmitWriteLine(string message) { }

/// <summary cref="IILEmitter.Finish"/>
public void Finish() { }

Expand Down

0 comments on commit 872582e

Please sign in to comment.