# POSSIBILITY OF SUCH DAMAGE.
#
# NOTE: operands are arranged in NASM / Intel order (e.g. dest, src)
+
+from sys import stdout, version_info
+
rcstag = "$Id$"
try:
scriptname = rcstag.split()[1]
XOPL1 = 0x84
XOPpp = 0x80 # OR with value
+def lprint(s, f = stdout, e = '\n') :
+ f.write(s + e)
+
def cpu_lcd(cpu1, cpu2):
"""Find the lowest common denominator of two CPU sets."""
retval = set()
if kwargs:
for arg in kwargs:
- print "Warning: unrecognized arg %s" % arg
+ lprint("Warning: unrecognized arg %s" % arg)
def __str__(self):
return "{"+ ", ".join(["OPT_%s" % self.type,
if kwargs:
for arg in kwargs:
- print "Warning: unrecognized arg %s" % arg
+ lprint("Warning: unrecognized arg %s" % arg)
def __str__(self):
if hasattr(self, "opcode"):
def finalize_insns():
unused_groups = set(groups.keys())
- for name, opts in insns.iteritems():
- for insn in opts:
+ for name in insns:
+ for insn in insns[name]:
group = groups[insn.groupname]
unused_groups.discard(insn.groupname)
unused_groups.discard("empty")
unused_groups.discard("not64")
if unused_groups:
- print "warning: unused groups: %s" % ", ".join(unused_groups)
+ lprint("warning: unused groups: %s" % ", ".join(unused_groups))
def output_insns(f, parser, insns):
- print >>f, "/* Generated by %s r%s, do not edit */" % \
- (scriptname, scriptrev)
- print >>f, """%%ignore-case
+ lprint("/* Generated by %s r%s, do not edit */" % \
+ (scriptname, scriptrev), f)
+ lprint("""%%ignore-case
%%language=ANSI-C
%%compare-strncmp
%%readonly-tables
%%define hash-function-name insnprefix_%s_hash
%%define lookup-function-name insnprefix_%s_find
struct insnprefix_parse_data;
-%%%%""" % (parser, parser)
+%%%%""" % (parser, parser), f)
for keyword in sorted(insns):
- print >>f, "%s,\t%s" % (keyword.lower(), insns[keyword])
+ lprint("%s,\t%s" % (keyword.lower(), insns[keyword]), f)
def output_gas_insns(f):
output_insns(f, "gas", gas_insns)
# Merge all operand lists into single list
# Sort by number of operands to shorten output
all_operands = []
- for form in sorted((form for g in groups.itervalues() for form in g),
+ gi = groups.itervalues() if version_info[0] == 2 else groups.values()
+ for form in sorted((form for g in gi for form in g),
key=lambda x:len(x.operands), reverse=True):
num_operands = len(form.operands)
- for i in xrange(len(all_operands)):
+ for i in range(len(all_operands)):
if all_operands[i:i+num_operands] == form.operands:
form.all_operands_index = i
break
all_operands.extend(form.operands)
# Output operands list
- print >>f, "/* Generated by %s r%s, do not edit */" % \
- (scriptname, scriptrev)
- print >>f, "static const x86_info_operand insn_operands[] = {"
- print >>f, " ",
- print >>f, ",\n ".join(str(x) for x in all_operands)
- print >>f, "};\n"
+ lprint("/* Generated by %s r%s, do not edit */" % \
+ (scriptname, scriptrev), f)
+ lprint("static const x86_info_operand insn_operands[] = {", f)
+ lprint(" ", f, '')
+ lprint(",\n ".join(str(x) for x in all_operands), f)
+ lprint("};\n", f)
# Output groups
seen = set()
if name in seen:
continue
seen.add(name)
- print >>f, "static const x86_insn_info %s_insn[] = {" % name
- print >>f, " ",
- print >>f, ",\n ".join(str(x) for x in groups[name])
- print >>f, "};\n"
+ lprint("static const x86_insn_info %s_insn[] = {" % name, f)
+ lprint(" ", f, '')
+ lprint(",\n ".join(str(x) for x in groups[name]), f)
+ lprint("};\n", f)
#####################################################################
# General instruction groupings
# Output generation
#####################################################################
-output_groups(file("x86insns.c", "wt"))
-output_gas_insns(file("x86insn_gas.gperf", "wt"))
-output_nasm_insns(file("x86insn_nasm.gperf", "wt"))
+output_groups(open("x86insns.c", "wt"))
+output_gas_insns(open("x86insn_gas.gperf", "wt"))
+output_nasm_insns(open("x86insn_nasm.gperf", "wt"))
+