X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=absyn.py;h=ecd3846516ddf89e773c7b3bdb20754cf52e5e8b;hb=10c1bd0020878f84ededfa7c47d0ed4fd43f50bf;hp=60a87ba077da641885a424a0b3b50903a9b11a01;hpb=6a8eb41c41826fc26f159e66172d436c09a8f53a;p=sv2nmigen.git diff --git a/absyn.py b/absyn.py index 60a87ba..ecd3846 100644 --- a/absyn.py +++ b/absyn.py @@ -46,19 +46,28 @@ class Assignment: class Absyn: def __init__(self, outputfn): - self.outputfile = open(outputfn, "w") - self.outputfile.write(preamble) + self.outputfn = outputfn + self.outputfile = None self.assign = [] self.ports = [] + self.wires = [] + + def open(self): + if(self.outputfile is None): + self.outputfile = open(self.outputfn, "w") + self.outputfile.write(preamble) def printpy(self, p): + self.open() self.outputfile.write(str(p)+"\n") def assign(self, p): p = list(p) if(p[1] == "assign"): self.printpy(p[4]) - # m.d.comb += [l.eq(r)] + + def assign3(self, left, op, right): + return Assignment(left, op, right) def indent(self, count): if(indent_debug): @@ -77,6 +86,12 @@ class Absyn: self.ports += [port] return port + def isPort(self, name): + for p in self.ports: + if(str(p.name) == str(name)): + return True + return False + def initFunc(self, ports, params): params = [Leaf(token.LPAR, '('), Leaf( token.NAME, "self")] + [Leaf(token.RPAR, ')')] @@ -110,22 +125,31 @@ class Absyn: stmts.children.append(Leaf(token.STRING, "m = Module()")) stmts.children.append(self.nl()) + for w in self.wires: + wirename = w[0] + hasdims = (len(w) >= 4) + stmts.children.append(self.indent(2)) + stmts.children.append(Leaf(token.STRING, wirename)) + stmts.children.append(Leaf(token.STRING, " = Signal(")) + if(hasdims): + stmts.children.append(Leaf(token.STRING, str(w[3]))) + stmts.children.append(Leaf(token.STRING, ")")) + stmts.children.append(self.nl()) + 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 += self.")) + 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(self.")) + 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()) - # for a in self.assign: - # - # - #ports = a[8] - # - stmts.children.append(self.indent(2)) stmts.children.append(Leaf(token.STRING, "return m")) stmts.children.append(self.nl()) @@ -154,11 +178,18 @@ class Absyn: clsdecl = Node(syms.compound_stmt, [clsdecl]) self.printpy(str(clsdecl)) - print("=====================") - print(str(clsdecl)) return clsdecl + def module_item_2(self, signaltype, dims, mlist): + if(signaltype == "wire"): + for m in mlist: + if(dims): + self.wires.append(m+dims) + else: + self.wires.append(m) + def appendComments(self, data): + self.open() self.outputfile.write(data) #lines = data.split("\n") # for line in lines: @@ -166,5 +197,10 @@ class Absyn: # combinatorical assign def cont_assign_1(self, p): - # print("#ASSIGN:BROKEN"+str(list(p))) self.assign += [Assignment(p[1], p[2], p[3])] + + def always_comb(self, p3, p1): + print("always_comb") + slist = p3[6] + for s in slist.statements: + self.assign += [s]