-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
16ecea6
commit 89d2541
Showing
35 changed files
with
981 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
using System; | ||
|
||
namespace Mosa.Compiler.Framework | ||
{ | ||
public delegate void StubMethodDelegate(Context context, MethodCompiler methodCompiler); | ||
|
||
/// <summary> | ||
/// Used for defining targets when using intrinsic replacements | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] | ||
public class StubMethodAttribute : Attribute | ||
{ | ||
public string Target { get; } | ||
|
||
public StubMethodAttribute(string target) | ||
{ | ||
Target = target; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
namespace Mosa.Compiler.Framework.Intrinsics | ||
{ | ||
/// <summary> | ||
/// IntrinsicMethods | ||
/// </summary> | ||
static partial class StubMethods | ||
{ | ||
[StubMethod("System.ByReference`1::.ctor")] | ||
public static void ByReference__ctor(Context context, MethodCompiler methodCompiler) | ||
{ | ||
var instance = methodCompiler.Parameters[0]; | ||
var value = methodCompiler.Parameters[1]; | ||
var opInstance = methodCompiler.AllocateVirtualRegisterOrStackSlot(instance.Type); | ||
var opValue = methodCompiler.AllocateVirtualRegisterOrStackSlot(value.Type); | ||
|
||
// Load instance parameter | ||
var loadInstance = BaseMethodCompilerStage.GetLoadParameterInstruction(instance.Type, methodCompiler.Architecture.Is32BitPlatform); | ||
context.AppendInstruction(loadInstance, opInstance, instance); | ||
|
||
// Load value parameter | ||
var loadValue = BaseMethodCompilerStage.GetLoadParameterInstruction(value.Type, methodCompiler.Architecture.Is32BitPlatform); | ||
context.AppendInstruction(loadValue, opValue, value); | ||
|
||
// Store value inside instance | ||
var store = methodCompiler.Architecture.Is32BitPlatform ? (BaseInstruction)IRInstruction.Store32 : IRInstruction.Store64; | ||
context.AppendInstruction(store, null, opInstance, methodCompiler.ConstantZero, opValue); | ||
context.MosaType = methodCompiler.TypeSystem.BuiltIn.I; | ||
|
||
context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock); | ||
} | ||
|
||
[StubMethod("System.ByReference`1::get_Value")] | ||
public static void ByReference_get_Value(Context context, MethodCompiler methodCompiler) | ||
{ | ||
var instance = methodCompiler.Parameters[0]; | ||
var opInstance = methodCompiler.AllocateVirtualRegisterOrStackSlot(instance.Type); | ||
var opReturn = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType); | ||
|
||
// Load instance parameter | ||
var loadInstance = BaseMethodCompilerStage.GetLoadParameterInstruction(instance.Type, methodCompiler.Architecture.Is32BitPlatform); | ||
context.AppendInstruction(loadInstance, opInstance, instance); | ||
|
||
// Load value from instance into return operand | ||
var loadValue = methodCompiler.Architecture.Is32BitPlatform ? (BaseInstruction)IRInstruction.Load32 : IRInstruction.Load64; | ||
context.AppendInstruction(loadValue, opReturn, opInstance, methodCompiler.ConstantZero); | ||
context.MosaType = methodCompiler.TypeSystem.BuiltIn.I; | ||
|
||
// Set return | ||
var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Architecture.Is32BitPlatform); | ||
context.AppendInstruction(setReturn, null, opReturn); | ||
|
||
context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) MOSA Project. Licensed under the New BSD License. | ||
|
||
namespace Mosa.Compiler.Framework.Intrinsics | ||
{ | ||
/// <summary> | ||
/// IntrinsicMethods | ||
/// </summary> | ||
static partial class StubMethods | ||
{ | ||
[StubMethod("System.Runtime.CompilerServices.RuntimeHelpers::IsReferenceOrContainsReferences")] | ||
public static void RuntimeHelpers_IsReferenceOrContainsReferences(Context context, MethodCompiler methodCompiler) | ||
{ | ||
var type = methodCompiler.Method.GenericArguments[0]; | ||
var opReturn = methodCompiler.AllocateVirtualRegisterOrStackSlot(methodCompiler.Method.Signature.ReturnType); | ||
|
||
// FIXME: we're only checking if the current type is a reference type, we aren't checking if it contains references | ||
var isReferenceOrContainsReferences = type.IsReferenceType; | ||
|
||
// Move constant into return operand | ||
var move = methodCompiler.Architecture.Is32BitPlatform ? (BaseInstruction)IRInstruction.Move32 : IRInstruction.Move64; | ||
context.AppendInstruction(move, opReturn, methodCompiler.CreateConstant(isReferenceOrContainsReferences ? 1 : 0)); | ||
|
||
// Set return | ||
var setReturn = BaseMethodCompilerStage.GetSetReturnInstruction(opReturn.Type, methodCompiler.Architecture.Is32BitPlatform); | ||
context.AppendInstruction(setReturn, null, opReturn); | ||
|
||
context.AppendInstruction(IRInstruction.Jmp, methodCompiler.BasicBlocks.EpilogueBlock); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.