Skip to content

Commit e71a051

Browse files
committed
Synchronize public and private repositories
Signed-off-by: Ramon Bertran Monfort <rbertra@us.ibm.com>
2 parents 3b90053 + 38d0e25 commit e71a051

File tree

25 files changed

+140
-59
lines changed

25 files changed

+140
-59
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ jobs:
7777
- set -e
7878
- . ./dev_tools/ci/travis_prolog
7979
- ./dev_tools/ci/code_conventions_003_documentation.sh
80+
- stage: tests
81+
name: mypy
82+
script:
83+
- set -e
84+
- . ./dev_tools/ci/travis_prolog
85+
- ./dev_tools/ci/code_conventions_004_mypy.sh
8086
- stage: tests
8187
name: tools RISCV
8288
script:

dev_tools/ci/check_ci.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ shellcheck -x -s sh ./*.sh dev_tools/*/*.sh ./targets/*/dev_tools/*/*.sh
2323
./dev_tools/ci/code_conventions_001_pycodestyle.sh
2424
./dev_tools/ci/code_conventions_002_pylint.sh
2525
./dev_tools/ci/code_conventions_003_documentation.sh
26+
./dev_tools/ci/code_conventions_004_mypy.sh
2627
# Fast Functional Tests (run for branches and PR)
2728
./dev_tools/ci/test_001_end2end_tools.sh
2829
./dev_tools/ci/test_002_end2end_examples.sh
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env sh
2+
# Copyright 2011-2021 IBM Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Microprobe CI support scripts
17+
#
18+
19+
set -e # Finish right after a non-zero return command
20+
21+
if [ "$WORKSPACE" = "" ]; then
22+
WORKSPACE=$(pwd)
23+
export WORKSPACE
24+
fi
25+
26+
# shellcheck source=dev_tools/ci/environment.sh
27+
. "$WORKSPACE/dev_tools/ci/environment.sh"
28+
start_script "$0"
29+
30+
echo "Running mypy version:"
31+
python "$(command -v mypy)" --version
32+
33+
set +e
34+
# shellcheck disable=SC2046
35+
$NICE python "$(command -v mypy)" src/microprobe/code src/microprobe/target --ignore-missing-imports --install-types --non-interactive > "mypy$PYTHON_VERSION.out"
36+
error=$?
37+
set -e
38+
39+
echo "Return code: $error"
40+
41+
error=$(echo "obase=2;$error" | bc | /usr/bin/tail -c 3)
42+
if [ "$error" != "0" ]; then
43+
echo "Errors found, check mypy$PYTHON_VERSION.out file and fix them"
44+
exit_error "$0" "mypy$PYTHON_VERSION.out"
45+
fi
46+
47+
# TODO: check other error codes to be more strict
48+
echo "No errors found!"
49+
exit_success "$0"
50+
51+
# vim: set tabstop=4 softtabstop=4 shiftwidth=4 expandtab

src/microprobe/code/bbl.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def __init__(self, size: int, instructions: List[Instruction] = []):
8282

8383
self._instdic = {}
8484

85-
self._address = None
86-
self._displacement = 0
85+
self._address: Address | None = None
86+
self._displacement: int | None = 0
8787

8888
if MICROPROBE_RC["verbose"]:
8989
progress = Progress(size, "Initializing BBL:")
@@ -104,7 +104,12 @@ def __init__(self, size: int, instructions: List[Instruction] = []):
104104
self._instrs[self._pointer] = instructions[idx]
105105
else:
106106
self._instrs[self._pointer] = Instruction()
107-
self._instdic[self._instrs[self._pointer]] = self._pointer
107+
108+
# Type hinting needs some help here :)
109+
instr_index: Instruction | None = self._instrs[self._pointer]
110+
assert instr_index is not None
111+
112+
self._instdic[instr_index] = self._pointer
108113
self._pointer += 10
109114
if MICROPROBE_RC["verbose"]:
110115
progress()
@@ -153,7 +158,7 @@ def size(self):
153158
"""Size of the basic block, number of instructions (::class:`~.int`)"""
154159
return len(self.instrs)
155160

