Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'torus'
[simgrid.git] / tools / normalize-pointers.py
1 #!/usr/bin/python
2 """
3 Tool for normalizing pointers such as two runs have the same 'addresses'
4
5 first address encountered will be replaced by 0X0000001, second by 0X0000002, ...
6
7 """
8
9 import sys, re
10
11 if len(sys.argv)!=2:
12   print "Usage ./normalize-pointers.py <filename>"
13   sys.exit(1)
14
15 f = open(sys.argv[1])
16 t = f.read()
17 f.close()
18
19 r = re.compile(r"0x[0-9a-f]{7}")
20 s = r.search(t)
21 offset = 0
22 pointers = {}
23 while (s):
24   if s.group() not in pointers:
25     pointers[s.group()] = "0X%07d"%len(pointers)
26   print t[offset:s.start()],
27   print pointers[s.group()],
28   offset = s.end()
29   s = r.search(t, offset)
30
31 print t[offset:]
32
33
34
35