예제 #1
0
        public override C_Variable Clone()
        {
            ObservableCollection <C_Variable> members = new ObservableCollection <C_Variable>();
            C_Primitive cpTmp = new C_Primitive()
            {
                Type        = this.Type,
                Name        = this.Name,
                Value       = this.Value,
                Members     = members,
                DisplayType = this.DisplayType,
                Parent      = this.Parent,
                Passed      = this.Passed,
                CheckEqual  = this.CheckEqual,
                IsArray     = this.IsArray,
                IsPointer   = this.IsPointer,
                FixedAddr   = this.FixedAddr
            };

            foreach (C_Variable cvItem in Members)
            {
                C_Variable cvItemClone = cvItem.Clone();
                cvItemClone.Parent = cpTmp;
                members.Add(cvItemClone);
            }
            cpTmp.SetAddress(Address);
            return(cpTmp);
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            C_Primitive cp = obj as C_Primitive;

            if (cp != null)
            {
                bool nameEqual = Name == cp.Name;

                bool valueEqual;

                if (Value != null && cp.Value != null)
                {
                    valueEqual = Value.Equals(cp.Value);
                }
                else
                {
                    valueEqual = Value == cp.Value;
                }
                return(nameEqual & valueEqual);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        private void Populate(Dictionary <UInt32, SortedDictionary <long, UInt32> > memory,
                              C_Variable variableObj,
                              UInt32 addrBase,
                              UInt32?[] mem,
                              ref UInt32 addrOffset,
                              ref int byteIndex,
                              ref int bitIndex,
                              long timeInNS,
                              bool littleEndian           = true,
                              ICollection <String> output = null)
        {
            UInt32 word       = 0;
            int    shiftCount = 0;

            if (!littleEndian)
            {
                throw new NotImplementedException("Big Endian is not currently supported");
            }

            try
            {
                word = mem[addrOffset] ?? 0;
                variableObj.Passed = null;

                if (variableObj.IsPointer)
                {
                    UInt32 addrBasePtr    = word;
                    int    byteIndexPtr   = 0;
                    int    bitIndexPtr    = 0;
                    UInt32 addrIndexPtr   = 0;
                    UInt32 sizeInBytesPtr = Math.Max(variableObj.SizeInBits / 8, 1);
                    if (sizeInBytesPtr % 4 != 0)
                    {
                        sizeInBytesPtr = sizeInBytesPtr - (sizeInBytesPtr % 4) + 4;
                    }
                    variableObj.Value = addrBasePtr;
                    UInt32?[] data = GetRangeWords(memory, addrBasePtr, sizeInBytesPtr, timeInNS);
                    foreach (C_Variable cvItem in variableObj.Members)
                    {
                        cvItem.Populate(memory, addrBasePtr, data, ref addrIndexPtr, ref byteIndexPtr, ref bitIndexPtr, timeInNS, littleEndian, output);
                    }
                    addrOffset++;
                }
                else
                {
                    if (variableObj.IsArray)
                    {
                        if (byteIndex > 0 && bitIndex == 0)
                        {
                            bitIndex = byteIndex * 8;
                        }
                        C_Array caTmp = variableObj as C_Array;
                        if (caTmp.ArrayLength != caTmp.Members.Count)
                        {
                            throw new Exception("Array length mismatch!!!");
                        }
                        for (int i = 0; i < caTmp.ArrayLength; i++)
                        {
                            caTmp.Members[i].Populate(memory, addrBase, mem, ref addrOffset, ref byteIndex, ref bitIndex, timeInNS, littleEndian, output);
                            caTmp.Members[i].Name = String.Format("({0})", i);
                        }
                        caTmp.ToolTip = caTmp.FormattedValueArray;
                    }
                    else
                    {
                        switch (variableObj.Type)
                        {
                        case C_Type.BIT:
                            (variableObj as C_Primitive).Value = new Bit(word, bitIndex++);
                            if ((byteIndex = ((bitIndex) / 8)) > 3)
                            {
                                bitIndex  = 0;
                                byteIndex = 0;
                                addrOffset++;
                            }
                            break;

                        case C_Type.U8:
                        case C_Type.S8:
                            shiftCount = 8 * byteIndex;
                            (variableObj as C_Primitive).Value = (byte)(word >> shiftCount);
                            if ((byteIndex = (byteIndex + 1) % 4) == 0)
                            {
                                addrOffset++;
                            }
                            break;

                        case C_Type.U16:
                        case C_Type.S16:
                            UInt16 val16;
                            if (byteIndex == 0)
                            {
                                val16      = (UInt16)word;
                                byteIndex += 2;
                            }
                            else
                            {
                                shiftCount = 8 * byteIndex;
                                val16      = (UInt16)(word >> shiftCount);
                                if ((byteIndex = (byteIndex + 1) % 4) == 0)
                                {
                                    word       = mem[++addrOffset] ?? 0;
                                    shiftCount = 0x20 - shiftCount;
                                    val16     |= (UInt16)(word << shiftCount);
                                }
                                byteIndex++;
                                if (byteIndex % 4 == 0)
                                {
                                    byteIndex = 0;
                                    addrOffset++;
                                }
                            }
                            C_Primitive cp16 = (variableObj as C_Primitive);
                            cp16.Value = val16;
                            break;

                        case C_Type.BOOL:
                        case C_Type.U32:
                        case C_Type.S32:
                            UInt32 val32;
                            if (byteIndex == 0)
                            {
                                val32 = word;
                                addrOffset++;
                            }
                            else
                            {
                                shiftCount = 8 * byteIndex;
                                val32      = word >> shiftCount;
                                word       = mem[++addrOffset] ?? 0;
                                val32     |= word << (0x20 - shiftCount);
                            }
                            C_Primitive cp32 = (variableObj as C_Primitive);
                            cp32.Value = val32;
                            break;

                        case C_Type.U64:
                        case C_Type.S64:
                            UInt64 val64;
                            if (byteIndex == 0)
                            {
                                val64  = word;
                                val64 |= (UInt64)(mem[++addrOffset] ?? 0) << 0x20;
                                addrOffset++;
                            }
                            else
                            {
                                shiftCount = 8 * byteIndex;
                                val64      = word >> shiftCount;
                                shiftCount = 0x20 - shiftCount;
                                word       = mem[++addrOffset] ?? 0;
                                val64     |= (UInt64)word << shiftCount;
                                word       = mem[++addrOffset] ?? 0;
                                val64     |= (UInt64)word << (shiftCount + 0x20);
                            }

                            if (!littleEndian)
                            {
                                byte[] bArrTmp = BitConverter.GetBytes(val64);
                                Array.Reverse(bArrTmp);
                                val64 = BitConverter.ToUInt64(bArrTmp, 0);
                            }

                            C_Primitive cp64 = (variableObj as C_Primitive);
                            cp64.Value = val64;
                            break;

                        case C_Type.ENUM:
                            C_Enum ceEnum = (variableObj as C_Enum);
                            shiftCount   = 8 * (littleEndian ? byteIndex : 3 - byteIndex);
                            ceEnum.Value = word >> shiftCount;
                            if (byteIndex != 0)
                            {
                                byteIndex    = 4 - byteIndex;
                                shiftCount   = 8 * (littleEndian ? byteIndex : 3 - byteIndex);
                                word         = mem[++addrOffset] ?? 0;
                                ceEnum.Value = (UInt32)ceEnum.Value | (word >> shiftCount);
                            }
                            else
                            {
                                addrOffset++;
                            }
                            break;

                        case C_Type.STRUCT:
                            C_Struct csTmp = variableObj as C_Struct;
                            csTmp.SetAddress(addrBase + addrOffset * 4);
                            foreach (C_Variable cvItem in csTmp.Members)
                            {
                                cvItem.Populate(memory, addrBase, mem, ref addrOffset, ref byteIndex, ref bitIndex, timeInNS, littleEndian, output);
                            }
                            csTmp.ToolTip = csTmp.FormattedValueStruct;

                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogWriter.Instance.WriteToLog(ex, "Error parsing: {0}", variableObj.Name);
                output?.Add(String.Format("Parsing error: {0}\n{1}", ex.Message, ex.StackTrace));
            }
        }