From 8e440dc9eab8c9b626a8d9b5c7aa501513d026f0 Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 21 Mar 2022 16:57:00 +0100 Subject: [PATCH] soc/integration: Add LiteXSocArgumentParser to be able to expose CPU parameters to user on targets. Currently used for CPU parameters could problably be extented to simplify other parts of the code in the future. --- litex/soc/integration/soc.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/litex/soc/integration/soc.py b/litex/soc/integration/soc.py index 26ba6ebe4..91915b8f3 100644 --- a/litex/soc/integration/soc.py +++ b/litex/soc/integration/soc.py @@ -1,7 +1,7 @@ # # This file is part of LiteX. # -# This file is Copyright (c) 2014-2021 Florent Kermarrec +# This file is Copyright (c) 2014-2022 Florent Kermarrec # This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq # This file is Copyright (c) 2019 Gabriel L. Somlo # SPDX-License-Identifier: BSD-2-Clause @@ -9,6 +9,7 @@ import sys import time import logging +import argparse import datetime from math import log2, ceil @@ -1894,3 +1895,27 @@ class LiteXSoC(SoC): self.add_constant("VIDEO_FRAMEBUFFER_VRES", vres) self.add_constant("VIDEO_FRAMEBUFFER_DEPTH", vfb.depth) +# LiteXSoCArgumentParser --------------------------------------------------------------------------- + +class LiteXSoCArgumentParser(argparse.ArgumentParser): + def parse_args(self): + + def get_selected_cpu_name(): + for name, cpu_cls in cpu.CPUS.items(): + if f"--cpu-type={name}" in sys.argv: # FIXME: Improve. + return cpu_cls + return None + + # Intercept selected CPU to fill arguments. + cpu_cls = get_selected_cpu_name() + if cpu_cls is not None and hasattr(cpu_cls, "args_fill"): + cpu_cls.args_fill(self) + + # Get Command-line arguments. + args = argparse.ArgumentParser.parse_args(self) + + # Re-inject CPU read arguments. + if cpu_cls is not None and hasattr(cpu_cls, "args_read"): + cpu_cls.args_read(args) + + return args \ No newline at end of file