python: Make all scripts python 2/3 compatible

This commit is contained in:
Olivier Galibert 2015-07-30 11:44:44 +02:00
parent 93bd0f0daf
commit 4b1e08c1bb
7 changed files with 384 additions and 370 deletions

View File

@ -11,7 +11,7 @@ drivlist = []
def parse_file(srcfile): def parse_file(srcfile):
try: try:
fp = open(srcfile, 'rb') fp = open(srcfile, 'rt')
except IOError: except IOError:
sys.stderr.write("Unable to open source file '%s'\n" % srcfile) sys.stderr.write("Unable to open source file '%s'\n" % srcfile)
return 1 return 1

View File

@ -143,15 +143,16 @@ And now, my famous members
""" """
# http://www.python.org/doc/2.2.3/whatsnew/node5.html # http://www.python.org/doc/2.2.3/whatsnew/node5.html
from __future__ import generators from __future__ import generators,print_function
__version__ = "0.0.17" __version__ = "0.0.17"
from array import array from array import array
try: # See :pyver:old try:
import itertools from itertools import imap
except ImportError: except ImportError:
pass imap = map
from itertools import starmap
import math import math
# http://www.python.org/doc/2.4.4/lib/module-operator.html # http://www.python.org/doc/2.4.4/lib/module-operator.html
import operator import operator
@ -1650,11 +1651,10 @@ class Reader:
spb = 8//self.bitdepth spb = 8//self.bitdepth
out = array('B') out = array('B')
mask = 2**self.bitdepth - 1 mask = 2**self.bitdepth - 1
shifts = map(self.bitdepth.__mul__, reversed(range(spb))) shifts = list(map(self.bitdepth.__mul__, reversed(range(spb))))
for o in raw: for o in raw:
out.extend(map(lambda i: mask&(o>>i), shifts)) out.extend(list(map(lambda i: mask&(o>>i), shifts)))
return out[:width] return out[:width]
return itertools.imap(asvalues, rows) return itertools.imap(asvalues, rows)
def serialtoflat(self, bytes, width=None): def serialtoflat(self, bytes, width=None):
@ -1915,8 +1915,8 @@ class Reader:
while True: while True:
try: try:
type, data = self.chunk(lenient=lenient) type, data = self.chunk(lenient=lenient)
except ValueError, e: except ValueError:
raise ChunkError(e.args[0]) raise ChunkError(sys.exc_info()[1].args[0])
if type == 'IEND': if type == 'IEND':
# http://www.w3.org/TR/PNG/#11IEND # http://www.w3.org/TR/PNG/#11IEND
break break
@ -1947,7 +1947,6 @@ class Reader:
self.preamble(lenient=lenient) self.preamble(lenient=lenient)
raw = iterdecomp(iteridat()) raw = iterdecomp(iteridat())
if self.interlace: if self.interlace:
raw = array('B', itertools.chain(*raw)) raw = array('B', itertools.chain(*raw))
arraycode = 'BH'[self.bitdepth>8] arraycode = 'BH'[self.bitdepth>8]
@ -2062,10 +2061,10 @@ class Reader:
meta['alpha'] = bool(self.trns) meta['alpha'] = bool(self.trns)
meta['bitdepth'] = 8 meta['bitdepth'] = 8
meta['planes'] = 3 + bool(self.trns) meta['planes'] = 3 + bool(self.trns)
plte = self.palette() plte = list(self.palette())
def iterpal(pixels): def iterpal(pixels):
for row in pixels: for row in pixels:
row = map(plte.__getitem__, row) row = list(map(plte.__getitem__, row))
yield array('B', itertools.chain(*row)) yield array('B', itertools.chain(*row))
pixels = iterpal(pixels) pixels = iterpal(pixels)
elif self.trns: elif self.trns:
@ -2779,5 +2778,5 @@ def _main(argv):
if __name__ == '__main__': if __name__ == '__main__':
try: try:
_main(sys.argv) _main(sys.argv)
except Error, e: except Error:
print >>sys.stderr, e print (sys.exc_info()[1], file=e)

View File

@ -59,6 +59,13 @@ import os
import png import png
import sys import sys
if sys.version_info >= (3,):
def b2p(v):
return bytes([v])
else:
def b2p(v):
return chr(v)
######################################## ########################################
## Helper classes ## Helper classes
@ -117,27 +124,27 @@ def renderFontSaveCached(font, filename, hash32):
CACHED_HEADER_SIZE = 16 CACHED_HEADER_SIZE = 16
try: try:
fp.write('f') fp.write(b'f')
fp.write('o') fp.write(b'o')
fp.write('n') fp.write(b'n')
fp.write('t') fp.write(b't')
fp.write(chr(hash32 >> 24 & 0xff)) fp.write(b2p(hash32 >> 24 & 0xff))
fp.write(chr(hash32 >> 16 & 0xff)) fp.write(b2p(hash32 >> 16 & 0xff))
fp.write(chr(hash32 >> 8 & 0xff)) fp.write(b2p(hash32 >> 8 & 0xff))
fp.write(chr(hash32 >> 0 & 0xff)) fp.write(b2p(hash32 >> 0 & 0xff))
fp.write(chr(font.height >> 8 & 0xff)) fp.write(b2p(font.height >> 8 & 0xff))
fp.write(chr(font.height >> 0 & 0xff)) fp.write(b2p(font.height >> 0 & 0xff))
fp.write(chr(font.yOffs >> 8 & 0xff)) fp.write(b2p(font.yOffs >> 8 & 0xff))
fp.write(chr(font.yOffs >> 0 & 0xff)) fp.write(b2p(font.yOffs >> 0 & 0xff))
fp.write(chr(numChars >> 24 & 0xff)) fp.write(b2p(numChars >> 24 & 0xff))
fp.write(chr(numChars >> 16 & 0xff)) fp.write(b2p(numChars >> 16 & 0xff))
fp.write(chr(numChars >> 8 & 0xff)) fp.write(b2p(numChars >> 8 & 0xff))
fp.write(chr(numChars >> 0 & 0xff)) fp.write(b2p(numChars >> 0 & 0xff))
# Write a blank table at first (?) # Write a blank table at first (?)
charTable = [0]*(numChars * CACHED_CHAR_SIZE) charTable = [0]*(numChars * CACHED_CHAR_SIZE)
for i in range(numChars * CACHED_CHAR_SIZE): for i in range(numChars * CACHED_CHAR_SIZE):
fp.write(chr(charTable[i])) fp.write(b2p(charTable[i]))
# Loop over all characters # Loop over all characters
tableIndex = 0 tableIndex = 0
@ -173,7 +180,7 @@ def renderFontSaveCached(font, filename, hash32):
# Write the data # Write the data
for j in range(len(dBuffer)): for j in range(len(dBuffer)):
fp.write(chr(dBuffer[j])) fp.write(b2p(dBuffer[j]))
destIndex = tableIndex * CACHED_CHAR_SIZE destIndex = tableIndex * CACHED_CHAR_SIZE
charTable[destIndex + 0] = i >> 8 & 0xff charTable[destIndex + 0] = i >> 8 & 0xff
@ -193,12 +200,13 @@ def renderFontSaveCached(font, filename, hash32):
# Seek back to the beginning and rewrite the table # Seek back to the beginning and rewrite the table
fp.seek(CACHED_HEADER_SIZE, 0) fp.seek(CACHED_HEADER_SIZE, 0)
for i in range(numChars * CACHED_CHAR_SIZE): for i in range(numChars * CACHED_CHAR_SIZE):
fp.write(chr(charTable[i])) fp.write(b2p(charTable[i]))
fp.close() fp.close()
return 0 return 0
except: except:
print(sys.exc_info[1])
return 1 return 1
@ -347,7 +355,7 @@ def main():
except: except:
sys.stderr.write("Error reading PNG file.\n") sys.stderr.write("Error reading PNG file.\n")
return 1 return 1
error = bitmapToChars(pngObject, font) error = bitmapToChars(pngObject, font)
if error: if error:
return 1 return 1

View File

