Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bb2f59a5a3461ddd20c97e713203b5b5eb20df7c
[simgrid.git] / tools / normalize-pointers.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2013-2014. The SimGrid Team.
4 # All rights reserved.
5
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
8
9 """
10 Tool for normalizing pointers such as two runs have the same 'addresses'
11
12 first address encountered will be replaced by 0X0000001, second by 0X0000002, ...
13
14 """
15
16 import sys
17 import re
18
19 if len(sys.argv) != 2:
20     print "Usage ./normalize-pointers.py <filename>"
21     sys.exit(1)
22
23 f = open(sys.argv[1])
24 t = f.read()
25 f.close()
26
27 r = re.compile(r"0x[0-9a-f]+")
28 s = r.search(t)
29 offset = 0
30 pointers = {}
31 while (s):
32     if s.group() not in pointers:
33         pointers[s.group()] = "0X%07d" % len(pointers)
34     print t[offset:s.start()],
35     print pointers[s.group()],
36     offset = s.end()
37     s = r.search(t, offset)
38
39 print t[offset:]