+#Sorts out instructions according to sequence number
+def compare_by_sn(a, b):
+ return cmp(a['sn'], b['sn'])
+
+# Puts new instruction into the print queue.
+# Sorts out and prints instructions when their number reaches threshold value
+def queue_inst(outfile, inst, cycle_time, width, color, timestamps, store_completions):
+ global insts
+ l_copy = copy.deepcopy(inst)
+ insts['queue'].append(l_copy)
+ if len(insts['queue']) > insts['max_threshold']:
+ print_insts(outfile, cycle_time, width, color, timestamps, store_completions, insts['min_threshold'])
+
+# Sorts out and prints instructions in print queue
+def print_insts(outfile, cycle_time, width, color, timestamps, store_completions, lower_threshold):
+ global insts
+ insts['queue'].sort(compare_by_sn)
+ while len(insts['queue']) > lower_threshold:
+ print_item=insts['queue'].pop(0)
+ # As the instructions are processed out of order the main loop starts
+ # earlier then specified by start_sn/tick and finishes later then what
+ # is defined in stop_sn/tick.
+ # Therefore, here we have to filter out instructions that reside out of
+ # the specified boundaries.
+ if (insts['sn_start'] > 0 and print_item['sn'] < insts['sn_start']):
+ continue; # earlier then the starting sequence number
+ if (insts['sn_stop'] > 0 and print_item['sn'] > insts['sn_stop']):
+ continue; # later then the ending sequence number
+ if (insts['tick_start'] > 0 and print_item['fetch'] < insts['tick_start']):
+ continue; # earlier then the starting tick number
+ if (insts['tick_stop'] > 0 and print_item['fetch'] > insts['tick_stop']):
+ continue; # later then the ending tick number
+
+ if (insts['only_committed'] != 0 and print_item['retire'] == 0):
+ continue; # retire is set to zero if it hasn't been completed
+ print_inst(outfile, print_item, cycle_time, width, color, timestamps, store_completions)
+
+# Prints a single instruction
+def print_inst(outfile, inst, cycle_time, width, color, timestamps, store_completions):