Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mosa/MOSA-Project into 49…
Browse files Browse the repository at this point in the history
…0-wip
  • Loading branch information
tgiphil committed May 10, 2024
2 parents 9176511 + a6f7beb commit 4d462d3
Show file tree
Hide file tree
Showing 26 changed files with 553 additions and 529 deletions.
1 change: 1 addition & 0 deletions Source/Mosa.Packages/Mosa.Tools.Package.Qemu.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
<file src="..\..\bin\SkiaSharp.dll" target="contentFiles/any/net8.0/Tools" />
<file src="..\..\bin\HarfBuzzSharp.dll" target="contentFiles/any/net8.0/Tools" />
<file src="..\..\bin\Tmds.DBus.Protocol.dll" target="contentFiles/any/net8.0/Tools" />
<file src="..\..\bin\MicroCom.Runtime.dll" target="contentFiles/any/net8.0/Tools" />
</files>
</package>
1 change: 1 addition & 0 deletions Source/Mosa.Packages/Mosa.Tools.Package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
<file src="..\..\bin\SkiaSharp.dll" target="contentFiles/any/net8.0/Tools" />
<file src="..\..\bin\HarfBuzzSharp.dll" target="contentFiles/any/net8.0/Tools" />
<file src="..\..\bin\Tmds.DBus.Protocol.dll" target="contentFiles/any/net8.0/Tools" />
<file src="..\..\bin\MicroCom.Runtime.dll" target="contentFiles/any/net8.0/Tools" />
</files>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "Tools/Mosa.Tool.Launcher.dll Mosa.Starter.x86.dll",
"workingDirectory": "bin"
"workingDirectory": "$(ProjectDir)bin"
}
}
}
9 changes: 5 additions & 4 deletions Source/Mosa.Tool.Debugger/Views/InstructionView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ private void UpdateDisplay(ulong address, byte[] memory)
{
instructions.Clear();

var disassembler = new Disassembler("x86");
disassembler.SetMemory(memory, address);
var disassembler = new Disassembler("x86", memory, address);
var instruction = disassembler.DecodeNext();

foreach (var instruction in disassembler.Decode())
while (instruction != null)
{
var entry = new InstructionEntry()
{
IP = instruction.Address,
Length = instruction.Length,
Length = (int)instruction.Length,
Instruction = instruction.Instruction.ToString()
};

instructions.Add(entry);
instruction = disassembler.DecodeNext();
}
}

Expand Down
9 changes: 5 additions & 4 deletions Source/Mosa.Tool.Debugger/Views/MethodView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ private void UpdateDisplay(ulong address, byte[] memory)
{
instructions.Clear();

var disassembler = new Disassembler("x86");
disassembler.SetMemory(memory, address);
var disassembler = new Disassembler("x86", memory, address);
var instruction = disassembler.DecodeNext();

foreach (var instruction in disassembler.Decode())
while (instruction != null)
{
var addr = MainForm.ParseAddress(instruction.Instruction);

Expand All @@ -160,12 +160,13 @@ private void UpdateDisplay(ulong address, byte[] memory)
var entry = new MethodInstructionEntry()
{
IP = instruction.Address, // Offset?
Length = instruction.Length,
Length = (int)instruction.Length,
Instruction = instruction.Instruction,
Info = info
};

instructions.Add(entry);
instruction = disassembler.DecodeNext();
}
}

Expand Down
8 changes: 4 additions & 4 deletions Source/Mosa.Tool.Debugger/Views/StatusView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ private void UpdateDisplay(ulong address, byte[] memory)
if (address != InstructionPointer)
return;

var disassembler = new Disassembler("x86");
disassembler.SetMemory(memory, address);
var disassembler = new Disassembler("x86", memory, address);

tbInstruction.Text = "Unable to decode!";

foreach (var instruction in disassembler.Decode())
var instruction = disassembler.DecodeNext();
while (instruction != null)
{
tbInstruction.Text = instruction.Instruction;
break;
instruction = disassembler.DecodeNext();
}
}
}
8 changes: 4 additions & 4 deletions Source/Mosa.Tool.Debugger/Views/TraceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ private void UpdateDisplay(ulong address, byte[] memory)

if (address == InstructionPointer)
{
var disassembler = new Disassembler("x86");
disassembler.SetMemory(memory, address);
var disassembler = new Disassembler("x86", memory, address);
var instruction = disassembler.DecodeNext();

foreach (var instruction in disassembler.Decode())
while (instruction != null)
{
opinstruction = instruction.Instruction;
break;
instruction = disassembler.DecodeNext();
}
}

Expand Down
6 changes: 0 additions & 6 deletions Source/Mosa.Tool.Explorer.Avalonia/CompilerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public void UpdateLog(string section, List<string> lines, bool dirty)
}

lock (log)
{
log.AddRange(lines);
}

DirtyLog = dirty;
}
Expand All @@ -59,9 +57,7 @@ private void UpdateLog(string section, string line)
}