@ -1,351 +1,352 @@
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
import sys import sys
def EmitGroup04_Handle_NZ_Flags(f, funcname, opname): def EmitGroup04_Handle_NZ_Flags(f, funcname, opname):
print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f)
print >>f, " else { STATUS32_CLEAR_N; }" print(" else { STATUS32_CLEAR_N; }", file=f)
print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f)
print >>f, " else { STATUS32_CLEAR_Z; }" print(" else { STATUS32_CLEAR_Z; }", file=f)
def EmitGroup04_Handle_NZC_LSR1_Flags(f, funcname, opname): def EmitGroup04_Handle_NZC_LSR1_Flags(f, funcname, opname):
print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f)
print >>f, " else { STATUS32_CLEAR_N; }" print(" else { STATUS32_CLEAR_N; }", file=f)
print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f)
print >>f, " else { STATUS32_CLEAR_Z; }" print(" else { STATUS32_CLEAR_Z; }", file=f)
print >>f, " if (c == 0x00000001) { STATUS32_SET_C; }" print(" if (c == 0x00000001) { STATUS32_SET_C; }", file=f)
print >>f, " else { STATUS32_CLEAR_C; }" print(" else { STATUS32_CLEAR_C; }", file=f)
def EmitGroup04_Handle_NZCV_ADD_Flags(f, funcname, opname): def EmitGroup04_Handle_NZCV_ADD_Flags(f, funcname, opname):
print >>f, " if (result & 0x80000000) { STATUS32_SET_N; }" print(" if (result & 0x80000000) { STATUS32_SET_N; }", file=f)
print >>f, " else { STATUS32_CLEAR_N; }" print(" else { STATUS32_CLEAR_N; }", file=f)
print >>f, " if (result == 0x00000000) { STATUS32_SET_Z; }" print(" if (result == 0x00000000) { STATUS32_SET_Z; }", file=f)
print >>f, " else { STATUS32_CLEAR_Z; }" print(" else { STATUS32_CLEAR_Z; }", file=f)
print >>f, " if ((b & 0x80000000) == (c & 0x80000000))" print(" if ((b & 0x80000000) == (c & 0x80000000))", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " if ((result & 0x80000000) != (b & 0x80000000))" print(" if ((result & 0x80000000) != (b & 0x80000000))", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " STATUS32_SET_V;" print(" STATUS32_SET_V;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " else" print(" else", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " STATUS32_CLEAR_V;" print(" STATUS32_CLEAR_V;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " if (b < c)" print(" if (b < c)", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " STATUS32_SET_C;" print(" STATUS32_SET_C;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " else" print(" else", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " STATUS32_CLEAR_C;" print(" STATUS32_CLEAR_C;", file=f)
print >>f, " }" print(" }", file=f)
def EmitGroup04_no_Flags(f, funcname, opname): def EmitGroup04_no_Flags(f, funcname, opname):
print >>f, " // no flag changes" print(" // no flag changes", file=f)
def EmitGroup04_unsupported_Flags(f, funcname, opname): def EmitGroup04_unsupported_Flags(f, funcname, opname):
print >>f, " arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname) print(" arcompact_fatal(\"arcompact_handle%s (%s) (F set)\\n\"); // not yet supported" % (funcname, opname), file=f)
def EmitGroup04_Flaghandler(f,funcname, opname, flagcondition, flaghandler): def EmitGroup04_Flaghandler(f,funcname, opname, flagcondition, flaghandler):
if flagcondition == -1: if flagcondition == -1:
print >>f, " if (F)" print(" if (F)", file=f)
print >>f, " {" print(" {", file=f)
flaghandler(f, funcname, opname) flaghandler(f, funcname, opname)
print >>f, " }" print(" }", file=f)
elif flagcondition == 0: elif flagcondition == 0:
print >>f, " if (0)" print(" if (0)", file=f)
print >>f, " {" print(" {", file=f)
flaghandler(f, funcname, opname) flaghandler(f, funcname, opname)
print >>f, " }" print(" }", file=f)
elif flagcondition == 1: elif flagcondition == 1:
print >>f, " if (1)" print(" if (1)", file=f)
print >>f, " {" print(" {", file=f)
flaghandler(f, funcname, opname) flaghandler(f, funcname, opname)
print >>f, " }" print(" }", file=f)
def EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): def EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler):
print >>f, " int size = 4;" print(" int size = 4;", file=f)
if breg_is_dst_only == 0: if breg_is_dst_only == 0:
print >>f, " UINT32 limm = 0;" print(" UINT32 limm = 0;", file=f)
print >>f, "/* int got_limm = 0; */" print("/* int got_limm = 0; */", file=f)
print >>f, " " print(" ", file=f)
print >>f, " COMMON32_GET_breg;" print(" COMMON32_GET_breg;", file=f)
if flagcondition == -1: if flagcondition == -1:
print >>f, " COMMON32_GET_F;" print(" COMMON32_GET_F;", file=f)
print >>f, " COMMON32_GET_u6;" print(" COMMON32_GET_u6;", file=f)
if ignore_a == 0: if ignore_a == 0:
print >>f, " COMMON32_GET_areg;" print(" COMMON32_GET_areg;", file=f)
elif ignore_a == 1: elif ignore_a == 1:
print >>f, " //COMMON32_GET_areg; // areg is reserved / not used" print(" //COMMON32_GET_areg; // areg is reserved / not used", file=f)
elif ignore_a == 2: elif ignore_a == 2:
print >>f, " //COMMON32_GET_areg; // areg bits already used as opcode select" print(" //COMMON32_GET_areg; // areg bits already used as opcode select", file=f)
elif ignore_a == 3: elif ignore_a == 3:
print >>f, " //COMMON32_GET_areg; // areg bits already used as condition code select" print(" //COMMON32_GET_areg; // areg bits already used as condition code select", file=f)
print >>f, " " print(" ", file=f)
print >>f, " UINT32 c;" print(" UINT32 c;", file=f)
if breg_is_dst_only == 0: if breg_is_dst_only == 0:
print >>f, " UINT32 b;" print(" UINT32 b;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */" print(" /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f)
print >>f, " if (breg == LIMM_REG)" print(" if (breg == LIMM_REG)", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " GET_LIMM_32;" print(" GET_LIMM_32;", file=f)
print >>f, " size = 8;" print(" size = 8;", file=f)
print >>f, "/* got_limm = 1; */" print("/* got_limm = 1; */", file=f)
print >>f, " b = limm;" print(" b = limm;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " else" print(" else", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " b = m_regs[breg];" print(" b = m_regs[breg];", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " " print(" ", file=f)
print >>f, " c = u;" print(" c = u;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f)
def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler): def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler):
# the mode 0x00 handler # the mode 0x00 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname, file=f)
print >>f, "{" print("{", file=f)
print >>f, " int size = 4;" print(" int size = 4;", file=f)
print >>f, " UINT32 limm = 0;" print(" UINT32 limm = 0;", file=f)
print >>f, " int got_limm = 0;" print(" int got_limm = 0;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " COMMON32_GET_breg;" print(" COMMON32_GET_breg;", file=f)
if flagcondition == -1: if flagcondition == -1:
print >>f, " COMMON32_GET_F;" print(" COMMON32_GET_F;", file=f)
print >>f, " COMMON32_GET_creg;" print(" COMMON32_GET_creg;", file=f)
if ignore_a == 0: if ignore_a == 0:
print >>f, " COMMON32_GET_areg;" print(" COMMON32_GET_areg;", file=f)
elif ignore_a == 1: elif ignore_a == 1:
print >>f, " //COMMON32_GET_areg; // areg is reserved / not used" print(" //COMMON32_GET_areg; // areg is reserved / not used", file=f)
elif ignore_a == 2: elif ignore_a == 2:
print >>f, " //COMMON32_GET_areg; // areg bits already used as opcode select" print(" //COMMON32_GET_areg; // areg bits already used as opcode select", file=f)
print >>f, " " print(" ", file=f)
print >>f, " UINT32 c;" print(" UINT32 c;", file=f)
if breg_is_dst_only == 0: if breg_is_dst_only == 0:
print >>f, " UINT32 b;" print(" UINT32 b;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " if (breg == LIMM_REG)" print(" if (breg == LIMM_REG)", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " GET_LIMM_32;" print(" GET_LIMM_32;", file=f)
print >>f, " size = 8;" print(" size = 8;", file=f)
print >>f, " got_limm = 1;" print(" got_limm = 1;", file=f)
print >>f, " b = limm;" print(" b = limm;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " else" print(" else", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " b = m_regs[breg];" print(" b = m_regs[breg];", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " " print(" ", file=f)
print >>f, " if (creg == LIMM_REG)" print(" if (creg == LIMM_REG)", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " if (!got_limm)" print(" if (!got_limm)", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " GET_LIMM_32;" print(" GET_LIMM_32;", file=f)
print >>f, " size = 8;" print(" size = 8;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " c = limm;" print(" c = limm;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " else" print(" else", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " c = m_regs[creg];" print(" c = m_regs[creg];", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " /* todo: is the limm, limm syntax valid? (it's pointless.) */" print(" /* todo: is the limm, limm syntax valid? (it's pointless.) */", file=f)
print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " %s" % opwrite print(" %s" % opwrite, file=f)
print >>f, " " print(" ", file=f)
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# the mode 0x01 handler # the mode 0x01 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname, file=f)
print >>f, "{" print("{", file=f)
EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler) EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " %s" % opwrite print(" %s" % opwrite, file=f)
print >>f, " " print(" ", file=f)
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# the mode 0x10 handler # the mode 0x10 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname, file=f)
if ignore_a == 2: if ignore_a == 2:
print >>f, "{" print("{", file=f)
print >>f, " int size = 4;" print(" int size = 4;", file=f)
print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p10 (ares bits already used as opcode select, can't be used as s12) (%s)\\n\");" % (funcname, opname) print(" arcompact_fatal(\"illegal arcompact_handle%s_p10 (ares bits already used as opcode select, can't be used as s12) (%s)\\n\");" % (funcname, opname), file=f)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
else: else:
print >>f, "{" print("{", file=f)
print >>f, " int size = 4;" print(" int size = 4;", file=f)
if breg_is_dst_only == 0: if breg_is_dst_only == 0:
print >>f, " UINT32 limm = 0;" print(" UINT32 limm = 0;", file=f)
print >>f, "/* int got_limm = 0; */" print("/* int got_limm = 0; */", file=f)
print >>f, " " print(" ", file=f)
print >>f, " COMMON32_GET_breg;" print(" COMMON32_GET_breg;", file=f)
if flagcondition == -1: if flagcondition == -1:
print >>f, " COMMON32_GET_F;" print(" COMMON32_GET_F;", file=f)
print >>f, " COMMON32_GET_s12;" print(" COMMON32_GET_s12;", file=f)
# areg can't be used here, it's used for s12 bits # areg can't be used here, it's used for s12 bits
print >>f, " " print(" ", file=f)
print >>f, " UINT32 c;" print(" UINT32 c;", file=f)
if breg_is_dst_only == 0: if breg_is_dst_only == 0:
print >>f, " UINT32 b;" print(" UINT32 b;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */" print(" /* is having b as LIMM valid here? LIMM vs. fixed u6 value makes no sense */", file=f)
print >>f, " if (breg == LIMM_REG)" print(" if (breg == LIMM_REG)", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " GET_LIMM_32;" print(" GET_LIMM_32;", file=f)
print >>f, " size = 8;" print(" size = 8;", file=f)
print >>f, "/* got_limm = 1; */" print("/* got_limm = 1; */", file=f)
print >>f, " b = limm;" print(" b = limm;", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " else" print(" else", file=f)
print >>f, " {" print(" {", file=f)
print >>f, " b = m_regs[breg];" print(" b = m_regs[breg];", file=f)
print >>f, " }" print(" }", file=f)
print >>f, " " print(" ", file=f)
print >>f, " c = (UINT32)S;" print(" c = (UINT32)S;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */" print(" /* todo: if areg = LIMM then there is no result (but since that register can never be read, I guess it doesn't matter if we store it there anyway?) */", file=f)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " %s" % opwrite_alt print(" %s" % opwrite_alt, file=f)
print >>f, " " print(" ", file=f)
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# the mode 0x11 m0 handler # the mode 0x11 m0 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname, file=f)
if ignore_a == 2: if ignore_a == 2:
print >>f, "{" print("{", file=f)
print >>f, " int size = 4;" print(" int size = 4;", file=f)
print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p11_m0 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname) print(" arcompact_fatal(\"illegal arcompact_handle%s_p11_m0 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname), file=f)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
else: else:
print >>f, "{" print("{", file=f)
print >>f, " int size = 4;" print(" int size = 4;", file=f)
print >>f, " arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");" % (funcname, opname) print(" arcompact_fatal(\"arcompact_handle%s_p11_m0 (%s)\\n\");" % (funcname, opname), file=f)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# the mode 0x11 m1 handler # the mode 0x11 m1 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname, file=f)
if ignore_a == 2: if ignore_a == 2:
print >>f, "{" print("{", file=f)
print >>f, " int size = 4;" print(" int size = 4;", file=f)
print >>f, " arcompact_fatal(\"illegal arcompact_handle%s_p11_m1 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname) print(" arcompact_fatal(\"illegal arcompact_handle%s_p11_m1 (ares bits already used as opcode select, can't be used as Q condition) (%s)\\n\");" % (funcname, opname), file=f)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
else: else:
print >>f, "{" print("{", file=f)
EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, 3, breg_is_dst_only, flagcondition, flaghandler) EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, 3, breg_is_dst_only, flagcondition, flaghandler)
print >>f, " COMMON32_GET_CONDITION;" print(" COMMON32_GET_CONDITION;", file=f)
print >>f, " if (!check_condition(condition))" print(" if (!check_condition(condition))", file=f)
print >>f, " return m_pc + (size>>0);" print(" return m_pc + (size>>0);", file=f)
print >>f, "" print("", file=f)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " %s" % opwrite_alt print(" %s" % opwrite_alt, file=f)
print >>f, " " print(" ", file=f)
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler) EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);" print(" return m_pc + (size >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# xxx_S c, b, u3 format opcodes (note c is destination) # xxx_S c, b, u3 format opcodes (note c is destination)
def EmitGroup0d(f,funcname, opname, opexecute, opwrite): def EmitGroup0d(f,funcname, opname, opexecute, opwrite):
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f)
print >>f, "{" print("{", file=f)
print >>f, " int u, breg, creg;" print(" int u, breg, creg;", file=f)
print >>f, "" print("", file=f)
print >>f, " COMMON16_GET_u3;" print(" COMMON16_GET_u3;", file=f)
print >>f, " COMMON16_GET_breg;" print(" COMMON16_GET_breg;", file=f)
print >>f, " COMMON16_GET_creg;" print(" COMMON16_GET_creg;", file=f)
print >>f, "" print("", file=f)
print >>f, " REG_16BIT_RANGE(breg);" print(" REG_16BIT_RANGE(breg);", file=f)
print >>f, " REG_16BIT_RANGE(creg);" print(" REG_16BIT_RANGE(creg);", file=f)
print >>f, "" print("", file=f)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " %s" % opwrite print(" %s" % opwrite, file=f)
print >>f, "" print("", file=f)
print >>f, " return m_pc + (2 >> 0);" print(" return m_pc + (2 >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# xxx_S b <- b,c format opcodes # xxx_S b <- b,c format opcodes
def EmitGroup0f(f,funcname, opname, opexecute, opwrite): def EmitGroup0f(f,funcname, opname, opexecute, opwrite):
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname, file=f)
print >>f, "{" print("{", file=f)
print >>f, " int breg, creg;" print(" int breg, creg;", file=f)
print >>f, "" print("", file=f)
print >>f, " COMMON16_GET_breg;" print(" COMMON16_GET_breg;", file=f)
print >>f, " COMMON16_GET_creg;" print(" COMMON16_GET_creg;", file=f)
print >>f, "" print("", file=f)
print >>f, " REG_16BIT_RANGE(breg);" print(" REG_16BIT_RANGE(breg);", file=f)
print >>f, " REG_16BIT_RANGE(creg);" print(" REG_16BIT_RANGE(creg);", file=f)
print >>f, "" print("", file=f)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " %s" % opwrite print(" %s" % opwrite, file=f)
print >>f, "" print("", file=f)
print >>f, " return m_pc + (2 >> 0);" print(" return m_pc + (2 >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)
# xxx_S b, b, u5 format opcodes # xxx_S b, b, u5 format opcodes
def EmitGroup17(f,funcname, opname, opexecute): def EmitGroup17(f,funcname, opname, opexecute):
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname print("ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname, file=f)
print >>f, "{" print("{", file=f)
print >>f, " int breg, u;" print(" int breg, u;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " COMMON16_GET_breg;" print(" COMMON16_GET_breg;", file=f)
print >>f, " COMMON16_GET_u5;" print(" COMMON16_GET_u5;", file=f)
print >>f, " " print(" ", file=f)
print >>f, " REG_16BIT_RANGE(breg);" print(" REG_16BIT_RANGE(breg);", file=f)
print >>f, " " print(" ", file=f)
print >>f, " %s" % opexecute print(" %s" % opexecute, file=f)
print >>f, " " print(" ", file=f)
print >>f, " return m_pc + (2 >> 0);" print(" return m_pc + (2 >> 0);", file=f)
print >>f, "}" print("}", file=f)
print >>f, "" print("", file=f)
print >>f, "" print("", file=f)

View File

@ -1,5 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
USAGE = """ USAGE = """
Usage: Usage:
%s h8.lst <type> h8.inc (type = o/h/s20/s26) %s h8.lst <type> h8.inc (type = o/h/s20/s26)
@ -45,45 +47,45 @@ def has_eat(ins):
return False return False
def save_full_one(f, t, name, source): def save_full_one(f, t, name, source):
print >>f, "void %s::%s_full()" % (t, name) print("void %s::%s_full()" % (t, name), file=f)
print >>f, "{" print("{", file=f)
substate = 1 substate = 1
for line in source: for line in source:
if has_memory(line): if has_memory(line):
print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f)
print >>f, line print(line, file=f)
substate += 1 substate += 1
elif has_eat(line): elif has_eat(line):
print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f)
substate += 1 substate += 1
else: else:
print >>f, line print(line, file=f)
print >>f, "}" print("}", file=f)
print >>f print("", file=f)
def save_partial_one(f, t, name, source): def save_partial_one(f, t, name, source):
print >>f, "void %s::%s_partial()" % (t, name) print("void %s::%s_partial()" % (t, name), file=f)
print >>f, "{" print("{", file=f)
print >>f, "switch(inst_substate) {" print("switch(inst_substate) {", file=f)
print >>f, "case 0:" print("case 0:", file=f)
substate = 1 substate = 1
for line in source: for line in source:
if has_memory(line): if has_memory(line):
print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate print("\tif(icount <= bcount) { inst_substate = %d; return; }" % substate, file=f)
print >>f, "case %d:;" % substate print("case %d:;" % substate, file=f)
print >>f, line print(line, file=f)
substate += 1 substate += 1
elif has_eat(line): elif has_eat(line):
print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate print("\tif(icount) icount = bcount; inst_substate = %d; return;" % substate, file=f)
print >>f, "case %d:;" % substate print("case %d:;" % substate, file=f)
substate += 1 substate += 1
else: else:
print >>f, line print(line, file=f)
print >>f, "\tbreak;" print("\tbreak;", file=f)
print >>f, "}" print("}", file=f)
print >>f, "\tinst_substate = 0;" print("\tinst_substate = 0;", file=f)
print >>f, "}" print("}", file=f)
print >>f print("", file=f)
class Hash: class Hash:
def __init__(self, premask): def __init__(self, premask):
@ -185,7 +187,7 @@ class Opcode:
else: else:
flags = "%d" % size flags = "%d" % size
print >>f, "\t{ %d, 0x%08x, 0x%08x, 0x%04x, 0x%04x, \"%s\", DASM_%s, DASM_%s, %s }, // %s" % ( slot, val, mask, val2, mask2, self.name, self.am1 if self.am1 != "-" else "none", self.am2 if self.am2 != "-" else "none", flags, "needed" if self.needed else "inherited") print("\t{ %d, 0x%08x, 0x%08x, 0x%04x, 0x%04x, \"%s\", DASM_%s, DASM_%s, %s }, // %s" % ( slot, val, mask, val2, mask2, self.name, self.am1 if self.am1 != "-" else "none", self.am2 if self.am2 != "-" else "none", flags, "needed" if self.needed else "inherited"), file=f)
class Special: class Special:
def __init__(self, val, name, otype, dtype): def __init__(self, val, name, otype, dtype):
@ -244,7 +246,7 @@ class DispatchStep:
return True return True
def source(self): def source(self):
start = self.pos / 2 start = self.pos // 2
end = start + self.skip end = start + self.skip
s = [] s = []
for i in range(start, end+1): for i in range(start, end+1):
@ -345,13 +347,13 @@ class OpcodeList:
h = self.get(d.id) h = self.get(d.id)
def save_dasm(self, f, dname): def save_dasm(self, f, dname):
print >>f, "const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname) print("const %s::disasm_entry %s::disasm_entries[] = {" % (dname, dname), file=f)
for opc in self.opcode_info: for opc in self.opcode_info:
if opc.enabled: if opc.enabled:
opc.save_dasm(f) opc.save_dasm(f)
print >>f, "\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 }," print("\t{ 0, 0, 0, 0, 0, \"illegal\", 0, 0, 2 },", file=f)
print >>f, "};" print("};", file=f)
print >>f print("", file=f)
def save_opcodes(self, f, t): def save_opcodes(self, f, t):
for opc in self.opcode_info: for opc in self.opcode_info:
@ -370,24 +372,24 @@ class OpcodeList:
save_partial_one(f, t, "dispatch_" + dsp.name, dsp.source()) save_partial_one(f, t, "dispatch_" + dsp.name, dsp.source())
def save_exec(self, f, t, dtype, v): def save_exec(self, f, t, dtype, v):
print >>f, "void %s::do_exec_%s()" % (t, v) print("void %s::do_exec_%s()" % (t, v), file=f)
print >>f, "{" print("{", file=f)
print >>f, "\tswitch(inst_state >> 16) {" print("\tswitch(inst_state >> 16) {", file=f)
for i in range(0, len(self.dispatch_info)+2): for i in range(0, len(self.dispatch_info)+2):
if i == 1: if i == 1:
print >>f, "\tcase 0x01: {" print("\tcase 0x01: {", file=f)
print >>f, "\t\tswitch(inst_state & 0xffff) {" print("\t\tswitch(inst_state & 0xffff) {", file=f)
for sta in self.states_info: for sta in self.states_info:
if sta.enabled: if sta.enabled:
print >>f, "\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v) print("\t\tcase 0x%02x: state_%s_%s(); break;" % (sta.val & 0xffff, sta.name, v), file=f)
print >>f, "\t\t}" print("\t\t}", file=f)
print >>f, "\t\tbreak;" print("\t\tbreak;", file=f)
print >>f, "\t}" print("\t}", file=f)
else: else:
if i == 0 or self.dispatch_info[i-2].enabled: if i == 0 or self.dispatch_info[i-2].enabled:
print >>f, "\tcase 0x%02x: {" % i print("\tcase 0x%02x: {" % i, file=f)
h = self.get(i) h = self.get(i)
print >>f, "\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask print("\t\tswitch((inst_state >> 8) & 0x%02x) {" % h.mask, file=f)
for val, h2 in sorted(h.d.items()): for val, h2 in sorted(h.d.items()):
if h2.enabled: if h2.enabled:
fmask = h2.premask | (h.mask ^ 0xff) fmask = h2.premask | (h.mask ^ 0xff)
@ -398,16 +400,16 @@ class OpcodeList:
s += 1 s += 1
while s & fmask: while s & fmask:
s += s & fmask s += s & fmask
print >>f, "\t\t%s{" % c print("\t\t%s{" % c, file=f)
if h2.mask == 0x00: if h2.mask == 0x00:
n = h2.d[0] n = h2.d[0]
if n.is_dispatch(): if n.is_dispatch():
print >>f, "\t\t\tdispatch_%s_%s();" % (n.name, v) print("\t\t\tdispatch_%s_%s();" % (n.name, v), file=f)
else: else:
print >>f, "\t\t\t%s_%s();" % (n.function_name(), v) print("\t\t\t%s_%s();" % (n.function_name(), v), file=f)
print >>f, "\t\t\tbreak;" print("\t\t\tbreak;", file=f)
else: else:
print >>f, "\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask print("\t\t\tswitch(inst_state & 0x%02x) {" % h2.mask, file=f)
if i == 0: if i == 0:
mpos = 1 mpos = 1
else: else:
@ -427,23 +429,23 @@ class OpcodeList:
while s & fmask: while s & fmask:
s += s & fmask s += s & fmask
if n.is_dispatch(): if n.is_dispatch():
print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v) print("\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v), file=f)
else: else:
print >>f, "\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v) print("\t\t\t%s%s_%s(); break;" % (c, n.function_name(), v), file=f)
print >>f, "\t\t\tdefault: illegal(); break;" print("\t\t\tdefault: illegal(); break;", file=f)
print >>f, "\t\t\t}" print("\t\t\t}", file=f)
print >>f, "\t\t\tbreak;" print("\t\t\tbreak;", file=f)
print >>f, "\t\t}" print("\t\t}", file=f)
print >>f, "\t\tdefault: illegal(); break;" print("\t\tdefault: illegal(); break;", file=f)
print >>f, "\t\t}" print("\t\t}", file=f)
print >>f, "\t\tbreak;" print("\t\tbreak;", file=f)
print >>f, "\t}" print("\t}", file=f)
print >>f, "\t}" print("\t}", file=f)
print >>f, "}" print("}", file=f)
def main(argv): def main(argv):
if len(argv) != 4: if len(argv) != 4:
print USAGE % argv[0] print(USAGE % argv[0])
return 1 return 1
dtype = name_to_type(argv[2]) dtype = name_to_type(argv[2])

View File

@ -1,5 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
USAGE = """ USAGE = """
Usage: Usage:
%s device_name {opc.lst|-} disp.lst device.inc %s device_name {opc.lst|-} disp.lst device.inc
@ -52,7 +54,7 @@ def load_disp(fname):
def emit(f, text): def emit(f, text):
"""write string to file""" """write string to file"""
print >>f, text, print(text, file=f)
FULL_PROLOG="""\ FULL_PROLOG="""\
void %(device)s::%(opcode)s_full() void %(device)s::%(opcode)s_full()
@ -252,7 +254,7 @@ def main(argv):
if len(argv) != 5: if len(argv) != 5:
print USAGE % argv[0] print(USAGE % argv[0])
return 1 return 1
device_name = argv[1] device_name = argv[1]

View File

@ -1,5 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
from __future__ import print_function
USAGE = """ USAGE = """
Usage: Usage:
%s mcs96ops.lst mcs96.inc %s mcs96ops.lst mcs96.inc
@ -7,12 +9,12 @@ Usage:
import sys import sys
def save_full_one(f, t, name, source): def save_full_one(f, t, name, source):
print >>f, "void %s_device::%s_full()" % (t, name) print("void %s_device::%s_full()" % (t, name), file=f)
print >>f, "{" print("{", file=f)
for line in source: for line in source:
print >>f, line print(line, file=f)
print >>f, "}" print("}", file=f)
print >>f print("", file=f)
class Opcode: class Opcode:
def __init__(self, rng, name, amode, is_196, ea): def __init__(self, rng, name, amode, is_196, ea):
@ -113,7 +115,7 @@ class OpcodeList:
self.opcode_per_id[i] = inf self.opcode_per_id[i] = inf
def save_dasm(self, f, t): def save_dasm(self, f, t):
print >>f, "const %s_device::disasm_entry %s_device::disasm_entries[0x100] = {" % (t, t) print("const %s_device::disasm_entry %s_device::disasm_entries[0x100] = {" % (t, t), file=f)
for i in range(0, 0x100): for i in range(0, 0x100):
if i in self.opcode_per_id: if i in self.opcode_per_id:
opc = self.opcode_per_id[i] opc = self.opcode_per_id[i]
@ -126,11 +128,11 @@ class OpcodeList:
flags = "DASMFLAG_STEP_OUT" flags = "DASMFLAG_STEP_OUT"
else: else:
flags = "0" flags = "0"
print >>f, "\t{ \"%s\", %s, DASM_%s, %s }," % (opc.name, alt, opc.amode, flags) print("\t{ \"%s\", %s, DASM_%s, %s }," % (opc.name, alt, opc.amode, flags), file=f)
else: else:
print >>f, "\t{ \"???\", NULL, DASM_none, 0 }," print("\t{ \"???\", NULL, DASM_none, 0 },", file=f)
print >>f, "};" print("};", file=f)
print >>f print("", file=f)
def save_opcodes(self, f, t): def save_opcodes(self, f, t):
pf = "" pf = ""
@ -146,9 +148,9 @@ class OpcodeList:
save_full_one(f, t, "fetch_noirq", self.fetch_noirq.source) save_full_one(f, t, "fetch_noirq", self.fetch_noirq.source)
def save_exec(self, f, t): def save_exec(self, f, t):
print >>f, "void %s_device::do_exec_full()" % t print("void %s_device::do_exec_full()" % t, file=f)
print >>f, "{" print("{", file=f)
print >>f, "\tswitch(inst_state) {" print("\tswitch(inst_state) {", file=f)
for i in range(0x000, 0x200): for i in range(0x000, 0x200):
opc = None opc = None
if i >= 0x100 and i-0x100+0xfe00 in self.opcode_per_id: if i >= 0x100 and i-0x100+0xfe00 in self.opcode_per_id:
@ -159,15 +161,15 @@ class OpcodeList:
nm = opc.name + "_" + opc.amode nm = opc.name + "_" + opc.amode
if opc.is_196: if opc.is_196:
nm += "_196" nm += "_196"
print >>f, "\tcase 0x%03x: %s_full(); break;" % (i, nm) print("\tcase 0x%03x: %s_full(); break;" % (i, nm), file=f)
print >>f, "\tcase 0x200: fetch_full(); break;" print("\tcase 0x200: fetch_full(); break;", file=f)
print >>f, "\tcase 0x201: fetch_noirq_full(); break;" print("\tcase 0x201: fetch_noirq_full(); break;", file=f)
print >>f, "\t}" print("\t}", file=f)
print >>f, "}" print("}", file=f)
def main(argv): def main(argv):
if len(argv) != 4: if len(argv) != 4:
print USAGE % argv[0] print(USAGE % argv[0])
return 1 return 1
t = argv[1] t = argv[1]