Cosmos/source/Indy.IL2CPU.IL.X86/X86MethodHeaderOp.cs
mterwoord_cp 40968f0865
2008-01-03 17:59:51 +00:00

51 lines
No EOL
2 KiB
C#

//#define EXT_DEBUG
using System;
using System.Linq;
using Indy.IL2CPU.Assembler;
using Mono.Cecil;
using CPU = Indy.IL2CPU.Assembler;
using CPUx86 = Indy.IL2CPU.Assembler.X86;
using Instruction = Mono.Cecil.Cil.Instruction;
namespace Indy.IL2CPU.IL.X86 {
public class X86MethodHeaderOp: MethodHeaderOp {
public readonly int[] Locals;
public readonly string LabelName = "";
public readonly MethodInformation.Argument[] Args;
public X86MethodHeaderOp(Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
LabelName = aMethodInfo.LabelName;
Args = aMethodInfo.Arguments.ToArray();
Locals = (from local in aMethodInfo.Locals
select local.Size).ToArray();
}
public override void DoAssemble() {
// TODO: add support for variables with a diff datasize, other than 32bit
AssembleHeader(Assembler, LabelName, Locals, Args);
}
public static void AssembleHeader(Assembler.Assembler aAssembler, string aLabelName, int[] aLocals, MethodInformation.Argument[] aArguments) {
new CPU.Label(aLabelName);
new CPUx86.Pushd(CPUx86.Registers.EBP);
#if EXT_DEBUG
new CPUx86.Move("edi", LdStr.GetContentsArrayName(aAssembler, aLabelName) + "__Contents");
new CPUx86.Add("edi", "0x10");
#endif
new CPUx86.Move(CPUx86.Registers.EBP, CPUx86.Registers.ESP);
//new CPUx86.Push("0");
//if (!(aLabelName.Contains("Cosmos.Kernel.Serial") || aLabelName.Contains("Cosmos.Kernel.Heap"))) {
// new CPUx86.Push(LdStr.GetContentsArrayName(aAssembler, aLabelName));
// MethodDefinition xTempMethod = Engine.GetMethodDefinition(Engine.GetTypeDefinition("Cosmos.Kernel", "Cosmos.Kernel.Serial"), "Write", "System.Byte", "System.String");
// new CPUx86.Call(Label.GenerateLabelName(xTempMethod));
// Engine.QueueMethod(xTempMethod);
//}
foreach (int xLocalSize in aLocals) {
aAssembler.StackSizes.Push(xLocalSize);
for (int i = 0; i < (xLocalSize / 4); i++) {
new CPUx86.Pushd("0");
}
}
}
}
}