From 29f176adeb80ca2a77f8df0f52ace39dca4b2866 Mon Sep 17 00:00:00 2001 From: Tobias Platen Date: Fri, 1 Nov 2019 17:54:57 +0100 Subject: [PATCH] cleanup, add example output --- Makefile | 2 +- absyn.py | 11 ++++++++--- parse_sv.py | 2 +- svparse.py | 6 +++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b81ad8c..57bc2b7 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,2 @@ test: - python3 svparse.py examples/assignment.sv + python3 svparse.py examples/counter.sv diff --git a/absyn.py b/absyn.py index d522502..6ccbb05 100644 --- a/absyn.py +++ b/absyn.py @@ -39,8 +39,8 @@ class Assignment: self.right = right class Absyn: - def __init__(self): - self.outputfile = open("output.py","w") + def __init__(self,outputfn): + self.outputfile = open(outputfn,"w") self.outputfile.write(preamble) self.assign = [] self.ports = [] @@ -147,7 +147,12 @@ class Absyn: print(str(clsdecl)) return clsdecl + def appendComments(self,data): + lines = data.split("\n") + for line in lines: + self.printpy("#"+line) + # combinatorical assign def cont_assign_1(self,p): - print("#ASSIGN:BROKEN"+str(list(p))) + # print("#ASSIGN:BROKEN"+str(list(p))) self.assign += [Assignment(p[1],p[2],p[3])] diff --git a/parse_sv.py b/parse_sv.py index fd25dbf..4973540 100644 --- a/parse_sv.py +++ b/parse_sv.py @@ -25,7 +25,7 @@ from lib2to3.pygram import python_symbols as syms yacc1_debug = 0 yacc2_debug = 0 -parse_debug = 1 +parse_debug = 0 from ply import yacc, lex diff --git a/svparse.py b/svparse.py index 39d8c5a..9822485 100644 --- a/svparse.py +++ b/svparse.py @@ -5,11 +5,15 @@ import parse_sv import absyn from ply import * +import os if __name__ == '__main__': fname = sys.argv[1] + outputfn = os.path.splitext(fname)[0]+'.py' + print(outputfn) with open(fname) as f: data = f.read() - parse_sv.absyn = absyn.Absyn() + parse_sv.absyn = absyn.Absyn(outputfn) yacc.parse(data, debug=parse_sv.yacc2_debug) print("No Error") + parse_sv.absyn.appendComments(data) -- 2.30.2