예제 #1
0
        internal Ldc(global::Truesight.Parser.Impl.MethodBody source, global::System.IO.BinaryReader reader, global::System.Collections.ObjectModel.ReadOnlyCollection<global::Truesight.Parser.Impl.ILOp> prefixes)
            : base(source, AssertSupportedOpCode(reader), (int)reader.BaseStream.Position - global::System.Linq.Enumerable.Sum(global::System.Linq.Enumerable.Select(prefixes ?? global::XenoGears.Functional.EnumerableExtensions.ToReadOnly(global::System.Linq.Enumerable.Empty<global::Truesight.Parser.Impl.ILOp>()), prefix => prefix.Size)), prefixes ?? global::XenoGears.Functional.EnumerableExtensions.ToReadOnly(global::System.Linq.Enumerable.Empty<global::Truesight.Parser.Impl.ILOp>()))
        {
            // this is necessary for further verification
            var origPos = reader.BaseStream.Position;

            // initializing _constValue
            switch((ushort)OpSpec.OpCode.Value)
            {
                case 0x14: //ldnull
                    _constValue = null;
                    break;
                case 0x15: //ldc.i4.m1
                    _constValue = -1;
                    break;
                case 0x16: //ldc.i4.0
                    _constValue = 0;
                    break;
                case 0x17: //ldc.i4.1
                    _constValue = 1;
                    break;
                case 0x18: //ldc.i4.2
                    _constValue = 2;
                    break;
                case 0x19: //ldc.i4.3
                    _constValue = 3;
                    break;
                case 0x1a: //ldc.i4.4
                    _constValue = 4;
                    break;
                case 0x1b: //ldc.i4.5
                    _constValue = 5;
                    break;
                case 0x1c: //ldc.i4.6
                    _constValue = 6;
                    break;
                case 0x1d: //ldc.i4.7
                    _constValue = 7;
                    break;
                case 0x1e: //ldc.i4.8
                    _constValue = 8;
                    break;
                case 0x1f: //ldc.i4.s
                case 0x20: //ldc.i4
                case 0x21: //ldc.i8
                case 0x22: //ldc.r4
                case 0x23: //ldc.r8
                    _constValue = default(global::System.Object);
                    break;
                case 0x72: //ldstr
                    _constValue = ((global::System.Func<global::System.String>)(() => { var token = ReadMetadataToken(reader); return StringFromToken(token) ?? ("string at 0x" + token.ToString("x8")); }))();
                    break;
                case 0xd0: //ldtoken
                    _constValue = ((global::System.Func<global::System.Object>)(() => { var i_token = ReadMetadataToken(reader); var token = new global::Truesight.Parser.Api.Ops.RuntimeHandle(Source.Module, Source.Type, Source.Method, i_token); try {     var resolved = token.ResolveHandle();     if (resolved != null) return resolved;     else     {         return token;     } } catch {     return token; } }))();
                    break;
                default:
                    throw global::XenoGears.Assertions.AssertionHelper.Fail();
            }

            // initializing _useConstValue
            switch((ushort)OpSpec.OpCode.Value)
            {
                case 0x14: //ldnull
                case 0x15: //ldc.i4.m1
                case 0x16: //ldc.i4.0
                case 0x17: //ldc.i4.1
                case 0x18: //ldc.i4.2
                case 0x19: //ldc.i4.3
                case 0x1a: //ldc.i4.4
                case 0x1b: //ldc.i4.5
                case 0x1c: //ldc.i4.6
                case 0x1d: //ldc.i4.7
                case 0x1e: //ldc.i4.8
                case 0x72: //ldstr
                case 0xd0: //ldtoken
                    _useConstValue = true;
                    break;
                case 0x1f: //ldc.i4.s
                case 0x20: //ldc.i4
                case 0x21: //ldc.i8
                case 0x22: //ldc.r4
                case 0x23: //ldc.r8
                    _useConstValue = default(bool);
                    break;
                default:
                    throw global::XenoGears.Assertions.AssertionHelper.Fail();
            }

            // initializing _value
            switch((ushort)OpSpec.OpCode.Value)
            {
                case 0x14: //ldnull
                case 0x15: //ldc.i4.m1
                case 0x16: //ldc.i4.0
                case 0x17: //ldc.i4.1
                case 0x18: //ldc.i4.2
                case 0x19: //ldc.i4.3
                case 0x1a: //ldc.i4.4
                case 0x1b: //ldc.i4.5
                case 0x1c: //ldc.i4.6
                case 0x1d: //ldc.i4.7
                case 0x1e: //ldc.i4.8
                case 0x20: //ldc.i4
                    _value = _useConstValue ? _constValue : ReadI4(reader);
                    break;
                case 0x1f: //ldc.i4.s
                    _value = _useConstValue ? _constValue : (int)ReadI1(reader);
                    break;
                case 0x21: //ldc.i8
                    _value = _useConstValue ? _constValue : ReadI8(reader);
                    break;
                case 0x22: //ldc.r4
                    _value = _useConstValue ? _constValue : ReadR4(reader);
                    break;
                case 0x23: //ldc.r8
                    _value = _useConstValue ? _constValue : ReadR8(reader);
                    break;
                case 0x72: //ldstr
                    _value = _useConstValue ? _constValue : ReadStr(reader);
                    break;
                case 0xd0: //ldtoken
                    _value = _useConstValue ? _constValue : ReadToken(reader);
                    break;
                default:
                    throw global::XenoGears.Assertions.AssertionHelper.Fail();
            }

            // verify that we've read exactly the amount of bytes we should
            var bytesRead = reader.BaseStream.Position - origPos;
            global::XenoGears.Assertions.AssertionHelper.AssertTrue(bytesRead == SizeOfOperand);

            // now when the initialization is completed verify that we've got only prefixes we support
            global::XenoGears.Assertions.AssertionHelper.AssertAll(Prefixes, prefix => 
            {
                return false;
            });
        }
