Skip to content

Commit

Permalink
Merge pull request #360 from tgiphil/master
Browse files Browse the repository at this point in the history
Fixed inlining with delegate method
  • Loading branch information
tgiphil authored Jan 24, 2017
2 parents 974d34d + c90645f commit bdb4eeb
Show file tree
Hide file tree
Showing 187 changed files with 1,106 additions and 1,142 deletions.
4 changes: 2 additions & 2 deletions Source/Mosa.Compiler.Framework/BaseCodeEmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ public void Write(byte[] buffer, int offset, int count)
/// Emits the specified opcode.
/// </summary>
/// <param name="opcode">The opcode.</param>
public void Emit(OpcodeEncoder opcode)
public void Emit(BaseOpcodeEncoder opcode)
{
opcode.WriteTo(codeStream);
}

public void Emit(OpcodeEncoder opcode, Operand symbolOperand, int patchOffset, int referenceOffset = 0)
public void Emit(BaseOpcodeEncoder opcode, Operand symbolOperand, int patchOffset, int referenceOffset = 0)
{
int pos = (int)codeStream.Position + patchOffset;

Expand Down
1 change: 1 addition & 0 deletions Source/Mosa.Compiler.Framework/BaseCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void Initialize(MosaCompiler compiler)
Compiler = compiler;

Architecture = Compiler.CompilerOptions.Architecture;

TypeSystem = Compiler.TypeSystem;
TypeLayout = Compiler.TypeLayout;
CompilerTrace = Compiler.CompilerTrace;
Expand Down
30 changes: 20 additions & 10 deletions Source/Mosa.Compiler.Framework/DelegatePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ private static void PatchConstructor(BaseMethodCompiler methodCompiler)
Operand v2 = methodCompiler.CreateVirtualRegister(methodPointerOperand.Type);
Operand v3 = methodCompiler.CreateVirtualRegister(instanceOperand.Type);

context.AppendInstruction(IRInstruction.LoadInteger, v1, methodCompiler.StackFrame, thisOperand);
context.AppendInstruction(IRInstruction.LoadInteger, v2, methodCompiler.StackFrame, methodPointerOperand);
context.AppendInstruction(IRInstruction.LoadInteger, v3, methodCompiler.StackFrame, instanceOperand);
context.AppendInstruction(IRInstruction.LoadParameterInteger, v1, thisOperand);
context.AppendInstruction(IRInstruction.LoadParameterInteger, v2, methodPointerOperand);
context.AppendInstruction(IRInstruction.LoadParameterInteger, v3, instanceOperand);

context.AppendInstruction(IRInstruction.StoreInteger, size, null, v1, methodPointerOffsetOperand, v2);
context.MosaType = methodPointerOperand.Type;
Expand Down Expand Up @@ -88,13 +88,23 @@ private static void PatchInvoke(BaseMethodCompiler methodCompiler)

for (int i = 0; i < methodCompiler.Parameters.Length; i++)
{
vrs[i] = methodCompiler.VirtualRegisters.Allocate(methodCompiler.Parameters[i].Type);

//fixme: handle structs
var loadInstruction = BaseMethodCompilerStage.GetLoadInstruction(vrs[i].Type);
var moveSize = BaseMethodCompilerStage.GetInstructionSize(vrs[i].Type);

b0.AppendInstruction(loadInstruction, moveSize, vrs[i], methodCompiler.StackFrame, methodCompiler.Parameters[i]);
var type = methodCompiler.Parameters[i].Type;

if (methodCompiler.StoreOnStack(type))
{
b0.AppendInstruction(IRInstruction.LoadParameterCompound, vrs[i], methodCompiler.Parameters[i]);
b0.MosaType = type;
}
else
{
vrs[i] = methodCompiler.VirtualRegisters.Allocate(methodCompiler.Parameters[i].Type);

var loadInstruction = BaseMethodCompilerStage.GetLoadParameterInstruction(vrs[i].Type);
var loadsize = BaseMethodCompilerStage.GetInstructionSize(vrs[i].Type);

b0.AppendInstruction(loadInstruction, loadsize, vrs[i], methodCompiler.Parameters[i]);
b0.MosaType = type;
}
}

Operand thisOperand = vrs[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
<SubType>
</SubType>
</Compile>
<Compile Include="Platform\OpcodeEncoder.cs" />
<Compile Include="Platform\BaseOpcodeEncoder.cs" />
<Compile Include="Platform\XOpcodeEncoder.cs" />
<Compile Include="RegisterAllocator\BasicRegisterAllocator.cs" />
<Compile Include="RegisterAllocator\MoveExtended.cs" />
<Compile Include="RegisterAllocator\Move.cs" />
Expand Down
11 changes: 11 additions & 0 deletions Source/Mosa.Compiler.Framework/Platform/BaseOpcodeEncoder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) MOSA Project. Licensed under the New BSD License.

using System.IO;

namespace Mosa.Compiler.Framework.Platform
{
public abstract class BaseOpcodeEncoder
{
public abstract void WriteTo(Stream writer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Mosa.Compiler.Framework.Platform
{
public sealed class OpcodeEncoder
public sealed class OpcodeEncoder : BaseOpcodeEncoder
{
private ulong data1 = 0;
private ulong data2 = 0;
Expand All @@ -27,7 +27,7 @@ public byte GetByte(int index)
}
}

public void WriteTo(Stream writer)
public override void WriteTo(Stream writer)
{
Debug.Assert(Size % 8 == 0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1796,8 +1796,6 @@ private void Unbox(Context context)
context.Result = tmp;
context.ResultCount = 1;

var size = GetInstructionSize(type);

if (StoreOnStack(type))
{
context.AppendInstruction(IRInstruction.LoadCompound, result, tmp, ConstantZero);
Expand All @@ -1806,6 +1804,8 @@ private void Unbox(Context context)
else
{
var loadInstruction = GetLoadInstruction(type);
var size = GetInstructionSize(type);

context.AppendInstruction(loadInstruction, size, result, tmp, ConstantZero);
context.MosaType = type;
}
Expand Down
Loading

0 comments on commit bdb4eeb

Please sign in to comment.