Make hctdb compatiable with python 3 (#173)

Make sure we only use python3 compatible code.  In the process of compatibility
fixes I found a bug in how we check for duplicate instruction classes. The fixed
code triggers an assert because we have duplicate instruction classes. I have
commented out the assert for now and we can re-enable it when we sort out what
we want to do about the duplicated classes.
This commit is contained in:
David Peixotto 2017-03-31 15:41:53 -07:00 коммит произвёл GitHub
Родитель 8693031f38
Коммит c9bdb370d7
2 изменённых файлов: 14 добавлений и 15 удалений

Просмотреть файл

@ -1062,24 +1062,22 @@ class db_dxil(object):
import itertools
class_sort_func = lambda x, y: x < y
class_key_func = lambda x : x.dxil_class
instr_ordered_by_class = sorted([i for i in self.instr if i.is_dxil_op], class_sort_func)
instr_grouped_by_class = itertools.groupby(instr_ordered_by_class, class_key_func)
instr_ordered_by_class = sorted([i for i in self.instr if i.is_dxil_op], key=class_key_func)
instr_grouped_by_class = itertools.groupby(instr_ordered_by_class, key=class_key_func)
def calc_oload_sig(inst):
result = ""
for o in inst.ops:
result += o.llvm_type
return result
for k, g in instr_grouped_by_class:
it = g.__iter__()
try:
first = it.next()
group = list(g)
if len(group) > 1:
first = group[0]
first_group = calc_oload_sig(first)
while True:
other = it.next()
for other in group[1:]:
other_group = calc_oload_sig(other)
assert first_group == other_group, "overload signature %s for instruction %s differs from %s in %s" % (first.name, first_group, other.name, other_group)
except StopIteration:
pass
# TODO: uncomment assert when opcodes are fixed
#assert first_group == other_group, "overload signature %s for instruction %s differs from %s in %s" % (first.name, first_group, other.name, other_group)
def populate_extended_docs(self):
"Update the documentation with text from external files."
@ -1127,7 +1125,7 @@ class db_dxil(object):
def add_pass(name, type_name, doc, opts):
apass = db_dxil_pass(name, type_name=type_name, doc=doc)
for o in opts:
assert o.has_key('n'), "option in %s has no 'n' member" % name
assert 'n' in o, "option in %s has no 'n' member" % name
apass.args.append(db_dxil_pass_arg(o['n'], ident=o.get('i'), type_name=o.get('t'), is_ctor_param=o.get('c'), doc=o.get('d')))
p.append(apass)
# Add discriminators is a DWARF 4 thing, useful for the profiler.
@ -1383,7 +1381,7 @@ class db_dxil(object):
CSIn, Invalid, Compute, None, Invalid
Invalid, Invalid, Invalid, Invalid, Invalid
"""
table = [map(str.strip, line.split(',')) for line in SigPointCSV.splitlines() if line.strip()]
table = [list(map(str.strip, line.split(','))) for line in SigPointCSV.splitlines() if line.strip()]
for row in table[1:]: assert(len(row) == len(table[0])) # Ensure table is rectangular
# Make sure labels match enums, otherwise the table isn't aligned or in-sync
if not ([row[0] for row in table[1:]] == SigPointKind.value_names()):
@ -1436,7 +1434,7 @@ class db_dxil(object):
TessFactor,NA,NA,NA,NA,NA,NA,TessFactor,TessFactor,NA,NA,NA,NA,NA,NA,NA,NA
InsideTessFactor,NA,NA,NA,NA,NA,NA,TessFactor,TessFactor,NA,NA,NA,NA,NA,NA,NA,NA
"""
table = [map(str.strip, line.split(',')) for line in SemanticInterpretationCSV.splitlines() if line.strip()]
table = [list(map(str.strip, line.split(','))) for line in SemanticInterpretationCSV.splitlines() if line.strip()]
for row in table[1:]: assert(len(row) == len(table[0])) # Ensure table is rectangular
# Make sure labels match enums, otherwise the table isn't aligned or in-sync
assert(table[0][1:] == SigPointKind.value_names()[:-1]) # exclude Invalid

Просмотреть файл

@ -1,6 +1,7 @@
# Copyright (C) Microsoft Corporation. All rights reserved.
# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
import argparse
import functools
import collections
from hctdb import *
@ -538,11 +539,11 @@ class macro_table_gen:
def format_row(self, row, widths, sep=', '):
frow = [str(item) + sep + (' ' * (width - len(item)))
for item, width in zip(row, widths)[:-1]] + [str(row[-1])]
for item, width in list(zip(row, widths))[:-1]] + [str(row[-1])]
return ''.join(frow)
def format_table(self, table, *args, **kwargs):
widths = [ reduce(max, [ len(row[i])
widths = [ functools.reduce(max, [ len(row[i])
for row in table], 1)
for i in range(len(table[0]))]
formatted = []