P4C
The P4 Compiler
Loading...
Searching...
No Matches
Overview of bf-p4c

Overview of passes performed by the bf-p4c binary.

Overview of passes performed by the bf-p4c binary.

Copyright (C) 2024 Intel Corporation

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

SPDX-License-Identifier: Apache-2.0

The compiler goes through this sequence of high-level passes:

  1. Frontend
    • Parses input P4 file
    • Creates IR
    • See bf-p4c/frontend.h, bf-p4c/frontend.cpp, and p4c/frontends/
  2. Generate P4 Runtime
    • Creates the Barefoot runtime JSON file
    • Currently also:
      • replaces typedefs (P4::EliminateTypedef) – this is also done in midend
      • rewrites action selectors to newer syntax (BFN::RewriteActionSelector)
    • See bf-p4c/control-plane/p4runtime.h, bf-p4c/control-plane/p4runtime.cpp, p4c/control-plane/p4RuntimeSerializer.h, and p4c/control-plane/p4RuntimeSerializer.cpp
  3. Midend
  4. Post-midend
    • Bridge Packing
      • Flexible header repack (bridged metadata egress->ingress)
    • Substitute Packed Headers
      • Transforms the IR towards backend IR (vector of pipes, no longer able to be type-checked)
      • Replaces flexible type definition with packed version
    • See bf-p4c/arch/bridge.h and bf-p4c/arch/bridge.cpp
  5. Source Info Logging
    • Creates a JSON file with source info for P4I
    • This is done via information that were collected in different parts of the compiler by CollectSourceInfoLogging
    • See bf-p4c/logging/source_info_logging.h and bf-p4c/logging/source_info_logging.cpp
  6. Generate graphs
    • Essentially a backend for generating graphs of programs
    • See p4c/backends/graphs/
  7. Backend