예제 #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 createStateNode(infval, width):
    statelabels = []
    minval = infval.minval
    maxval = infval.maxval
    if minval is None: minval = 0
    if maxval is None: maxval = util.maxValue(width)
    ret = StateNode(((minval, maxval), ), 0, util.maxValue(width), None)
    if infval.inv: ret = notStateNodeList(ret)
    return ret
예제 #4
0
def createStateNode(infval, width):
    statelabels = []
    minval = infval.minval
    maxval = infval.maxval
    if minval is None: minval = 0
    if maxval is None: maxval = util.maxValue(width)
    ret = StateNode( ((minval, maxval),), 0, util.maxValue(width), None)
    if infval.inv: ret = notStateNodeList(ret)
    return ret
예제 #5
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
예제 #6
0
def walkCondlist(condlist, termname, termwidth=32):
    node = None
    if len(condlist) == 0:
        maxvalue = util.maxValue(termwidth)
        return StateNode(maxvalue=maxvalue, isany=True)
    for cond in condlist:
        rslt = walkCond(cond, termname, termwidth)
        if node and rslt: node = andStateNodeList(node, rslt)
        elif rslt: node = rslt
    return node
예제 #7
0
def walkCondlist(condlist, termname, termwidth=32):
    node = None
    if len(condlist) == 0: 
        maxvalue = util.maxValue(termwidth)
        return StateNode(maxvalue=maxvalue, isany=True)
    for cond in condlist:
        rslt = walkCond(cond, termname, termwidth)
        if node and rslt: node = andStateNodeList(node, rslt)
        elif rslt: node = rslt
    return node
예제 #8
0
def walkCond(cond, termname, termwidth=32):
    if isinstance(cond, DFOperator):
        if len(cond.nextnodes) == 1:
            return _walkCond_DFOperator_unary(cond, termname, termwidth)
        if len(cond.nextnodes) == 2:
            return _walkCond_DFOperator_dual(cond, termname, termwidth)
    if isinstance(cond, DFTerminal):
        comp_cond = DFOperator((cond, DFEvalValue(0)), 'GreaterThan')
        return _walkCond_DFOperator_dual(comp_cond, termname, termwidth)
    maxvalue = util.maxValue(termwidth)
    return StateNode(transcond=cond, maxvalue=maxvalue, isany=True)
예제 #9
0
def walkCond(cond, termname, termwidth=32):
    if isinstance(cond, DFOperator):
        if len(cond.nextnodes) == 1:
            return _walkCond_DFOperator_unary(cond, termname, termwidth)
        if len(cond.nextnodes) == 2:
            return _walkCond_DFOperator_dual(cond, termname, termwidth)
    if isinstance(cond, DFTerminal):
        comp_cond = DFOperator((cond, DFEvalValue(0)), 'GreaterThan')
        return _walkCond_DFOperator_dual(comp_cond, termname, termwidth)
    maxvalue = util.maxValue(termwidth)
    return StateNode(transcond=cond, maxvalue=maxvalue, isany=True)