示例#1
0
class Xor:
    def __init__(self):
        # components:
        self.not1 = Not()
        self.not2 = Not()
        self.and1 = And()
        self.and2 = And()
        self.or1 = Or()

        # connections:

        self.a = self.and1.a
        self.not2.a = self.and1.a
        self.b = self.and2.b
        self.not1.a = self.and2.b
        self.and1.b = self.not1.x
        self.and2.a = self.not2.x
        self.or1.a = self.and1.x
        self.or1.b = self.and2.x
        self.x = self.or1.x

    def update(self):
        self.not1.update()
        self.not2.update()
        self.and1.update()
        self.and2.update()
        self.or1.update()
示例#2
0
 def derive(self, s):
     left = self.children[0]
     right = self.children[1]
     if left.containsEpsilon():
         orChildren = []
         orChildren.append(Concat.getERE(left.derive(s), right.__copy__()))
         orChildren.append(right.derive(s))
         return Or.getERE(orChildren)
     return Concat.getEre(left.derive(s), right.__copy__())
示例#3
0
    def derive(self, s):
        left = self.children[0]
        right = self.children[1]

        if left.containsEpsilon():
            orlist = [
                Concat.getERE(left.derive(s), right.__copy__()),
                right.derive(s)
            ]
            return Or.getERE(orlist)
        return self.getERE(left.derive(s), right.__copy__())
示例#4
0
def Ifxtheny(a, b, z):
    notx = Signal(0)
    out = Signal(0)

    n1 = Not(a, notx)
    n2 = Or(notx, b, out)

    @always_comb
    def f():
        z.next = out

    return f, n1, n2
示例#5
0
def Nor(a, b, z):
    orab = Signal(0)
    out = Signal(0)

    n1 = Or(a, b, orab)
    n2 = Not(orab, out)

    @always_comb
    def f():
        z.next = out

    return f, n1, n2
示例#6
0
def Ifythenx(a, b, z):
    noty = Signal(0)
    out = Signal(0)

    n1 = Not(b, noty)
    n2 = Or(noty, a, out)

    @always_comb
    def f():
        z.next = out

    return f, n1, n2
示例#7
0
def Ifxtheny(x, y, out):
    out1 = Signal(0)
    n1 = Signal(0)
    n2 = Signal(0)
    n3 = Signal(0)
    n4 = Signal(0)
    n5 = Signal(0)
    n6 = Signal(0)

    s1 = Not(x, n3)
    s2 = Or(n3, y, out1)

    @always_comb
    def f():
        out.next = out1

    return f, s1, s2
示例#8
0
def Nor(x, y, out):
    out1 = Signal(0)
    n1 = Signal(0)
    n2 = Signal(0)
    n3 = Signal(0)
    n4 = Signal(0)
    n5 = Signal(0)
    n6 = Signal(0)

    s1 = Or(x, y, n1)
    s2 = Not(n1, out1)

    @always_comb
    def f():
        out.next = out1

    return f, s1, s2
示例#9
0
def Xor(x, y, out):
    out1 = Signal(0)
    n1 = Signal(0)
    n2 = Signal(0)
    n3 = Signal(0)
    n4 = Signal(0)
    n5 = Signal(0)
    n6 = Signal(0)

    s1 = Xandnoty(x, y, n3)
    s2 = Notxandy(x, y, n6)
    s3 = Or(n3, n6, out1)

    @always_comb
    def f():
        out.next = out1

    return f, s1, s2, s3
示例#10
0
def Equivalence(a, b, z):
    notx = Signal(0)
    noty = Signal(0)
    andxy = Signal(0)
    andnotxnoty = Signal(0)
    out = Signal(0)

    n1 = Not(a, notx)
    n2 = Not(b, noty)
    n3 = And(a, b, andxy)
    n4 = And(notx, noty, andnotxnoty)
    n5 = Or(andxy, andnotxnoty, out)

    @always_comb
    def f():
        z.next = out

    return f, n1, n2, n3, n4, n5
示例#11
0
def Xor(a, b, z):
    nota = Signal(0)
    notb = Signal(0)
    andanotb = Signal(0)
    andbnota = Signal(0)
    out = Signal(0)

    n1 = Not(a,nota)
    n2 = Not(b,notb)
    n3 = And(a,notb,andanotb)
    n4 = And(b,nota,andbnota)
    n5 = Or(andanotb,andbnota,out)
    
    @always_comb
    def f():
        z.next = out

    return f, n1, n2, n3, n4, n5
示例#12
0
    def makeERE(erlist, symbols):
        if type(erlist) is list:
            negflag = False
            orflag = False
            catflag = False
            andflag = False
            #need some initial ERE to make sure this works correctly
            currentERE = Empty()
            for ind, obj in enumerate(erlist):
                if obj == "*":
                    if ind == 0:
                        raise SyntaxError("Kleene closure must be after stuff")
                    currentERE = Kleene.getERE(currentERE)
                elif obj == "~":
                    negflag = True
                    continue
                elif obj == "|":
                    orflag = True
                    continue
                elif obj == "+":
                    catflag = True
                    continue
                elif obj == "&":
                    andflag = True
                    continue
                else:
                    if ind == 0 | negflag:
                        currentERE = EREMachine.makeERE(obj, symbols)
                    elif orflag:
                        currentERE = Or.getERE(
                            [currentERE,
                             EREMachine.makeERE(obj, symbols)])
                        orflag = False
                    elif catflag:
                        currentERE = Concat.getERE(
                            currentERE, EREMachine.makeERE(obj, symbols))
                        catflag = False
                    elif andflag:
                        currentERE = Negation.getERE(
                            Concat.getERE(
                                Negation.getERE(currentERE),
                                Negation.getERE(
                                    EREMachine.makeERE(obj, symbols))))
                        andflag = False
                    else:
                        currentERE = Concat.getERE(
                            currentERE, EREMachine.makeERE(obj, symbols))
                    if negflag:
                        currentERE = Negation.getERE(currentERE)
                        negflag = False
            return currentERE

        else:
            if erlist == 'empty':
                return Empty.getERE()
            elif erlist == 'epsilon':
                return Epsilon.getERE()
            elif erlist in symbols:
                return Symbol.getERE(erlist)
            elif not erlist:
                return
            else:
                raise ValueError(
                    'Either you have used a symbol not tied to event, or epsilon/empty is misspelled'
                )