scripts:
[testub10.git] / scripts / clr.py
1 #!/usr/bin/python
2 # http://www.informatik-forum.at/showthread.php?73283-SCRIPT-Einf%E4rben-von-Assembler-Code
3 # Einfaerben von amd64 Assembler-Code
4 # thp/a\thpinfo.com; 2009-05-22
5
6 import sys
7 import re
8
9 # Farbcodes siehe http://www.pixelbeat.org/docs/terminal_colours/
10 colorify = (
11         # Return-Register: violett
12         (r'()(%rax)()', '35'),
13         # Argument-Register: gruen
14         (r'()(%rdi|%rsi|%rdx|%rcx|%r8|%r9)()', '32'),
15         # Temporary Register: gelb
16         (r'()(%r10|%r11|%xmm\d{1,2})()', '33'),
17         # Callee-saved Register: rot
18         (r'()(%rbx|%r15|%r14|%r13|%r12)()', '31'),
19         # Stack- u. Frame-Pointer: grau
20         (r'()(%rsp|%rbp)()', '1;30'),
21         # Zahlenwerte: tuerkis
22         (r'()(\$[-]?\d+)()', '36'),
23         # Disposition von M/R-Berechnungen: tuerkis
24         (r'()([-]?\d+)(\([^)]*\))', '36'),
25         # Scale von M/R-Berechnungen: tuerkis
26         (r'(,[ ]?)(1|2|4|8)(\))', '36'),
27 )
28
29 for line in sys.stdin:
30     for match, color in colorify:
31         line = re.sub(match, '\\1\033['+color+'m\\2\033[0m\\3', line)
32     sys.stdout.write(line)