示例#1
0
 ///<summary>
 ///Returns a <see cref="T:System.String"/> that represents the current <see cref="UsbInterfaceInfo"/>.
 ///</summary>
 ///
 ///<param name="prefixSeperator">The field prefix string.</param>
 ///<param name="entitySperator">The field/value seperator string.</param>
 ///<param name="suffixSeperator">The value suffix string.</param>
 ///<returns>A formatted representation of the <see cref="UsbInterfaceInfo"/>.</returns>
 public string ToString(string prefixSeperator, string entitySperator, string suffixSeperator)
 {
     string[] names  = { "ManufacturerString", "ProductString", "SerialString" };
     Object[] values = { ManufacturerString, ProductString, SerialString };
     return(Descriptor.ToString(prefixSeperator, entitySperator, suffixSeperator) +
            LHelper.ToString(prefixSeperator, names, entitySperator, values, suffixSeperator));
 }
示例#2
0
        public void Fneg_ParseCheck()
        {
            LFneg fneg = new LFneg(_op1, _result);

            Assert.AreEqual($"{_result.Identifier} = fneg {_result.ParseType()} {_op1.ValueOrIdentifier}",
                            LHelper.Trim(fneg.ParseInstruction()));
        }
示例#3
0
        public void SimpleAshr_ParseCheck()
        {
            LAshr ashr = new LAshr(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = ashr {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(ashr.ParseInstruction()));
        }
示例#4
0
        public void SimpleLshr_ParseCheck()
        {
            LShl shl = new LShl(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = shl {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(shl.ParseInstruction()));
        }
示例#5
0
        public void Ret_ParseCheck_i32_Value_Ok()
        {
            LValueRef valueRef = new LValueRef(LType.Int32Type(), "12");
            LRet      ret      = new LRet(valueRef);

            Assert.AreEqual($"{LKeywords.Ret} i32 12", LHelper.Trim(ret.ParseInstruction()));
        }
示例#6
0
        public void SimpleXor_ParseCheck()
        {
            LXor xor = new LXor(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = xor {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(xor.ParseInstruction()));
        }
示例#7
0
        /// <summary>
        /// String representation of the UsbDescriptor class.
        /// </summary>
        public override string ToString()
        {
            Object[] values = { Length, DescriptorType };
            string[] names  = { "Length", "DescriptorType" };

            return(LHelper.ToString("", names, ToStringParamValueSeperator, values, ToStringFieldSeperator));
        }
示例#8
0
        public void SimpleAnd_ParseCheck()
        {
            LAnd and = new LAnd(_valueResult, _valueOp1, _valueOp2);

            Assert.AreEqual($"{_valueResult.Identifier} = and {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(and.ParseInstruction()));
        }
        ///<summary>
        ///Returns a <see cref="T:System.String"/> that represents the current <see cref="UsbConfigDescriptor"/>.
        ///</summary>
        ///
        ///<param name="prefixSeperator">The field prefix string.</param>
        ///<param name="entitySperator">The field/value seperator string.</param>
        ///<param name="suffixSeperator">The value suffix string.</param>
        ///<returns>A formatted representation of the <see cref="UsbConfigDescriptor"/>.</returns>
        public string ToString(string prefixSeperator, string entitySperator, string suffixSeperator)
        {
            Object[] values = { Length, DescriptorType, TotalLength, InterfaceCount, ConfigID, StringIndex, "0x" + Attributes.ToString("X2"), MaxPower };
            string[] names  = { "Length", "DescriptorType", "TotalLength", "InterfaceCount", "ConfigID", "StringIndex", "Attributes", "MaxPower" };

            return(LHelper.ToString(prefixSeperator, names, entitySperator, values, suffixSeperator));
        }
示例#10
0
        public void Ret_ParseCheck_i32_Identifier_Ok()
        {
            LValueRef valueRef = new LValueRef(LType.Int32Type(), _function.GetValueRefIdentifier());
            LRet      ret      = new LRet(valueRef);

            Assert.AreEqual($"{LKeywords.Ret} i32 {valueRef.ValueOrIdentifier}", LHelper.Trim(ret.ParseInstruction()));
        }
示例#11
0
 ///<summary>
 ///Returns a <see cref="T:System.String"/> that represents the current <see cref="UsbConfigInfo"/>.
 ///</summary>
 ///
 ///<param name="prefixSeperator">The field prefix string.</param>
 ///<param name="entitySperator">The field/value seperator string.</param>
 ///<param name="suffixSeperator">The value suffix string.</param>
 ///<returns>A formatted representation of the <see cref="UsbConfigInfo"/>.</returns>
 public string ToString(string prefixSeperator, string entitySperator, string suffixSeperator)
 {
     Object[] values = { ConfigString };
     string[] names  = { "ConfigString" };
     return(Descriptor.ToString(prefixSeperator, entitySperator, suffixSeperator) +
            LHelper.ToString(prefixSeperator, names, entitySperator, values, suffixSeperator));
 }
示例#12
0
        public void SimpleAllocaParse_Expected_True()
        {
            LAlloca alloca = new LAlloca(_function, LType.Int32Type());

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}",
                            LHelper.Trim(alloca.ParseInstruction()));
        }
示例#13
0
        public void UnconditionalBr_ParseCheck()
        {
            LUnconditionalBr unconditionalBr = new LUnconditionalBr(_ifTrueLabel);

            Assert.AreEqual(
                $"{LKeywords.Br} {LKeywords.Label} {_ifTrueLabel.Identifier}",
                LHelper.Trim(unconditionalBr.ParseInstruction()));
        }
示例#14
0
        public void Fneg_ParseCheck_FastMathFlags()
        {
            LFneg fneg = new LFneg(_op1, _result);

            fneg.Flags.Add(LFastMathFlags.fast);
            Assert.AreEqual($"{_result.Identifier} = fneg {LFastMathFlags.fast.Parse()} {_result.ParseType()} {_op1.ValueOrIdentifier}",
                            LHelper.Trim(fneg.ParseInstruction()));
        }
示例#15
0
        public void AllocaLiteralStruct_Expected_Ok()
        {
            var     @struct = new LLiteralStruct(new LValueRef(LType.Int128Type(), ""), new LValueRef(LType.Int16Type(), ""));
            LAlloca alloca  = new LAlloca(_function, @struct);

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {{ i128, i16 }}", LHelper.Trim(alloca.ParseInstruction()));
            Assert.AreEqual("{ i128, i16 }*", LHelper.Trim(alloca.PointerRef.ParseType()));
        }
示例#16
0
        public void SimpleLshr_WithConstant_ParseCheck()
        {
            LValueRef op2 = new LValueRef(LType.Int32Type(), "12");
            LShl      shl = new LShl(_valueResult, _valueOp1, op2);

            Assert.AreEqual($"{_valueResult.Identifier} = shl {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {op2.ValueOrIdentifier}",
                            LHelper.Trim(shl.ParseInstruction()));
        }
示例#17
0
        public void SimpleLoadParse_Expected_True()
        {
            LLoad load = new LLoad(_function, _alloca.PointerRef);

            Assert.AreEqual(
                $"{load.ValueRef.Identifier} = {LKeywords.Load} {LType.Int32Type().Parse()}, {load.PointerRef.ParseType()} {load.PointerRef.Identifier}",
                LHelper.Trim(load.ParseInstruction()));
        }
示例#18
0
        public void SimpleAnd_WithConstant_ParseCheck()
        {
            LValueRef op2 = new LValueRef(LType.Int32Type(), "12");
            LAnd      and = new LAnd(_valueResult, _valueOp1, op2);

            Assert.AreEqual($"{_valueResult.Identifier} = and {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {op2.ValueOrIdentifier}",
                            LHelper.Trim(and.ParseInstruction()));
        }
示例#19
0
        public void AllocaTriplePointerType_Expected_Equal()
        {
            LPointerRef singlePointer = new LPointerRef(new LValueRef(LType.Int32Type(), ""), _function.GetPointerRefIdentifier());
            LPointerRef doublePointer = new LPointerRef(singlePointer, _function.GetPointerRefIdentifier());
            LAlloca     alloca        = new LAlloca(_function, doublePointer);

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}**", LHelper.Trim(alloca.ParseInstruction()));
            Assert.AreEqual($"{LType.Int32Type().Parse()}***", LHelper.Trim(alloca.PointerRef.ParseType()));
        }
示例#20
0
        internal static List <UsbConfigInfo> GetDeviceConfigs(UsbDevice usbDevice)
        {
            List <UsbConfigInfo> rtnConfigs = new List <UsbConfigInfo>();

            byte[] cfgBuffer = new byte[UsbConstants.MAX_CONFIG_SIZE];

            int iConfigs = usbDevice.Info.Descriptor.ConfigurationCount;

            for (int iConfig = 0; iConfig < iConfigs; iConfig++)
            {
                int  iBytesTransmitted;
                bool bSuccess = usbDevice.GetDescriptor((byte)DescriptorType.Configuration, 0, 0, cfgBuffer, cfgBuffer.Length, out iBytesTransmitted);
                if (bSuccess)
                {
                    if (iBytesTransmitted >= UsbConfigDescriptor.Size && cfgBuffer[1] == (byte)DescriptorType.Configuration)
                    {
                        UsbConfigDescriptor configDescriptor = new UsbConfigDescriptor();
                        LHelper.BytesToObject(cfgBuffer, 0, Math.Min(UsbConfigDescriptor.Size, cfgBuffer[0]), configDescriptor);

                        if (configDescriptor.TotalLength == iBytesTransmitted)
                        {
                            List <byte[]> rawDescriptorList  = new List <byte[]>();
                            int           iRawLengthPosition = configDescriptor.Length;
                            while (iRawLengthPosition < configDescriptor.TotalLength)
                            {
                                byte[] rawDescriptor = new byte[cfgBuffer[iRawLengthPosition]];
                                if (iRawLengthPosition + rawDescriptor.Length > iBytesTransmitted)
                                {
                                    throw new UsbException(usbDevice, "Descriptor length is out of range.");
                                }

                                Array.Copy(cfgBuffer, iRawLengthPosition, rawDescriptor, 0, rawDescriptor.Length);
                                rawDescriptorList.Add(rawDescriptor);
                                iRawLengthPosition += rawDescriptor.Length;
                            }
                            rtnConfigs.Add(new UsbConfigInfo(usbDevice, configDescriptor, ref rawDescriptorList));
                        }
                        else
                        {
                            UsbError.Error(ErrorCode.InvalidConfig,
                                           0,
                                           "GetDeviceConfigs: USB config descriptor length doesn't match the length received.",
                                           usbDevice);
                        }
                    }
                    else
                    {
                        UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs: USB config descriptor is invalid.", usbDevice);
                    }
                }
                else
                {
                    UsbError.Error(ErrorCode.InvalidConfig, 0, "GetDeviceConfigs", usbDevice);
                }
            }
            return(rtnConfigs);
        }
示例#21
0
        public void Switch_Unconditional_ParseCheck()
        {
            LValueRef  valueRef     = new LValueRef(LType.Int32Type(), "%1");
            LLabelType defaultLabel = new LLabelType("%default");
            LSwitch    @switch      = new LSwitch(valueRef, defaultLabel);

            Assert.AreEqual("switch i32 %1, label %default [ ]",
                            LHelper.Trim(@switch.ParseInstruction()));
        }
示例#22
0
        public void AllocaIdentifiedStruct_Expected_Ok()
        {
            string  structIdentifier = "abcTestStruct";
            var     @struct          = new LIdentifiedStruct(structIdentifier, new LValueRef(LType.Int128Type(), ""), new LValueRef(LType.Int16Type(), ""));
            LAlloca alloca           = new LAlloca(_function, @struct);

            Assert.AreEqual($"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {structIdentifier}", LHelper.Trim(alloca.ParseInstruction()));
            Assert.AreEqual($"{structIdentifier}*", LHelper.Trim(alloca.PointerRef.ParseType()));
        }
示例#23
0
        public void SimpleLshr_Exact_ParseCheck()
        {
            LLshr lshr = new LLshr(_valueResult, _valueOp1, _valueOp2)
            {
                Exact = true
            };

            Assert.AreEqual($"{_valueResult.Identifier} = lshr exact {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(lshr.ParseInstruction()));
        }
示例#24
0
        public void ConditionalBr_ParseCheck()
        {
            LValueRef      condition     = new LValueRef(LType.BoolType(), _function.GetValueRefIdentifier());
            LConditionalBr conditionalBr = new LConditionalBr(
                condition, _ifTrueLabel, _ifFalseLabel);

            Assert.AreEqual(
                $"{LKeywords.Br} i1 {condition.ValueOrIdentifier}, {LKeywords.Label} {_ifTrueLabel.Identifier}, {LKeywords.Label} {_ifFalseLabel.Identifier}",
                LHelper.Trim(conditionalBr.ParseInstruction()));
        }
示例#25
0
        public void StoreIsAtomic_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                IsAtomic = true
            };

            Assert.AreEqual(
                $"{LKeywords.Store} {LKeywords.Atomic} {_src.ParseType()} {_src.ValueOrIdentifier}, {_dst.ParseType()} {_dst.Identifier}",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#26
0
        public void AllocaParseNumOfElements_Expected_True()
        {
            LAlloca alloca = new LAlloca(_function, LType.Int32Type())
            {
                NumOfElements = 5
            };

            Assert.AreEqual(
                $"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}, {LType.Int32Type().Parse()} 5",
                LHelper.Trim(alloca.ParseInstruction()));
        }
示例#27
0
        public void AllocaParseAddrspace_Expected_True()
        {
            LAlloca alloca = new LAlloca(_function, LType.Int32Type())
            {
                Addrspace = 4
            };

            Assert.AreEqual(
                $"{alloca.PointerRef.Identifier} = {LKeywords.Alloca} {LType.Int32Type().Parse()}, {LKeywords.Addrspace}(4)",
                LHelper.Trim(alloca.ParseInstruction()));
        }
        ///<summary>
        ///Returns a <see cref="T:System.String"/> that represents the current <see cref="UsbEndpointDescriptor"/>.
        ///</summary>
        ///
        ///<param name="prefixSeperator">The field prefix string.</param>
        ///<param name="entitySperator">The field/value seperator string.</param>
        ///<param name="suffixSeperator">The value suffix string.</param>
        ///<returns>A formatted representation of the <see cref="UsbEndpointDescriptor"/>.</returns>
        public string ToString(string prefixSeperator, string entitySperator, string suffixSeperator)
        {
            Object[] values =
            {
                Length,  DescriptorType, "0x" + EndpointID.ToString("X2"), "0x" + Attributes.ToString("X2"), MaxPacketSize, Interval,
                Refresh, "0x" + SynchAddress.ToString("X2")
            };
            string[] names = { "Length", "DescriptorType", "EndpointID", "Attributes", "MaxPacketSize", "Interval", "Refresh", "SynchAddress" };

            return(LHelper.ToString(prefixSeperator, names, entitySperator, values, suffixSeperator));
        }
示例#29
0
        public void StoreAlignment_Expected_Ok()
        {
            LStore store = new LStore(_src, _dst)
            {
                Alignment = 5012
            };

            Assert.AreEqual(
                $"{LKeywords.Store} {_src.ParseType()} {_src.ValueOrIdentifier}, {_dst.ParseType()} {_dst.Identifier}, {LKeywords.Align} 5012",
                LHelper.Trim(store.ParseInstruction()));
        }
示例#30
0
        public void SimpleLshr_NuwNsw_ParseCheck()
        {
            LShl shl = new LShl(_valueResult, _valueOp1, _valueOp2)
            {
                NoUnsignedWrap = true,
                NoSignedWrap   = true,
            };

            Assert.AreEqual($"{_valueResult.Identifier} = shl nuw nsw {_valueResult.ParseType()} {_valueOp1.ValueOrIdentifier}, {_valueOp2.ValueOrIdentifier}",
                            LHelper.Trim(shl.ParseInstruction()));
        }