more Python script cleanups based on PyCharm inspection (nw)

This commit is contained in:
Oliver Stöneberg 2015-03-05 16:38:07 +01:00
parent ad02fe3b8b
commit 87fb14a840
7 changed files with 77 additions and 77 deletions

View File

@ -5,7 +5,7 @@ from __future__ import with_statement
import sys
import os
if (len(sys.argv) < 4) :
if len(sys.argv) < 4:
print('Usage:')
print(' file2str <source.lay> <output.h> <varname> [<type>]')
print('')
@ -17,7 +17,7 @@ srcfile = sys.argv[1]
dstfile = sys.argv[2]
varname = sys.argv[3]
if (len(sys.argv) >= 5) :
if len(sys.argv) >= 5:
type = sys.argv[4]
terminate = 0
else:
@ -32,8 +32,8 @@ except IOError:
byteCount = os.path.getsize(srcfile)
try:
dst = open(dstfile,'w')
dst.write('extern const %s %s[];\n' % ( type, varname ));
dst.write('const %s %s[] =\n{\n\t' % ( type, varname));
dst.write('extern const %s %s[];\n' % ( type, varname ))
dst.write('const %s %s[] =\n{\n\t' % ( type, varname))
offs = 0
with open(srcfile, "rb") as src:
while True:
@ -44,7 +44,7 @@ try:
if isinstance(b, str):
b = ord(b)
dst.write('0x%02x' % b)
offs = offs + 1
offs += 1
if offs != byteCount:
dst.write(',')
else:

View File

@ -120,7 +120,7 @@ if outfmt == 'rc':
fp.write('\tFILEVERSION %s,%s,%s,%s\n' % (version_major, version_minor, version_build, version_subbuild))
fp.write('\tPRODUCTVERSION %s,%s,%s,%s\n' % (version_major, version_minor, version_build, version_subbuild))
fp.write('\tFILEFLAGSMASK 0x3fL\n')
if (version_build == 0):
if version_build == 0:
fp.write('\tFILEFLAGS 0x0L\n')
else:
fp.write('\tFILEFLAGS VS_FF_PRERELEASE\n')

View File

