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:
@@ -2,6 +2,7 @@
|
|||||||
#
|
#
|
||||||
# This script is run from src/libcretonne/build.rs to generate Rust files.
|
# This script is run from src/libcretonne/build.rs to generate Rust files.
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
import argparse
|
import argparse
|
||||||
import isa
|
import isa
|
||||||
import gen_instr
|
import gen_instr
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ The `constant_hash` module can generate constant pre-populated hash tables. We
|
|||||||
don't attempt parfect hashing, but simply generate an open addressed
|
don't attempt parfect hashing, but simply generate an open addressed
|
||||||
quadratically probed hash table.
|
quadratically probed hash table.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
|
||||||
def simple_hash(s):
|
def simple_hash(s):
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Cretonne meta language module.
|
|||||||
This module provides classes and functions used to describe Cretonne
|
This module provides classes and functions used to describe Cretonne
|
||||||
instructions.
|
instructions.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
import re
|
import re
|
||||||
import importlib
|
import importlib
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
@@ -156,7 +156,7 @@ class SettingGroup(object):
|
|||||||
.format(self, SettingGroup._current))
|
.format(self, SettingGroup._current))
|
||||||
SettingGroup._current = None
|
SettingGroup._current = None
|
||||||
if globs:
|
if globs:
|
||||||
from predicates import Predicate
|
from .predicates import Predicate
|
||||||
for name, obj in globs.iteritems():
|
for name, obj in globs.iteritems():
|
||||||
if isinstance(obj, Setting):
|
if isinstance(obj, Setting):
|
||||||
assert obj.name is None, obj.name
|
assert obj.name is None, obj.name
|
||||||
@@ -365,7 +365,7 @@ class IntType(ScalarType):
|
|||||||
assert bits > 0, 'IntType must have positive number of bits'
|
assert bits > 0, 'IntType must have positive number of bits'
|
||||||
super(IntType, self).__init__(
|
super(IntType, self).__init__(
|
||||||
name='i{:d}'.format(bits),
|
name='i{:d}'.format(bits),
|
||||||
membytes=bits/8,
|
membytes=bits // 8,
|
||||||
doc="An integer type with {} bits.".format(bits))
|
doc="An integer type with {} bits.".format(bits))
|
||||||
self.bits = bits
|
self.bits = bits
|
||||||
|
|
||||||
@@ -379,7 +379,7 @@ class FloatType(ScalarType):
|
|||||||
def __init__(self, bits, doc):
|
def __init__(self, bits, doc):
|
||||||
assert bits > 0, 'FloatType must have positive number of bits'
|
assert bits > 0, 'FloatType must have positive number of bits'
|
||||||
super(FloatType, self).__init__(name='f{:d}'.format(bits),
|
super(FloatType, self).__init__(name='f{:d}'.format(bits),
|
||||||
membytes=bits/8, doc=doc)
|
membytes=bits // 8, doc=doc)
|
||||||
self.bits = bits
|
self.bits = bits
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -393,7 +393,7 @@ class BoolType(ScalarType):
|
|||||||
assert bits > 0, 'BoolType must have positive number of bits'
|
assert bits > 0, 'BoolType must have positive number of bits'
|
||||||
super(BoolType, self).__init__(
|
super(BoolType, self).__init__(
|
||||||
name='b{:d}'.format(bits),
|
name='b{:d}'.format(bits),
|
||||||
membytes=bits/8,
|
membytes=bits // 8,
|
||||||
doc="A boolean type with {} bits.".format(bits))
|
doc="A boolean type with {} bits.".format(bits))
|
||||||
self.bits = bits
|
self.bits = bits
|
||||||
|
|
||||||
@@ -845,7 +845,7 @@ class BoundInstruction(object):
|
|||||||
assert len(typevars) <= 1 + len(inst.other_typevars)
|
assert len(typevars) <= 1 + len(inst.other_typevars)
|
||||||
|
|
||||||
def __str__(self):
|
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):
|
def bind(self, *args):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ Cretonne base instruction set.
|
|||||||
This module defines the basic Cretonne instruction set that all targets
|
This module defines the basic Cretonne instruction set that all targets
|
||||||
support.
|
support.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . import TypeVar, Operand, Instruction, InstructionGroup, variable_args
|
from . import TypeVar, Operand, Instruction, InstructionGroup, variable_args
|
||||||
from types import i8, f32, f64
|
from .types import i8, f32, f64
|
||||||
from immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
|
from .immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
|
||||||
import entities
|
from . import entities
|
||||||
|
|
||||||
instructions = InstructionGroup("base", "Shared base instruction set")
|
instructions = InstructionGroup("base", "Shared base instruction set")
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ The `cretonne.entities` module predefines all the Cretonne entity reference
|
|||||||
operand types. Thee are corresponding definitions in the `cretonne.entities`
|
operand types. Thee are corresponding definitions in the `cretonne.entities`
|
||||||
Rust module.
|
Rust module.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . import EntityRefKind
|
from . import EntityRefKind
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
Rust representation of cretonne IL, so all instruction formats must be defined
|
||||||
in this module.
|
in this module.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from . import InstructionFormat, value, variable_args
|
from . import InstructionFormat, value, variable_args
|
||||||
from immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
|
from .immediates import imm64, uimm8, ieee32, ieee64, immvector, intcc, floatcc
|
||||||
from entities import ebb, function, jump_table
|
from .entities import ebb, function, jump_table
|
||||||
|
|
||||||
Nullary = InstructionFormat()
|
Nullary = InstructionFormat()
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
The `cretonne.immediates` module predefines all the Cretonne immediate operand
|
The `cretonne.immediates` module predefines all the Cretonne immediate operand
|
||||||
types.
|
types.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . import ImmediateKind
|
from . import ImmediateKind
|
||||||
|
|
||||||
#: A 64-bit immediate integer operand.
|
#: A 64-bit immediate integer operand.
|
||||||
|
|||||||
@@ -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
|
For an ISA predicate, the context is the ISA settings group. For an instruction
|
||||||
predicate, the context is the instruction format.
|
predicate, the context is the instruction format.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
|
||||||
def _is_parent(a, b):
|
def _is_parent(a, b):
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Cretonne shared settings.
|
|||||||
|
|
||||||
This module defines settings are are relevant for all code generators.
|
This module defines settings are are relevant for all code generators.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . import SettingGroup, BoolSetting, EnumSetting
|
from . import SettingGroup, BoolSetting, EnumSetting
|
||||||
|
|
||||||
group = SettingGroup('shared')
|
group = SettingGroup('shared')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
The cretonne.types module predefines all the Cretonne scalar types.
|
The cretonne.types module predefines all the Cretonne scalar types.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . import ScalarType, IntType, FloatType, BoolType
|
from . import ScalarType, IntType, FloatType, BoolType
|
||||||
|
|
||||||
#: Boolean.
|
#: Boolean.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ If the build script outputs lines of the form:
|
|||||||
cargo will rerun the build script when those files have changed since the last
|
cargo will rerun the build script when those files have changed since the last
|
||||||
build.
|
build.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import, print_function
|
||||||
import os
|
import os
|
||||||
from os.path import dirname, abspath, join
|
from os.path import dirname, abspath, join
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ def source_files(top):
|
|||||||
|
|
||||||
|
|
||||||
def generate():
|
def generate():
|
||||||
print "Dependencies from meta language directory:"
|
print("Dependencies from meta language directory:")
|
||||||
meta = dirname(abspath(__file__))
|
meta = dirname(abspath(__file__))
|
||||||
for path in source_files(meta):
|
for path in source_files(meta):
|
||||||
print "cargo:rerun-if-changed=" + path
|
print("cargo:rerun-if-changed=" + path)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Generate sources with instruction info.
|
Generate sources with instruction info.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
import srcgen
|
import srcgen
|
||||||
import constant_hash
|
import constant_hash
|
||||||
from unique_table import UniqueTable, UniqueSeqTable
|
from unique_table import UniqueTable, UniqueSeqTable
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Generate sources with settings.
|
Generate sources with settings.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
import srcgen
|
import srcgen
|
||||||
from unique_table import UniqueSeqTable
|
from unique_table import UniqueSeqTable
|
||||||
import constant_hash
|
import constant_hash
|
||||||
@@ -102,7 +102,7 @@ def gen_pred_getter(pred, fmt):
|
|||||||
"""
|
"""
|
||||||
Emit a getter for a pre-computed predicate.
|
Emit a getter for a pre-computed predicate.
|
||||||
"""
|
"""
|
||||||
fmt.doc_comment('Computed predicate `{}`.'.format(pred.rust_predicate(0)));
|
fmt.doc_comment('Computed predicate `{}`.'.format(pred.rust_predicate(0)))
|
||||||
proto = 'pub fn {}(&self) -> bool'.format(pred.name)
|
proto = 'pub fn {}(&self) -> bool'.format(pred.name)
|
||||||
with fmt.indented(proto + ' {', '}'):
|
with fmt.indented(proto + ' {', '}'):
|
||||||
fmt.line('(self.bytes[{}] & (1 << {})) != 0'.format(
|
fmt.line('(self.bytes[{}] & (1 << {})) != 0'.format(
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Cretonne target ISA definitions
|
|||||||
The :py:mod:`isa` package contains sub-packages for each target instruction set
|
The :py:mod:`isa` package contains sub-packages for each target instruction set
|
||||||
architecture supported by Cretonne.
|
architecture supported by Cretonne.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from . import riscv
|
from . import riscv
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ RV32G / RV64G
|
|||||||
F, and D instruction sets listed above.
|
F, and D instruction sets listed above.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
import defs
|
from . import defs
|
||||||
import encodings
|
from . import encodings
|
||||||
import settings
|
from . import settings
|
||||||
|
|
||||||
# Re-export the primary target ISA definition.
|
# Re-export the primary target ISA definition.
|
||||||
isa = defs.isa
|
isa = defs.isa
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ RISC-V definitions.
|
|||||||
|
|
||||||
Commonly used definitions.
|
Commonly used definitions.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from cretonne import TargetISA, CPUMode
|
from cretonne import TargetISA, CPUMode
|
||||||
import cretonne.base
|
import cretonne.base
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
RISC-V Encodings.
|
RISC-V Encodings.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from cretonne import base
|
from cretonne import base
|
||||||
from defs import RV32, RV64
|
from .defs import RV32, RV64
|
||||||
from recipes import OPIMM, OPIMM32, OP, OP32, R, Rshamt
|
from .recipes import OPIMM, OPIMM32, OP, OP32, R, Rshamt
|
||||||
|
|
||||||
# Basic arithmetic binary instructions are encoded in an R-type instruction.
|
# Basic arithmetic binary instructions are encoded in an R-type instruction.
|
||||||
for inst, f3, f7 in [
|
for inst, f3, f7 in [
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ instruction formats described in the reference:
|
|||||||
Volume I: User-Level ISA
|
Volume I: User-Level ISA
|
||||||
Version 2.1
|
Version 2.1
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from cretonne import EncRecipe
|
from cretonne import EncRecipe
|
||||||
from cretonne.formats import Binary, BinaryImm
|
from cretonne.formats import Binary, BinaryImm
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
"""
|
"""
|
||||||
RISC-V settings.
|
RISC-V settings.
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
from cretonne import SettingGroup, BoolSetting
|
from cretonne import SettingGroup, BoolSetting
|
||||||
from cretonne.predicates import And
|
from cretonne.predicates import And
|
||||||
import cretonne.settings as shared
|
import cretonne.settings as shared
|
||||||
from defs import isa
|
from .defs import isa
|
||||||
|
|
||||||
isa.settings = SettingGroup('riscv', parent=shared.group)
|
isa.settings = SettingGroup('riscv', parent=shared.group)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ The `srcgen` module contains generic helper routines and classes for generating
|
|||||||
source code.
|
source code.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|||||||
Reference in New Issue
Block a user