do not create output files on error
authorTobias Platen <tplaten@posteo.de>
Thu, 23 Jan 2020 12:12:48 +0000 (13:12 +0100)
committerTobias Platen <tplaten@posteo.de>
Thu, 23 Jan 2020 12:12:48 +0000 (13:12 +0100)
absyn.py

index 60a87ba077da641885a424a0b3b50903a9b11a01..e81e429510dd504feb19c6aa8921b23ff7b68c9a 100644 (file)
--- a/absyn.py
+++ b/absyn.py
@@ -46,12 +46,18 @@ 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 = []
 
+    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):
@@ -159,6 +165,7 @@ class Absyn:
         return clsdecl
 
     def appendComments(self, data):
+        self.open()
         self.outputfile.write(data)
         #lines = data.split("\n")
         # for line in lines: