Skip to content

Commit

Permalink
Added Source Information to Explorer Tool (#585)
Browse files Browse the repository at this point in the history
* - Debug Info Stage for Explorer
  • Loading branch information
tgiphil committed Feb 4, 2019
1 parent 30f4fd1 commit d447003
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
109 changes: 109 additions & 0 deletions Source/Mosa.Compiler.Framework/Stages/DebugInfoStage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;

namespace Mosa.Compiler.Framework.Stages
{
/// <summary>
/// Base class for code generation stages.
/// </summary>
public class DebugInfoStage : BaseMethodCompilerStage
{
protected override void Run()
{
DumpByInstructions();
DumpRegions();
DumpSourceInfo();
}

protected void DumpByInstructions()
{
var trace = CreateTraceLog("Instructions");

trace.Log("Label\tAddress\tLength\tStartLine\tEndLine\tStartColumn\tEndColumn\tInstruction\tDocument");

foreach (var block in BasicBlocks)
{
for (var node = block.First; !node.IsBlockEndInstruction; node = node.Next)
{
if (node.IsEmpty)
continue;

if (node.Instruction.IgnoreDuringCodeGeneration)
continue;

int Label = node.Label;
int StartLine = -1;
int EndLine = 0;
int EndColumn = 0;
int StartColumn = 0;
string Document = string.Empty;

//int Offset = node.Offset;

int Address = -1;
int Length = 0;

foreach (var instruction in Method.Code)
{
if (instruction.Offset != Label)
continue;

StartLine = instruction.StartLine;
EndLine = instruction.EndLine;
StartColumn = instruction.StartColumn;
EndColumn = instruction.EndColumn;
Document = instruction.Document;

break;
}

if (StartLine == -1)
continue;

foreach (var region in MethodData.LabelRegions)
{
if (region.Label != Label)
continue;

Address = region.Start;
Length = region.Length;
break;
}

if (Address == -1)
continue;

trace.Log(String.Format("{0:X5}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}",
Label, Address, Length, StartLine, EndLine, StartColumn, EndColumn, node.ToString(), Document));
}
}
}

protected void DumpRegions()
{
var trace = CreateTraceLog("Regions");

trace.Log("Label\tAddress\tLength");

foreach (var region in MethodData.LabelRegions)
{
trace.Log(String.Format("{0:X5}\t{1}\t{2}",
region.Label, region.Start, region.Length));
}
}

protected void DumpSourceInfo()
{
var trace = CreateTraceLog("Source");

trace.Log("Label\tStartLine\tEndLine\tStartColumn\tEndColumn\tDocument");

foreach (var instruction in Method.Code)
{
trace.Log(String.Format("{0:X5}\t{1}\t{2}\t{3}\t{4}\t{5}",
instruction.Offset, instruction.StartLine, instruction.EndLine, instruction.StartColumn, instruction.EndColumn, instruction.Document));
}
}
}
}
5 changes: 5 additions & 0 deletions Source/Mosa.Tool.Explorer/ExplorerCompilerExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using Mosa.Compiler.Framework;
using Mosa.Compiler.Framework.Stages;

namespace Mosa.Tool.Explorer
{
Expand All @@ -14,6 +15,10 @@ public override void ExtendMethodCompilerPipeline(Pipeline<BaseMethodCompilerSta
pipeline.Add(
new DisassemblyStage()
);

pipeline.Add(
new DebugInfoStage()
);
}
}
}

0 comments on commit d447003

Please sign in to comment.