Skip to content
Merged
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ repos:
*assembler_tools/hec-assembler-tools/debug_tools/main\.py|
*assembler_tools/hec-assembler-tools/debug_tools/xinst_timing_check/|
*assembler_tools/hec-assembler-tools/he_as\.py|
*assembler_tools/hec-assembler-tools/linker/__init__\.py|
*assembler_tools/hec-assembler-tools/linker/instructions/__init__\.py|
*assembler_tools/hec-assembler-tools/assembler/spec_config/isa_spec.py)
args: ["--follow-imports=skip", "--install-types", "--non-interactive"]
- repo: local
Expand All @@ -81,8 +79,6 @@ repos:
*assembler_tools/hec-assembler-tools/debug_tools/main\.py|
*assembler_tools/hec-assembler-tools/debug_tools/xinst_timing_check/|
*assembler_tools/hec-assembler-tools/he_as\.py|
*assembler_tools/hec-assembler-tools/linker/__init__\.py|
*assembler_tools/hec-assembler-tools/linker/instructions/__init__\.py|
*assembler_tools/hec-assembler-tools/assembler/spec_config/isa_spec.py)
args:
- -rn # Only display messages
Expand Down
33 changes: 19 additions & 14 deletions assembler_tools/hec-assembler-tools/assembler/common/config.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@

# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""A configuration class for controlling various aspects of the assembler's behavior."""


class GlobalConfig:
"""
A configuration class for controlling various aspects of the assembler's behavior.

Attributes:
suppressComments (bool):
suppress_comments (bool):
If True, no comments will be emitted in the output generated by the assembler.
useHBMPlaceHolders (bool):
Specifies whether to use placeholders (names) for variable locations in HBM

useHBMPlaceHolders (bool):
Specifies whether to use placeholders (names) for variable locations in HBM
or the actual variable locations.
useXInstFetch (bool):
Specifies whether `xinstfetch` instructions should be added into CInstQ or not.
When no `xinstfetch` instructions are added, it is assumed that the HERACLES

useXInstFetch (bool):
Specifies whether `xinstfetch` instructions should be added into CInstQ or not.
When no `xinstfetch` instructions are added, it is assumed that the HERACLES
automated mechanism for `xinstfetch` will be activated.
debugVerbose (int):
If greater than 0, verbose prints will occur. Its value indicates how often to
print within loops (every `debugVerbose` iterations). This is used for internal

debugVerbose (int):
If greater than 0, verbose prints will occur. Its value indicates how often to
print within loops (every `debugVerbose` iterations). This is used for internal
debugging purposes.
hashHBM (bool): Specifies whether the target architecture has HBM or not.
"""

suppressComments = False
suppress_comments = False
useHBMPlaceHolders = True
useXInstFetch = True
debugVerbose: int = 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@

class classproperty(object):
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""
This module provides decorator utilities for the assembler.

It contains decorators that enhance class and function behavior,
including property-like decorators for class methods.
"""


# pylint: disable=invalid-name
class classproperty(property):
"""
A decorator that allows a method to be accessed as a class-level property
rather than on instances of the class.
"""

def __init__(self, f):
"""
Initializes the classproperty with the given function.

Args:
f (function): The function to be used as a class-level property.
"""
self.f = f

def __get__(self, obj, owner):
def __get__(self, cls, owner):
"""
Retrieves the value of the class-level property.

Args:
obj: The instance of the class (ignored in this context).
owner: The class that owns the property.
cls: The class that owns the property.
owner: The owner of the class (ignored in this context).

Returns:
The result of calling the decorated function with the class as an argument.
"""
return self.f(owner)
return self.fget(owner)
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import io

from .decorators import *
from . import constants
from .config import GlobalConfig


class RunConfig:
"""
Configuration class for running the assembler with specific settings.
Expand All @@ -12,11 +16,21 @@ class RunConfig:
policies, and other options that affect the behavior of the assembler.
"""

__initialized = False # Specifies whether static members have been initialized
__default_config = {} # Dictionary of all configuration items supported and their default values

def __init__(self,
**kwargs):
# Type annotations for class attributes
has_hbm: bool
hbm_size: int
spad_size: int
repl_policy: str
suppress_comments: bool
use_xinstfetch: bool
debug_verbose: int

__initialized = False # Specifies whether static members have been initialized
__default_config = (
{}
) # Dictionary of all configuration items supported and their default values

def __init__(self, **kwargs):
"""
Constructs a new RunConfig object from input parameters.

