def run(self): self.SyntaxCheck() stmt = copy.deepcopy(self.source) self.buildDict(stmt) count = 0 if self.optLevel == 0: newstmt = [] newstmt = self.removeUnusedVariables(stmt) self.buildDict(newstmt) else: newstmt = [] cmpstmt = copy.deepcopy(stmt) while True: # print cmpstmt count += 1 newstmt = self.removeUnusedVariables(stmt) boolval = self.listscheck(newstmt, cmpstmt) # print boolval if boolval == False and len(newstmt) != 0: self.buildDict(newstmt) cmpstmt = copy.deepcopy(newstmt) self.removeVariables = [] else: # print newstmt break if len(newstmt) > 0: live = liveanalysis.LiveAnalysis(newstmt) live.run() if self.listscheck(newstmt, live.getLAStmt()) == False: newstmt = live.getLAStmt() self.buildDict(newstmt) # print newstmt # print "\nIntermediate Code:" print live.allocReg cgen = CGen.CodeGen(self.asmfile, live.allocReg, self.Dict, self.removeVariables) cgen.generateIntermediateCode() cgen.generateASM() else: print "\nNo code generation required.!\n"
Parser_05.run(data, copypropagation, constpropagation, loopinvariant, commonsubexpelim) else: print "File: <%s> is empty.!" % (fileName) sys.exit(-1) ## Static Semantic Analysis ## print "Intermediate Code: ", Parser_05.intermediateCode print copypropagation print # ''' # Live Analysis ## import liveanalysis live = liveanalysis.LiveAnalysis(Parser_05.intermediateCode, copypropagation, constpropagation, loopinvariant, commonsubexpelim) live.run() print live.allocReg # print live.Dict asmfile = fileName.split('.')[0] + '.asm' removeVariables = [] # ''' ## Final Code Generation ## import CGen cgen = CGen.CodeGen(asmfile, live.allocReg, live.stmt) cgen.generateIntermediateCode() cgen.generateASM() # '''
data = readInput(fid) ## Closing the opened file descriptor ## fid.close() if data: Parser.run(data) else: print "File: <%s> is empty.!" % (fileName) sys.exit(-1) ## Static Semantic Analysis ## # print "Intermediate Code: ", Parser.intermediateCode # ''' ## Live Analysis ## import liveanalysis live = liveanalysis.LiveAnalysis(Parser.intermediateCode) live.run() print live.allocReg print live.Dict # ''' asmfile = fileName.split('.')[0] + '.asm' removeVariables = [] ## Final Code Generation ## import CGen cgen = CGen.CodeGen(asmfile, live.allocReg, live.Dict, removeVariables) cgen.generateIntermediateCode() cgen.generateASM() # '''