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('([0-9a-fA-F]{8}|[0-9a-fA-F]{16}) <(.*)>:');
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 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));
71 outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), wrapped_val));
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.
83 for i in range (0, 3):
84 # 6-character margin, 2-characters + 1 space for each field
86 octetstr = line[idx:idx+3]
87 if not numpattern.match(octetstr):
90 if curr_octet > octets:
93 curr_val += int('0x%s' % octetstr, 16) << (curr_octet * 8);
96 match = pattern.match(line)
100 # Print previous symbol
103 v8match = v8dbg.match(match.group(2));
106 curr_sym = match.group(2);
113 #endif /* V8_CONSTANTS_H */