Skip to content

Commit dee868d

Browse files
authored
[hec-assembler]: Complete format fixes on the Linker (#105)
Fix pylint/mypy on linker instructions Add Copyright/License header Change docstring style to Doxygen
1 parent 4734fa0 commit dee868d

38 files changed

+766
-717
lines changed
Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1-

2-
from . import bload, bones, cexit, cload, cnop, cstore, csyncm, ifetch, kgload, kgseed, kgstart, nload, xinstfetch
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
33

4-
# MInst aliases
4+
"""@brief This module provides all the supported C-instructions for the linker toolchain."""
55

6+
from . import (
7+
# Import all instruction modules
8+
bload,
9+
bones,
10+
cexit,
11+
cload,
12+
cnop,
13+
cstore,
14+
csyncm,
15+
ifetch,
16+
kgload,
17+
kgseed,
18+
kgstart,
19+
nload,
20+
xinstfetch,
21+
)
22+
23+
# CInst aliases
624
BLoad = bload.Instruction
725
BOnes = bones.Instruction
826
CExit = cexit.Instruction
@@ -17,24 +35,25 @@
1735
NLoad = nload.Instruction
1836
XInstFetch = xinstfetch.Instruction
1937

38+
2039
def factory() -> set:
2140
"""
22-
Creates a set of all instruction classes.
41+
@brief Creates a set of all instruction classes.
2342
24-
Returns:
25-
set: A set containing all instruction classes.
43+
@return A set containing all instruction classes.
2644
"""
27-
28-
return { BLoad,
29-
BOnes,
30-
CExit,
31-
CLoad,
32-
CNop,
33-
CStore,
34-
CSyncm,
35-
IFetch,
36-
KGLoad,
37-
KGSeed,
38-
KGStart,
39-
NLoad,
40-
XInstFetch }
45+
return {
46+
BLoad,
47+
BOnes,
48+
CExit,
49+
CLoad,
50+
CNop,
51+
CStore,
52+
CSyncm,
53+
IFetch,
54+
KGLoad,
55+
KGSeed,
56+
KGStart,
57+
NLoad,
58+
XInstFetch,
59+
}

assembler_tools/hec-assembler-tools/linker/instructions/cinst/bload.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
from .cinstruction import CInstruction
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""@brief This module implements the bload C-instruction which loads from the SPAD to the register files."""
5+
6+
from .cinstruction import CInstruction
7+
28

39
class Instruction(CInstruction):
410
"""
5-
Encapsulates the `bload` CInstruction.
11+
@brief Encapsulates a `bload` CInstruction.
612
713
The `bload` instruction loads metadata from the scratchpad to special registers in the register file.
8-
14+
915
For more information, check the `bload` Specification:
1016
https://github.com/IntelLabs/hec-assembler-tools/blob/master/docsrc/inst_spec/cinst/cinst_bload.md
1117
"""
1218

1319
@classmethod
14-
def _get_num_tokens(cls)->int:
20+
def _get_num_tokens(cls) -> int:
1521
"""
16-
Gets the number of tokens required for the instruction.
22+
@brief Gets the number of tokens required for the instruction.
1723
1824
The `bload` instruction requires 5 tokens:
1925
<line: uint>, bload, <meta_target_idx: uint>, <spad_src: uint>, <src_col_num: uint>
2026
21-
Returns:
22-
int: The number of tokens, which is 5.
27+
@return The number of tokens, which is 5.
2328
"""
2429
# 5 tokens:
2530
# <line: uint>, bload, <meta_target_idx: uint>, <spad_src: uint>, <src_col_num: uint>
@@ -30,31 +35,26 @@ def _get_num_tokens(cls)->int:
3035
@classmethod
3136
def _get_name(cls) -> str:
3237
"""
33-
Gets the name of the instruction.
38+
@brief Gets the name of the instruction.
3439
35-
Returns:
36-
str: The name of the instruction, which is "bload".
40+
@return The name of the instruction, which is "bload".
3741
"""
3842
return "bload"
3943

4044
def __init__(self, tokens: list, comment: str = ""):
4145
"""
42-
Constructs a new `bload` CInstruction.
43-
44-
Args:
45-
tokens (list): A list of tokens representing the instruction.
46-
comment (str, optional): An optional comment for the instruction. Defaults to an empty string.
46+
@brief Constructs a new `bload` CInstruction.
4747
48-
Raises:
49-
ValueError: If the number of tokens is invalid or the instruction name is incorrect.
48+
@param tokens A list of tokens representing the instruction.
49+
@param comment An optional comment for the instruction.
50+
@throws ValueError If the number of tokens is invalid or the instruction name is incorrect.
5051
"""
5152
super().__init__(tokens, comment=comment)
5253

53-
5454
@property
5555
def source(self) -> str:
5656
"""
57-
Name of the source.
57+
@brief Name of the source.
5858
This is a Variable name when loaded. Should be set to HBM address to write back.
5959
"""
6060
return self.tokens[3]

assembler_tools/hec-assembler-tools/linker/instructions/cinst/bones.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
from .cinstruction import CInstruction
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""@brief This module implements the bones C-instruction which loads a ones buffer from SPAD to registers."""
5+
6+
from .cinstruction import CInstruction
7+
28

39
class Instruction(CInstruction):
410
"""
5-
Encapsulates a `bones` CInstruction.
6-
11+
@brief Encapsulates a `bones` CInstruction.
12+
713
The `bones` instruction loads metadata of identity (one) from the scratchpad to the register file.
8-
14+
915
For more information, check the `bones` Specification:
1016
https://github.com/IntelLabs/hec-assembler-tools/blob/master/docsrc/inst_spec/cinst/cinst_bones.md
1117
"""
1218

1319
@classmethod
14-
def _get_num_tokens(cls)->int:
20+
def _get_num_tokens(cls) -> int:
1521
"""
16-
Gets the number of tokens required for the instruction.
22+
@brief Gets the number of tokens required for the instruction.
1723
1824
The `bones` instruction requires 4 tokens:
1925
<line: uint>, bones, <spad_src: uint>, <col_num: uint>
2026
21-
Returns:
22-
int: The number of tokens, which is 4.
27+
@return The number of tokens, which is 4.
2328
"""
2429
# 4 tokens:
2530
# <line: uint>, bones, <spad_src: uint>, <col_num: uint>
@@ -30,30 +35,26 @@ def _get_num_tokens(cls)->int:
3035
@classmethod
3136
def _get_name(cls) -> str:
3237
"""
33-
Gets the name of the instruction.
38+
@brief Gets the name of the instruction.
3439
35-
Returns:
36-
str: The name of the instruction, which is "bones".
40+
@return The name of the instruction, which is "bones".
3741
"""
3842
return "bones"
3943

4044
def __init__(self, tokens: list, comment: str = ""):
4145
"""
42-
Constructs a new `bones` CInstruction.
43-
44-
Args:
45-
tokens (list): A list of tokens representing the instruction.
46-
comment (str, optional): An optional comment for the instruction. Defaults to an empty string.
46+
@brief Constructs a new `bones` CInstruction.
4747
48-
Raises:
49-
ValueError: If the number of tokens is invalid or the instruction name is incorrect.
48+
@param tokens A list of tokens representing the instruction.
49+
@param comment An optional comment for the instruction.
50+
@throws ValueError If the number of tokens is invalid or the instruction name is incorrect.
5051
"""
5152
super().__init__(tokens, comment=comment)
5253

5354
@property
5455
def source(self) -> str:
5556
"""
56-
Name of the source.
57+
@brief Name of the source.
5758
This is a Variable name when loaded. Should be set to HBM address to write back.
5859
"""
5960
return self.tokens[2]
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
from .cinstruction import CInstruction
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""@brief This module implements the cexit C-instruction which terminates the control flow execution."""
5+
6+
from .cinstruction import CInstruction
7+
28

39
class Instruction(CInstruction):
410
"""
5-
Encapsulates a `cexit` CInstruction.
6-
11+
@brief Encapsulates a `cexit` CInstruction.
12+
713
This instruction terminates execution of a HERACLES program.
814
915
For more information, check the `cexit` Specification:
@@ -13,35 +19,30 @@ class Instruction(CInstruction):
1319
@classmethod
1420
def _get_num_tokens(cls) -> int:
1521
"""
16-
Gets the number of tokens required for the instruction.
22+
@brief Gets the number of tokens required for the instruction.
1723
1824
The `cexit` instruction requires 2 tokens:
1925
<line: uint>, cexit
2026
21-
Returns:
22-
int: The number of tokens, which is 2.
27+
@return The number of tokens, which is 2.
2328
"""
2429
return 2
2530

2631
@classmethod
2732
def _get_name(cls) -> str:
2833
"""
29-
Gets the name of the instruction.
34+
@brief Gets the name of the instruction.
3035
31-
Returns:
32-
str: The name of the instruction, which is "cexit".
36+
@return The name of the instruction, which is "cexit".
3337
"""
3438
return "cexit"
3539

3640
def __init__(self, tokens: list, comment: str = ""):
3741
"""
38-
Constructs a new `cexit` CInstruction.
39-
40-
Args:
41-
tokens (list): A list of tokens representing the instruction.
42-
comment (str, optional): An optional comment for the instruction. Defaults to an empty string.
42+
@brief Constructs a new `cexit` CInstruction.
4343
44-
Raises:
45-
ValueError: If the number of tokens is invalid or the instruction name is incorrect.
44+
@param tokens A list of tokens representing the instruction.
45+
@param comment An optional comment for the instruction.
46+
@throws ValueError If the number of tokens is invalid or the instruction name is incorrect.
4647
"""
47-
super().__init__(tokens, comment=comment)
48+
super().__init__(tokens, comment=comment)

assembler_tools/hec-assembler-tools/linker/instructions/cinst/cinstruction.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
# Copyright (C) 2025 Intel Corporation
22
# SPDX-License-Identifier: Apache-2.0
33

4-
"""This module implements the base class for CInstructions."""
4+
"""@brief This module implements the base class for all C-instructions."""
55

66
from linker.instructions.instruction import BaseInstruction
77

88

99
class CInstruction(BaseInstruction):
1010
"""
11-
Represents a CInstruction, inheriting from BaseInstruction.
11+
@brief Represents a CInstruction, inheriting from BaseInstruction.
1212
"""
1313

1414
@classmethod
1515
def _get_name(cls) -> str:
1616
"""
17-
Derived classes should implement this method and return correct
18-
name for the instruction.
17+
@brief Returns the name of the instruction.
1918
20-
Raises:
21-
NotImplementedError: Abstract method. This base method should not be called.
19+
@return The instruction name.
20+
@throws NotImplementedError Abstract method. This base method should not be called.
2221
"""
2322
raise NotImplementedError()
2423

2524
@classmethod
2625
def _get_name_token_index(cls) -> int:
2726
"""
28-
Gets the index of the token containing the name of the instruction.
27+
@brief Gets the index of the token containing the name of the instruction.
2928
30-
Returns:
31-
int: The index of the name token, which is 1.
29+
@return The index of the name token.
3230
"""
3331
return 1
3432

3533
@classmethod
3634
def _get_num_tokens(cls) -> int:
3735
"""
38-
Derived classes should implement this method and return correct
39-
required number of tokens for the instruction.
36+
@brief Returns the required number of tokens for the instruction.
4037
41-
Raises:
42-
NotImplementedError: Abstract method. This base method should not be called.
38+
@return The number of required tokens.
39+
@throws NotImplementedError Abstract method. This base method should not be called.
4340
"""
4441
raise NotImplementedError()
4542

@@ -48,14 +45,11 @@ def _get_num_tokens(cls) -> int:
4845

4946
def __init__(self, tokens: list, comment: str = ""):
5047
"""
51-
Constructs a new CInstruction.
52-
53-
Parameters:
54-
tokens (list): List of tokens for the instruction.
55-
comment (str): Optional comment for the instruction.
48+
@brief Constructs a new CInstruction.
5649
57-
Raises:
58-
ValueError: If the number of tokens is invalid or the instruction name is incorrect.
50+
@param tokens List of tokens for the instruction.
51+
@param comment Optional comment for the instruction.
52+
@throws ValueError If the number of tokens is invalid or the instruction name is incorrect.
5953
"""
6054
super().__init__(tokens, comment=comment)
6155

0 commit comments

Comments
 (0)