Skip to content

Commit bdb4eeb

Browse files
authored
Merge pull request #360 from tgiphil/master
Fixed inlining with delegate method
2 parents 974d34d + c90645f commit bdb4eeb

187 files changed

Lines changed: 1106 additions & 1142 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/Mosa.Compiler.Framework/BaseCodeEmitter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ public void Write(byte[] buffer, int offset, int count)
181181
/// Emits the specified opcode.
182182
/// </summary>
183183
/// <param name="opcode">The opcode.</param>
184-
public void Emit(OpcodeEncoder opcode)
184+
public void Emit(BaseOpcodeEncoder opcode)
185185
{
186186
opcode.WriteTo(codeStream);
187187
}
188188

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

Source/Mosa.Compiler.Framework/BaseCompiler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public void Initialize(MosaCompiler compiler)
108108
Compiler = compiler;
109109

110110
Architecture = Compiler.CompilerOptions.Architecture;
111+
111112
TypeSystem = Compiler.TypeSystem;
112113
TypeLayout = Compiler.TypeLayout;
113114
CompilerTrace = Compiler.CompilerTrace;

Source/Mosa.Compiler.Framework/DelegatePatcher.cs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ private static void PatchConstructor(BaseMethodCompiler methodCompiler)
5353
Operand v2 = methodCompiler.CreateVirtualRegister(methodPointerOperand.Type);
5454
Operand v3 = methodCompiler.CreateVirtualRegister(instanceOperand.Type);
5555

56-
context.AppendInstruction(IRInstruction.LoadInteger, v1, methodCompiler.StackFrame, thisOperand);
57-
context.AppendInstruction(IRInstruction.LoadInteger, v2, methodCompiler.StackFrame, methodPointerOperand);
58-
context.AppendInstruction(IRInstruction.LoadInteger, v3, methodCompiler.StackFrame, instanceOperand);
56+
context.AppendInstruction(IRInstruction.LoadParameterInteger, v1, thisOperand);
57+
context.AppendInstruction(IRInstruction.LoadParameterInteger, v2, methodPointerOperand);
58+
context.AppendInstruction(IRInstruction.LoadParameterInteger, v3, instanceOperand);
5959

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

8989
for (int i = 0; i < methodCompiler.Parameters.Length; i++)
9090
{
91-
vrs[i] = methodCompiler.VirtualRegisters.Allocate(methodCompiler.Parameters[i].Type);
92-
93-
//fixme: handle structs
94-
var loadInstruction = BaseMethodCompilerStage.GetLoadInstruction(vrs[i].Type);
95-
var moveSize = BaseMethodCompilerStage.GetInstructionSize(vrs[i].Type);
96-
97-
b0.AppendInstruction(loadInstruction, moveSize, vrs[i], methodCompiler.StackFrame, methodCompiler.Parameters[i]);
91+
var type = methodCompiler.Parameters[i].Type;
92+
93+
if (methodCompiler.StoreOnStack(type))
94+
{
95+
b0.AppendInstruction(IRInstruction.LoadParameterCompound, vrs[i], methodCompiler.Parameters[i]);
96+
b0.MosaType = type;
97+
}
98+
else
99+
{
100+
vrs[i] = methodCompiler.VirtualRegisters.Allocate(methodCompiler.Parameters[i].Type);
101+
102+
var loadInstruction = BaseMethodCompilerStage.GetLoadParameterInstruction(vrs[i].Type);
103+
var loadsize = BaseMethodCompilerStage.GetInstructionSize(vrs[i].Type);
104+
105+
b0.AppendInstruction(loadInstruction, loadsize, vrs[i], methodCompiler.Parameters[i]);
106+
b0.MosaType = type;
107+
}
98108
}
99109

100110
Operand thisOperand = vrs[0];

Source/Mosa.Compiler.Framework/Mosa.Compiler.Framework.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@
164164
<SubType>
165165
</SubType>
166166
</Compile>
167-
<Compile Include="Platform\OpcodeEncoder.cs" />
167+
<Compile Include="Platform\BaseOpcodeEncoder.cs" />
168+
<Compile Include="Platform\XOpcodeEncoder.cs" />
168169
<Compile Include="RegisterAllocator\BasicRegisterAllocator.cs" />
169170
<Compile Include="RegisterAllocator\MoveExtended.cs" />
170171
<Compile Include="RegisterAllocator\Move.cs" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) MOSA Project. Licensed under the New BSD License.
2+
3+
using System.IO;
4+
5+
namespace Mosa.Compiler.Framework.Platform
6+
{
7+
public abstract class BaseOpcodeEncoder
8+
{
9+
public abstract void WriteTo(Stream writer);
10+
}
11+
}

Source/Mosa.Compiler.Framework/Platform/OpcodeEncoder.cs renamed to Source/Mosa.Compiler.Framework/Platform/XOpcodeEncoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Mosa.Compiler.Framework.Platform
77
{
8-
public sealed class OpcodeEncoder
8+
public sealed class OpcodeEncoder : BaseOpcodeEncoder
99
{
1010
private ulong data1 = 0;
1111
private ulong data2 = 0;
@@ -27,7 +27,7 @@ public byte GetByte(int index)
2727
}
2828
}
2929

30-
public void WriteTo(Stream writer)
30+
public override void WriteTo(Stream writer)
3131
{
3232
Debug.Assert(Size % 8 == 0);
3333

Source/Mosa.Compiler.Framework/Stages/CILTransformationStage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,6 @@ private void Unbox(Context context)
17961796
context.Result = tmp;
17971797
context.ResultCount = 1;
17981798

1799-
var size = GetInstructionSize(type);
1800-
18011799
if (StoreOnStack(type))
18021800
{
18031801
context.AppendInstruction(IRInstruction.LoadCompound, result, tmp, ConstantZero);
@@ -1806,6 +1804,8 @@ private void Unbox(Context context)
18061804
else
18071805
{
18081806
var loadInstruction = GetLoadInstruction(type);
1807+
var size = GetInstructionSize(type);
1808+
18091809
context.AppendInstruction(loadInstruction, size, result, tmp, ConstantZero);
18101810
context.MosaType = type;
18111811
}

0 commit comments

Comments
 (0)