Expand All @@ -33,7 +47,7 @@ def __init__(self,

suppress_comments (bool, optional):
If true, no comments will be emitted in the output generated by the assembler.
Defaults to GlobalConfig.suppressComments (`False`).
Defaults to GlobalConfig.suppress_comments (`False`).

use_hbm_placeholders (bool, optional):
[DEPRECATED]/[UNUSED] Specifies whether to use placeholders (names) for variable locations in HBM (`True`)
Expand All @@ -52,45 +66,66 @@ def __init__(self,
ValueError: If at least one of the arguments passed is invalid.
"""

RunConfig.init_default_config()

# Initialize class members
for config_name, default_value in self.__default_config.items():
setattr(self, config_name, kwargs.get(config_name, default_value))
value = kwargs.get(config_name)
if value is not None:
setattr(self, config_name, value)
else:
setattr(self, config_name, default_value)

# Validate inputs
if self.repl_policy not in constants.Constants.REPLACEMENT_POLICIES:
raise ValueError('Invalid `repl_policy`. "{}" not in {}'.format(self.repl_policy,
constants.Constants.REPLACEMENT_POLICIES))
raise ValueError(
'Invalid `repl_policy`. "{}" not in {}'.format(
self.repl_policy, constants.Constants.REPLACEMENT_POLICIES
)
)

@classproperty
def DEFAULT_HBM_SIZE_KB(cls) -> int:
return int(constants.MemoryModel.HBM.MAX_CAPACITY / constants.Constants.KILOBYTE)
return int(
constants.MemoryModel.HBM.MAX_CAPACITY / constants.Constants.KILOBYTE
)

@classproperty
def DEFAULT_SPAD_SIZE_KB(cls) -> int:
return int(constants.MemoryModel.SPAD.MAX_CAPACITY / constants.Constants.KILOBYTE)
return int(
constants.MemoryModel.SPAD.MAX_CAPACITY / constants.Constants.KILOBYTE
)

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

@classmethod
def init_static(cls):
def init_default_config(cls):
"""
Initializes static members of the RunConfig class.

This method sets up default configuration values for the class, ensuring
that they are only initialized once.
"""
if not cls.__initialized:
cls.__default_config["hbm_size"] = cls.DEFAULT_HBM_SIZE_KB
cls.__default_config["spad_size"] = cls.DEFAULT_SPAD_SIZE_KB
cls.__default_config["repl_policy"] = cls.DEFAULT_REPL_POLICY
cls.__default_config["suppress_comments"] = GlobalConfig.suppressComments
#cls.__default_config["use_hbm_placeholders"] = GlobalConfig.useHBMPlaceHolders
cls.__default_config["use_xinstfetch"] = GlobalConfig.useXInstFetch
cls.__default_config["debug_verbose"] = GlobalConfig.debugVerbose
cls.__default_config["has_hbm"] = True
cls.__default_config["hbm_size"] = cls.DEFAULT_HBM_SIZE_KB
cls.__default_config["spad_size"] = cls.DEFAULT_SPAD_SIZE_KB
cls.__default_config["repl_policy"] = cls.DEFAULT_REPL_POLICY
cls.__default_config["suppress_comments"] = GlobalConfig.suppress_comments
# cls.__default_config["use_hbm_placeholders"] = GlobalConfig.useHBMPlaceHolders
cls.__default_config["use_xinstfetch"] = GlobalConfig.useXInstFetch
cls.__default_config["debug_verbose"] = GlobalConfig.debugVerbose

cls.__initialized = True

# For testing only
@classmethod
def reset_class_state(cls):
cls.__initialized = False
cls.__default_config = {}

def __str__(self):
"""
Returns a string representation of the configuration.
Expand All @@ -113,4 +148,7 @@ def as_dict(self) -> dict:
dict: A dictionary representation of the current configuration settings.
"""
tmp_self_dict = vars(self)
return { config_name: tmp_self_dict[config_name] for config_name in self.__default_config }
return {
config_name: tmp_self_dict[config_name]
for config_name in self.__default_config
}
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ def to_string_format(self, preamble, op_name: str, *extra_args) -> str:
retval = f'{", ".join(str(x) for x in preamble)}, {retval}'
if extra_args:
retval += f', {", ".join([str(extra) for extra in extra_args])}'
if not GlobalConfig.suppressComments:
if not GlobalConfig.suppress_comments:
if self.comment:
retval += f" #{self.comment}"
return retval
Expand Down
Loading