Commit 0f7b18fa authored by Mathieu Bridon's avatar Mathieu Bridon Committed by Dylan Baker

python: Use the print function

In Python 2, `print` was a statement, but it became a function in
Python 3.

Using print functions everywhere makes the script compatible with Python
versions >= 2.6, including Python 3.
Signed-off-by: Mathieu Bridon's avatarMathieu Bridon <bochecha@daitauha.fr>
Acked-by: Eric Engestrom's avatarEric Engestrom <eric.engestrom@intel.com>
Acked-by: Dylan Baker's avatarDylan Baker <dylan@pnwbakers.com>
parent b3a42fa0
from __future__ import print_function
CopyRight = '''
/*
......@@ -333,10 +334,10 @@ def write_tables(asics, packets):
strings_offsets = IntTable("int")
fields = FieldTable()
print '/* This file is autogenerated by sid_tables.py from sid.h. Do not edit directly. */'
print
print CopyRight.strip()
print '''
print('/* This file is autogenerated by sid_tables.py from sid.h. Do not edit directly. */')
print()
print(CopyRight.strip())
print('''
#ifndef SID_TABLES_H
#define SID_TABLES_H
......@@ -358,17 +359,17 @@ struct si_packet3 {
unsigned name_offset;
unsigned op;
};
'''
''')
print 'static const struct si_packet3 packet3_table[] = {'
print('static const struct si_packet3 packet3_table[] = {')
for pkt in packets:
print '\t{%s, %s},' % (strings.add(pkt[5:]), pkt)
print '};'
print
print('\t{%s, %s},' % (strings.add(pkt[5:]), pkt))
print('};')
print()
regs = {}
for asic in asics:
print 'static const struct si_reg %s_reg_table[] = {' % (asic.name)
print('static const struct si_reg %s_reg_table[] = {' % (asic.name))
for reg in asic.registers:
# Only output a register that was changed or added relative to
# the previous generation
......@@ -377,27 +378,27 @@ struct si_packet3 {
continue
if len(reg.fields):
print '\t{%s, %s, %s, %s},' % (strings.add(reg.name), reg.r_name,
len(reg.fields), fields.add(reg.fields))
print('\t{%s, %s, %s, %s},' % (strings.add(reg.name), reg.r_name,
len(reg.fields), fields.add(reg.fields)))
else:
print '\t{%s, %s},' % (strings.add(reg.name), reg.r_name)
print('\t{%s, %s},' % (strings.add(reg.name), reg.r_name))
regs[reg.r_name] = reg
print '};'
print
print('};')
print()
fields.emit(sys.stdout, strings, strings_offsets)
print
print()
strings.emit(sys.stdout, "sid_strings")
print
print()
strings_offsets.emit(sys.stdout, "sid_strings_offsets")
print
print '#endif'
print()
print('#endif')
def main():
......
from __future__ import print_function
CopyRight = '''
/**************************************************************************
......@@ -79,24 +80,24 @@ def print_channels(format, func):
if format.nr_channels() <= 1:
func(format.le_channels, format.le_swizzles)
else:
print '#ifdef PIPE_ARCH_BIG_ENDIAN'
print('#ifdef PIPE_ARCH_BIG_ENDIAN')
func(format.be_channels, format.be_swizzles)
print '#else'
print('#else')
func(format.le_channels, format.le_swizzles)
print '#endif'
print('#endif')
def write_format_table(formats):
print '/* This file is autogenerated by vk_format_table.py from vk_format_layout.csv. Do not edit directly. */'
print
print('/* This file is autogenerated by vk_format_table.py from vk_format_layout.csv. Do not edit directly. */')
print()
# This will print the copyright message on the top of this file
print CopyRight.strip()
print
print '#include "stdbool.h"'
print '#include "vk_format.h"'
print
print(CopyRight.strip())
print()
print('#include "stdbool.h"')
print('#include "vk_format.h"')
print()
def do_channel_array(channels, swizzles):
print " {"
print(" {")
for i in range(4):
channel = channels[i]
if i < 3:
......@@ -104,13 +105,13 @@ def write_format_table(formats):
else:
sep = ""
if channel.size:
print " {%s, %s, %s, %s, %u, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), bool_map(channel.pure), bool_map(channel.scaled), channel.size, channel.shift, sep, "xyzw"[i], channel.name)
print(" {%s, %s, %s, %s, %u, %u}%s\t/* %s = %s */" % (type_map[channel.type], bool_map(channel.norm), bool_map(channel.pure), bool_map(channel.scaled), channel.size, channel.shift, sep, "xyzw"[i], channel.name))
else:
print " {0, 0, 0, 0, 0}%s" % (sep,)
print " },"
print(" {0, 0, 0, 0, 0}%s" % (sep,))
print(" },")
def do_swizzle_array(channels, swizzles):
print " {"
print(" {")
for i in range(4):
swizzle = swizzles[i]
if i < 3:
......@@ -121,43 +122,43 @@ def write_format_table(formats):
comment = colorspace_channels_map[format.colorspace][i]
except (KeyError, IndexError):
comment = 'ignored'
print " %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment)
print " },"
print(" %s%s\t/* %s */" % (swizzle_map[swizzle], sep, comment))
print(" },")
for format in formats:
print 'static const struct vk_format_description'
print 'vk_format_%s_description = {' % (format.short_name(),)
print " %s," % (format.name,)
print " \"%s\"," % (format.name,)
print " \"%s\"," % (format.short_name(),)
print " {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size())
print " %s," % (layout_map(format.layout),)
print " %u,\t/* nr_channels */" % (format.nr_channels(),)
print " %s,\t/* is_array */" % (bool_map(format.is_array()),)
print " %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),)
print " %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),)
print('static const struct vk_format_description')
print('vk_format_%s_description = {' % (format.short_name(),))
print(" %s," % (format.name,))
print(" \"%s\"," % (format.name,))
print(" \"%s\"," % (format.short_name(),))
print(" {%u, %u, %u},\t/* block */" % (format.block_width, format.block_height, format.block_size()))
print(" %s," % (layout_map(format.layout),))
print(" %u,\t/* nr_channels */" % (format.nr_channels(),))
print(" %s,\t/* is_array */" % (bool_map(format.is_array()),))
print(" %s,\t/* is_bitmask */" % (bool_map(format.is_bitmask()),))
print(" %s,\t/* is_mixed */" % (bool_map(format.is_mixed()),))
print_channels(format, do_channel_array)
print_channels(format, do_swizzle_array)
print " %s," % (colorspace_map(format.colorspace),)
print "};"
print
print(" %s," % (colorspace_map(format.colorspace),))
print("};")
print()
print "const struct vk_format_description *"
print "vk_format_description(VkFormat format)"
print "{"
print " if (format > VK_FORMAT_END_RANGE) {"
print " return NULL;"
print " }"
print
print " switch (format) {"
print("const struct vk_format_description *")
print("vk_format_description(VkFormat format)")
print("{")
print(" if (format > VK_FORMAT_END_RANGE) {")
print(" return NULL;")
print(" }")
print()
print(" switch (format) {")
for format in formats:
print " case %s:" % format.name
print " return &vk_format_%s_description;" % (format.short_name(),)
print " default:"
print " return NULL;"
print " }"
print "}"
print
print(" case %s:" % format.name)
print(" return &vk_format_%s_description;" % (format.short_name(),))
print(" default:")
print(" return NULL;")
print(" }")
print("}")
print()
def main():
......
from __future__ import print_function
template = """\
/* Copyright (C) 2015 Broadcom
......@@ -68,4 +69,4 @@ from nir_opcodes import opcodes
from nir_intrinsics import INTR_OPCODES
from mako.template import Template
print Template(template).render(opcodes=opcodes, INTR_OPCODES=INTR_OPCODES)
print(Template(template).render(opcodes=opcodes, INTR_OPCODES=INTR_OPCODES))
from __future__ import print_function
import re
......@@ -431,8 +432,8 @@ nir_eval_const_opcode(nir_op op, unsigned num_components,
from nir_opcodes import opcodes
from mako.template import Template
print Template(template).render(opcodes=opcodes, type_sizes=type_sizes,
print(Template(template).render(opcodes=opcodes, type_sizes=type_sizes,
type_has_size=type_has_size,
type_add_size=type_add_size,
op_bit_sizes=op_bit_sizes,
get_const_field=get_const_field)
get_const_field=get_const_field))
......@@ -23,6 +23,8 @@
# Authors:
# Connor Abbott (cwabbott0@gmail.com)
from __future__ import print_function
from nir_opcodes import opcodes
from mako.template import Template
......@@ -135,4 +137,4 @@ const nir_op_info nir_op_infos[nir_num_opcodes] = {
};
""")
print template.render(opcodes=opcodes)
print(template.render(opcodes=opcodes))
from __future__ import print_function
template = """\
/* Copyright (C) 2014 Connor Abbott
......@@ -43,4 +44,4 @@ typedef enum {
from nir_opcodes import opcodes
from mako.template import Template
print Template(template).render(opcodes=opcodes)
print(Template(template).render(opcodes=opcodes))
......@@ -23,6 +23,8 @@
# Authors:
# Jason Ekstrand (jason@jlekstrand.net)
from __future__ import print_function
from collections import OrderedDict
import nir_algebraic
import itertools
......@@ -791,8 +793,8 @@ late_optimizations = [
(('b2f@32', a), ('iand', a, 1.0), 'options->lower_b2f'),
]
print nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render()
print nir_algebraic.AlgebraicPass("nir_opt_algebraic_before_ffma",
before_ffma_optimizations).render()
print nir_algebraic.AlgebraicPass("nir_opt_algebraic_late",
late_optimizations).render()
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic", optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_before_ffma",
before_ffma_optimizations).render())
print(nir_algebraic.AlgebraicPass("nir_opt_algebraic_late",
late_optimizations).render())
from __future__ import print_function
copyright = '''
/*
* Copyright 2009 VMware, Inc.
......@@ -53,9 +55,9 @@ outtype_idx = dict(ushort='OUT_USHORT', uint='OUT_UINT')
def prolog():
print '''/* File automatically generated by u_unfilled_gen.py */'''
print copyright
print r'''
print('''/* File automatically generated by u_unfilled_gen.py */''')
print(copyright)
print(r'''
/**
* @file
......@@ -93,7 +95,7 @@ static unsigned in_size_idx( unsigned index_size )
static u_generate_func generate_line[OUT_COUNT][PRIM_COUNT];
static u_translate_func translate_line[IN_COUNT][OUT_COUNT][PRIM_COUNT];
'''
''')
def vert( intype, outtype, v0 ):
if intype == GENERATE:
......@@ -102,8 +104,8 @@ def vert( intype, outtype, v0 ):
return '(' + outtype + ')in[' + v0 + ']'
def line( intype, outtype, ptr, v0, v1 ):
print ' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';'
print ' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';'
print(' (' + ptr + ')[0] = ' + vert( intype, outtype, v0 ) + ';')
print(' (' + ptr + ')[1] = ' + vert( intype, outtype, v1 ) + ';')
# XXX: have the opportunity here to avoid over-drawing shared lines in
# tristrips, fans, etc, by integrating this into the calling functions
......@@ -127,89 +129,89 @@ def name(intype, outtype, prim):
return 'translate_' + prim + '_' + intype + '2' + outtype
def preamble(intype, outtype, prim):
print 'static void ' + name( intype, outtype, prim ) + '('
print('static void ' + name( intype, outtype, prim ) + '(')
if intype != GENERATE:
print ' const void * _in,'
print ' unsigned start,'
print(' const void * _in,')
print(' unsigned start,')
if intype != GENERATE:
print ' unsigned in_nr,'
print ' unsigned out_nr,'
print(' unsigned in_nr,')
print(' unsigned out_nr,')
if intype != GENERATE:
print ' unsigned restart_index,'
print ' void *_out )'
print '{'
print(' unsigned restart_index,')
print(' void *_out )')
print('{')
if intype != GENERATE:
print ' const ' + intype + '*in = (const ' + intype + '*)_in;'
print ' ' + outtype + ' *out = (' + outtype + '*)_out;'
print ' unsigned i, j;'
print ' (void)j;'
print(' const ' + intype + '*in = (const ' + intype + '*)_in;')
print(' ' + outtype + ' *out = (' + outtype + '*)_out;')
print(' unsigned i, j;')
print(' (void)j;')
def postamble():
print '}'
print('}')
def tris(intype, outtype):
preamble(intype, outtype, prim='tris')
print ' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { '
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=3) { ')
do_tri( intype, outtype, 'out+j', 'i', 'i+1', 'i+2' );
print ' }'
print(' }')
postamble()
def tristrip(intype, outtype):
preamble(intype, outtype, prim='tristrip')
print ' for (i = start, j = 0; j < out_nr; j+=6, i++) { '
print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
do_tri( intype, outtype, 'out+j', 'i', 'i+1/*+(i&1)*/', 'i+2/*-(i&1)*/' );
print ' }'
print(' }')
postamble()
def trifan(intype, outtype):
preamble(intype, outtype, prim='trifan')
print ' for (i = start, j = 0; j < out_nr; j+=6, i++) { '
print(' for (i = start, j = 0; j < out_nr; j+=6, i++) { ')
do_tri( intype, outtype, 'out+j', '0', 'i+1', 'i+2' );
print ' }'
print(' }')
postamble()
def polygon(intype, outtype):
preamble(intype, outtype, prim='polygon')
print ' for (i = start, j = 0; j < out_nr; j+=2, i++) { '
print(' for (i = start, j = 0; j < out_nr; j+=2, i++) { ')
line( intype, outtype, 'out+j', 'i', '(i+1)%(out_nr/2)' )
print ' }'
print(' }')
postamble()
def quads(intype, outtype):
preamble(intype, outtype, prim='quads')
print ' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { '
print(' for (i = start, j = 0; j < out_nr; j+=8, i+=4) { ')
do_quad( intype, outtype, 'out+j', 'i+0', 'i+1', 'i+2', 'i+3' );
print ' }'
print(' }')
postamble()
def quadstrip(intype, outtype):
preamble(intype, outtype, prim='quadstrip')
print ' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { '
print(' for (i = start, j = 0; j < out_nr; j+=8, i+=2) { ')
do_quad( intype, outtype, 'out+j', 'i+2', 'i+0', 'i+1', 'i+3' );
print ' }'
print(' }')
postamble()
def trisadj(intype, outtype):
preamble(intype, outtype, prim='trisadj')
print ' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { '
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=6) { ')
do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
print ' }'
print(' }')
postamble()
def tristripadj(intype, outtype):
preamble(intype, outtype, prim='tristripadj')
print ' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { '
print(' for (i = start, j = 0; j < out_nr; j+=6, i+=2) { ')
do_tri( intype, outtype, 'out+j', 'i', 'i+2', 'i+4' );
print ' }'
print(' }')
postamble()
......@@ -227,16 +229,16 @@ def emit_funcs():
def init(intype, outtype, prim):
if intype == GENERATE:
print ('generate_line[' +
print(('generate_line[' +
outtype_idx[outtype] +
'][' + longprim[prim] +
'] = ' + name( intype, outtype, prim ) + ';')
'] = ' + name( intype, outtype, prim ) + ';'))
else:
print ('translate_line[' +
print(('translate_line[' +
intype_idx[intype] +
'][' + outtype_idx[outtype] +
'][' + longprim[prim] +
'] = ' + name( intype, outtype, prim ) + ';')
'] = ' + name( intype, outtype, prim ) + ';'))
def emit_all_inits():
......@@ -246,19 +248,19 @@ def emit_all_inits():
init(intype, outtype, prim)
def emit_init():
print 'void u_unfilled_init( void )'
print '{'
print ' static int firsttime = 1;'
print ' if (!firsttime) return;'
print ' firsttime = 0;'
print('void u_unfilled_init( void )')
print('{')
print(' static int firsttime = 1;')
print(' if (!firsttime) return;')
print(' firsttime = 0;')
emit_all_inits()
print '}'
print('}')
def epilog():
print '#include "indices/u_unfilled_indices.c"'
print('#include "indices/u_unfilled_indices.c"')
def main():
......
This diff is collapsed.
......@@ -20,6 +20,8 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
from __future__ import print_function
import argparse
import sys
......@@ -40,9 +42,9 @@ def main():
def run():
import nir_algebraic # pylint: disable=import-error
print '#include "ir3_nir.h"'
print nir_algebraic.AlgebraicPass("ir3_nir_apply_trig_workarounds",
trig_workarounds).render()
print('#include "ir3_nir.h"')
print(nir_algebraic.AlgebraicPass("ir3_nir_apply_trig_workarounds",
trig_workarounds).render())
if __name__ == '__main__':
......
from __future__ import print_function
CopyRight = '''
/*
......@@ -217,10 +218,10 @@ def write_tables(regs, packets):
strings = StringTable()
strings_offsets = IntTable("int")
print '/* This file is autogenerated by egd_tables.py from evergreend.h. Do not edit directly. */'
print
print CopyRight.strip()
print '''
print('/* This file is autogenerated by egd_tables.py from evergreend.h. Do not edit directly. */')
print()
print(CopyRight.strip())
print('''
#ifndef EG_TABLES_H
#define EG_TABLES_H
......@@ -242,20 +243,20 @@ struct eg_packet3 {
unsigned name_offset;
unsigned op;
};
'''
''')
print 'static const struct eg_packet3 packet3_table[] = {'
print('static const struct eg_packet3 packet3_table[] = {')
for pkt in packets:
print '\t{%s, %s},' % (strings.add(pkt[5:]), pkt)
print '};'
print
print('\t{%s, %s},' % (strings.add(pkt[5:]), pkt))
print('};')
print()
print 'static const struct eg_field egd_fields_table[] = {'
print('static const struct eg_field egd_fields_table[] = {')
fields_idx = 0
for reg in regs:
if len(reg.fields) and reg.own_fields:
print '\t/* %s */' % (fields_idx)
print('\t/* %s */' % (fields_idx))
reg.fields_idx = fields_idx
......@@ -266,34 +267,34 @@ struct eg_packet3 {
while value[1] >= len(values_offsets):
values_offsets.append(-1)
values_offsets[value[1]] = strings.add(strip_prefix(value[0]))
print '\t{%s, %s(~0u), %s, %s},' % (
print('\t{%s, %s(~0u), %s, %s},' % (
strings.add(field.name), field.s_name,
len(values_offsets), strings_offsets.add(values_offsets))
len(values_offsets), strings_offsets.add(values_offsets)))
else:
print '\t{%s, %s(~0u)},' % (strings.add(field.name), field.s_name)
print('\t{%s, %s(~0u)},' % (strings.add(field.name), field.s_name))
fields_idx += 1
print '};'
print
print('};')
print()
print 'static const struct eg_reg egd_reg_table[] = {'
print('static const struct eg_reg egd_reg_table[] = {')
for reg in regs:
if len(reg.fields):
print '\t{%s, %s, %s, %s},' % (strings.add(reg.name), reg.r_name,
len(reg.fields), reg.fields_idx if reg.own_fields else reg.fields_owner.fields_idx)
print('\t{%s, %s, %s, %s},' % (strings.add(reg.name), reg.r_name,
len(reg.fields), reg.fields_idx if reg.own_fields else reg.fields_owner.fields_idx))
else:
print '\t{%s, %s},' % (strings.add(reg.name), reg.r_name)
print '};'
print
print('\t{%s, %s},' % (strings.add(reg.name), reg.r_name))
print('};')
print()
strings.emit(sys.stdout, "egd_strings")
print
print()
strings_offsets.emit(sys.stdout, "egd_strings_offsets")
print
print '#endif'
print()
print('#endif')
def main():
......
......@@ -31,6 +31,8 @@
# amplitude slightly. Apparently this also minimizes the error function,
# reducing the maximum error from 0.00006 to about 0.00003.
from __future__ import print_function
import argparse
import sys
......@@ -51,9 +53,9 @@ def main():
def run():
import nir_algebraic # pylint: disable=import-error
print '#include "brw_nir.h"'
print nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
TRIG_WORKAROUNDS).render()
print('#include "brw_nir.h"')
print(nir_algebraic.AlgebraicPass("brw_nir_apply_trig_workarounds",
TRIG_WORKAROUNDS).render())
if __name__ == '__main__':
......
......@@ -24,6 +24,8 @@
# Authors:
# Ian Romanick <idr@us.ibm.com>
from __future__ import print_function
import gl_XML, glX_XML
import string
......@@ -80,12 +82,12 @@ class glx_print_proto(gl_XML.gl_print_base):
compsize = self.size_call(f)
if compsize:
print ' const GLuint compsize = %s;' % (compsize)
print(' const GLuint compsize = %s;' % (compsize))
if bias:
print ' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias)
print(' const GLuint cmdlen = %s - %u;' % (f.command_length(), bias))
else:
print ' const GLuint cmdlen = %s;' % (f.command_length())
print(' const GLuint cmdlen = %s;' % (f.command_length()))
#print ''
return compsize
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.