예제 #2
0
        internal Ldc(global::Truesight.Parser.Impl.MethodBody source, global::System.IO.BinaryReader reader, global::System.Collections.ObjectModel.ReadOnlyCollection <global::Truesight.Parser.Impl.ILOp> prefixes)
            : base(source, AssertSupportedOpCode(reader), (int)reader.BaseStream.Position - global::System.Linq.Enumerable.Sum(global::System.Linq.Enumerable.Select(prefixes ?? global::XenoGears.Functional.EnumerableExtensions.ToReadOnly(global::System.Linq.Enumerable.Empty <global::Truesight.Parser.Impl.ILOp>()), prefix => prefix.Size)), prefixes ?? global::XenoGears.Functional.EnumerableExtensions.ToReadOnly(global::System.Linq.Enumerable.Empty <global::Truesight.Parser.Impl.ILOp>()))
        {
            // this is necessary for further verification
            var origPos = reader.BaseStream.Position;

            // initializing _constValue
            switch ((ushort)OpSpec.OpCode.Value)
            {
            case 0x14:     //ldnull
                _constValue = null;
                break;

            case 0x15:     //ldc.i4.m1
                _constValue = -1;
                break;

            case 0x16:     //ldc.i4.0
                _constValue = 0;
                break;

            case 0x17:     //ldc.i4.1
                _constValue = 1;
                break;

            case 0x18:     //ldc.i4.2
                _constValue = 2;
                break;

            case 0x19:     //ldc.i4.3
                _constValue = 3;
                break;

            case 0x1a:     //ldc.i4.4
                _constValue = 4;
                break;

            case 0x1b:     //ldc.i4.5
                _constValue = 5;
                break;

            case 0x1c:     //ldc.i4.6
                _constValue = 6;
                break;

            case 0x1d:     //ldc.i4.7
                _constValue = 7;
                break;

            case 0x1e:     //ldc.i4.8
                _constValue = 8;
                break;

            case 0x1f:     //ldc.i4.s
            case 0x20:     //ldc.i4
            case 0x21:     //ldc.i8
            case 0x22:     //ldc.r4
            case 0x23:     //ldc.r8
                _constValue = default(global::System.Object);
                break;

            case 0x72:     //ldstr
                _constValue = ((global::System.Func <global::System.String>)(() => { var token = ReadMetadataToken(reader); return(StringFromToken(token) ?? ("string at 0x" + token.ToString("x8"))); }))();
                break;

            case 0xd0:     //ldtoken
                _constValue = ((global::System.Func <global::System.Object>)(() => { var i_token = ReadMetadataToken(reader); var token = new global::Truesight.Parser.Api.Ops.RuntimeHandle(Source.Module, Source.Type, Source.Method, i_token); try { var resolved = token.ResolveHandle();     if (resolved != null)
                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                            return(resolved);
                                                                                                                                                                                                                                                        }
                                                                                                                                                                                                                                                        else
                                                                                                                                                                                                                                                        {
                                                                                                                                                                                                                                                            return(token);
                                                                                                                                                                                                                                                        } } catch { return(token); } }))();
                break;

            default:
                throw global::XenoGears.Assertions.AssertionHelper.Fail();
            }

            // initializing _useConstValue
            switch ((ushort)OpSpec.OpCode.Value)
            {
            case 0x14:     //ldnull
            case 0x15:     //ldc.i4.m1
            case 0x16:     //ldc.i4.0
            case 0x17:     //ldc.i4.1
            case 0x18:     //ldc.i4.2
            case 0x19:     //ldc.i4.3
            case 0x1a:     //ldc.i4.4
            case 0x1b:     //ldc.i4.5
            case 0x1c:     //ldc.i4.6
            case 0x1d:     //ldc.i4.7
            case 0x1e:     //ldc.i4.8
            case 0x72:     //ldstr
            case 0xd0:     //ldtoken
                _useConstValue = true;
                break;

            case 0x1f:     //ldc.i4.s
            case 0x20:     //ldc.i4
            case 0x21:     //ldc.i8
            case 0x22:     //ldc.r4
            case 0x23:     //ldc.r8
                _useConstValue = default(bool);
                break;

            default:
                throw global::XenoGears.Assertions.AssertionHelper.Fail();
            }

            // initializing _value
            switch ((ushort)OpSpec.OpCode.Value)
            {
            case 0x14:     //ldnull
            case 0x15:     //ldc.i4.m1
            case 0x16:     //ldc.i4.0
            case 0x17:     //ldc.i4.1
            case 0x18:     //ldc.i4.2
            case 0x19:     //ldc.i4.3
            case 0x1a:     //ldc.i4.4
            case 0x1b:     //ldc.i4.5
            case 0x1c:     //ldc.i4.6
            case 0x1d:     //ldc.i4.7
            case 0x1e:     //ldc.i4.8
            case 0x20:     //ldc.i4
                _value = _useConstValue ? _constValue : ReadI4(reader);
                break;

            case 0x1f:     //ldc.i4.s
                _value = _useConstValue ? _constValue : (int)ReadI1(reader);
                break;

            case 0x21:     //ldc.i8
                _value = _useConstValue ? _constValue : ReadI8(reader);
                break;

            case 0x22:     //ldc.r4
                _value = _useConstValue ? _constValue : ReadR4(reader);
                break;

            case 0x23:     //ldc.r8
                _value = _useConstValue ? _constValue : ReadR8(reader);
                break;

            case 0x72:     //ldstr
                _value = _useConstValue ? _constValue : ReadStr(reader);
                break;

            case 0xd0:     //ldtoken
                _value = _useConstValue ? _constValue : ReadToken(reader);
                break;

            default:
                throw global::XenoGears.Assertions.AssertionHelper.Fail();
            }

            // verify that we've read exactly the amount of bytes we should
            var bytesRead = reader.BaseStream.Position - origPos;

            global::XenoGears.Assertions.AssertionHelper.AssertTrue(bytesRead == SizeOfOperand);

            // now when the initialization is completed verify that we've got only prefixes we support
            global::XenoGears.Assertions.AssertionHelper.AssertAll(Prefixes, prefix =>
            {
                return(false);
            });
        }