diff --git a/meta/build.py b/meta/build.py index 6ca4425823..2806426e6d 100644 --- a/meta/build.py +++ b/meta/build.py @@ -2,6 +2,7 @@ # # This script is run from src/libcretonne/build.rs to generate Rust files. +from __future__ import absolute_import import argparse import isa import gen_instr diff --git a/meta/constant_hash.py b/meta/constant_hash.py index 27a30476a4..aa43694a50 100644 --- a/meta/constant_hash.py +++ b/meta/constant_hash.py @@ -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 quadratically probed hash table. """ +from __future__ import absolute_import def simple_hash(s): diff --git a/meta/cretonne/__init__.py b/meta/cretonne/__init__.py index cc31f47cf5..ecfea17989 100644 --- a/meta/cretonne/__init__.py +++ b/meta/cretonne/__init__.py @@ -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): """ diff --git a/meta/cretonne/base.py b/meta/cretonne/base.py index 84d595e73b..2dd3c1bf95 100644 --- a/meta/cretonne/base.py +++ b/meta/cretonne/base.py @@ -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") diff --git a/meta/cretonne/entities.py b/meta/cretonne/entities.py index 14587d402f..bd55fa6eed 100644 --- a/meta/cretonne/entities.py +++ b/meta/cretonne/entities.py @@ -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 diff --git a/meta/cretonne/formats.py b/meta/cretonne/formats.py index 4798b9ed25..efd535b693 100644 --- a/meta/cretonne/formats.py +++ b/meta/cretonne/formats.py @@ -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() diff --git a/meta/cretonne/immediates.py b/meta/cretonne/immediates.py index f20a6142d3..61ba418c9c 100644 --- a/meta/cretonne/immediates.py +++ b/meta/cretonne/immediates.py @@ -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. diff --git a/meta/cretonne/predicates.py b/meta/cretonne/predicates.py index dd50613a37..caedae14fb 100644 --- a/meta/cretonne/predicates.py +++ b/meta/cretonne/predicates.py @@ -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): diff --git a/meta/cretonne/settings.py b/meta/cretonne/settings.py index 2876dfd84f..ba95bda36c 100644 --- a/meta/cretonne/settings.py +++ b/meta/cretonne/settings.py @@ -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') diff --git a/meta/cretonne/types.py b/meta/cretonne/types.py index d92e6f9113..05dcb53e16 100644 --- a/meta/cretonne/types.py +++ b/meta/cretonne/types.py @@ -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. diff --git a/meta/gen_build_deps.py b/meta/gen_build_deps.py index 4d0c0cb260..32ae2f7238 100644 --- a/meta/gen_build_deps.py +++ b/meta/gen_build_deps.py @@ -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 build. """ - +from __future__ import absolute_import, print_function import os from os.path import dirname, abspath, join @@ -30,7 +30,7 @@ def source_files(top): def generate(): - print "Dependencies from meta language directory:" + print("Dependencies from meta language directory:") meta = dirname(abspath(__file__)) for path in source_files(meta): - print "cargo:rerun-if-changed=" + path + print("cargo:rerun-if-changed=" + path) diff --git a/meta/gen_instr.py b/meta/gen_instr.py index 64c726ad9d..92808524c5 100644 --- a/meta/gen_instr.py +++ b/meta/gen_instr.py @@ -1,7 +1,7 @@ """ Generate sources with instruction info. """ - +from __future__ import absolute_import import srcgen import constant_hash from unique_table import UniqueTable, UniqueSeqTable diff --git a/meta/gen_settings.py b/meta/gen_settings.py index 85c154648d..65bb7c428a 100644 --- a/meta/gen_settings.py +++ b/meta/gen_settings.py @@ -1,7 +1,7 @@ """ Generate sources with settings. """ - +from __future__ import absolute_import import srcgen from unique_table import UniqueSeqTable import constant_hash @@ -102,7 +102,7 @@ def gen_pred_getter(pred, fmt): """ 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) with fmt.indented(proto + ' {', '}'): fmt.line('(self.bytes[{}] & (1 << {})) != 0'.format( diff --git a/meta/isa/__init__.py b/meta/isa/__init__.py index b566a521ef..addc70b8a9 100644 --- a/meta/isa/__init__.py +++ b/meta/isa/__init__.py @@ -5,7 +5,7 @@ Cretonne target ISA definitions The :py:mod:`isa` package contains sub-packages for each target instruction set architecture supported by Cretonne. """ - +from __future__ import absolute_import from . import riscv diff --git a/meta/isa/riscv/__init__.py b/meta/isa/riscv/__init__.py index ce8c47ea3d..1f9ebd3f46 100644 --- a/meta/isa/riscv/__init__.py +++ b/meta/isa/riscv/__init__.py @@ -24,10 +24,10 @@ RV32G / RV64G F, and D instruction sets listed above. """ - -import defs -import encodings -import settings +from __future__ import absolute_import +from . import defs +from . import encodings +from . import settings # Re-export the primary target ISA definition. isa = defs.isa diff --git a/meta/isa/riscv/defs.py b/meta/isa/riscv/defs.py index 6e009ccdf4..4fccbf09a6 100644 --- a/meta/isa/riscv/defs.py +++ b/meta/isa/riscv/defs.py @@ -3,7 +3,7 @@ RISC-V definitions. Commonly used definitions. """ - +from __future__ import absolute_import from cretonne import TargetISA, CPUMode import cretonne.base diff --git a/meta/isa/riscv/encodings.py b/meta/isa/riscv/encodings.py index da5870422f..3ce5102760 100644 --- a/meta/isa/riscv/encodings.py +++ b/meta/isa/riscv/encodings.py @@ -1,9 +1,10 @@ """ RISC-V Encodings. """ +from __future__ import absolute_import from cretonne import base -from defs import RV32, RV64 -from recipes import OPIMM, OPIMM32, OP, OP32, R, Rshamt +from .defs import RV32, RV64 +from .recipes import OPIMM, OPIMM32, OP, OP32, R, Rshamt # Basic arithmetic binary instructions are encoded in an R-type instruction. for inst, f3, f7 in [ diff --git a/meta/isa/riscv/recipes.py b/meta/isa/riscv/recipes.py index 49352b817a..25ea74870f 100644 --- a/meta/isa/riscv/recipes.py +++ b/meta/isa/riscv/recipes.py @@ -8,6 +8,7 @@ instruction formats described in the reference: Volume I: User-Level ISA Version 2.1 """ +from __future__ import absolute_import from cretonne import EncRecipe from cretonne.formats import Binary, BinaryImm diff --git a/meta/isa/riscv/settings.py b/meta/isa/riscv/settings.py index ade60372d6..1ab2917036 100644 --- a/meta/isa/riscv/settings.py +++ b/meta/isa/riscv/settings.py @@ -1,11 +1,11 @@ """ RISC-V settings. """ - +from __future__ import absolute_import from cretonne import SettingGroup, BoolSetting from cretonne.predicates import And import cretonne.settings as shared -from defs import isa +from .defs import isa isa.settings = SettingGroup('riscv', parent=shared.group) diff --git a/meta/srcgen.py b/meta/srcgen.py index 42f39c96de..99bb808435 100644 --- a/meta/srcgen.py +++ b/meta/srcgen.py @@ -5,7 +5,7 @@ The `srcgen` module contains generic helper routines and classes for generating source code. """ - +from __future__ import absolute_import import sys import os import re