@ -114,7 +114,7 @@ def EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt,
def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler):
# the mode 0x00 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p00(OPS_32)" % funcname
print >>f, "{"
print >>f, " int size = 4;"
@ -170,8 +170,8 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, " }"
print >>f, " /* todo: is the limm, limm syntax valid? (it's pointless.) */"
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 >>f, " %s" % (opexecute)
print >>f, " %s" % (opwrite)
print >>f, " %s" % opexecute
print >>f, " %s" % opwrite
print >>f, " "
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);"
@ -179,11 +179,11 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, ""
print >>f, ""
# the mode 0x01 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p01(OPS_32)" % funcname
print >>f, "{"
EmitGroup04_u5fragment(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, breg_is_dst_only, flagcondition, flaghandler)
print >>f, " %s" % (opexecute)
print >>f, " %s" % (opwrite)
print >>f, " %s" % opexecute
print >>f, " %s" % opwrite
print >>f, " "
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);"
@ -191,7 +191,7 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, ""
print >>f, ""
# the mode 0x10 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p10(OPS_32)" % funcname
if ignore_a == 2:
print >>f, "{"
print >>f, " int size = 4;"
@ -237,8 +237,8 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, " c = (UINT32)S;"
print >>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 >>f, " %s" % (opexecute)
print >>f, " %s" % (opwrite_alt)
print >>f, " %s" % opexecute
print >>f, " %s" % opwrite_alt
print >>f, " "
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);"
@ -246,7 +246,7 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, ""
print >>f, ""
# the mode 0x11 m0 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m0(OPS_32)" % funcname
if ignore_a == 2:
print >>f, "{"
print >>f, " int size = 4;"
@ -262,7 +262,7 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, ""
print >>f, ""
# the mode 0x11 m1 handler
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s_p11_m1(OPS_32)" % funcname
if ignore_a == 2:
print >>f, "{"
print >>f, " int size = 4;"
@ -276,8 +276,8 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
print >>f, " if (!check_condition(condition))"
print >>f, " return m_pc + (size>>0);"
print >>f, ""
print >>f, " %s" % (opexecute)
print >>f, " %s" % (opwrite_alt)
print >>f, " %s" % opexecute
print >>f, " %s" % opwrite_alt
print >>f, " "
EmitGroup04_Flaghandler(f,funcname,opname,flagcondition,flaghandler)
print >>f, " return m_pc + (size >> 0);"
@ -288,7 +288,7 @@ def EmitGroup04(f,funcname, opname, opexecute, opwrite, opwrite_alt, ignore_a, b
# xxx_S c, b, u3 format opcodes (note c is destination)
def EmitGroup0d(f,funcname, opname, opexecute, opwrite):
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname
print >>f, "{"
print >>f, " int u, breg, creg;"
print >>f, ""
@ -299,8 +299,8 @@ def EmitGroup0d(f,funcname, opname, opexecute, opwrite):
print >>f, " REG_16BIT_RANGE(breg);"
print >>f, " REG_16BIT_RANGE(creg);"
print >>f, ""
print >>f, " %s" % (opexecute)
print >>f, " %s" % (opwrite)
print >>f, " %s" % opexecute
print >>f, " %s" % opwrite
print >>f, ""
print >>f, " return m_pc + (2 >> 0);"
print >>f, "}"
@ -310,7 +310,7 @@ def EmitGroup0d(f,funcname, opname, opexecute, opwrite):
# xxx_S b <- b,c format opcodes
def EmitGroup0f(f,funcname, opname, opexecute, opwrite):
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)"% funcname
print >>f, "{"
print >>f, " int breg, creg;"
print >>f, ""
@ -320,8 +320,8 @@ def EmitGroup0f(f,funcname, opname, opexecute, opwrite):
print >>f, " REG_16BIT_RANGE(breg);"
print >>f, " REG_16BIT_RANGE(creg);"
print >>f, ""
print >>f, " %s" % (opexecute)
print >>f, " %s" % (opwrite)
print >>f, " %s" % opexecute
print >>f, " %s" % opwrite
print >>f, ""
print >>f, " return m_pc + (2 >> 0);"
print >>f, "}"
@ -331,7 +331,7 @@ def EmitGroup0f(f,funcname, opname, opexecute, opwrite):
# xxx_S b, b, u5 format opcodes
def EmitGroup17(f,funcname, opname, opexecute):
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % (funcname)
print >>f, "ARCOMPACT_RETTYPE arcompact_device::arcompact_handle%s(OPS_16)" % funcname
print >>f, "{"
print >>f, " int breg, u;"
print >>f, " "
@ -340,7 +340,7 @@ def EmitGroup17(f,funcname, opname, opexecute):
print >>f, " "
print >>f, " REG_16BIT_RANGE(breg);"
print >>f, " "
print >>f, " %s" % (opexecute)
print >>f, " %s" % opexecute
print >>f, " "
print >>f, " return m_pc + (2 >> 0);"
print >>f, "}"

View File

