Cosmos/source/Indy.IL2CPU.IL.X86/Ldflda.cs
2007-11-18 16:51:28 +00:00

40 lines
No EOL
1.5 KiB
C#

using System;
using System.IO;
using Mono.Cecil;
using Mono.Cecil.Cil;
using CPUx86 = Indy.IL2CPU.Assembler.X86;
namespace Indy.IL2CPU.IL.X86 {
[OpCode(Code.Ldflda)]
public class Ldflda: Op {
private readonly string mRelativeAddress;
public Ldflda(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
: base(aInstruction, aMethodInfo) {
FieldDefinition xField = aInstruction.Operand as FieldDefinition;
if (xField == null) {
FieldReference xFieldRef = aInstruction.Operand as FieldReference;
if (xFieldRef == null) {
string typeName = aInstruction.Operand == null ? "" : aInstruction.Operand.GetType().FullName;
throw new Exception("Field not found! (Operand = '" + (aInstruction.Operand ?? "**NULL**") + "'[" + typeName + "])");
}
xField = Engine.GetDefinitionFromFieldReference(xFieldRef);
}
string xFieldId = xField.ToString();
TypeInformation.Field xTheField;
int xStorageSize;
xTheField = Engine.GetTypeFieldInfo(Engine.GetDefinitionFromTypeReference(xField.DeclaringType), out xStorageSize)[xFieldId];
mRelativeAddress = xTheField.RelativeAddress;
}
public Ldflda(string aRelativeAddress):base(null, null) {
mRelativeAddress = aRelativeAddress;
}
public override void DoAssemble() {
new CPUx86.Pop(CPUx86.Registers.EAX);
new CPUx86.Add(CPUx86.Registers.EAX, mRelativeAddress.Trim().Substring(1));
new CPUx86.Pushd(CPUx86.Registers.EAX);
Assembler.StackSizes.Push(4);
}
}
}