lock (log)
{
log.Add(line);
}

DirtyLog = true;
}
Expand All @@ -70,9 +66,7 @@ private void UpdateLog(string section, string line)
public List<string> GetLog(string section)
{
lock (Logs)
{
return Logs.GetValueOrDefault(section);
}
}

public void AddTraceEvent(CompilerEvent compilerEvent, string message, int threadID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ protected override void Finalization()
var log = new TraceLog(TraceType.GlobalDebug, null, null, "Compiler Time");

log.Log("Ticks\tMilliseconds\tCompiler Count\tMethod");

foreach (var data in methods)
log.Log($"{data.ElapsedTicks}{'\t'}{data.ElapsedTicks / TimeSpan.TicksPerMillisecond}{'\t'}{data.Version}{'\t'}{data.Method.FullName}");

Expand Down
193 changes: 193 additions & 0 deletions Source/Mosa.Tool.Explorer.Avalonia/FormatInstructions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.Text;

namespace Mosa.Tool.Explorer.Avalonia;

public static class FormatInstructions
{
private const int Padding = 34;

public static string Format(List<InstructionRecord> records, string blockLabel, bool strip, bool removeNop, bool lineBetweenBlocks)
{
var sb = new StringBuilder();
var blocks = new StringBuilder();

if (records == null || records.Count == 0)
return string.Empty;

var allLines = string.IsNullOrWhiteSpace(blockLabel);
var inBlock = allLines;

foreach (var record in records)
{
switch (record.Type)
{
case "M":
{
sb.AppendLine($"{record.MethodName} [v{record.Version}] @ {record.Stage}:");
sb.AppendLine();
break;
}
case "S":
{
inBlock = record.BlockLabel == blockLabel;

if (!inBlock && !allLines)
continue;

sb.Append($"{record.BlockLabel}:");

blocks.Clear();

// Previous Branch Targets
if (record.PreviousBlockCount != 0)
{
for (var i = 0; i < record.PreviousBlockCount; i++)
{
if (i != 0)
blocks.Append(' ');

var op = record.GetPreviousBlocks(i);

blocks.Append(op);
}

sb.Append("".PadRight(record.PreviousBlockCount == 1 ? Padding : Padding - 8));

sb.Append(blocks);
}

sb.AppendLine();
break;
}
case "I":
{
if (!inBlock && !allLines)
continue;

if (record.Instruction is "IR.BlockStart" or "IR.BlockEnd")
break;

if (removeNop && record.Instruction == "IR.Nop")
continue;

sb.Append(" ");

var instruction = record.Instruction;
var condition = !string.IsNullOrEmpty(record.Condition) ? " [" + record.Condition + "]" : string.Empty;

var both = $"{instruction}{condition}";

blocks.Clear();

// Branch Targets
if (record.BranchTargetCount != 0)
{
if (condition.Length != 0)
blocks.Append(' ');

for (var i = 0; i < record.BranchTargetCount; i++)
{
if (i != 0)
blocks.Append(' ');

var op = record.GetBranchTarget(i);

blocks.Append(op);
}
}

var count = Padding + 2 - both.Length - blocks.Length;
if (count < 0)
count = 1;

var padding = string.Empty.PadRight(count);

sb.Append($"{record.Label[..5]}:{record.Mark.PadLeft(1)}{both}{padding}{blocks} ");

// Result
for (var i = 0; i < record.ResultCount; i++)
{
if (i != 0)
sb.Append(", ");

var op = record.GetResult(i);

op = Simplify(op);

if (strip)
op = StripBracketData(op);

sb.Append(op);
}

if (record.ResultCount != 0 && record.OperandCount != 0)
sb.Append(" <= ");

// Operands
for (var i = 0; i < record.OperandCount; i++)
{
if (i != 0)
sb.Append(", ");

var op = record.GetOperand(i);

op = Simplify(op);

if (strip)
op = StripBracketData(op);

sb.Append(op);
}

// Phi Blocks
if (record.PhiBlockCount != 0)
{
sb.Append(" (");

for (var i = 0; i < record.PhiBlockCount; i++)
{
if (i != 0)
sb.Append(", ");

var op = record.GetPhilBlock(i);

sb.Append(op);
}

sb.Append(") ");
}

while (sb.Length > 0 && sb[^1] == ' ')
sb.Length--;

sb.AppendLine();
break;
}
case "E":
{
inBlock = false;

if (!inBlock && !allLines)
continue;

if (lineBetweenBlocks)
sb.AppendLine();

break;
}
}
}

return sb.ToString();
}

private static string StripBracketData(string s)
{
var i = s.IndexOf('[');
return i <= 0 ? s : s[..(i - 1)].Trim();
}

private static string Simplify(string s) => s.Replace("const=", string.Empty);
}
Loading

0 comments on commit 4d462d3

Please sign in to comment.