Permalink
Browse files

- Added BasePlatformInstruction (has methods to assist with register …

…allocator)
  • Loading branch information...
1 parent d70412c commit 39eb52205278861e8e50967363d8c852c5bd980d @tgiphil tgiphil committed Mar 31, 2012
Showing with 184 additions and 63 deletions.
  1. +125 −0 Source/Mosa.Compiler.Framework/BasePlatformInstruction.cs
  2. +1 −3 Source/Mosa.Compiler.Framework/Mosa.Compiler.Framework.csproj
  3. +1 −3 Source/Mosa.Platform.x86/BaseTransformationStage.cs
  4. +3 −1 Source/{Mosa.Compiler.Framework → Mosa.Platform.x86/Constraints}/IRegisterConstraint.cs
  5. +1 −1 Source/Mosa.Platform.x86/IRTransformationStage.cs
  6. +2 −2 Source/Mosa.Platform.x86/Instructions/AdcInstruction.cs
  7. +2 −2 Source/Mosa.Platform.x86/Instructions/AddInstruction.cs
  8. +2 −2 Source/Mosa.Platform.x86/Instructions/AndInstruction.cs
  9. +8 −11 Source/Mosa.Platform.x86/Instructions/BaseInstruction.cs
  10. +1 −1 Source/Mosa.Platform.x86/Instructions/BranchInstruction.cs
  11. +1 −1 Source/Mosa.Platform.x86/Instructions/BreakInstruction.cs
  12. +1 −1 Source/Mosa.Platform.x86/Instructions/CallInstruction.cs
  13. +1 −1 Source/Mosa.Platform.x86/Instructions/CallPointerInstruction.cs
  14. +1 −1 Source/Mosa.Platform.x86/Instructions/CdqInstruction.cs
  15. +1 −1 Source/Mosa.Platform.x86/Instructions/CldInstruction.cs
  16. +1 −1 Source/Mosa.Platform.x86/Instructions/CliInstruction.cs
  17. +1 −1 Source/Mosa.Platform.x86/Instructions/FarJmpInstruction.cs
  18. +1 −1 Source/Mosa.Platform.x86/Instructions/HltInstruction.cs
  19. +1 −1 Source/Mosa.Platform.x86/Instructions/IRetdInstruction.cs
  20. +1 −1 Source/Mosa.Platform.x86/Instructions/JmpInstruction.cs
  21. +1 −1 Source/Mosa.Platform.x86/Instructions/LeaveInstruction.cs
  22. +1 −1 Source/Mosa.Platform.x86/Instructions/LiteralInstruction.cs
  23. +1 −1 Source/Mosa.Platform.x86/Instructions/LockInstruction.cs
  24. +2 −2 Source/Mosa.Platform.x86/Instructions/MovInstruction.cs
  25. +1 −1 Source/Mosa.Platform.x86/Instructions/NopInstruction.cs
  26. +1 −1 Source/Mosa.Platform.x86/Instructions/OneOperandInstruction.cs
  27. +2 −2 Source/Mosa.Platform.x86/Instructions/OrInstruction.cs
  28. +1 −1 Source/Mosa.Platform.x86/Instructions/PauseInstruction.cs
  29. +1 −1 Source/Mosa.Platform.x86/Instructions/PopInstruction.cs
  30. +1 −1 Source/Mosa.Platform.x86/Instructions/PopadInstruction.cs
  31. +1 −1 Source/Mosa.Platform.x86/Instructions/PopfdInstruction.cs
  32. +1 −1 Source/Mosa.Platform.x86/Instructions/PushInstruction.cs
  33. +1 −1 Source/Mosa.Platform.x86/Instructions/PushadInstruction.cs
  34. +1 −1 Source/Mosa.Platform.x86/Instructions/PushfdInstruction.cs
  35. +1 −1 Source/Mosa.Platform.x86/Instructions/RepInstruction.cs
  36. +1 −1 Source/Mosa.Platform.x86/Instructions/RetInstruction.cs
  37. +1 −1 Source/Mosa.Platform.x86/Instructions/SetccInstruction.cs
  38. +1 −1 Source/Mosa.Platform.x86/Instructions/SseRoundInstruction.cs
  39. +1 −1 Source/Mosa.Platform.x86/Instructions/StiInstruction.cs
  40. +1 −1 Source/Mosa.Platform.x86/Instructions/StosbInstruction.cs
  41. +1 −1 Source/Mosa.Platform.x86/Instructions/StosdInstruction.cs
  42. +2 −2 Source/Mosa.Platform.x86/Instructions/SubInstruction.cs
  43. +1 −1 Source/Mosa.Platform.x86/Instructions/ThreeOperandInstruction.cs
  44. +1 −1 Source/Mosa.Platform.x86/Instructions/TwoOperandInstruction.cs
  45. +1 −0 Source/Mosa.Platform.x86/Mosa.Platform.x86.csproj
