Skip to content

Commit

Permalink
Add a bf-asm command line option in addition to environment variables.
Browse files Browse the repository at this point in the history
Signed-off-by: fruffy <[email protected]>
  • Loading branch information
fruffy committed Dec 18, 2024
1 parent 8062920 commit 0f64f6f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
37 changes: 20 additions & 17 deletions backends/tofino/bf-p4c/driver/barefoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -115,10 +102,6 @@ def __init__(self, target, arch, argParser):
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
Expand Down Expand Up @@ -196,6 +179,12 @@ 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,
help="Use the assembler to generate a binary.",
)
self._argGroup.add_argument(
"--bf-rt-schema",
action="store",
Expand Down Expand Up @@ -498,6 +487,20 @@ 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 opts.enable_bf_asm or os.getenv("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)
self._commandsEnabled.append('assembler')

BackendDriver.process_command_line_options(self, opts)

# P4 program name is by default derived from the source file name,
Expand Down
8 changes: 5 additions & 3 deletions backends/tofino/bf-p4c/driver/p4c.tofino.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@
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)

# command options
self.config_preprocessor("__TARGET_TOFINO__=1")
self.config_compiler("__TARGET_TOFINO__=1")
if enable_bf_asm:

def process_command_line_options(self, opts):
if opts.enable_bf_asm or os.getenv("ENABLE_BF_ASM"):
self.config_assembler("tofino")
bfn.BarefootBackend.process_command_line_options(self, opts)


# Tofino Native Architecture
tna_target = TofinoBackend('tofino', 'tna', argParser)
Expand Down
9 changes: 5 additions & 4 deletions backends/tofino/bf-p4c/driver/p4c.tofino2.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -37,8 +35,11 @@ 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:
self.config_assembler(target)

def process_command_line_options(self, opts):
if opts.enable_bf_asm or os.getenv("ENABLE_BF_ASM"):
self.config_assembler(self.target)
bfn.BarefootBackend.process_command_line_options(self, opts)

for t in Tofino2Variants.keys():
config.target.append(Tofino2Backend(t, 't2na', argParser))
Expand Down

0 comments on commit 0f64f6f

Please sign in to comment.