Revert "sunos: unbreak build after v8 downgrade"
[platform/upstream/nodejs.git] / tools / genv8constants.py
1 #!/usr/bin/env python
2
3 #
4 # genv8constants.py output_file libv8_base.a
5 #
6 # Emits v8dbg constants stored in libv8_base.a in a format suitable for the V8
7 # ustack helper.
8 #
9
10 import re
11 import subprocess
12 import sys
13 import errno
14
15 if len(sys.argv) != 3:
16   print "usage: objsym.py outfile libv8_base.a"
17   sys.exit(2);
18
19 outfile = file(sys.argv[1], 'w');
20 try:
21   pipe = subprocess.Popen([ 'objdump', '-z', '-D', sys.argv[2] ],
22       bufsize=-1, stdout=subprocess.PIPE).stdout;
23 except OSError, e:
24   if e.errno == errno.ENOENT:
25     print '''
26       Node.js compile error: could not find objdump
27
28       Check that GNU binutils are installed and included in PATH
29       '''
30   else:
31     print 'problem running objdump: ', e.strerror
32
33   sys.exit()
34
35 pattern = re.compile('([0-9a-fA-F]{8}|[0-9a-fA-F]{16}) <(.*)>:');
36 v8dbg = re.compile('^v8dbg.*$')
37 numpattern = re.compile('^[0-9a-fA-F]{2} $');
38 octets = 4
39
40 outfile.write("""
41 /*
42  * File automatically generated by genv8constants. Do not edit.
43  *
44  * The following offsets are dynamically from libv8_base.a.  See src/v8ustack.d
45  * for details on how these values are used.
46  */
47
48 #ifndef V8_CONSTANTS_H
49 #define V8_CONSTANTS_H
50
51 """);
52
53 curr_sym = None;
54 curr_val = 0;
55 curr_octet = 0;
56
57 def out_reset():
58   global curr_sym, curr_val, curr_octet
59   curr_sym = None;
60   curr_val = 0;
61   curr_octet = 0;
62
63 def out_define():
64   global curr_sym, curr_val, curr_octet, outfile, octets
65   if curr_sym != None:
66     wrapped_val = curr_val & 0xffffffff;
67     if curr_val & 0x80000000 != 0:
68       wrapped_val = 0x100000000 - wrapped_val;
69       outfile.write("#define %s -0x%x\n" % (curr_sym.upper(), wrapped_val));
70     else:
71       outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), wrapped_val));
72   out_reset();
73
74 for line in pipe:
75   if curr_sym != None:
76     #
77     # This bit of code has nasty knowledge of the objdump text output
78     # format, but this is the most obvious robust approach.  We could almost
79     # rely on looking at numbered fields, but some instructions look very
80     # much like hex numbers (e.g., "adc"), and we don't want to risk picking
81     # those up by mistake, so we look at character-based columns intead.
82     #
83     for i in range (0, 3):
84       # 6-character margin, 2-characters + 1 space for each field
85       idx = 6 + i * 3;
86       octetstr = line[idx:idx+3]
87       if not numpattern.match(octetstr):
88         break;
89
90       if curr_octet > octets:
91         break;
92
93       curr_val += int('0x%s' % octetstr, 16) << (curr_octet * 8);
94       curr_octet += 1;
95
96   match = pattern.match(line)
97   if match == None:
98     continue;
99
100   # Print previous symbol
101   out_define();
102
103   v8match = v8dbg.match(match.group(2));
104   if v8match != None:
105     out_reset();
106     curr_sym = match.group(2);
107
108 # Print last symbol
109 out_define();
110
111 outfile.write("""
112
113 #endif /* V8_CONSTANTS_H */
114 """);