@@ -0,0 +1,125 @@
+/*
+ * (c) 2008 MOSA - The Managed Operating System Alliance
+ *
+ * Licensed under the terms of the New BSD License.
+ *
+ * Authors:
+ * Phil Garcia (tgiphil) <phil@thinkedge.com>
+ */
+
+using System;
+using System.Text;
+
+namespace Mosa.Compiler.Framework
+{
+ /// <summary>
+ ///
+ /// </summary>
+ public abstract class BasePlatformInstruction : BaseInstruction
+ {
+
+ #region Data members
+
+ /// <summary>
+ /// Gets the usable result registers.
+ /// </summary>
+ public virtual Register[] UsableResultRegisters { get { return null; } }
+
+ /// <summary>
+ /// Gets the usable operand registers.
+ /// </summary>
+ public virtual Register[] UsableOperandRegisters { get { return null; } }
+
+ #endregion
+
+ #region Construction
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BaseInstruction"/> class.
+ /// </summary>
+ public BasePlatformInstruction()
+ : base()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BaseInstruction"/> class.
+ /// </summary>
+ /// <param name="operandCount">The operand count.</param>
+ public BasePlatformInstruction(byte operandCount)
+ : base(operandCount)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="BaseInstruction"/> class.
+ /// </summary>
+ /// <param name="operandCount">The operand count.</param>
+ /// <param name="resultCount">The result count.</param>
+ public BasePlatformInstruction(byte operandCount, byte resultCount)
+ : base(operandCount, resultCount)
+ {
+ }
+
+ #endregion // Construction
+
+ #region Methods
+
+ /// <summary>
+ /// Gets the used registers.
+ /// </summary>
+ /// <param name="results">The results.</param>
+ /// <param name="operand1">The operand1.</param>
+ /// <returns></returns>
+ public virtual Register[] GetUsedRegisters(Register results, Register operand1)
+ {
+ return GetUsedRegisters(results, operand1, null);
+ }
+
+ /// <summary>
+ /// Determines whether [is valid operand] [the specified result].
+ /// </summary>
+ /// <param name="result">The result.</param>
+ /// <returns>
+ /// <c>true</c> if [is valid operand] [the specified result]; otherwise, <c>false</c>.
+ /// </returns>
+ public bool IsValidOperand(Register result)
+ {
+ foreach (var register in UsableOperandRegisters)
+ if (result == register)
+ return true;
+
+ return false;
+ }
+
+ /// <summary>
+ /// Determines whether [is valid result operand] [the specified result].
+ /// </summary>
+ /// <param name="result">The result.</param>
+ /// <returns>
+ /// <c>true</c> if [is valid result operand] [the specified result]; otherwise, <c>false</c>.
+ /// </returns>
+ public bool IsValidResult(Register result)
+ {
+ foreach (var register in UsableResultRegisters)
+ if (result == register)
+ return true;
+
+ return false;
+ }
+
+ /// <summary>
+ /// Gets the used registers.
+ /// </summary>
+ /// <param name="results">The results.</param>
+ /// <param name="operand1">The operand1.</param>
+ /// <param name="operand2">The operand2.</param>
+ /// <returns></returns>
+ public virtual Register[] GetUsedRegisters(Register results, Register operand1, Register operand2)
+ {
+ return null;
+ }
+
+ #endregion // Methods
+ }
+}
@@ -89,6 +89,7 @@
<Compile Include="CIL\BreakInstruction.cs" />
<Compile Include="BaseAssemblyCompilerStage.cs" />
<Compile Include="ConstantFoldingStage.cs" />
+ <Compile Include="BasePlatformInstruction.cs" />
<Compile Include="OperandUsageAnalyzerStage.cs" />
<Compile Include="SingleUseMarkerStage.cs" />
<Compile Include="IPlugSystem.cs" />
@@ -338,9 +339,6 @@
<Compile Include="IPlatformStage.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="IRegisterConstraint.cs">
- <SubType>Code</SubType>
- </Compile>
<Compile Include="IStackLayoutProvider.cs">
<SubType>Code</SubType>
</Compile>
@@ -63,10 +63,8 @@ protected void EmitOperandConstants(Context ctx)
/// <param name="ctx">The context.</param>
protected void EmitResultConstants(Context ctx)
{
- if (ctx.ResultCount > 0)
+ if (ctx.ResultCount == 1)
ctx.Result = EmitConstant(ctx.Result);
- else if (ctx.OperandCount > 1)
- ctx.Result2 = EmitConstant(ctx.Result2);
}
/// <summary>
@@ -9,7 +9,9 @@
using Mosa.Compiler.Framework.Operands;
-namespace Mosa.Compiler.Framework
+using Mosa.Compiler.Framework;
+
+namespace Mosa.Platform.x86.Constraints
{
/// <summary>
/// This interface is used to present register constraints by native
@@ -480,7 +480,7 @@ void IR.IIRVisitor.MoveInstruction(Context context)
}
}
- private void MoveFloatingPoint(Context context, Instructions.BaseInstruction instruction)
+ private void MoveFloatingPoint(Context context, Instructions.X86Instruction instruction)
{
RegisterOperand xmm0 = new RegisterOperand(context.Result.Type, SSE2Register.XMM0);
Operand result = context.Result;
@@ -58,9 +58,9 @@ public override void Visit(IX86Visitor visitor, Context context)
}
/// <summary>
- /// Gets the usable registers.
+ /// Gets the usable result registers.
/// </summary>
- public override Register[] UsableRegisters
+ public override Register[] UsableResultRegisters
{
get { return GeneralPurpose32BitRegisters; }
}
@@ -60,9 +60,9 @@ public override void Visit(IX86Visitor visitor, Context context)
}
/// <summary>
- /// Gets the usable registers.
+ /// Gets the usable result registers.
/// </summary>
- public override Register[] UsableRegisters
+ public override Register[] UsableResultRegisters
{
get { return GeneralPurpose32BitRegisters; }
}
@@ -66,9 +66,9 @@ public override void Visit(IX86Visitor visitor, Context context)
}
/// <summary>
- /// Gets the usable registers.
+ /// Gets the usable result registers.
/// </summary>
- public override Register[] UsableRegisters
+ public override Register[] UsableResultRegisters
{
get { return GeneralPurpose32BitRegisters; }
}
@@ -15,11 +15,11 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
///
/// </summary>
- public abstract class BaseInstruction : Mosa.Compiler.Framework.BaseInstruction, IX86Instruction
+ public abstract class X86Instruction : BasePlatformInstruction, IX86Instruction
{
#region Data Members
-
+
/// <summary>
/// Defines the register set of the target architecture.
/// </summary>
@@ -56,27 +56,27 @@ public abstract class BaseInstruction : Mosa.Compiler.Framework.BaseInstruction,
#region Construction
/// <summary>
- /// Initializes a new instance of the <see cref="BaseInstruction"/> class.
+ /// Initializes a new instance of the <see cref="X86Instruction"/> class.
/// </summary>
- protected BaseInstruction()
+ protected X86Instruction()
{
}
/// <summary>
- /// Initializes a new instance of the <see cref="BaseInstruction"/> class.
+ /// Initializes a new instance of the <see cref="X86Instruction"/> class.
/// </summary>
/// <param name="operandCount">The operand count.</param>
- private BaseInstruction(byte operandCount)
+ private X86Instruction(byte operandCount)
: base(operandCount)
{
}
/// <summary>
- /// Initializes a new instance of the <see cref="BaseInstruction"/> class.
+ /// Initializes a new instance of the <see cref="X86Instruction"/> class.
/// </summary>
/// <param name="operandCount">The operand count.</param>
/// <param name="resultCount">The result count.</param>
- protected BaseInstruction(byte operandCount, byte resultCount)
+ protected X86Instruction(byte operandCount, byte resultCount)
: base(operandCount, resultCount)
{
}
@@ -151,9 +151,6 @@ public override string ToString()
return "X86." + base.ToString();
}
- /// <summary>
- /// Gets the usable registers.
- /// </summary>
public virtual Register[] UsableRegisters
{
get { return null; }
@@ -17,7 +17,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representation a x86 branch instruction.
/// </summary>
- public sealed class BranchInstruction : BaseInstruction
+ public sealed class BranchInstruction : X86Instruction
{
#region Data Members
@@ -14,7 +14,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
///
/// </summary>
- public class BreakInstruction : BaseInstruction
+ public class BreakInstruction : X86Instruction
{
#region Methods
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 call instruction.
/// </summary>
- public sealed class CallInstruction : BaseInstruction
+ public sealed class CallInstruction : X86Instruction
{
private static readonly OpCode RegCall = new OpCode(new byte[] { 0xFF }, 2);
private static readonly byte[] LabelCall = new byte[] { 0xE8 };
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 call instruction.
/// </summary>
- public sealed class CallPointerInstruction : BaseInstruction
+ public sealed class CallPointerInstruction : X86Instruction
{
private static readonly OpCode RegCall = new OpCode(new byte[] { 0xFF }, 2);
private static readonly byte[] LabelCall = new byte[] { 0xE8 };
@@ -14,7 +14,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 cdq instruction.
/// </summary>
- public sealed class CdqInstruction : BaseInstruction
+ public sealed class CdqInstruction : X86Instruction
{
#region Methods
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 cld instruction.
/// </summary>
- public sealed class CldInstruction : BaseInstruction
+ public sealed class CldInstruction : X86Instruction
{
#region Methods
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 cli instruction.
/// </summary>
- public sealed class CliInstruction : BaseInstruction
+ public sealed class CliInstruction : X86Instruction
{
#region Methods
@@ -15,7 +15,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representation the x86 jump instruction.
/// </summary>
- public sealed class FarJmpInstruction : BaseInstruction
+ public sealed class FarJmpInstruction : X86Instruction
{
#region Methods
@@ -14,7 +14,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 hlt instruction.
/// </summary>
- public sealed class HltInstruction : BaseInstruction
+ public sealed class HltInstruction : X86Instruction
{
#region Methods
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 iretd instruction.
/// </summary>
- public sealed class IRetdInstruction : BaseInstruction
+ public sealed class IRetdInstruction : X86Instruction
{
/// <summary>
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representation the x86 jump instruction.
/// </summary>
- public sealed class JmpInstruction : BaseInstruction
+ public sealed class JmpInstruction : X86Instruction
{
#region Data Members
@@ -15,7 +15,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
///
/// </summary>
- public sealed class LeaveInstruction : BaseInstruction
+ public sealed class LeaveInstruction : X86Instruction
{
#region Methods
@@ -16,7 +16,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Intermediate representation of the literal instruction.
/// </summary>
- public sealed class LiteralInstruction : BaseInstruction
+ public sealed class LiteralInstruction : X86Instruction
{
#region Methods
@@ -15,7 +15,7 @@ namespace Mosa.Platform.x86.Instructions
/// <summary>
/// Representations the x86 lock instruction.
/// </summary>
- public sealed class LockIntruction : BaseInstruction
+ public sealed class LockIntruction : X86Instruction
{
#region Methods
Oops, something went wrong.

0 comments on commit 39eb522

Please sign in to comment.