public static void PopOperand(this ILTranslator tr, IIROperand operand) { if (operand is IRRegister) { var reg = ILRegister.LookupRegister(((IRRegister)operand).Register); tr.Instructions.Add(new ILInstruction(ILOpCode.POP, reg)); } else if (operand is IRPointer pointer) { var reg = ILRegister.LookupRegister(pointer.Register.Register); tr.Instructions.Add(new ILInstruction(pointer.Register.GetPUSHR(), reg)); if (pointer.Offset != 0) { tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, ILImmediate.Create(pointer.Offset, ASTType.I4))); if (pointer.Register.Type == ASTType.I4) { tr.Instructions.Add(new ILInstruction(ILOpCode.ADD_DWORD)); } else { tr.Instructions.Add(new ILInstruction(ILOpCode.ADD_QWORD)); } } tr.Instructions.Add(new ILInstruction(pointer.GetSIND())); } else { throw new NotSupportedException(); } }
private void FixupReferences() { foreach (Tuple <MethodDef, ILBlock> block in this.basicBlocks) { foreach (ILInstruction instr in block.Item2.Content) { if (instr.Operand is ILRelReference reference) { instr.Operand = ILImmediate.Create(reference.Resolve(this), ASTType.I4); } } } }
private void FixupReferences() { foreach (var block in basicBlocks) { foreach (var instr in block.Item2.Content) { if (instr.Operand is ILRelReference) { var reference = (ILRelReference)instr.Operand; instr.Operand = ILImmediate.Create(reference.Resolve(this), ASTType.I4); } } } }
public static void PushOperand(this ILTranslator tr, IIROperand operand) { if (operand is IRRegister) { var reg = ILRegister.LookupRegister(((IRRegister)operand).Register); tr.Instructions.Add(new ILInstruction(((IRRegister)operand).GetPUSHR(), reg)); } else if (operand is IRPointer pointer) { var reg = ILRegister.LookupRegister(pointer.Register.Register); tr.Instructions.Add(new ILInstruction(pointer.Register.GetPUSHR(), reg)); if (pointer.Offset != 0) { tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, ILImmediate.Create(pointer.Offset, ASTType.I4))); switch (pointer.Register.Type) { case ASTType.I4: tr.Instructions.Add(new ILInstruction(ILOpCode.ADD_DWORD)); break; default: tr.Instructions.Add(new ILInstruction(ILOpCode.ADD_QWORD)); break; } } tr.Instructions.Add(new ILInstruction(pointer.GetLIND())); } else if (operand is IRConstant constant) { if (constant.Value != null) { tr.Instructions.Add(new ILInstruction(constant.Type.Value.GetPUSHI(), ILImmediate.Create(constant.Value, constant.Type.Value))); } else { tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, ILImmediate.Create(0, ASTType.O))); } } else if (operand is IRMetaTarget) { var method = (MethodDef)((IRMetaTarget)operand).MetadataItem; tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, new ILMethodTarget(method))); } else if (operand is IRBlockTarget) { CFG.IBasicBlock target = ((IRBlockTarget)operand).Target; tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, new ILBlockTarget(target))); } else if (operand is IRJumpTable) { CFG.IBasicBlock[] targets = ((IRJumpTable)operand).Targets; tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, new ILJumpTable(targets))); } else if (operand is IRDataTarget) { RT.BinaryChunk target = ((IRDataTarget)operand).Target; tr.Instructions.Add(new ILInstruction(ILOpCode.PUSHI_DWORD, new ILDataTarget(target))); } else { throw new NotSupportedException(); } }