Пример #1
0
def _walkCond_DFOperator_dual(cond, termname, termwidth=32):
    maxvalue = util.maxValue(termwidth)
    if signaltype.isNonConditionOp(cond.operator):
        return StateNode(transcond=cond, maxvalue=maxvalue, isany=True)

    if not signaltype.isCompare(cond.operator) and signaltype.isOr(cond.operator):
        lnode = walkCond(cond.nextnodes[0], termname, termwidth)
        rnode = walkCond(cond.nextnodes[1], termname, termwidth)
        ret = orStateNodeList(lnode, rnode)
        if ret: return ret
    if not signaltype.isCompare(cond.operator) and signaltype.isAnd(cond.operator):
        lnode = walkCond(cond.nextnodes[0], termname, termwidth)
        rnode = walkCond(cond.nextnodes[1], termname, termwidth)
        ret = andStateNodeList(lnode, rnode)
        if ret: return ret

    l = cond.nextnodes[0]
    r = cond.nextnodes[1]

    if isinstance(l, DFTerminal) and l.name == termname:
        infval = inference.infer(cond.operator, r)
        return createStateNode(infval, termwidth)
    if isinstance(r, DFTerminal) and r.name == termname:
        new_op = re.sub('Greater', 'TMP', cond.operator)
        new_op = re.sub('Less', 'Greater', new_op)
        new_op = re.sub('TMP', 'Less', new_op)
        infval = inference.infer(new_op, l)
        return createStateNode(infval, termwidth)

    maxvalue = util.maxValue(termwidth)
    return StateNode(transcond=cond, maxvalue=maxvalue, isany=True)
Пример #2
0
def _walkCond_DFOperator_dual(cond, termname, termwidth=32):
    maxvalue = util.maxValue(termwidth)
    if signaltype.isNonConditionOp(cond.operator):
        return StateNode(transcond=cond, maxvalue=maxvalue, isany=True)

    if not signaltype.isCompare(cond.operator) and signaltype.isOr(
            cond.operator):
        lnode = walkCond(cond.nextnodes[0], termname, termwidth)
        rnode = walkCond(cond.nextnodes[1], termname, termwidth)
        ret = orStateNodeList(lnode, rnode)
        if ret: return ret
    if not signaltype.isCompare(cond.operator) and signaltype.isAnd(
            cond.operator):
        lnode = walkCond(cond.nextnodes[0], termname, termwidth)
        rnode = walkCond(cond.nextnodes[1], termname, termwidth)
        ret = andStateNodeList(lnode, rnode)
        if ret: return ret

    l = cond.nextnodes[0]
    r = cond.nextnodes[1]

    if isinstance(l, DFTerminal) and l.name == termname:
        infval = inference.infer(cond.operator, r)
        return createStateNode(infval, termwidth)
    if isinstance(r, DFTerminal) and r.name == termname:
        new_op = re.sub('Greater', 'TMP', cond.operator)
        new_op = re.sub('Less', 'Greater', new_op)
        new_op = re.sub('TMP', 'Less', new_op)
        infval = inference.infer(new_op, l)
        return createStateNode(infval, termwidth)

    maxvalue = util.maxValue(termwidth)
    return StateNode(transcond=cond, maxvalue=maxvalue, isany=True)
Пример #3
0
    def _walkActiveCond_DFOperator_dual(self, cond):
        l = cond.nextnodes[0]
        r = cond.nextnodes[1]

        if signaltype.isOr(cond.operator):
            lactivecond = self.walkActiveCond(l)
            ractivecond = self.walkActiveCond(r)
            if lactivecond is None and ractivecond is not None: return ractivecond
            if lactivecond is not None and ractivecond is None: return lactivecond
            return self._activecond_opOr(lactivecond, ractivecond)

        if signaltype.isAnd(cond.operator):
            lactivecond = self.walkActiveCond(l)
            ractivecond = self.walkActiveCond(r)
            if lactivecond is None and ractivecond is not None: return ractivecond
            if lactivecond is not None and ractivecond is None: return lactivecond
            return self._activecond_opAnd(lactivecond, ractivecond)

        if isinstance(l, DFTerminal):
            infval = inference.infer(cond.operator, r)
            minval = 0
            maxval = util.maxValue(self.getWidth(l.name))
            range_pairs = ((infval.minval, infval.maxval),)
            return ActiveTerm(l.name, range_pairs, minval, maxval)

        if isinstance(r, DFTerminal):
            new_op = re.sub('Greater', 'TMP', cond.operator)
            new_op = re.sub('Less', 'Greater', new_op)
            new_op = re.sub('TMP', 'Less', new_op)
            infval = inference.infer(new_op, l)
            minval = 0
            maxval = util.maxValue(self.getWidth(r.name))
            range_pairs = ((infval.minval, infval.maxval),)
            return ActiveTerm(r.name, range_pairs, minval, maxval)

        if cond.operator == 'Eq':
            lactivecond = self.walkActiveCond(l)
            ractivecond = self.walkActiveCond(r)
            if lactivecond is not None and ractivecond is None and isinstance(r, DFEvalValue):
                if r.value > 0: return lactivecond
                return self._activecond_opNot(lactivecond)
            if lactivecond is None and ractivecond is not None and isinstance(l, DFEvalValue):
                if l.value > 0: return ractivecond
                return self._activecond_opNot(ractivecond)
            return self._activecond_opAnd(lactivecond, ractivecond)

        if cond.operator == 'NotEq':
            lactivecond = self.walkActiveCond(l)
            ractivecond = self.walkActiveCond(r)
            if lactivecond is not None and ractivecond is None and isinstance(r, DFEvalValue):
                if r.value == 0: return lactivecond
                return self._activecond_opNot(lactivecond)
            if lactivecond is None and ractivecond is not None and isinstance(l, DFEvalValue):
                if l.value == 0: return ractivecond
                return self._activecond_opNot(ractivecond)
            return None
        return None