Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
using trace timestamp precision when printing to trace files
[simgrid.git] / tools / normalize-pointers.py
1 #!/usr/bin/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, re
17
18 if len(sys.argv)!=2:
19   print "Usage ./normalize-pointers.py <filename>"
20   sys.exit(1)
21
22 f = open(sys.argv[1])
23 t = f.read()
24 f.close()
25
26 r = re.compile(r"0x[0-9a-f]+")
27 s = r.search(t)
28 offset = 0
29 pointers = {}
30 while (s):
31   if s.group() not in pointers:
32     pointers[s.group()] = "0X%07d"%len(pointers)
33   print t[offset:s.start()],
34   print pointers[s.group()],
35   offset = s.end()
36   s = r.search(t, offset)
37
38 print t[offset:]
39
40
41
42