1+ # Copyright (C) 2025 Intel Corporation
2+ # SPDX-License-Identifier: Apache-2.0
3+
14import io
25
36from .decorators import *
47from . import constants
58from .config import GlobalConfig
69
10+
711class 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+ }
0 commit comments