From 57daa92c80e338003537256b45d6e97cfee89af0 Mon Sep 17 00:00:00 2001 From: fruffy Date: Tue, 17 Dec 2024 14:14:37 +0100 Subject: [PATCH] Add a bf-asm command line option in addition to environment variables. Signed-off-by: fruffy --- backends/tofino/bf-p4c/driver/barefoot.py | 40 +++++++++++-------- backends/tofino/bf-p4c/driver/p4c.tofino.cfg | 4 +- backends/tofino/bf-p4c/driver/p4c.tofino2.cfg | 4 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/backends/tofino/bf-p4c/driver/barefoot.py b/backends/tofino/bf-p4c/driver/barefoot.py index 3baff46962..71822ef7ac 100755 --- a/backends/tofino/bf-p4c/driver/barefoot.py +++ b/backends/tofino/bf-p4c/driver/barefoot.py @@ -76,19 +76,6 @@ def checkEnv(): return None -# Search the environment for assets -enable_bf_asm = os.getenv("ENABLE_BF_ASM") - -if enable_bf_asm: - if os.environ['P4C_BUILD_TYPE'] == "DEVELOPER": - bfas = find_file('bf-asm', 'bfas') - else: - bfas = find_file(os.environ['P4C_BIN_DIR'], 'bfas') - - bfrt_schema = find_file(os.environ['P4C_BIN_DIR'], 'bfrt_schema.py') - p4c_gen_conf = find_file(os.environ['P4C_BIN_DIR'], 'p4c-gen-conf') - - class BarefootBackend(BackendDriver): """! Customized version of public driver to specify our options, @@ -109,16 +96,15 @@ def __init__(self, target, arch, argParser): self.metrics = {} self.program_name = None + # Search the environment for assets + self.enable_bf_asm = os.getenv("ENABLE_BF_ASM") + # commands self.add_command('preclean-dirs', 'find') self.add_command('preclean-files', 'find') self.add_command('preclean-runtime', 'rm') self.add_command('preprocessor', 'cc') self.add_command('compiler', os.path.join(os.environ['P4C_BIN_DIR'], 'p4c-barefoot')) - if enable_bf_asm: - self.add_command('assembler', bfas) - self.add_command('bf-rt-verifier', bfrt_schema) - self.add_command('p4c-gen-conf', p4c_gen_conf) self.add_command('cleaner', 'rm') self.runVerifiers = False @@ -196,6 +182,13 @@ def add_command_line_options(self): default=False, help="Add source outputs to the archive.", ) + self._argGroup.add_argument( + "--enable-bf-asm", + action="store_true", + default=False, + target=self.enable_bf_asm, + help="Use the assembler to generate a binary.", + ) self._argGroup.add_argument( "--bf-rt-schema", action="store", @@ -498,6 +491,19 @@ def process_command_line_options(self, opts): """! Main parsing or command line options @param opts Object holding set arguments """ + # Add assembler options if they are available. + if self.enable_bf_asm: + if os.environ['P4C_BUILD_TYPE'] == "DEVELOPER": + bfas = find_file('bf-asm', 'bfas') + else: + bfas = find_file(os.environ['P4C_BIN_DIR'], 'bfas') + + bfrt_schema = find_file(os.environ['P4C_BIN_DIR'], 'bfrt_schema.py') + p4c_gen_conf = find_file(os.environ['P4C_BIN_DIR'], 'p4c-gen-conf') + self.add_command('assembler', bfas) + self.add_command('bf-rt-verifier', bfrt_schema) + self.add_command('p4c-gen-conf', p4c_gen_conf) + BackendDriver.process_command_line_options(self, opts) # P4 program name is by default derived from the source file name, diff --git a/backends/tofino/bf-p4c/driver/p4c.tofino.cfg b/backends/tofino/bf-p4c/driver/p4c.tofino.cfg index ad1e0b6f02..e227a15484 100644 --- a/backends/tofino/bf-p4c/driver/p4c.tofino.cfg +++ b/backends/tofino/bf-p4c/driver/p4c.tofino.cfg @@ -18,8 +18,6 @@ from p4c_src.driver import BackendDriver import p4c_src.barefoot as bfn -enable_bf_asm = os.getenv("ENABLE_BF_ASM") - class TofinoBackend(bfn.BarefootBackend): def __init__(self, target, arch, argParser): bfn.BarefootBackend.__init__(self, target, arch, argParser) @@ -27,7 +25,7 @@ class TofinoBackend(bfn.BarefootBackend): # command options self.config_preprocessor("__TARGET_TOFINO__=1") self.config_compiler("__TARGET_TOFINO__=1") - if enable_bf_asm: + if self.enable_bf_asm: self.config_assembler("tofino") # Tofino Native Architecture diff --git a/backends/tofino/bf-p4c/driver/p4c.tofino2.cfg b/backends/tofino/bf-p4c/driver/p4c.tofino2.cfg index 10e11edeff..f3c2280cf7 100644 --- a/backends/tofino/bf-p4c/driver/p4c.tofino2.cfg +++ b/backends/tofino/bf-p4c/driver/p4c.tofino2.cfg @@ -26,8 +26,6 @@ Tofino2Variants = { 'tofino2' : 1 } -enable_bf_asm = os.getenv("ENABLE_BF_ASM") - class Tofino2Backend(bfn.BarefootBackend): def __init__(self, target, arch, argParser): bfn.BarefootBackend.__init__(self, target, arch, argParser) @@ -37,7 +35,7 @@ class Tofino2Backend(bfn.BarefootBackend): self.config_preprocessor("__TOFINO2_VARIANT__={}".format(Tofino2Variants[target])) self.config_compiler("__TARGET_TOFINO__=2") self.config_compiler("__TOFINO2_VARIANT__={}".format(Tofino2Variants[target])) - if enable_bf_asm: + if self.enable_bf_asm: self.config_assembler(target) for t in Tofino2Variants.keys():