public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos) { if (varInfos == null || varInfos.Length == 0) { return(null); } NibbleWriter writer = new NibbleWriter(); writer.WriteUInt((uint)varInfos.Length); foreach (var nativeVarInfo in varInfos) { writer.WriteUInt(nativeVarInfo.startOffset); writer.WriteUInt(nativeVarInfo.endOffset - nativeVarInfo.startOffset); writer.WriteUInt((uint)(nativeVarInfo.varNumber - (int)ILNum.MAX_ILNUM)); VarLocType varLocType = nativeVarInfo.varLoc.LocationType; writer.WriteUInt((uint)varLocType); switch (varLocType) { case VarLocType.VLT_REG: case VarLocType.VLT_REG_FP: case VarLocType.VLT_REG_BYREF: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); break; case VarLocType.VLT_STK: case VarLocType.VLT_STK_BYREF: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteInt(nativeVarInfo.varLoc.C); break; case VarLocType.VLT_REG_REG: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); break; case VarLocType.VLT_REG_STK: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); writer.WriteInt(nativeVarInfo.varLoc.D); break; case VarLocType.VLT_STK_REG: writer.WriteInt(nativeVarInfo.varLoc.B); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); writer.WriteUInt((uint)nativeVarInfo.varLoc.D); break; case VarLocType.VLT_STK2: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteInt(nativeVarInfo.varLoc.C); break; case VarLocType.VLT_FPSTK: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); break; case VarLocType.VLT_FIXED_VA: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); break; default: throw new BadImageFormatException("Unexpected var loc type"); } } return(writer.ToArray()); }
public static byte[] CreateVarBlobForMethod(NativeVarInfo[] varInfos, TargetDetails target) { if (varInfos == null || varInfos.Length == 0) { return(null); } bool isX86 = target.Architecture == TargetArchitecture.X86; NibbleWriter writer = new NibbleWriter(); writer.WriteUInt((uint)varInfos.Length); foreach (var nativeVarInfo in varInfos) { writer.WriteUInt(nativeVarInfo.startOffset); writer.WriteUInt(nativeVarInfo.endOffset - nativeVarInfo.startOffset); writer.WriteUInt((uint)(nativeVarInfo.varNumber - (int)ILNum.MAX_ILNUM)); VarLocType varLocType = nativeVarInfo.varLoc.LocationType; writer.WriteUInt((uint)varLocType); switch (varLocType) { case VarLocType.VLT_REG: case VarLocType.VLT_REG_FP: case VarLocType.VLT_REG_BYREF: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); break; case VarLocType.VLT_STK: case VarLocType.VLT_STK_BYREF: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.C, assume4ByteAligned: isX86); break; case VarLocType.VLT_REG_REG: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); break; case VarLocType.VLT_REG_STK: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.D, assume4ByteAligned: isX86); break; case VarLocType.VLT_STK_REG: WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.B, assume4ByteAligned: isX86); writer.WriteUInt((uint)nativeVarInfo.varLoc.C); writer.WriteUInt((uint)nativeVarInfo.varLoc.D); break; case VarLocType.VLT_STK2: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); WriteEncodedStackOffset(writer, nativeVarInfo.varLoc.C, assume4ByteAligned: isX86); break; case VarLocType.VLT_FPSTK: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); break; case VarLocType.VLT_FIXED_VA: writer.WriteUInt((uint)nativeVarInfo.varLoc.B); break; default: throw new BadImageFormatException("Unexpected var loc type"); }