Skip to content

Commit

Permalink
- WIP (working)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgiphil committed Oct 28, 2023
1 parent c4a1c9d commit 841b7f6
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Source/Mosa.Compiler.Framework/CompilerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Version GetVersion()
if (version.Build == 0)
{
// Revision and build number are reversed by design
version = new Version(2, 5, 0, 0);
version = new Version(2, 6, 0, 0);
}

return version;
Expand Down
1 change: 0 additions & 1 deletion Source/Mosa.Compiler.Framework/MosaCompiler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System;
using Mosa.Compiler.Framework.Linker;
using Mosa.Compiler.MosaTypeSystem;
using Mosa.Utility.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ public override void Transform(Context context, Transform transform)
}

var handlerBlock = transform.BasicBlocks.GetByLabel(handler.HandlerStart);
var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

context.SetInstruction(IRInstruction.MoveObject, transform.LeaveTargetRegister, Operand.CreateConstant32(target.Label));
context.AppendInstruction(IRInstruction.MoveObject, exceptionRegister, Operand.NullObject);
context.AppendInstruction(IRInstruction.MoveObject, transform.ExceptionRegister, Operand.NullObject);
context.AppendInstruction(IRInstruction.Jmp, handlerBlock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ public ExceptionStart() : base(IRInstruction.ExceptionStart, TransformType.Manua
public override void Transform(Context context, Transform transform)
{
var exceptionVirtualRegister = context.Result;
var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

context.SetInstruction(IRInstruction.KillAll);
context.AppendInstruction(IRInstruction.Gen, exceptionRegister);
context.AppendInstruction(IRInstruction.MoveObject, exceptionVirtualRegister, exceptionRegister);
context.AppendInstruction(IRInstruction.Gen, transform.ExceptionRegister);
context.AppendInstruction(IRInstruction.MoveObject, exceptionVirtualRegister, transform.ExceptionRegister);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public override void Transform(Context context, Transform transform)
context.SetInstruction(IRInstruction.BranchObject, ConditionCode.NotEqual, null, exceptionVirtualRegister, Operand.NullObject, exceptionCallBlock.Block);
context.AppendInstruction(IRInstruction.Jmp, newBlocks[1].Block);

var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

exceptionCallBlock.AppendInstruction(IRInstruction.MoveObject, exceptionRegister, exceptionVirtualRegister);
exceptionCallBlock.AppendInstruction(IRInstruction.MoveObject, transform.ExceptionRegister, exceptionVirtualRegister);
exceptionCallBlock.AppendInstruction(IRInstruction.CallStatic, null, Operand.CreateLabel(exceptionManager.ExceptionHandler, transform.Is32BitPlatform));

transform.MethodScanner.MethodInvoked(exceptionManager.ExceptionHandler, transform.Method);
Expand All @@ -76,7 +74,7 @@ public override void Transform(Context context, Transform transform)

if (next != null)
{
finallyCallBlock.AppendInstruction(IRInstruction.MoveObject, exceptionRegister, Operand.NullObject);
finallyCallBlock.AppendInstruction(IRInstruction.MoveObject, transform.ExceptionRegister, Operand.NullObject);
finallyCallBlock.AppendInstruction(IRInstruction.MoveObject, transform.LeaveTargetRegister, leaveTargetRegister);
finallyCallBlock.AppendInstruction(IRInstruction.Jmp, transform.BasicBlocks.GetByLabel(next.HandlerStart));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ public override void Transform(Context context, Transform transform)

var exceptionVirtualRegister = context.Result;
var leaveTargetVirtualRegister = context.Result2;
var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

context.SetInstruction(IRInstruction.KillAll);
context.AppendInstruction(IRInstruction.Gen, exceptionRegister);
context.AppendInstruction(IRInstruction.Gen, transform.ExceptionRegister);
context.AppendInstruction(IRInstruction.Gen, transform.LeaveTargetRegister);

context.AppendInstruction(IRInstruction.MoveObject, exceptionVirtualRegister, exceptionRegister);
context.AppendInstruction(IRInstruction.MoveObject, exceptionVirtualRegister, transform.ExceptionRegister);
context.AppendInstruction(IRInstruction.MoveObject, leaveTargetVirtualRegister, transform.LeaveTargetRegister);

exceptionManager.ExceptionVirtualRegisters.Add(context.Block, exceptionVirtualRegister);
Expand Down
3 changes: 1 addition & 2 deletions Source/Mosa.Compiler.Framework/Transforms/Exception/Throw.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ public Throw() : base(IRInstruction.Throw, TransformType.Manual | TransformType.
public override void Transform(Context context, Transform transform)
{
var method = transform.Compiler.PlatformInternalRuntimeType.FindMethodByName("ExceptionHandler");
var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

context.SetInstruction(IRInstruction.MoveObject, exceptionRegister, context.Operand1);
context.SetInstruction(IRInstruction.MoveObject, transform.ExceptionRegister, context.Operand1);
context.AppendInstruction(IRInstruction.CallStatic, null, Operand.CreateLabel(method, transform.Is32BitPlatform));

transform.MethodScanner.MethodInvoked(method, transform.Method);
Expand Down
8 changes: 2 additions & 6 deletions Source/Mosa.Compiler.Framework/Transforms/Exception/TryEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public override void Transform(Context context, Transform transform)

if (immediate.ExceptionHandlerType == ExceptionHandlerType.Finally)
{
var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

context.SetInstruction(IRInstruction.MoveObject, transform.LeaveTargetRegister, Operand.CreateConstant32(target.Label));
context.AppendInstruction(IRInstruction.MoveObject, exceptionRegister, Operand.NullObject);
context.AppendInstruction(IRInstruction.MoveObject, transform.ExceptionRegister, Operand.NullObject);
context.AppendInstruction(IRInstruction.Jmp, transform.BasicBlocks.GetByLabel(immediate.HandlerStart));
return;
}
Expand All @@ -38,10 +36,8 @@ public override void Transform(Context context, Transform transform)

if (next != null && next.HandlerEnd > immediate.HandlerEnd)
{
var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

context.SetInstruction(IRInstruction.MoveObject, transform.LeaveTargetRegister, Operand.CreateConstant32(target.Label));
context.AppendInstruction(IRInstruction.MoveObject, exceptionRegister, Operand.NullObject);
context.AppendInstruction(IRInstruction.MoveObject, transform.ExceptionRegister, Operand.NullObject);
context.AppendInstruction(IRInstruction.Jmp, transform.BasicBlocks.GetByLabel(next.HandlerStart));
return;
}
Expand Down
4 changes: 1 addition & 3 deletions Source/Mosa.Compiler.x64/Intrinsic/FrameJump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ private static void FrameJump(Context context, Transform transform)
var rbx = transform.PhysicalRegisters.Allocate64(CPURegister.RBX);
var rcx = transform.PhysicalRegisters.Allocate64(CPURegister.RCX);

var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

// Move all virtual registers into physical registers - necessary since stack frame pointer will change
context.SetInstruction(X64.Mov64, rax, v0);
context.AppendInstruction(X64.Mov64, rbx, v1);
context.AppendInstruction(X64.Mov64, rcx, v2);
context.AppendInstruction(X64.Mov64, exceptionRegister, v3);
context.AppendInstruction(X64.Mov64, transform.ExceptionRegister, v3);

// Update the frame and stack registers
context.AppendInstruction(X64.Mov64, rbp, rcx);
Expand Down
4 changes: 1 addition & 3 deletions Source/Mosa.Compiler.x86/Intrinsic/FrameJump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ private static void FrameJump(Context context, Transform transform)
var ebx = transform.PhysicalRegisters.Allocate32(CPURegister.EBX);
var ecx = transform.PhysicalRegisters.Allocate32(CPURegister.ECX);

var exceptionRegister = transform.PhysicalRegisters.AllocateObject(transform.Architecture.ExceptionRegister);

// Move all virtual registers into physical registers - necessary since stack frame pointer will change
context.SetInstruction(X86.Mov32, eax, v0);
context.AppendInstruction(X86.Mov32, ebx, v1);
context.AppendInstruction(X86.Mov32, ecx, v2);
context.AppendInstruction(X86.Mov32, exceptionRegister, v3);
context.AppendInstruction(X86.Mov32, transform.ExceptionRegister, v3);

// Update the frame and stack registers
context.AppendInstruction(X86.Mov32, ebp, ecx);
Expand Down

0 comments on commit 841b7f6

Please sign in to comment.