Cosmos/source/Indy.IL2CPU.IL.X86/Ldobj.cs
2007-10-11 14:17:11 +00:00

46 lines
No EOL
1.2 KiB
C#

using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using CPU = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldobj)]
public class Ldobj: Op {
public Ldobj(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
TypeReference xTypeRef = aInstruction.Operand as TypeReference;
if (xTypeRef == null) {
throw new Exception("Type specification not found!");
}
TypeDefinition xTypeDef = Engine.GetDefinitionFromTypeReference(xTypeRef);
mSize = Engine.GetFieldStorageSize(xTypeDef);
}
private int mSize;
public override void DoAssemble() {
Pop("eax");
for (int i = 0; i < (mSize / 4); i++) {
Assembler.Add(new CPU.Pushd("[eax]"));
Assembler.Add(new CPU.Add("eax", "4"));
}
switch (mSize % 4) {
case 1: {
Assembler.Add(new CPU.Push("byte [eax]"));
break;
}
case 2: {
Assembler.Add(new CPU.Push("word [eax]"));
break;
}
case 0: {
break;
}
default: {
throw new Exception("Remainder not supported!");
}
}
Assembler.StackSizes.Push(mSize);
}
}
}