self.op = op
self.right = right
+ def debugInfo(self):
+ return "Assignment:"+str(self.left) + " "+str(self.op)+" "+str(self.right)
+
+
+class CondStatement:
+ def __init__(self, cond, ifpart, elsepart):
+ self.cond = cond
+ self.ifpart = ifpart
+ self.elsepart = elsepart
+
+
+def makeBlock(x):
+ if(type(x) == Assignment):
+ return [x]
+ elif(type(x) == CondStatement):
+ return [x]
+ else:
+ return x.statements
+
class Absyn:
def __init__(self, outputfn):
self.assign = []
self.ports = []
self.wires = []
+ self.comb = []
+ self.sync = []
def open(self):
if(self.outputfile is None):
def assign3(self, left, op, right):
return Assignment(left, op, right)
+ def cond_statement3(self, cond, ifpart, elsepart):
+ return CondStatement(cond, ifpart, elsepart)
+
def indent(self, count):
if(indent_debug):
return Leaf(token.INDENT, '>>> '*count)
stmts.children.append(self.nl())
return stmts
+ def do_assign(self, a, stmts, indent):
+ stmts.children.append(self.indent(indent))
+ stmts.children.append(Leaf(token.STRING, "m.d."))
+ stmts.children.append(Leaf(token.STRING, self.blocktype))
+ stmts.children.append(Leaf(token.STRING, " += "))
+ if(self.isPort(a.left)):
+ stmts.children.append(Leaf(token.STRING, "self."))
+ stmts.children.append(Leaf(token.STRING, a.left))
+ stmts.children.append(Leaf(token.STRING, ".eq("))
+ if(self.isPort(a.right)):
+ stmts.children.append(Leaf(token.STRING, "self."))
+ stmts.children.append(Leaf(token.STRING, a.right))
+ stmts.children.append(Leaf(token.STRING, ")"))
+ stmts.children.append(self.nl())
+
+ def do_ifblock(self, c, stmts, indent):
+ stmts.children.append(self.indent(indent))
+ stmts.children.append(Leaf(token.STRING, "with m.If("))
+ if(self.isPort(c.cond)):
+ stmts.children.append(Leaf(token.STRING, "self."))
+ stmts.children.append(Leaf(token.STRING, c.cond))
+ stmts.children.append(Leaf(token.STRING, "):"))
+ stmts.children.append(self.nl())
+
+ for c1 in makeBlock(c.ifpart):
+ if(type(c1) == Assignment):
+ self.do_assign(c1, stmts, indent+1)
+ else:
+ self.do_ifblock(c1, stmts, indent+1)
+
+ if(c.elsepart):
+ stmts.children.append(self.indent(indent))
+ stmts.children.append(Leaf(token.STRING, "with m.Else():"))
+ stmts.children.append(self.nl())
+
+ for c1 in makeBlock(c.elsepart):
+ if(type(c1) == Assignment):
+ self.do_assign(c1, stmts, indent+1)
+ else:
+ self.do_ifblock(c1, stmts, indent+1)
+
def elaborateFunc(self):
params = [Leaf(token.LPAR, '('), Leaf(
token.NAME, "self, platform=None"), Leaf(token.RPAR, ')')]
stmts.children.append(Leaf(token.STRING, ")"))
stmts.children.append(self.nl())
+ self.blocktype = "comb"
for a in self.assign:
- stmts.children.append(self.indent(2))
- # m.d.sync += self.left.eq(right)
- stmts.children.append(Leaf(token.STRING, "m.d.comb += "))
- if(self.isPort(a.left)):
- stmts.children.append(Leaf(token.STRING, "self."))
- stmts.children.append(Leaf(token.STRING, a.left))
- stmts.children.append(Leaf(token.STRING, ".eq("))
- if(self.isPort(a.right)):
- stmts.children.append(Leaf(token.STRING, "self."))
- stmts.children.append(Leaf(token.STRING, a.right))
- stmts.children.append(Leaf(token.STRING, ")"))
- stmts.children.append(self.nl())
+ self.do_assign(a, stmts, 2)
+
+ for c in self.comb:
+ if(type(c) == Assignment):
+ self.do_assign(c, stmts, 2)
+ else:
+ self.do_ifblock(c, stmts, 2)
+
+ self.blocktype = "sync"
+ for c in self.sync:
+ if(type(c) == Assignment):
+ self.do_assign(c, stmts, 2)
+ else:
+ self.do_ifblock(c, stmts, 2)
stmts.children.append(self.indent(2))
stmts.children.append(Leaf(token.STRING, "return m"))
def cont_assign_1(self, p):
self.assign += [Assignment(p[1], p[2], p[3])]
+ # cond assigmments and other nested blocks
def always_comb(self, p3, p1):
- print("always_comb")
slist = p3[6]
- for s in slist.statements:
- self.assign += [s]
+ self.comb += slist.statements
+
+ def always_ff(self, p3, p1):
+ slist = p3[1]
+ self.sync += slist.statements