Exemplo n.º 1
0
 /// <inheritdoc />
 public void WriteFloat32(int offset, Float32Value value)
 {
     if (IsKnown)
     {
         BasePointer.WriteFloat32(CurrentOffset + offset, value);
     }
 }
Exemplo n.º 2
0
 /// <inheritdoc />
 public void WriteFloat32(int offset, Float32Value value)
 {
     if (IsKnown)
     {
         ReferencedMemory.WriteFloat32(CurrentOffset + offset, value);
     }
 }
Exemplo n.º 3
0
        public void ReadWriteFloat32()
        {
            var ptrValue = new MemoryBlockValue(4);

            var value = new Float32Value(0.12345678f);

            ptrValue.WriteFloat32(0, value);
            Assert.Equal(value.F32, ptrValue.ReadFloat32(0).F32);
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public unsafe void WriteFloat32(int offset, Float32Value value)
        {
            AssertOffsetValidity(offset, sizeof(float));

            // Note: There is unfortunately no BinaryPrimitives method for writing single or double values in
            // .NET Standard 2.0. Hence we go the unsafe route.

            using var handle = _memory.Pin();
            *(float *)((byte *)handle.Pointer + offset) = value.F32;
            _knownBitMask.Span.Slice(offset, 4).Fill(0xFF);
        }
Exemplo n.º 5
0
        public void ReadWriteFloat32()
        {
            using var memoryOwner = MemoryPool <byte> .Shared.Rent(4);

            using var bitmaskOwner = MemoryPool <byte> .Shared.Rent(4);

            var ptrValue = new MemoryPointerValue(memoryOwner.Memory, bitmaskOwner.Memory, true);

            var value = new Float32Value(0.12345678f);

            ptrValue.WriteFloat32(0, value);
            Assert.Equal(value.F32, ptrValue.ReadFloat32(0).F32);
        }
Exemplo n.º 6
0
        public void PersistentBits()
        {
            const float testValue = 0.123f;

            var value = new Float32Value(testValue);

            Span <byte> buffer = stackalloc byte[sizeof(float)];
            Span <byte> mask   = stackalloc byte[sizeof(float)];

            value.GetBits(buffer);
            value.GetMask(mask);

            value.SetBits(buffer, mask);

            Assert.Equal(testValue, value.F32);
        }
Exemplo n.º 7
0
        // Methods
        public override string ToString()
        {
            switch (typetag)
            {
            case TypeTag.OscInt32:
                return(Int32Value.ToString());

            case TypeTag.OscFloat32:
                return(Float32Value.ToString());

            case TypeTag.OscString:
                return(StringValue ?? "null");

            case TypeTag.OscBlob:
                return(BlobValue != null ? BitConverter.ToString(BlobValue) : "null");

            default:
                return("unknown");
            }
        }
 /// <inheritdoc />
 public void WriteFloat32(int offset, Float32Value value) => Contents.WriteFloat32(offset, value);
Exemplo n.º 9
0
        public override void Execute(Context context, IEnumerable <MetadataMember> targets)
        {
            if (!context.IsReflectionCorlibSafe)
            {
                return;
            }
            foreach (var Method in targets.OfType <MethodDefinition>().Where(m => m.CilMethodBody is not null))
            {
                var Instructions = Method.CilMethodBody.Instructions;
                Method.CilMethodBody.ConstructSymbolicFlowGraph(out var DFG); /* Dfg Constructing. */
                for (int x = 0; x < Instructions.Count; x++)
                {
                    var Instr = Instructions[x];   /* Some People Make It Callvirt To Deafet Public tools :p */
                    if ((Instr.IsCode(CilCode.Call) || Instr.IsCode(CilCode.Callvirt)) &&
                        Instr.IsFromNS("System", "Math") && DFG.Nodes.Contains(Instr.Offset))
                    {
                        var CallNode = DFG.Nodes[Instr.Offset]
                                       .GetOrderedDependencies(DependencyCollectionFlags.IncludeStackDependencies)
                                       .ToList();

                        if (CallNode.Any(x => x.Contents.OpCode.OperandType == CilOperandType.InlineMethod))
                        {
                            continue;
                        }

                        var vm = new CilVirtualMachine(Method.CilMethodBody,
                                                       context.Module.Is32Module());
                        var ex = new CilExecutionContext(vm, vm.CurrentState, default);

                        foreach (var Dep in CallNode)
                        {
                            var CInstr = Dep.Contents;
                            vm.Dispatcher.Execute(ex, CInstr);
                            CInstr.Nop();
                        }
                        var ISlot = new object[((IMethodDescriptor)Instr.Operand)
                                               .Signature.GetTotalParameterCount()];
                        for (int i = 0; i < ISlot.Length; i++)
                        {
                            var Value = vm.CurrentState.Stack.Pop();
                            ISlot[i] = Value switch {
                                I4Value I4 => I4.I32,
                                I8Value I8 => I8.I64,
                                FValue F => F.F64,
                                Float32Value F32 => F32.F32,
                                Float64Value F64 => F64.F64,
                                Integer16Value I6 => I6.I16,
                                Integer32Value I32 => I32.I32,
                                Integer64Value I64 => I64.I64,
                                        _ => throw new NotSupportedException(nameof(Value))
                            };
                        }
                        var InvocationValue = context.ReflectionCorlib.ResolveMethod(((IMethodDescriptor)Instr.Operand).MetadataToken.ToInt32())
                                              .Invoke(null, ISlot);
                        Instr.OpCode = ((IMethodDescriptor)Instr.Operand).Signature.ReturnType.ElementType switch {
                            ElementType.I4 => CilOpCodes.Ldc_I4,
                            ElementType.I8 => CilOpCodes.Ldc_I8,
                            ElementType.R4 => CilOpCodes.Ldc_R4,
                            ElementType.R8 => CilOpCodes.Ldc_R8,
                            _ => CilOpCodes.Ldc_I4,
                        };
                        Instr.Operand = InvocationValue;
                    }
                }
            }
        }
    }