11#! /usr/bin/env python3
22# encoding: utf-8
33"""
4- This module provides functionality for linking assembled kernels into a full HERACLES program for execution queues: MINST, CINST, and XINST.
5-
6- Classes:
7- LinkerRunConfig
8- Maintains the configuration data for the run.
9-
10- KernelFiles
11- Structure for kernel files.
12-
13- Functions:
14- main(run_config: LinkerRunConfig, verbose_stream=None)
15- Executes the linking process using the provided configuration.
16-
17- parse_args() -> argparse.Namespace
18- Parses command-line arguments for the linker script.
19-
20- Usage:
21- This script is intended to be run as a standalone program. It requires specific command-line arguments
22- to specify input and output files and configuration options for the linking process.
4+ @file
5+ @brief This module provides functionality for linking assembled kernels into a full HERACLES program for execution queues: MINST, CINST, and XINST.
236
7+ This script is intended to be run as a standalone program. It requires specific command-line arguments
8+ to specify input and output files and configuration options for the linking process.
249"""
2510import argparse
2611import io
4833
4934class LinkerRunConfig (RunConfig ):
5035 """
51- Maintains the configuration data for the run.
52-
53- Methods:
54- as_dict() -> dict
55- Returns the configuration as a dictionary.
36+ @brief Maintains the configuration data for the run.
5637 """
5738
5839 __initialized = False # specifies whether static members have been initialized
@@ -62,34 +43,27 @@ class LinkerRunConfig(RunConfig):
6243
6344 def __init__ (self , ** kwargs ):
6445 """
65- Constructs a new LinkerRunConfig Object from input parameters.
46+ @brief Constructs a new LinkerRunConfig Object from input parameters.
6647
6748 See base class constructor for more parameters.
6849
69- Args:
70- input_prefixes (list[str]):
71- List of input prefixes, including full path. For an input prefix, linker will
50+ @param kwargs Dictionary of configuration parameters:
51+ - input_prefixes: List of input prefixes, including full path. For an input prefix, linker will
7252 assume there are three files named `input_prefixes[i] + '.minst'`,
7353 `input_prefixes[i] + '.cinst'`, and `input_prefixes[i] + '.xinst'`.
7454 This list must not be empty.
75- output_prefix (str):
76- Prefix for the output file names.
55+ - output_prefix: Prefix for the output file names.
7756 Three files will be generated:
7857 `output_dir/output_prefix.minst`, `output_dir/output_prefix.cinst`, and
7958 `output_dir/output_prefix.xinst`.
8059 Output filenames cannot match input file names.
81- input_mem_file (str):
82- Input memory file associated with the result kernel.
83- output_dir (str): current working directory
84- OPTIONAL directory where to store all intermediate files and final output.
60+ - input_mem_file: Input memory file associated with the result kernel.
61+ - output_dir: OPTIONAL directory where to store all intermediate files and final output.
8562 This will be created if it doesn't exists.
8663 Defaults to current working directory.
8764
88- Raises:
89- TypeError:
90- A mandatory configuration value was missing.
91- ValueError:
92- At least, one of the arguments passed is invalid.
65+ @throws TypeError A mandatory configuration value was missing.
66+ @throws ValueError At least, one of the arguments passed is invalid.
9367 """
9468
9569 self .init_default_config ()
@@ -113,7 +87,7 @@ def __init__(self, **kwargs):
11387 @classmethod
11488 def init_default_config (cls ):
11589 """
116- Initializes static members of the class.
90+ @brief Initializes static members of the class.
11791 """
11892 if not cls .__initialized :
11993 cls .__default_config ["input_prefixes" ] = None
@@ -129,10 +103,9 @@ def init_default_config(cls):
129103
130104 def __str__ (self ):
131105 """
132- Provides a string representation of the configuration.
106+ @brief Provides a string representation of the configuration.
133107
134- Returns:
135- str: The string for the configuration.
108+ @return The string for the configuration.
136109 """
137110 self_dict = self .as_dict ()
138111 with io .StringIO () as retval_f :
@@ -143,10 +116,9 @@ def __str__(self):
143116
144117 def as_dict (self ) -> dict :
145118 """
146- Provides the configuration as a dictionary.
119+ @brief Provides the configuration as a dictionary.
147120
148- Returns:
149- dict: The configuration.
121+ @return The configuration.
150122 """
151123 retval = super ().as_dict ()
152124 tmp_self_dict = vars (self )
@@ -155,17 +127,12 @@ def as_dict(self) -> dict:
155127
156128class KernelFiles (NamedTuple ):
157129 """
158- Structure for kernel files.
159-
160- Attributes:
161- minst (str):
162- Index = 0. Name for file containing MInstructions for represented kernel.
163- cinst (str):
164- Index = 1. Name for file containing CInstructions for represented kernel.
165- xinst (str):
166- Index = 2. Name for file containing XInstructions for represented kernel.
167- prefix (str):
168- Index = 3
130+ @brief Structure for kernel files.
131+
132+ @var minst Index = 0. Name for file containing MInstructions for represented kernel.
133+ @var cinst Index = 1. Name for file containing CInstructions for represented kernel.
134+ @var xinst Index = 2. Name for file containing XInstructions for represented kernel.
135+ @var prefix Index = 3
169136 """
170137 minst : str
171138 cinst : str
@@ -174,17 +141,14 @@ class KernelFiles(NamedTuple):
174141
175142def main (run_config : LinkerRunConfig , verbose_stream = None ):
176143 """
177- Executes the linking process using the provided configuration.
144+ @brief Executes the linking process using the provided configuration.
178145
179146 This function prepares input and output file names, initializes the memory model, discovers variables,
180147 and links each kernel, writing the output to specified files.
181148
182- Args:
183- run_config (LinkerRunConfig): The configuration object containing run parameters.
184- verbose_stream: The stream to which verbose output is printed. Defaults to None.
185-
186- Returns:
187- None
149+ @param run_config The configuration object containing run parameters.
150+ @param verbose_stream The stream to which verbose output is printed. Defaults to None.
151+ @return None
188152 """
189153 if verbose_stream :
190154 print ("Linking..." , file = verbose_stream )
@@ -313,13 +277,12 @@ def main(run_config: LinkerRunConfig, verbose_stream = None):
313277
314278def parse_args ():
315279 """
316- Parses command-line arguments for the linker script.
280+ @brief Parses command-line arguments for the linker script.
317281
318282 This function sets up the argument parser and defines the expected arguments for the script.
319283 It returns a Namespace object containing the parsed arguments.
320284
321- Returns:
322- argparse.Namespace: Parsed command-line arguments.
285+ @return Parsed command-line arguments.
323286 """
324287 parser = argparse .ArgumentParser (
325288 description = ("HERACLES Linker.\n "
0 commit comments