Skip to content

Commit

Permalink
process_arguments: refactoring and documentation (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Feb 19, 2024
1 parent 9f1b7ea commit 449624e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 26 deletions.
7 changes: 6 additions & 1 deletion apio/commands/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def cli(ctx, board, project_dir, verbose):
scons = SCons(project_dir)

# -- Verify the project with the given parameters
exit_code = scons.verify({"board": board, "verbose": {"all": verbose}})
exit_code = scons.verify(
{
"board": board,
"verbose": {"all": verbose, "yosys": False, "pnr": False},
}
)

# -- Done!
ctx.exit(exit_code)
57 changes: 35 additions & 22 deletions apio/managers/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
SIZE = "size" # -- Key for the FPGA size
PACK = "pack" # -- Key for the FPGA pack
IDCODE = "idcode" # -- Key for the FPGA IDCODE
VERBOSE = "verbose" # -- Key for the Verbose flag
ALL = "all" # -- Key for Verbose all
YOSYS = "yosys" # -- Key for Verbose-yosys
PNR = "pnr" # -- Key for Verbose-pnr
TOP_MODULE = "top-module" # -- Key for top-module


def debug_params(fun):
Expand Down Expand Up @@ -113,8 +118,8 @@ def process_arguments(
SIZE: None,
PACK: None,
IDCODE: None,
"verbose": None,
"top-module": None,
VERBOSE: {ALL: False, "yosys": False, "pnr": False},
TOP_MODULE: None,
}

# -- Merge the initial configuration to the current configuration
Expand Down Expand Up @@ -196,29 +201,22 @@ def process_arguments(
perror_insuficient_arguments()
raise ValueError(f"Missing FPGA {item.upper()}")

# -- TODO: REFACTORING!
# -- Debug: Store arguments in local variables
var_verbose = config["verbose"]
var_topmodule = config["top-module"]

# raise ValueError("Missing board")

# -- Build Scons variables list
variables = format_vars(
# -- Build Scons flag list
flags = serialize_scons_flags(
{
"fpga_arch": config[ARCH],
"fpga_size": config[SIZE],
"fpga_type": config[TYPE],
"fpga_pack": config[PACK],
"fpga_idcode": config[IDCODE],
"verbose_all": var_verbose.get("all"),
"verbose_yosys": var_verbose.get("yosys"),
"verbose_pnr": var_verbose.get("pnr"),
"top_module": var_topmodule,
"verbose_all": config[VERBOSE][ALL],
"verbose_yosys": config[VERBOSE][YOSYS],
"verbose_pnr": config[VERBOSE][PNR],
"top_module": config[TOP_MODULE],
}
)

return variables, config[BOARD], config[ARCH]
return flags, config[BOARD], config[ARCH]


def update_config_fpga_item(config, item, resources):
Expand Down Expand Up @@ -295,6 +293,11 @@ def print_configuration(config: dict) -> None:
print(f" size: {config[SIZE]}")
print(f" pack: {config[PACK]}")
print(f" idcode: {config[IDCODE]}")
print(f" top-module: {config[TOP_MODULE]}")
print(" verbose:")
print(f" all: {config[VERBOSE][ALL]}")
print(f" yosys: {config[VERBOSE][YOSYS]}")
print(f" pnr: {config[VERBOSE][PNR]}")
print()


Expand All @@ -315,10 +318,20 @@ def perror_insuficient_arguments():
)


def format_vars(args):
"""Format the given vars in the form: 'flag=value'"""
variables = []
for key, value in args.items():
def serialize_scons_flags(flags: dict) -> list:
"""Format the scons flags as a list of string of
the form: 'flag=value'
"""

# -- Create and empty list
flag_list = []

# -- Read all the flags
for key, value in flags.items():

# -- Append to the list only the flags with value
if value:
variables += [f"{key}={value}"]
return variables
flag_list.append(f"{key}={value}")

# -- Return the list
return flag_list
7 changes: 4 additions & 3 deletions apio/managers/scons.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from apio import util
from apio.managers.arguments import process_arguments
from apio.managers.arguments import format_vars
from apio.managers.arguments import serialize_scons_flags
from apio.managers.system import System
from apio.profile import Profile
from apio.resources import Resources
Expand Down Expand Up @@ -87,8 +87,9 @@ def verify(self, args):
def lint(self, args):
"""DOC: TODO"""

__, __, arch = process_arguments(None, self.resources)
var = format_vars(
config = {}
__, __, arch = process_arguments(config, self.resources)
var = serialize_scons_flags(
{
"all": args.get("all"),
"top": args.get("top"),
Expand Down

0 comments on commit 449624e

Please sign in to comment.