Python 3 compat.

Try to keep our Python sources compatible with both Python 2.7 and 3.

Check with 'pylint --py3k' and 'python -3'.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-23 15:16:40 -07:00
parent cab356bd9f
commit 1e1baec50a
20 changed files with 40 additions and 34 deletions

View File

@@ -4,7 +4,7 @@ Cretonne meta language module.
This module provides classes and functions used to describe Cretonne
instructions.
"""
from __future__ import absolute_import
import re
import importlib
from collections import namedtuple
@@ -156,7 +156,7 @@ class SettingGroup(object):
.format(self, SettingGroup._current))
SettingGroup._current = None
if globs:
from predicates import Predicate
from .predicates import Predicate
for name, obj in globs.iteritems():
if isinstance(obj, Setting):
assert obj.name is None, obj.name
@@ -365,7 +365,7 @@ class IntType(ScalarType):
assert bits > 0, 'IntType must have positive number of bits'
super(IntType, self).__init__(
name='i{:d}'.format(bits),
membytes=bits/8,
membytes=bits // 8,
doc="An integer type with {} bits.".format(bits))
self.bits = bits
@@ -379,7 +379,7 @@ class FloatType(ScalarType):
def __init__(self, bits, doc):
assert bits > 0, 'FloatType must have positive number of bits'
super(FloatType, self).__init__(name='f{:d}'.format(bits),
membytes=bits/8, doc=doc)
membytes=bits // 8, doc=doc)
self.bits = bits
def __repr__(self):
@@ -393,7 +393,7 @@ class BoolType(ScalarType):
assert bits > 0, 'BoolType must have positive number of bits'
super(BoolType, self).__init__(
name='b{:d}'.format(bits),
membytes=bits/8,
membytes=bits // 8,
doc="A boolean type with {} bits.".format(bits))
self.bits = bits
@@ -845,7 +845,7 @@ class BoundInstruction(object):
assert len(typevars) <= 1 + len(inst.other_typevars)
def __str__(self):
return '.'.join([self.inst.name, ] + map(str, self.typevars))
return '.'.join([self.inst.name, ] + list(map(str, self.typevars)))
def bind(self, *args):
"""

View File

@@ -4,10 +4,11 @@ Cretonne base instruction set.
This module defines the basic Cretonne instruction set that all targets
support.
"""
from __future__ import absolute_import
from . import TypeVar, Operand, Instruction, InstructionGroup, variable_args
from types import i8, f32, f64
from immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
import entities
from .types import i8, f32, f64
from .immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
from . import entities
instructions = InstructionGroup("base", "Shared base instruction set")

View File

@@ -3,7 +3,7 @@ The `cretonne.entities` module predefines all the Cretonne entity reference
operand types. Thee are corresponding definitions in the `cretonne.entities`
Rust module.
"""
from __future__ import absolute_import
from . import EntityRefKind

View File

@@ -5,11 +5,10 @@ Every instruction format has a corresponding `InstructionData` variant in the
Rust representation of cretonne IL, so all instruction formats must be defined
in this module.
"""
from __future__ import absolute_import
from . import InstructionFormat, value, variable_args
from immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
from entities import ebb, function, jump_table
from .immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
from .entities import ebb, function, jump_table
Nullary = InstructionFormat()

View File

@@ -2,7 +2,7 @@
The `cretonne.immediates` module predefines all the Cretonne immediate operand
types.
"""
from __future__ import absolute_import
from . import ImmediateKind
#: A 64-bit immediate integer operand.

View File

@@ -21,6 +21,8 @@ All predicates have a *context* which determines where they can be evaluated.
For an ISA predicate, the context is the ISA settings group. For an instruction
predicate, the context is the instruction format.
"""
from __future__ import absolute_import
from functools import reduce
def _is_parent(a, b):

View File

@@ -3,7 +3,7 @@ Cretonne shared settings.
This module defines settings are are relevant for all code generators.
"""
from __future__ import absolute_import
from . import SettingGroup, BoolSetting, EnumSetting
group = SettingGroup('shared')

View File

@@ -1,7 +1,7 @@
"""
The cretonne.types module predefines all the Cretonne scalar types.
"""
from __future__ import absolute_import
from . import ScalarType, IntType, FloatType, BoolType
#: Boolean.