Add mypy types for gen_instr.py.
Declare the Instruction.number opcode number field.
This commit is contained in:
@@ -107,6 +107,9 @@ class Instruction(object):
|
|||||||
self.outs = self._to_operand_tuple(outs)
|
self.outs = self._to_operand_tuple(outs)
|
||||||
self.format = InstructionFormat.lookup(self.ins, self.outs)
|
self.format = InstructionFormat.lookup(self.ins, self.outs)
|
||||||
|
|
||||||
|
# Opcode number, assigned by gen_instr.py.
|
||||||
|
self.number = None # type: int
|
||||||
|
|
||||||
# Indexes into `self.outs` for value results.
|
# Indexes into `self.outs` for value results.
|
||||||
# Other results are `variable_args`.
|
# Other results are `variable_args`.
|
||||||
self.value_results = tuple(
|
self.value_results = tuple(
|
||||||
|
|||||||
@@ -8,15 +8,18 @@ from unique_table import UniqueTable, UniqueSeqTable
|
|||||||
from cdsl import camel_case
|
from cdsl import camel_case
|
||||||
from cdsl.operands import ImmediateKind
|
from cdsl.operands import ImmediateKind
|
||||||
from cdsl.formats import InstructionFormat
|
from cdsl.formats import InstructionFormat
|
||||||
|
from cdsl.instructions import Instruction
|
||||||
from cdsl.instructions import Instruction # noqa
|
|
||||||
from cdsl.operands import Operand # noqa
|
|
||||||
from cdsl.typevar import TypeVar # noqa
|
|
||||||
|
|
||||||
# The typing module is only required by mypy, and we don't use these imports
|
# The typing module is only required by mypy, and we don't use these imports
|
||||||
# outside type comments.
|
# outside type comments.
|
||||||
try:
|
try:
|
||||||
from typing import List # noqa
|
from typing import List, Sequence, Set, TYPE_CHECKING # noqa
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from cdsl.isa import TargetISA # noqa
|
||||||
|
from cdsl.instructions import InstructionGroup # noqa
|
||||||
|
from cdsl.operands import Operand # noqa
|
||||||
|
from cdsl.typevar import TypeVar # noqa
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -260,7 +263,8 @@ def gen_instruction_data_impl(fmt):
|
|||||||
|
|
||||||
|
|
||||||
def collect_instr_groups(isas):
|
def collect_instr_groups(isas):
|
||||||
seen = set()
|
# type: (Sequence[TargetISA]) -> List[InstructionGroup]
|
||||||
|
seen = set() # type: Set[InstructionGroup]
|
||||||
groups = []
|
groups = []
|
||||||
for isa in isas:
|
for isa in isas:
|
||||||
for g in isa.instruction_groups:
|
for g in isa.instruction_groups:
|
||||||
@@ -271,6 +275,7 @@ def collect_instr_groups(isas):
|
|||||||
|
|
||||||
|
|
||||||
def gen_opcodes(groups, fmt):
|
def gen_opcodes(groups, fmt):
|
||||||
|
# type: (Sequence[InstructionGroup], srcgen.Formatter) -> Sequence[Instruction] # noqa
|
||||||
"""
|
"""
|
||||||
Generate opcode enumerations.
|
Generate opcode enumerations.
|
||||||
|
|
||||||
@@ -389,6 +394,7 @@ def get_constraint(op, ctrl_typevar, type_sets):
|
|||||||
|
|
||||||
|
|
||||||
def gen_type_constraints(fmt, instrs):
|
def gen_type_constraints(fmt, instrs):
|
||||||
|
# type: (srcgen.Formatter, Sequence[Instruction]) -> None
|
||||||
"""
|
"""
|
||||||
Generate value type constraints for all instructions.
|
Generate value type constraints for all instructions.
|
||||||
|
|
||||||
@@ -487,6 +493,7 @@ def gen_type_constraints(fmt, instrs):
|
|||||||
|
|
||||||
|
|
||||||
def gen_format_constructor(iform, fmt):
|
def gen_format_constructor(iform, fmt):
|
||||||
|
# type: (InstructionFormat, srcgen.Formatter) -> None
|
||||||
"""
|
"""
|
||||||
Emit a method for creating and inserting inserting an `iform` instruction,
|
Emit a method for creating and inserting inserting an `iform` instruction,
|
||||||
where `iform` is an instruction format.
|
where `iform` is an instruction format.
|
||||||
@@ -543,6 +550,7 @@ def gen_format_constructor(iform, fmt):
|
|||||||
|
|
||||||
|
|
||||||
def gen_member_inits(iform, fmt):
|
def gen_member_inits(iform, fmt):
|
||||||
|
# type: (InstructionFormat, srcgen.Formatter) -> None
|
||||||
"""
|
"""
|
||||||
Emit member initializers for an `iform` instruction.
|
Emit member initializers for an `iform` instruction.
|
||||||
"""
|
"""
|
||||||
@@ -696,6 +704,7 @@ def gen_inst_builder(inst, fmt):
|
|||||||
|
|
||||||
|
|
||||||
def gen_builder(insts, fmt):
|
def gen_builder(insts, fmt):
|
||||||
|
# type: (Sequence[Instruction], srcgen.Formatter) -> None
|
||||||
"""
|
"""
|
||||||
Generate a Builder trait with methods for all instructions.
|
Generate a Builder trait with methods for all instructions.
|
||||||
"""
|
"""
|
||||||
@@ -723,6 +732,7 @@ def gen_builder(insts, fmt):
|
|||||||
|
|
||||||
|
|
||||||
def generate(isas, out_dir):
|
def generate(isas, out_dir):
|
||||||
|
# type: (Sequence[TargetISA], str) -> None
|
||||||
groups = collect_instr_groups(isas)
|
groups = collect_instr_groups(isas)
|
||||||
|
|
||||||
# opcodes.rs
|
# opcodes.rs
|
||||||
|
|||||||
Reference in New Issue
Block a user