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 17, 2024
1 parent 27b4d2f commit b0ab3d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
41 changes: 24 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 @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -498,8 +491,22 @@ 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,
# or it can be explicitly specified by command line option.
self.program_name = (
Expand Down
4 changes: 1 addition & 3 deletions backends/tofino/bf-p4c/driver/p4c.tofino.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
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:
if self.enable_bf_asm:
self.config_assembler("tofino")

# Tofino Native Architecture
Expand Down
4 changes: 1 addition & 3 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,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():
Expand Down

0 comments on commit b0ab3d5

Please sign in to comment.