mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-21 21:38:52 +00:00
34 lines
No EOL
1,011 B
C#
34 lines
No EOL
1,011 B
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.Initobj)]
|
|
public class Initobj: Op {
|
|
private int mObjSize;
|
|
public Initobj(Mono.Cecil.Cil.Instruction aInstruction, MethodInformation aMethodInfo)
|
|
: base(aInstruction, aMethodInfo) {
|
|
TypeReference xTypeRef = aInstruction.Operand as TypeReference;
|
|
if (xTypeRef == null) {
|
|
throw new Exception("Type not found!");
|
|
}
|
|
mObjSize = 0;
|
|
if (xTypeRef.IsValueType) {
|
|
Engine.GetTypeFieldInfo(Engine.GetDefinitionFromTypeReference(xTypeRef), out mObjSize);
|
|
}
|
|
if(((mObjSize/4)*4) != mObjSize) {
|
|
throw new Exception("For now, value type size must be a multiplicative of 4!");
|
|
}
|
|
}
|
|
|
|
public override void DoAssemble() {
|
|
Assembler.StackSizes.Pop();
|
|
Pop("eax");
|
|
for(int i = 0; i < (mObjSize/4);i++) {
|
|
Move(Assembler, "dword [eax + 0" + (i*4).ToString("X") + "h]", "0");
|
|
}
|
|
}
|
|
}
|
|
} |