X-Git-Url: https://git.libre-soc.org/?p=sv2nmigen.git;a=blobdiff_plain;f=absyn.py;h=a199daa4da6846ebe31ddf19fe9015248d712107;hp=60a87ba077da641885a424a0b3b50903a9b11a01;hb=b41a016efd59e3ee5ae118eb4e50d7b832c83b6e;hpb=6a8eb41c41826fc26f159e66172d436c09a8f53a diff --git a/absyn.py b/absyn.py index 60a87ba..a199daa 100644 --- a/absyn.py +++ b/absyn.py @@ -46,12 +46,19 @@ 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): @@ -77,6 +84,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,12 +123,27 @@ 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()) @@ -154,11 +182,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: