Skip to content

Commit e21a373

Browse files
authored
Automates mem files linking (#100)
* Initial linker automation commit * Unit tests * Doxygen style * Removing pyLint filters
1 parent 5c9b3e6 commit e21a373

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+6409
-905
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ repos:
6161
*assembler_tools/hec-assembler-tools/debug_tools/main\.py|
6262
*assembler_tools/hec-assembler-tools/debug_tools/xinst_timing_check/|
6363
*assembler_tools/hec-assembler-tools/he_as\.py|
64-
*assembler_tools/hec-assembler-tools/linker/__init__\.py|
65-
*assembler_tools/hec-assembler-tools/linker/instructions/__init__\.py|
6664
*assembler_tools/hec-assembler-tools/assembler/spec_config/isa_spec.py)
6765
args: ["--follow-imports=skip", "--install-types", "--non-interactive"]
6866
- repo: local
@@ -81,8 +79,6 @@ repos:
8179
*assembler_tools/hec-assembler-tools/debug_tools/main\.py|
8280
*assembler_tools/hec-assembler-tools/debug_tools/xinst_timing_check/|
8381
*assembler_tools/hec-assembler-tools/he_as\.py|
84-
*assembler_tools/hec-assembler-tools/linker/__init__\.py|
85-
*assembler_tools/hec-assembler-tools/linker/instructions/__init__\.py|
8682
*assembler_tools/hec-assembler-tools/assembler/spec_config/isa_spec.py)
8783
args:
8884
- -rn # Only display messages

assembler_tools/hec-assembler-tools/assembler/common/config.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-

1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""A configuration class for controlling various aspects of the assembler's behavior."""
5+
6+
27
class GlobalConfig:
38
"""
49
A configuration class for controlling various aspects of the assembler's behavior.
510
611
Attributes:
7-
suppressComments (bool):
12+
suppress_comments (bool):
813
If True, no comments will be emitted in the output generated by the assembler.
9-
10-
useHBMPlaceHolders (bool):
11-
Specifies whether to use placeholders (names) for variable locations in HBM
14+
15+
useHBMPlaceHolders (bool):
16+
Specifies whether to use placeholders (names) for variable locations in HBM
1217
or the actual variable locations.
13-
14-
useXInstFetch (bool):
15-
Specifies whether `xinstfetch` instructions should be added into CInstQ or not.
16-
When no `xinstfetch` instructions are added, it is assumed that the HERACLES
18+
19+
useXInstFetch (bool):
20+
Specifies whether `xinstfetch` instructions should be added into CInstQ or not.
21+
When no `xinstfetch` instructions are added, it is assumed that the HERACLES
1722
automated mechanism for `xinstfetch` will be activated.
18-
19-
debugVerbose (int):
20-
If greater than 0, verbose prints will occur. Its value indicates how often to
21-
print within loops (every `debugVerbose` iterations). This is used for internal
23+
24+
debugVerbose (int):
25+
If greater than 0, verbose prints will occur. Its value indicates how often to
26+
print within loops (every `debugVerbose` iterations). This is used for internal
2227
debugging purposes.
2328
hashHBM (bool): Specifies whether the target architecture has HBM or not.
2429
"""
2530

26-
suppressComments = False
31+
suppress_comments = False
2732
useHBMPlaceHolders = True
2833
useXInstFetch = True
2934
debugVerbose: int = 0
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-

2-
class classproperty(object):
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""
5+
This module provides decorator utilities for the assembler.
6+
7+
It contains decorators that enhance class and function behavior,
8+
including property-like decorators for class methods.
9+
"""
10+
11+
12+
# pylint: disable=invalid-name
13+
class classproperty(property):
314
"""
415
A decorator that allows a method to be accessed as a class-level property
516
rather than on instances of the class.
617
"""
718

8-
def __init__(self, f):
9-
"""
10-
Initializes the classproperty with the given function.
11-
12-
Args:
13-
f (function): The function to be used as a class-level property.
14-
"""
15-
self.f = f
16-
17-
def __get__(self, obj, owner):
19+
def __get__(self, cls, owner):
1820
"""
1921
Retrieves the value of the class-level property.
2022
2123
Args:
22-
obj: The instance of the class (ignored in this context).
23-
owner: The class that owns the property.
24+
cls: The class that owns the property.
25+
owner: The owner of the class (ignored in this context).
2426
2527
Returns:
2628
The result of calling the decorated function with the class as an argument.
2729
"""
28-
return self.f(owner)
30+
return self.fget(owner)

assembler_tools/hec-assembler-tools/assembler/common/run_config.py

Lines changed: 58 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
14
import io
25

36
from .decorators import *
47
from . import constants
58
from .config import GlobalConfig
69

10+
711
class RunConfig:
812
"""
913
Configuration class for running the assembler with specific settings.
@@ -12,11 +16,21 @@ class RunConfig:
1216
policies, and other options that affect the behavior of the assembler.
1317
"""
1418

15-
__initialized = False # Specifies whether static members have been initialized
16-
__default_config = {} # Dictionary of all configuration items supported and their default values
17-
18-
def __init__(self,
19-
**kwargs):
19+
# Type annotations for class attributes
20+
has_hbm: bool
21+
hbm_size: int
22+
spad_size: int
23+
repl_policy: str
24+
suppress_comments: bool
25+
use_xinstfetch: bool
26+
debug_verbose: int
27+
28+
__initialized = False # Specifies whether static members have been initialized
29+
__default_config = (
30+
{}
31+
) # Dictionary of all configuration items supported and their default values
32+
33+
def __init__(self, **kwargs):
2034
"""
2135
Constructs a new RunConfig object from input parameters.
2236
@@ -33,7 +47,7 @@ def __init__(self,
3347
3448
suppress_comments (bool, optional):
3549
If true, no comments will be emitted in the output generated by the assembler.
36-
Defaults to GlobalConfig.suppressComments (`False`).
50+
Defaults to GlobalConfig.suppress_comments (`False`).
3751
3852
use_hbm_placeholders (bool, optional):
3953
[DEPRECATED]/[UNUSED] Specifies whether to use placeholders (names) for variable locations in HBM (`True`)
@@ -52,45 +66,66 @@ def __init__(self,
5266
ValueError: If at least one of the arguments passed is invalid.
5367
"""
5468

69+
RunConfig.init_default_config()
70+
5571
# Initialize class members
5672
for config_name, default_value in self.__default_config.items():
57-
setattr(self, config_name, kwargs.get(config_name, default_value))
73+
value = kwargs.get(config_name)
74+
if value is not None:
75+
setattr(self, config_name, value)
76+
else:
77+
setattr(self, config_name, default_value)
5878

5979
# Validate inputs
6080
if self.repl_policy not in constants.Constants.REPLACEMENT_POLICIES:
61-
raise ValueError('Invalid `repl_policy`. "{}" not in {}'.format(self.repl_policy,
62-
constants.Constants.REPLACEMENT_POLICIES))
81+
raise ValueError(
82+
'Invalid `repl_policy`. "{}" not in {}'.format(
83+
self.repl_policy, constants.Constants.REPLACEMENT_POLICIES
84+
)
85+
)
86+
6387
@classproperty
6488
def DEFAULT_HBM_SIZE_KB(cls) -> int:
65-
return int(constants.MemoryModel.HBM.MAX_CAPACITY / constants.Constants.KILOBYTE)
89+
return int(
90+
constants.MemoryModel.HBM.MAX_CAPACITY / constants.Constants.KILOBYTE
91+
)
6692

6793
@classproperty
6894
def DEFAULT_SPAD_SIZE_KB(cls) -> int:
69-
return int(constants.MemoryModel.SPAD.MAX_CAPACITY / constants.Constants.KILOBYTE)
95+
return int(
96+
constants.MemoryModel.SPAD.MAX_CAPACITY / constants.Constants.KILOBYTE
97+
)
7098

7199
@classproperty
72100
def DEFAULT_REPL_POLICY(cls) -> int:
73101
return constants.Constants.REPLACEMENT_POLICY_FTBU
74102

75103
@classmethod
76-
def init_static(cls):
104+
def init_default_config(cls):
77105
"""
78106
Initializes static members of the RunConfig class.
79107
80108
This method sets up default configuration values for the class, ensuring
81109
that they are only initialized once.
82110
"""
83111
if not cls.__initialized:
84-
cls.__default_config["hbm_size"] = cls.DEFAULT_HBM_SIZE_KB
85-
cls.__default_config["spad_size"] = cls.DEFAULT_SPAD_SIZE_KB
86-
cls.__default_config["repl_policy"] = cls.DEFAULT_REPL_POLICY
87-
cls.__default_config["suppress_comments"] = GlobalConfig.suppressComments
88-
#cls.__default_config["use_hbm_placeholders"] = GlobalConfig.useHBMPlaceHolders
89-
cls.__default_config["use_xinstfetch"] = GlobalConfig.useXInstFetch
90-
cls.__default_config["debug_verbose"] = GlobalConfig.debugVerbose
112+
cls.__default_config["has_hbm"] = True
113+
cls.__default_config["hbm_size"] = cls.DEFAULT_HBM_SIZE_KB
114+
cls.__default_config["spad_size"] = cls.DEFAULT_SPAD_SIZE_KB
115+
cls.__default_config["repl_policy"] = cls.DEFAULT_REPL_POLICY
116+
cls.__default_config["suppress_comments"] = GlobalConfig.suppress_comments
117+
# cls.__default_config["use_hbm_placeholders"] = GlobalConfig.useHBMPlaceHolders
118+
cls.__default_config["use_xinstfetch"] = GlobalConfig.useXInstFetch
119+
cls.__default_config["debug_verbose"] = GlobalConfig.debugVerbose
91120

92121
cls.__initialized = True
93122

123+
# For testing only
124+
@classmethod
125+
def reset_class_state(cls):
126+
cls.__initialized = False
127+
cls.__default_config = {}
128+
94129
def __str__(self):
95130
"""
96131
Returns a string representation of the configuration.
@@ -113,4 +148,7 @@ def as_dict(self) -> dict:
113148
dict: A dictionary representation of the current configuration settings.
114149
"""
115150
tmp_self_dict = vars(self)
116-
return { config_name: tmp_self_dict[config_name] for config_name in self.__default_config }
151+
return {
152+
config_name: tmp_self_dict[config_name]
153+
for config_name in self.__default_config
154+
}

assembler_tools/hec-assembler-tools/assembler/instructions/instruction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def to_string_format(self, preamble, op_name: str, *extra_args) -> str:
552552
retval = f'{", ".join(str(x) for x in preamble)}, {retval}'
553553
if extra_args:
554554
retval += f', {", ".join([str(extra) for extra in extra_args])}'
555-
if not GlobalConfig.suppressComments:
555+
if not GlobalConfig.suppress_comments:
556556
if self.comment:
557557
retval += f" #{self.comment}"
558558
return retval

0 commit comments

Comments
 (0)