156-
def _index(self, instr: Instruction):
161+
def _index(self, instr: Instruction | None):
157162
"""Returns the index of the given instruction within the basic block.
158163
159164
Returns the index of the given instruction within the basic block.
@@ -163,7 +168,10 @@ def _index(self, instr: Instruction):
163168
:type instr: :class:`~.Instruction`
164169
165170
"""
166-
return self._instdic.get(instr, -1)
171+
if instr is None:
172+
return -1
173+
else:
174+
return self._instdic.get(instr, -1)
167175

168176
def get_instruction_index(self, instr: Instruction):
169177
"""Returns the index of the given instruction within the basic block.

src/microprobe/code/context.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self,
7979
self._symbolic = symbolic
8080
self._fabsolute = absolute
8181

82-
self._dat = None
82+
self._dat: DynamicAddressTranslation | None = None
8383

8484
if default_context is not None:
8585
self = default_context.copy()
@@ -167,7 +167,7 @@ def set_register_value(self, register: Register,
167167
# assert value in self._value_registers.keys()
168168
# assert self._register_values[register] == value
169169

170-
def get_closest_value(self, value: int | float | Address | str):
170+
def get_closest_value(self, value):
171171
"""Returns the closest value to the given value.
172172
173173
Returns the closest value to the given value. If there are
@@ -179,7 +179,7 @@ def get_closest_value(self, value: int | float | Address | str):
179179
180180
"""
181181

182-
possible_regs: List[Tuple[Register, int | float | Address | str]] = []
182+
possible_regs = []
183183

184184
for reg, val in self._register_values.items():
185185

@@ -224,7 +224,7 @@ def get_closest_address_value(self, address: Address):
224224

225225
return None
226226

227-
def get_register_closest_value(self, value: int | float | str):
227+
def get_register_closest_value(self, value):
228228
"""Returns the register with the closest value to the given value.
229229
230230
Returns the register with the closest value to the given value.
@@ -237,7 +237,7 @@ def get_register_closest_value(self, value: int | float | str):
237237
238238
"""
239239

240-
possible_regs: List[Tuple[Register, int | float | str]] = []
240+
possible_regs = []
241241

242242
for reg, reg_value in self._register_values.items():
243243

@@ -248,6 +248,8 @@ def get_register_closest_value(self, value: int | float | str):
248248
continue
249249

250250
if isinstance(reg_value, str):
251+
# Type hinting needs some help with this one :)
252+
assert isinstance(value, str)
251253
if reg_value.split("_")[1] != value.split(" ")[1]:
252254
continue
253255

@@ -310,7 +312,7 @@ def unset_registers(self, registers: List[Register]):
310312
for reg in registers:
311313
self.unset_register(reg)
312314

313-
def unset_register(self, register: Register):
315+
def unset_register(self, register):
314316
"""Remove the value from a register.
315317
316318
:param register: Registers

src/microprobe/code/ins.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# Built-in modules
2222
import copy
2323
from itertools import product
24-
from typing import TYPE_CHECKING, Callable
24+
from typing import TYPE_CHECKING, Callable, List
2525

