More python3
modified: scripts/brandelf.py modified: scripts/gpp_inc.py modified: src/arch/i086/cleanasm.py
This commit is contained in:
parent
59d5d25a77
commit
8ab47ba8a4
@ -54,32 +54,32 @@ def do_file(fn):
|
|||||||
|
|
||||||
def write(s):
|
def write(s):
|
||||||
if not opts.dry_run:
|
if not opts.dry_run:
|
||||||
fp.write(s)
|
fp.write(s.encode())
|
||||||
|
|
||||||
def brand_arm(s):
|
def brand_arm(s):
|
||||||
if e_ident[4:7] != s:
|
if e_ident[4:7] != s.encode():
|
||||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||||
write("\x61") # ELFOSABI_ARM
|
write("\x61") # ELFOSABI_ARM
|
||||||
def brand_freebsd(s):
|
def brand_freebsd(s):
|
||||||
if e_ident[4:7] != s:
|
if e_ident[4:7] != s.encode():
|
||||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||||
write("\x09")
|
write("\x09")
|
||||||
def brand_linux(s):
|
def brand_linux(s):
|
||||||
if e_ident[4:7] != s:
|
if e_ident[4:7] != s.encode():
|
||||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||||
##write("\x00Linux\x00\x00\x00")
|
##write("\x00Linux\x00\x00\x00")
|
||||||
write("\x00" * 9)
|
write("\x00" * 9)
|
||||||
def brand_netbsd(s):
|
def brand_netbsd(s):
|
||||||
if e_ident[4:7] != s:
|
if e_ident[4:7] != s.encode():
|
||||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||||
write("\x02")
|
write("\x02")
|
||||||
def brand_openbsd(s):
|
def brand_openbsd(s):
|
||||||
if e_ident[4:7] != s:
|
if e_ident[4:7] != s.encode():
|
||||||
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
raise Exception("%s is not %s" % (fn, opts.bfdname))
|
||||||
write("\x0c")
|
write("\x0c")
|
||||||
|
|
||||||
if opts.bfdname[:3] == "elf":
|
if opts.bfdname[:3] == "elf":
|
||||||
if e_ident[:4] != "\x7f\x45\x4c\x46":
|
if e_ident[:4] != "\x7f\x45\x4c\x46".encode():
|
||||||
raise Exception("%s is not %s" % (fn, "ELF"))
|
raise Exception("%s is not %s" % (fn, "ELF"))
|
||||||
fp.seek(7, 0)
|
fp.seek(7, 0)
|
||||||
if opts.bfdname == "elf32-bigarm" and opts.elfosabi == "arm":
|
if opts.bfdname == "elf32-bigarm" and opts.elfosabi == "arm":
|
||||||
|
|||||||
@ -83,7 +83,7 @@ def parse_comment(state, l, comment):
|
|||||||
|
|
||||||
|
|
||||||
def handle_inc_c(state, l, ofp):
|
def handle_inc_c(state, l, ofp):
|
||||||
m = re.search(r"^\s*\#\s*include\s+([\"\<])(.+?)([\"\>])(.*)$", l)
|
m = re.search(r"^\s*\#\s*include\s+([\"\<])(.+?)([\"\>])(.*)$", l.decode())
|
||||||
if not m:
|
if not m:
|
||||||
return l
|
return l
|
||||||
q1, inc, q2, comment = m.groups()
|
q1, inc, q2, comment = m.groups()
|
||||||
@ -93,7 +93,7 @@ def handle_inc_c(state, l, ofp):
|
|||||||
elif q1 == '"' and q2 == '"':
|
elif q1 == '"' and q2 == '"':
|
||||||
dirs = [state[1]] + opts.includes
|
dirs = [state[1]] + opts.includes
|
||||||
else:
|
else:
|
||||||
raise Exception("syntax error: include line " + l)
|
raise Exception("syntax error: include line " + l.decode())
|
||||||
for dir in dirs:
|
for dir in dirs:
|
||||||
fn = os.path.join(dir, inc)
|
fn = os.path.join(dir, inc)
|
||||||
if os.path.isfile(fn):
|
if os.path.isfile(fn):
|
||||||
@ -130,13 +130,13 @@ def handle_file(ifn, ofp, parent_state=None):
|
|||||||
ifp = open(ifn, "rb")
|
ifp = open(ifn, "rb")
|
||||||
for l in ifp.readlines():
|
for l in ifp.readlines():
|
||||||
state[2] += 1 # line counter
|
state[2] += 1 # line counter
|
||||||
l = l.rstrip("\n")
|
l = l.rstrip("\n".encode())
|
||||||
if opts.mode == "c":
|
if opts.mode == "c":
|
||||||
l = handle_inc_c(state, l, ofp)
|
l = handle_inc_c(state, l, ofp)
|
||||||
elif opts.mode == "nasm":
|
elif opts.mode == "nasm":
|
||||||
l = handle_inc_nasm(state, l, ofp)
|
l = handle_inc_nasm(state, l, ofp)
|
||||||
if l is not None:
|
if l is not None:
|
||||||
ofp.write(l + "\n")
|
ofp.write(l + "\n".encode())
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
@ -179,12 +179,12 @@ def main(argv):
|
|||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
if files_mmd:
|
if files_mmd:
|
||||||
fp = open(fn, "wb")
|
fp = open(fn, "wb")
|
||||||
fp.write("%s : \\\n" % opts.target_mmd)
|
fp.write(("%s : \\\n" % opts.target_mmd).encode())
|
||||||
for i, f in enumerate(files_mmd):
|
for i, f in enumerate(files_mmd):
|
||||||
if i < len(files_mmd) - 1:
|
if i < len(files_mmd) - 1:
|
||||||
fp.write(" %s \\\n" % f)
|
fp.write((" %s \\\n" % f).encode())
|
||||||
else:
|
else:
|
||||||
fp.write(" %s\n" % f)
|
fp.write((" %s\n" % f).encode())
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -99,11 +99,11 @@ def main(argv):
|
|||||||
k, v = m.group(1).strip(), [0, 0, None, 0]
|
k, v = m.group(1).strip(), [0, 0, None, 0]
|
||||||
assert k and v, (inst, args)
|
assert k and v, (inst, args)
|
||||||
v[2] = k # new name
|
v[2] = k # new name
|
||||||
if labels.has_key(k):
|
if k in labels:
|
||||||
assert labels[k][:2] == v[:2]
|
assert labels[k][:2] == v[:2]
|
||||||
return k, v
|
return k, v
|
||||||
def add_label(k, v):
|
def add_label(k, v):
|
||||||
if labels.has_key(k):
|
if k in labels:
|
||||||
assert labels[k][:2] == v[:2]
|
assert labels[k][:2] == v[:2]
|
||||||
else:
|
else:
|
||||||
labels[k] = v
|
labels[k] = v
|
||||||
@ -449,7 +449,7 @@ def main(argv):
|
|||||||
ofp = open(ofile, "wb")
|
ofp = open(ofile, "wb")
|
||||||
current_label = None
|
current_label = None
|
||||||
for label, inst, args, args_label in olines:
|
for label, inst, args, args_label in olines:
|
||||||
if labels.has_key(label):
|
if label in labels:
|
||||||
current_label = labels[label][2]
|
current_label = labels[label][2]
|
||||||
if opts.verbose:
|
if opts.verbose:
|
||||||
ofp.write("%s: /* %d */\n" % (labels[label][2], labels[label][3]))
|
ofp.write("%s: /* %d */\n" % (labels[label][2], labels[label][3]))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user