def splitOnWords(self, transaction, addrOffset=0): """ :return: generator of TransPart instance """ wordWidth = self.wordWidth end = addrOffset for tmp in transaction.walkFlatten(offset=addrOffset): if isinstance(tmp, OneOfTransaction): # unions split = [ self.splitOnWords(ch, end) for ch in tmp.possibleTransactions ] yield from groupIntoChoices(split, wordWidth, tmp) end = addrOffset + tmp.possibleTransactions[0].bitAddrEnd else: # constant size types (base, end), tmpl = tmp startOfPart = base while startOfPart != end: wordIndex = startOfPart // wordWidth endOfWord = (wordIndex + 1) * wordWidth endOfPart = min(endOfWord, end) inFieldOffset = startOfPart - base yield TransPart(self, tmpl, False, startOfPart, endOfPart, inFieldOffset) startOfPart = endOfPart
def splitOnWords(self, transaction, addrOffset=0): """ :return: generator of TransPart instance """ wordWidth = self.wordWidth end = addrOffset for tmp in transaction.walkFlatten(offset=addrOffset): if isinstance(tmp, OneOfTransaction): split = [ self.splitOnWords(ch, end) for ch in tmp.possibleTransactions ] yield from groupIntoChoices(split, wordWidth, tmp) end = addrOffset + tmp.possibleTransactions[0].bitAddrEnd elif isinstance(tmp, StreamTransaction): ch_len = tmp.child.bit_length() if end % self.wordWidth != 0 or ch_len != self.wordWidth: # assert start, end is aligned raise NotImplementedError(tmp) else: s = StreamOfFramePars(end, tmp) s.extend(self.splitOnWords(tmp.child, end)) s.setIsLast(True) s.resolveEnd() yield s end = addrOffset + tmp.child.bitAddrEnd else: (base, end), tmpl = tmp startOfPart = base while startOfPart != end: wordIndex = startOfPart // wordWidth endOfWord = (wordIndex + 1) * wordWidth endOfPart = min(endOfWord, end) inFieldOffset = startOfPart - base yield TransPart(self, tmpl, startOfPart, endOfPart, inFieldOffset) startOfPart = endOfPart
def getInDataSignal(self, transPart: TransPart): busDataSignal = self.dataIn.data high, low = transPart.getBusWordBitRange() return busDataSignal[high:low]
def walkWords(self, showPadding: bool=False): """ Walk enumerated words in this frame :attention: not all indexes has to be present, only words with items will be generated when not showPadding :param showPadding: padding TransParts are also present :return: generator of tuples (wordIndex, list of TransParts in this word) """ wIndex = 0 lastEnd = self.startBitAddr parts = [] for p in self.parts: end = p.startOfPart if showPadding and end != lastEnd: # insert padding before data while end != lastEnd: assert end >= lastEnd, (end, lastEnd) endOfWord = ceil( (lastEnd + 1) / self.wordWidth) * self.wordWidth endOfPadding = min(endOfWord, end) _p = TransPart(self, None, False, lastEnd, endOfPadding, 0) parts.append(_p) if endOfPadding >= endOfWord: yield (wIndex, parts) wIndex += 1 parts = [] lastEnd = endOfPadding if self._wordIndx(lastEnd) != self._wordIndx(p.startOfPart): # if input data continues to a next word, yield current word # and start processing next one yield (wIndex, parts) wIndex += 1 parts = [] lastEnd = p.endOfPart parts.append(p) lastEnd = p.endOfPart if lastEnd % self.wordWidth == 0: # if we can not add anything to this word, # yield it directly and continue on next word yield (wIndex, parts) wIndex += 1 parts = [] if showPadding and (parts or lastEnd != self.endBitAddr or lastEnd % self.wordWidth != 0): # align end to end of last word end = ceil(self.endBitAddr / self.wordWidth) * self.wordWidth # padding is non removable if it is part of data # and it is removable if it was generated by frame alignment endOfNonRemovablePadding = self.origin.bitAddrEnd while end != lastEnd: assert end >= lastEnd, (end, lastEnd) endOfWord = ((lastEnd // self.wordWidth) + 1) * self.wordWidth endOfPadding = min(endOfWord, end) if lastEnd < endOfNonRemovablePadding: endOfPadding = min(endOfPadding, endOfNonRemovablePadding) can_be_removed = False else: can_be_removed = True _p = TransPart(self, None, can_be_removed, lastEnd, endOfPadding, 0) _p.parent = self parts.append(_p) if endOfPadding >= endOfWord: yield (wIndex, parts) wIndex += 1 parts = [] lastEnd = endOfPadding if parts: # in the case end of frame is not aligned to end of word yield (wIndex, parts)
def walkWords(self, showPadding: bool = False): """ Walk enumerated words in this frame :attention: not all indexes has to be present, only words with items will be generated when not showPadding :param showPadding: padding TransParts are also present :return: generator of tuples (wordIndex, list of TransParts in this word) """ wIndex = 0 lastEnd = self.startBitAddr parts = [] for p in self.parts: end = p.startOfPart if showPadding and end != lastEnd: # insert padding while end != lastEnd: assert end >= lastEnd, (end, lastEnd) endOfWord = ceil( (lastEnd + 1) / self.wordWidth) * self.wordWidth endOfPadding = min(endOfWord, end) _p = TransPart(self, None, lastEnd, endOfPadding, 0) parts.append(_p) if endOfPadding >= endOfWord: yield (wIndex, parts) wIndex += 1 parts = [] lastEnd = endOfPadding if self._wordIndx(lastEnd) != self._wordIndx(p.startOfPart): yield (wIndex, parts) wIndex += 1 parts = [] lastEnd = p.endOfPart parts.append(p) lastEnd = p.endOfPart if lastEnd % self.wordWidth == 0: yield (wIndex, parts) wIndex += 1 parts = [] if showPadding and (parts or lastEnd != self.endBitAddr or lastEnd % self.wordWidth != 0): # align end to end of last word end = ceil(self.endBitAddr / self.wordWidth) * self.wordWidth while end != lastEnd: assert end >= lastEnd, (end, lastEnd) endOfWord = ((lastEnd // self.wordWidth) + 1) * self.wordWidth endOfPadding = min(endOfWord, end) _p = TransPart(self, None, lastEnd, endOfPadding, 0) _p.parent = self parts.append(_p) if endOfPadding >= endOfWord: yield (wIndex, parts) wIndex += 1 parts = [] lastEnd = endOfPadding if parts: # in the case end of frame is not aligned to end of word yield (wIndex, parts)