@ -7,23 +7,23 @@ Usage:
import sys
def name_to_type(name):
if(name == "o"):
if name == "o":
return 0
if(name == "h"):
if name == "h":
return 1
if(name == "s20"):
if name == "s20":
return 2
if(name == "s26"):
if name == "s26":
return 3
print "Unknown chip type name %s" % name
sys.exit(1)
def type_to_device(dtype):
if(dtype == 0):
if dtype == 0:
return "h8_device"
if(dtype == 1):
if dtype == 1:
return "h8h_device"
if(dtype == 2):
if dtype == 2:
return "h8s2000_device"
return "h8s2600_device"
@ -52,10 +52,10 @@ def save_full_one(f, t, name, source):
if has_memory(line):
print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate
print >>f, line
substate = substate + 1
substate += 1
elif has_eat(line):
print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate
substate = substate + 1
substate += 1
else:
print >>f, line
print >>f, "}"
@ -72,11 +72,11 @@ def save_partial_one(f, t, name, source):
print >>f, "\tif(icount <= bcount) { inst_substate = %d; return; }" % substate
print >>f, "case %d:;" % substate
print >>f, line
substate = substate + 1
substate += 1
elif has_eat(line):
print >>f, "\tif(icount) icount = bcount; inst_substate = %d; return;" % substate
print >>f, "case %d:;" % substate
substate = substate + 1
substate += 1
else:
print >>f, line
print >>f, "\tbreak;"
@ -122,22 +122,22 @@ class Opcode:
self.enabled = otype == -1 or (otype == 0 and dtype == 0) or (otype != 0 and dtype >= otype)
self.needed = self.enabled and (otype == dtype or (otype == -1 and dtype == 0))
if dtype == 0 and (am1 == "r16l" or am2 == "r16l"):
self.mask[len(self.mask)-1] = self.mask[len(self.mask)-1] | 0x08
self.mask[len(self.mask) - 1] |= 0x08
if dtype == 0 and (am1 == "r16h" or am2 == "r16h"):
self.mask[len(self.mask)-1] = self.mask[len(self.mask)-1] | 0x80
self.mask[len(self.mask) - 1] |= 0x80
extra_words = 0
if (am1 == "abs16" or am2 == "abs16" or am1 == "abs16e" or am1 == "abs24e") and self.skip == 0:
extra_words = extra_words + 1
extra_words += 1
if (am1 == "abs32" or am2 == "abs32") and self.skip == 0:
extra_words = extra_words + 2
extra_words += 2
if am1 == "imm16" or am1 == "rel16" or am1 == "r16d16h" or am2 == "r16d16h" or am1 == "r32d16h" or am2 == "r32d16h":
extra_words = extra_words + 1
extra_words += 1
if am1 == "imm32" or am1 == "r32d32hh" or am2 == "r32d32hh":
extra_words = extra_words + 2
extra_words += 2
self.extra_words = extra_words
base_offset = len(self.val)/2 + self.skip
for i in range(0, extra_words):
self.source.append("\tfetch(%d);\n" % (i+base_offset));
self.source.append("\tfetch(%d);\n" % (i+base_offset))
def description(self):
return "%s %s %s" % (self.name, self.am1, self.am2)
@ -217,7 +217,7 @@ class Macro:
lval = ""
for i in range(len(self.params)-1, len(tokens)-1):
if lval != "":
lval = lval + " "
lval += " "
lval = lval + tokens[i+1]
values.append(lval)
for i in range(0, len(self.source)):
@ -234,7 +234,7 @@ class DispatchStep:
self.enabled = False
self.mask = opc.mask[pos-1]
for i in range(0, pos):
self.name = self.name + ("%02x" % opc.val[i])
self.name += "%02x" % opc.val[i]
if pos == 2:
self.skip = opc.skip
else:
@ -250,7 +250,8 @@ class DispatchStep:
for i in range(start, end+1):
s.append("\tIR[%d] = fetch();" % i)
s.append("\tinst_state = 0x%x0000 | IR[%d];" % (self.id, end))
return s;
return s
class OpcodeList:
def __init__(self, fname, dtype):
@ -392,11 +393,11 @@ class OpcodeList:
fmask = h2.premask | (h.mask ^ 0xff)
c = ""
s = 0
while(s < 0x100):
c = c + "case 0x%02x: " % (val | s)
s = s + 1
while(s & fmask):
s = s + (s & fmask)
while s < 0x100:
c += "case 0x%02x: " % (val | s)
s += 1
while s & fmask:
s += s & fmask
print >>f, "\t\t%s{" % c
if h2.mask == 0x00:
n = h2.d[0]
@ -420,11 +421,11 @@ class OpcodeList:
fmask = fmask | n.mask[mpos]
c = ""
s = 0
while(s < 0x100):
c = c + "case 0x%02x: " % (val2 | s)
s = s + 1
while(s & fmask):
s = s + (s & fmask)
while s < 0x100:
c += "case 0x%02x: " % (val2 | s)
s += 1
while s & fmask:
s += s & fmask
if n.is_dispatch():
print >>f, "\t\t\t%sdispatch_%s_%s(); break;" % (c, n.name, v)
else:

