예제 #1
0
 static void WriteEncodedStackOffset(NibbleWriter _writer, int offset, bool assume4ByteAligned)
 {
     if (assume4ByteAligned)
     {
         Debug.Assert(offset % 4 == 0);
         _writer.WriteInt(offset / 4);
     }
     else
     {
         _writer.WriteInt(offset);
     }
 }
예제 #2
0
        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());
        }