2626
# Third party modules
2727
import six
@@ -114,11 +114,11 @@ def instruction_from_definition(definition: MicroprobeInstructionDefinition,
114114

115115

116116
def instruction_set_def_properties(instr,
117-
definition: MicroprobeInstructionDefinition,
117+
definition,
118118
building_block=None,
119-
target: Target | None = None,
119+
target=None,
120120
allowed_registers=None,
121-
fix_relative: bool = True,
121+
fix_relative=True,
122122
label_displ=None):
123123
"""
124124
Set instruction properties from an intruction definition.
@@ -168,7 +168,7 @@ def instruction_set_def_properties(instr,
168168
LOG.debug("Operands, not fixed: %s", operands)
169169
if len(operands) > 0:
170170

171-
fixed_operands = []
171+
fixed_operands: List[Address | InstructionAddress] = []
172172
relocation_mode = False
173173
LOG.debug("Fixed operands: %s", fixed_operands)
174174

@@ -298,13 +298,14 @@ def instruction_set_def_properties(instr,
298298
instr.add_decorator(decorator_key, decorator_value)
299299

300300
for register_name in allowed_registers:
301-
if register_name not in list(target.registers.keys()):
301+
assert target is not None
302+
if register_name not in list(target.isa.registers.keys()):
302303
raise MicroprobeCodeGenerationError(
303304
"Unknown register '%s'. Known registers: %s" %
304-
(register_name, list(target.registers.keys())))
305+
(register_name, list(target.isa.registers.keys())))
305306

306-
if target.registers[register_name] in instr.sets() + instr.uses():
307-
instr.add_allow_register(target.registers[register_name])
307+
if target.isa.registers[register_name] in instr.sets() + instr.uses():
308+
instr.add_allow_register(target.isa.registers[register_name])
308309

309310
# TODO : NO NEED TO CHECK ANYTHING JUST REPRODUCING!
310311
# reserve implicit operands (if they are not already
@@ -373,7 +374,7 @@ def __init__(self, operand_descriptor: OperandDescriptor):
373374
self._operand_descriptor = operand_descriptor
374375
self._value = None
375376
self._set_function = None
376-
self._unset_function = None
377+
self._unset_function: Callable[[], None] | None = None
377378

378379
@property
379380
def value(self):
@@ -613,7 +614,7 @@ def _compute_length(self):
613614

614615
return length
615616

616-
def _compute_possible_lengths(self, context: Context):
617+
def _compute_possible_lengths(self, context):
617618
"""Compute the possible lengths that can be generated.
618619
619620
Compute the possible lengths that can be generated from the context
@@ -1596,7 +1597,7 @@ def __init__(self):
15961597
self._mem_operands = []
15971598
self._operands = RejectingOrderedDict()
15981599

1599-
def set_arch_type(self, instrtype: InstructionType):
1600+
def set_arch_type(self, instrtype):
16001601
"""
16011602
16021603
:param instrtype:
@@ -1956,7 +1957,7 @@ def allowed_regs(self):
19561957
"""List of allowed registers of the instructon. """
19571958
return self._allowed_regs
19581959

1959-
def set_label(self, label: str):
1960+
def set_label(self, label: str | None):
19601961
"""
19611962
19621963
:param label:

src/microprobe/driver/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
1616
"""
1717

18+
from typing import List
19+
1820
# Constants
19-
__all__ = []
21+
__all__: List[str] = []
2022

2123
# Functions
2224

src/microprobe/driver/guided.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
1616
"""
1717

18+
from typing import List
19+
1820
# Constants
19-
__all__ = []
21+
__all__: List[str] = []
2022

2123
# Functions
2224

src/microprobe/schemas/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
<your module documentation here>.
1717
"""
1818

19+
from typing import List
1920

2021
# Constants
21-
__all__ = []
22+
__all__: List[str] = []
2223

2324
# Functions
2425

src/microprobe/target/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def import_definition(definition_tuple: str
9696
if isinstance(definition_tuple, str):
9797
definition_tuple = _parse_definition_tuple(definition_tuple)
9898

99+
# Type hinting needs some help here :)
100+
assert not isinstance(definition_tuple, str)
101+
99102
isa_def, uarch_def, env_def = definition_tuple
100103
isa = import_isa_definition(os.path.dirname(isa_def.filename))
101104
env = import_env_definition(env_def.filename,
@@ -349,10 +352,10 @@ def __init__(self,
349352
:return: Target instance
350353
:rtype: :class:`~.Target`
351354
"""
352-
self._uarch = None
353-
self._env = None
355+
self._uarch: Microarchitecture | None = None
356+
self._env: Environment | None = None
354357
self._policies = None
355-
self._wrapper = None
358+
self._wrapper: Wrapper | None = None
356359

357360
self.set_isa(isa)
358361

0 commit comments

Comments
 (0)