예제 #1
0
        internal void SerializeLocalSlots(Cci.BlobWriter writer)
        {
            int syntaxOffsetBaseline = -1;

            foreach (LocalSlotDebugInfo localSlot in this.LocalSlots)
            {
                if (localSlot.Id.SyntaxOffset < syntaxOffsetBaseline)
                {
                    syntaxOffsetBaseline = localSlot.Id.SyntaxOffset;
                }
            }

            if (syntaxOffsetBaseline != -1)
            {
                writer.WriteByte(SyntaxOffsetBaseline);
                writer.WriteCompressedUInt((uint)(-syntaxOffsetBaseline));
            }

            foreach (LocalSlotDebugInfo localSlot in this.LocalSlots)
            {
                SynthesizedLocalKind kind = localSlot.SynthesizedKind;
                Debug.Assert(kind <= SynthesizedLocalKind.MaxValidValueForLocalVariableSerializedToDebugInformation);

                if (!kind.IsLongLived())
                {
                    writer.WriteByte(0);
                    continue;
                }

                byte b = (byte)(kind + 1);
                Debug.Assert((b & (1 << 7)) == 0);

                bool hasOrdinal = localSlot.Id.Ordinal > 0;

                if (hasOrdinal)
                {
                    b |= 1 << 7;
                }

                writer.WriteByte(b);
                writer.WriteCompressedUInt((uint)(localSlot.Id.SyntaxOffset - syntaxOffsetBaseline));

                if (hasOrdinal)
                {
                    writer.WriteCompressedUInt((uint)localSlot.Id.Ordinal);
                }
            }
        }
예제 #2
0
        private static void WriteOpCode(Cci.BlobWriter writer, ILOpCode code)
        {
            var size = code.Size();

            if (size == 1)
            {
                writer.WriteByte((byte)code);
            }
            else
            {
                // IL opcodes that occupy two bytes are written to
                // the byte stream with the high-order byte first,
                // in contrast to the little-endian format of the
                // numeric arguments and tokens.

                Debug.Assert(size == 2);
                writer.WriteByte((byte)((ushort)code >> 8));
                writer.WriteByte((byte)((ushort)code & 0xff));
            }
        }
예제 #3
0
        public void Serialize(Cci.BlobWriter writer)
        {
            switch (this.Discriminator)
            {
            case ConstantValueTypeDiscriminator.Boolean:
                writer.WriteBool(this.BooleanValue);
                break;

            case ConstantValueTypeDiscriminator.SByte:
                writer.WriteSbyte(this.SByteValue);
                break;

            case ConstantValueTypeDiscriminator.Byte:
                writer.WriteByte(this.ByteValue);
                break;

            case ConstantValueTypeDiscriminator.Char:
            case ConstantValueTypeDiscriminator.Int16:
                writer.WriteShort(this.Int16Value);
                break;

            case ConstantValueTypeDiscriminator.UInt16:
                writer.WriteUshort(this.UInt16Value);
                break;

            case ConstantValueTypeDiscriminator.Single:
                writer.WriteFloat(this.SingleValue);
                break;

            case ConstantValueTypeDiscriminator.Int32:
                writer.WriteInt(this.Int32Value);
                break;

            case ConstantValueTypeDiscriminator.UInt32:
                writer.WriteUint(this.UInt32Value);
                break;

            case ConstantValueTypeDiscriminator.Double:
                writer.WriteDouble(this.DoubleValue);
                break;

            case ConstantValueTypeDiscriminator.Int64:
                writer.WriteLong(this.Int64Value);
                break;

            case ConstantValueTypeDiscriminator.UInt64:
                writer.WriteUlong(this.UInt64Value);
                break;

            default: throw ExceptionUtilities.UnexpectedValue(this.Discriminator);
            }
        }