4 # genv8constants.py output_file libv8_base.a
6 # Emits v8dbg constants stored in libv8_base.a in a format suitable for the V8
15 if len(sys.argv) != 3:
16 print "usage: objsym.py outfile libv8_base.a"
19 outfile = file(sys.argv[1], 'w');
21 pipe = subprocess.Popen([ 'objdump', '-z', '-D', sys.argv[2] ],
22 bufsize=-1, stdout=subprocess.PIPE).stdout;
24 if e.errno == errno.ENOENT:
26 Node.js compile error: could not find objdump
28 Check that GNU binutils are installed and included in PATH
31 print 'problem running objdump: ', e.strerror
35 pattern = re.compile('(00000000|0000000000000000) <(.*)>:');
36 v8dbg = re.compile('^v8dbg.*$')
37 numpattern = re.compile('^[0-9a-fA-F]{2} $');
42 * File automatically generated by genv8constants. Do not edit.
44 * The following offsets are dynamically from libv8_base.a. See src/v8ustack.d
45 * for details on how these values are used.
48 #ifndef V8_CONSTANTS_H
49 #define V8_CONSTANTS_H
58 global curr_sym, curr_val, curr_octet
64 global curr_sym, curr_val, curr_octet, outfile, octets
66 if curr_val & 0x80000000 != 0:
67 outfile.write("#define %s -0x%x\n" % (curr_sym.upper(), 0x100000000 - curr_val));
69 outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), curr_val));
75 # This bit of code has nasty knowledge of the objdump text output
76 # format, but this is the most obvious robust approach. We could almost
77 # rely on looking at numbered fields, but some instructions look very
78 # much like hex numbers (e.g., "adc"), and we don't want to risk picking
79 # those up by mistake, so we look at character-based columns intead.
81 for i in range (0, 3):
82 # 6-character margin, 2-characters + 1 space for each field
84 octetstr = line[idx:idx+3]
85 if not numpattern.match(octetstr):
88 if curr_octet > octets:
91 curr_val += int('0x%s' % octetstr, 16) << (curr_octet * 8);
94 match = pattern.match(line)
98 octets = len(match.group(1)) / 2;
100 # Print previous symbol
103 v8match = v8dbg.match(match.group(2));
106 curr_sym = match.group(2);
113 #endif /* V8_CONSTANTS_H */