View File

@ -12,7 +12,7 @@ states_to_dispatch = { 0 : "MAIN" }
def load_file(fname, lines):
path = fname.rpartition('/')[0]
if path != "":
path = path + '/'
path += '/'
try:
f = open(fname, "rU")
except Exception:
@ -28,7 +28,7 @@ def load_file(fname, lines):
load_file(path + line.split('"')[1], lines)
else:
lines.append(line)
count = count + 2
count += 2
f.close()
@ -57,12 +57,12 @@ while count < len(lines):
# Do we have a label?
label = line[:percent_pos].strip()
if (label != ""):
if label != "":
text += whitespace + label + "\n"
whitespace = whitespace + "\t"
whitespace += "\t"
# Create the goto command
if (dispatch[-1:] == "*"):
if dispatch[-1:] == "*":
goto_command = "if (is_register_register_op_16_bit()) goto %s16; else goto %s8;\n" %(dispatch[:-1], dispatch[:-1])
else:
goto_command = "goto %s;\n" % dispatch
@ -70,7 +70,7 @@ while count < len(lines):
# Are we right before a 'return'?
if next_line_is_return:
text += whitespace + goto_command
count = count + 1 # Skip the return
count += 1 # Skip the return
elif next_line_is_dispatch_and_return:
# We are followed by a dispatch/return combo; identify the next dispatch
percent_pos = lines[count+1].find("%")
@ -80,18 +80,18 @@ while count < len(lines):
if next_dispatch not in dispatch_to_states:
dispatch_to_states[next_dispatch] = state
states_to_dispatch[state] = next_dispatch
state = state + 1
state += 1
text += whitespace + "push_state(%s);\t// %s\n" % (dispatch_to_states[next_dispatch], next_dispatch)
text += whitespace + goto_command
count = count + 2 # Skip the dispatch/return
count += 2 # Skip the dispatch/return
else:
# Normal dispatch
text += whitespace + "push_state(%s);\n" % (state)
text += whitespace + "push_state(%s);\n" % state
text += whitespace + goto_command
text += "state_%s:\n" % (state)
state = state + 1
text += "state_%s:\n" % state
state += 1
else:
# "Normal" code
# Is there an '@' here?
@ -104,12 +104,12 @@ while count < len(lines):
# If we have to decrement the icount, output more info
if check_icount and not next_line_is_return:
text += whitespace + "if (UNEXPECTED(m_icount <= 0)) { push_state(%s); return; }\n" % (state)
text += "state_%s:\n" % (state)
state = state + 1
text += whitespace + "if (UNEXPECTED(m_icount <= 0)) { push_state(%s); return; }\n" % state
text += "state_%s:\n" % state
state += 1
# Advance to next line
count = count + 1
count += 1
# Output the case labels
for i in range(0, state):

View File

@ -158,7 +158,7 @@ class OpcodeList:
if opc != None:
nm = opc.name + "_" + opc.amode
if opc.is_196:
nm = nm + "_196"
nm += "_196"
print >>f, "\tcase 0x%03x: %s_full(); break;" % (i, nm)
print >>f, "\tcase 0x200: fetch_full(); break;"
print >>f, "\tcase 0x201: fetch_noirq_full(); break;"

View File

@ -269,8 +269,7 @@ class Instruction:
if v in flags_fixed:
#print "@@@@", f
vals.append("%s=%d" % (v, flags_fixed[v]))
out = []
out.append("case %d: // %s %s" % (no, self._name, " ".join(vals)))
out = ["case %d: // %s %s" % (no, self._name, " ".join(vals))]
for line in self.PreprocessRunString():
out.append(self.ExpandCintrp(line, flags_fixed))
out.append(" break;")