def main(): if len(sys.argv) != 3: print(len(sys.argv)-1, "is an incorrect amount of arguments.", end='') exit("") # Check both files if check_file_extension(sys.argv[1], 1) == True: if check_file_extension(sys.argv[2], 2) == True: parser.process_file(sys.argv[1], sys.argv[2])
def main(): program = parser.process_file(sys.argv[1]) graphs = [] for name, function in program.iteritems(): graphs.append(CFG(name, function['blocks'], function['args'])) for graph in graphs: optimiser.Optimiser.remove_unreachable_nodes(graph) while True: optimiser.Optimiser.remove_dead_code(graph) # this returns False if no changes were made if optimiser.Optimiser.fix_redundant_loads(graph) == False: break print graphs_to_code(graphs)
def main(): global functions try: if len(sys.argv) <= 1: raise FileNotGivenException() functions = parser.process_file(sys.argv[1]) process_program(sys.argv[2:]) except IOError: print "Error: File does not exist. Cannot execute." exit(1) except FileNotGivenException as e: print "Error: No input file given. Cannot execute." exit(1) except FunctionUndefinedException as e: print "Error: Function name '%s' is undefined." % (e.value) exit(1) except VariableUndefinedException as e: print "Error: Variable '%s' is undefined." % (e.value) exit(1) except RegisterUndefinedException as e: print "Error: Register '%s' is undefined." % (e.value) exit(1) except FunctionArgMismatchException as e: print "Error: Function '%s' requires %d argument(s), but %d given." % ( e.function, e.required, e.given) exit(1) except UndefinedIntermediateCodeException as e: print "Error: Intermediate function '%s' in function '%s' on block %d is undefined." % ( e.instruction, e.function, e.block) exit(1) except BlockUndefinedException as e: print "Error: Block %d does not exist in function '%s'." % (e.block, e.function) exit(1) except IndexError: print "Error: Corrupted intermediate file. Cannot execute." exit(1)
# Formatting prompt = '> ' line_break = '-=-' * 20 # Script arguments script, calendar_file = argv print line_break print "Welcome to %s v%s" % (script, str(script_version)) print line_break, "\n" sleep(1) print 'Processing "%s"...\n' % (calendar_file) list = process_file(calendar_file) if list: print "Success!\n" sleep(1) else: print "File unable to be read." exit(1) print 'What output would you like?\n' print '1 for onscreen. 2 for output.txt\n' output_choice = raw_input(prompt) if output_choice not in ['1', '2']: print 'Wrong answer choice. Please try script again.'