using System; using System.Collections.Generic; using System.Linq; using System.Text; using CPU = Cosmos.IL2CPU.X86; using Cosmos.IL2CPU.ILOpCodes; using System.Reflection; using Cosmos.IL2CPU.X86.IL; using Indy.IL2CPU.IL; using CPUx86 = Indy.IL2CPU.Assembler.X86; namespace Cosmos.IL2CPU.X86 { public abstract class ILOp : Cosmos.IL2CPU.ILOp { protected new readonly Assembler Assembler; protected ILOp( Cosmos.IL2CPU.Assembler aAsmblr ) : base( aAsmblr ) { Assembler = ( Assembler )aAsmblr; } protected void Jump_Exception(MethodInfo aMethod) { // todo: port to numeric labels new CPU.Jump { DestinationLabel = MethodInfoLabelGenerator.GenerateLabelName(aMethod.MethodBase) + AssemblerNasm.EndOfMethodLabelNameException }; } protected void Jump_End(MethodInfo aMethod) { new CPU.Jump { DestinationLabel = MethodInfoLabelGenerator.GenerateLabelName(aMethod.MethodBase) + AssemblerNasm.EndOfMethodLabelNameNormal }; } protected uint GetStackCountForLocal(MethodInfo aMethod, LocalVariableInfo aField) { var xSize = SizeOfType(aField.LocalType); var xResult = xSize / 4; if (xSize % 4 != 0) { xResult++; } return xResult; } protected uint GetEBPOffsetForLocal(MethodInfo aMethod, OpVar aOp) { var xBody = aMethod.MethodBase.GetMethodBody(); uint xOffset = 4; for(int i = 0; i < xBody.LocalVariables.Count;i++){ if (i == aOp.Value) { break; } var xField = xBody.LocalVariables[i]; xOffset += GetStackCountForLocal(aMethod, xField); } return xOffset; } public static uint Align( uint aSize, uint aAlign ) { var xSize = aSize; if ((xSize % aAlign) != 0) { xSize += aAlign - (xSize % aAlign); } return xSize; } protected void ThrowNotImplementedException(string aMessage) { new CPU.Push { DestinationRef = ElementReference.New(LdStr.GetContentsArrayName("Conv_Ovf_I4 instruction not implemented")) }; new CPU.Call { DestinationLabel = MethodInfoLabelGenerator.GenerateLabelName(typeof(ExceptionHelper).GetMethod("ThrowNotImplemented", BindingFlags.Static | BindingFlags.Public)) }; } } }