Skip to content

Commit

Permalink
tools: prepare tools/genv8constants.py for Python 3
Browse files Browse the repository at this point in the history
PR-URL: #24801
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
cclauss authored and BethGriggs committed Feb 12, 2019
1 parent 039097e commit 388ec8d
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions tools/genv8constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

if len(sys.argv) != 3:
print("usage: objsym.py outfile libv8_base.a")
sys.exit(2);
sys.exit(2)

outfile = file(sys.argv[1], 'w');
outfile = open(sys.argv[1], 'w')
try:
pipe = subprocess.Popen([ 'objdump', '-z', '-D', sys.argv[2] ],
bufsize=-1, stdout=subprocess.PIPE).stdout;
except OSError, e:
bufsize=-1, stdout=subprocess.PIPE).stdout
except OSError as e:
if e.errno == errno.ENOENT:
print('''
Node.js compile error: could not find objdump
Expand All @@ -33,9 +33,9 @@

sys.exit()

pattern = re.compile('([0-9a-fA-F]{8}|[0-9a-fA-F]{16}) <(.*)>:');
pattern = re.compile('([0-9a-fA-F]{8}|[0-9a-fA-F]{16}) <(.*)>:')
v8dbg = re.compile('^v8dbg.*$')
numpattern = re.compile('^[0-9a-fA-F]{2} $');
numpattern = re.compile('^[0-9a-fA-F]{2} $')
octets = 4

outfile.write("""
Expand All @@ -49,28 +49,28 @@
#ifndef V8_CONSTANTS_H
#define V8_CONSTANTS_H
""");
""")

curr_sym = None;
curr_val = 0;
curr_octet = 0;
curr_sym = None
curr_val = 0
curr_octet = 0

def out_reset():
global curr_sym, curr_val, curr_octet
curr_sym = None;
curr_val = 0;
curr_octet = 0;
curr_sym = None
curr_val = 0
curr_octet = 0

def out_define():
global curr_sym, curr_val, curr_octet, outfile, octets
if curr_sym != None:
wrapped_val = curr_val & 0xffffffff;
wrapped_val = curr_val & 0xffffffff
if curr_val & 0x80000000 != 0:
wrapped_val = 0x100000000 - wrapped_val;
outfile.write("#define %s -0x%x\n" % (curr_sym.upper(), wrapped_val));
wrapped_val = 0x100000000 - wrapped_val
outfile.write("#define %s -0x%x\n" % (curr_sym.upper(), wrapped_val))
else:
outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), wrapped_val));
out_reset();
outfile.write("#define %s 0x%x\n" % (curr_sym.upper(), wrapped_val))
out_reset()

for line in pipe:
if curr_sym != None:
Expand All @@ -81,35 +81,35 @@ def out_define():
# much like hex numbers (e.g., "adc"), and we don't want to risk picking
# those up by mistake, so we look at character-based columns instead.
#
for i in range (0, 3):
for i in range(0, 3):
# 6-character margin, 2-characters + 1 space for each field
idx = 6 + i * 3;
idx = 6 + i * 3
octetstr = line[idx:idx+3]
if curr_octet > octets:
break;
break

if not numpattern.match(octetstr):
break;
break

curr_val += int('0x%s' % octetstr, 16) << (curr_octet * 8);
curr_octet += 1;
curr_val += int('0x%s' % octetstr, 16) << (curr_octet * 8)
curr_octet += 1

match = pattern.match(line)
if match == None:
continue;
continue

# Print previous symbol
out_define();
out_define()

v8match = v8dbg.match(match.group(2));
v8match = v8dbg.match(match.group(2))
if v8match != None:
out_reset();
curr_sym = match.group(2);
out_reset()
curr_sym = match.group(2)

# Print last symbol
out_define();
out_define()

outfile.write("""
#endif /* V8_CONSTANTS_H */
""");
""")

0 comments on commit 388ec8d

Please sign in to comment.