Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/komaljai/p4c into default_n…
Browse files Browse the repository at this point in the history
…oaction_p4tc
  • Loading branch information
komaljai committed Apr 21, 2024
2 parents 69747ea + 8cb15e8 commit 5790cb4
Show file tree
Hide file tree
Showing 481 changed files with 1,338 additions and 1,260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-ubuntu-18-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches: [main]

jobs:
# Build with gcc and test p4c on Ubuntu 18.04.
# Build with GCC and test p4c on Ubuntu 18.04.
test-ubuntu18:
# Only run on pull requests with the "run-ubuntu18" label.
if: ${{ github.event_name == 'schedule' || contains(github.event.pull_request.labels.*.name, 'run-ubuntu18') }}
Expand Down
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,13 @@ add_custom_target(update_includes ALL
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/*.p4 ${P4C_BINARY_DIR}/p4include
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/bmv2
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/bmv2/psa.p4 ${P4C_BINARY_DIR}/p4include/bmv2
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/psa.p4 ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/pna.p4 ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND for h in ${OTHER_HEADERS} \; do
${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/\$$h ${P4C_BINARY_DIR}/p4include \;
done
)
if (ENABLE_DPDK)
add_custom_target(dpdk_includes ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/psa.p4 ${P4C_BINARY_DIR}/p4include/dpdk
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${P4C_SOURCE_DIR}/p4include/dpdk/pna.p4 ${P4C_BINARY_DIR}/p4include/dpdk
DEPENDS update_includes
)
endif()

# Installation
# Targets install themselves. Here we install the core headers
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to the P4 Compiler Project (p4c)
# Contributing to the P4 Compiler Project (P4C)

Thank you for considering contributing to the P4 Compiler Project (p4c)! Your contributions are valuable and help improve the project for everyone. Before getting started, please take a moment to review the following guidelines.
Thank you for considering contributing to the P4 Compiler Project (P4C)! Your contributions are valuable and help improve the project for everyone. Before getting started, please take a moment to review the following guidelines.

## Coding Standard Philosophy

Expand Down
76 changes: 38 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
[![Docker Container](https://github.com/p4lang/p4c/actions/workflows/ci-container-image.yml/badge.svg)](https://github.com/p4lang/p4c/actions/workflows/ci-container-image.yml)


p4c
P4C
=================

* [Getting started](#getting-started)
* [Installing packaged versions of p4c](#installing-packaged-versions-of-p4c)
* [Installing p4c from source](#installing-p4c-from-source)
* [Installing packaged versions of P4C](#installing-packaged-versions-of-p4c)
* [Installing P4C from source](#installing-p4c-from-source)
* [Dependencies](#dependencies)
* [Ubuntu dependencies](#ubuntu-dependencies)
* [Fedora dependencies](#fedora-dependencies)
Expand All @@ -31,16 +31,16 @@ p4c
* [P4 Compiler Onboarding](#p4-compiler-onboarding)
* [Contact](#contact)

p4c is a reference compiler for the P4 programming language.
P4C is a reference compiler for the P4 programming language.
It supports both P4-14 and P4-16; you can find more information about P4
[here](http://p4.org) and the specifications for both versions of the language
[here](https://p4.org/specs).
One fact attesting to the level of quality and completeness of p4c's
code is that its front-end code, mid-end code, and p4c-graphs back end
One fact attesting to the level of quality and completeness of P4C's
code is that its front-end code, mid-end code, and P4C-graphs back end
are used as the basis for at least one commercially supported P4
compiler.

p4c is modular; it provides a standard frontend and midend which can be combined
P4C is modular; it provides a standard frontend and midend which can be combined
with a target-specific backend to create a complete P4 compiler. The goal is to
make adding new backends easy.

Expand Down Expand Up @@ -76,7 +76,7 @@ p4c --target bmv2 --arch v1model --std p4-14 my-p4-14-prog.p4
```

By adding the option `--p4runtime-files <filename>.txt` as shown in
the example commands below, p4c will also create a file
the example commands below, P4C will also create a file
`<filename>.txt`. This is a text format "P4Info" file, containing a
description of the tables and other objects in your P4 program that
have an auto-generated control plane API.
Expand Down Expand Up @@ -128,13 +128,13 @@ dot -Tpdf ParserImpl.dot > ParserImpl.pdf

# Getting started

## Installing packaged versions of p4c
## Installing packaged versions of P4C

p4c has package support for several Ubuntu and Debian distributions.
P4C has package support for several Ubuntu and Debian distributions.

### Ubuntu

A p4c package is available in the following repositories for Ubuntu 20.04 and newer.
A P4C package is available in the following repositories for Ubuntu 20.04 and newer.

```bash
source /etc/lsb-release
Expand All @@ -155,20 +155,20 @@ sudo apt update
sudo apt install p4lang-p4c
```

If you cannot use a repository to install p4c, you can download the `.deb` file
If you cannot use a repository to install P4C, you can download the `.deb` file
for your release and install it manually. You need to download a new file each
time you want to upgrade p4c.
time you want to upgrade P4C.

1. Go to [p4lang-p4c package page on OpenSUSE Build Service](https://build.opensuse.org/package/show/home:p4lang/p4lang-p4c), click on
"Download package" and choose your operating system version.

2. Install p4c, changing the path below to the path where you downloaded the package.
2. Install P4C, changing the path below to the path where you downloaded the package.

```bash
sudo dpkg -i /path/to/package.deb
```

## Installing p4c from source
## Installing P4C from source
1. Clone the repository. It includes submodules, so be sure to use
`--recursive` to pull them in:
```
Expand Down Expand Up @@ -248,12 +248,12 @@ sudo dpkg -i /path/to/package.deb
p4c -b bmv2-ss-p4org program.p4 -o program.bmv2.json
```
If you plan to contribute to p4c, you'll find more useful information
If you plan to contribute to P4C, you'll find more useful information
[here](#development-tools).
# Dependencies
Ubuntu 20.04 is the officially supported platform for p4c. There's also
Ubuntu 20.04 is the officially supported platform for P4C. There's also
unofficial support for macOS 11. Other platforms are untested; you can try to
use them, but YMMV.
Expand All @@ -278,7 +278,7 @@ use them, but YMMV.
(2.38.0 or higher).
Backends may have additional dependencies. The dependencies for the backends
included with `p4c` are documented here:
included with `P4C` are documented here:
* [BMv2](backends/bmv2/README.md)
* [eBPF](backends/ebpf/README.md)
* [graphs](backends/graphs/README.md)
Expand All @@ -301,7 +301,7 @@ For documentation building:
sudo apt-get install -y doxygen graphviz texlive-full
```

`p4c` also depends on Google Protocol Buffers (Protobuf). `p4c` requires version
`P4C` also depends on Google Protocol Buffers (Protobuf). `P4C` requires version
3.0 or higher, so the packaged version provided in Ubuntu 20.04 **should**
work. However, P4C typically installs its own version of Protobuf using CMake's `FetchContent` module
(at the moment, 3.25.3). If you are experiencing issues with the Protobuf version shipped with your OS distribution, we recommend that to install Protobuf 3.25.3 from source. You can find instructions
Expand All @@ -311,13 +311,13 @@ After cloning Protobuf and before you build, check-out version 3.25.3:
`git checkout v3.25.3`

Please note that while all Protobuf versions newer than 3.0 should work for
`p4c` itself, you may run into trouble with some extensions and other p4lang
P4C itself, you may run into trouble with some extensions and other p4lang
projects unless you install version 3.25.3.

`p4c` also depends on Google Abseil library. This library is also a pre-requisite for Protobuf of any version newer than 3.21. Therefore the use of Protobuf of suitable version automatically fulfils Abseil dependency. P4C typically installs its own version of Abseil using CMake's `FetchContent` module (Abseil LTS 20240116.1 at the moment).
P4C also depends on Google Abseil library. This library is also a pre-requisite for Protobuf of any version newer than 3.21. Therefore the use of Protobuf of suitable version automatically fulfils Abseil dependency. P4C typically installs its own version of Abseil using CMake's `FetchContent` module (Abseil LTS 20240116.1 at the moment).

### CMake
p4c requires a CMake version of at least 3.16.3 or higher. On older systems, a newer version of CMake can be installed using `pip3 install --user cmake==3.16.3`. We have a CI test on Ubuntu 18.04 that uses this option, but there is no guarantee that this will lead to a successful build.
P4C requires a CMake version of at least 3.16.3 or higher. On older systems, a newer version of CMake can be installed using `pip3 install --user cmake==3.16.3`. We have a CI test on Ubuntu 18.04 that uses this option, but there is no guarantee that this will lead to a successful build.

## Fedora dependencies

Expand Down Expand Up @@ -378,7 +378,7 @@ Installing on macOS:
brew install doxygen graphviz
```
Homebrew offers a `protobuf` formula. It installs version 3.2, which should
work for p4c itself but may cause problems with some extensions. It's
work for P4C itself but may cause problems with some extensions. It's
preferable to use the version of Protobuf which is supplied with CMake's fetchcontent (3.25.3).

The `protobuf` formula requires the following CMake variables to be set,
Expand All @@ -396,7 +396,7 @@ Installing on macOS:
## Garbage collector

P4c relies on [BDW garbage collector](https://github.com/ivmai/bdwgc)
to manage its memory. By default, the p4c executables are linked with
to manage its memory. By default, the P4C executables are linked with
the garbage collector library. When the GC causes problems, this can
be disabled by setting `ENABLE_GC` cmake option to `OFF`. However,
this will dramatically increase the memory usage by the compiler, and
Expand Down Expand Up @@ -434,16 +434,16 @@ documentation. The HTML output is available in

## Git setup

Occasionally formatting commits are applied to p4c. These pollute the git history. To ignore these commits in git blame, run this command
Occasionally formatting commits are applied to P4C. These pollute the git history. To ignore these commits in git blame, run this command
```git config blame.ignoreRevsFile .git-blame-ignore-revs```

The p4c code base is subject to a series of linter checks which are checked by CI. To avoid failing these checks and wasting unnecessary CI cycles and resources, you can install [git commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) by running
The P4C code base is subject to a series of linter checks which are checked by CI. To avoid failing these checks and wasting unnecessary CI cycles and resources, you can install [git commit hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) by running
```./tools/install_git_hooks.sh```
These commit hooks will run on every commit and check the files you are planning to commit with cpplint and clang-format.

# Docker

A Dockerfile is included. You can generate an image which contains a copy of p4c
A Dockerfile is included. You can generate an image which contains a copy of P4C
in `/p4c/build` by running:

```
Expand All @@ -452,9 +452,9 @@ docker build -t p4c .

On some platforms Docker limits the memory usage of any container, even
containers used during the `docker build` process. On macOS in particular the
default is 2GB, which is not enough to build p4c. Increase the memory limit to
default is 2GB, which is not enough to build P4C. Increase the memory limit to
at least 4GB via Docker preferences or you are likely to see "internal compiler
errors" from gcc which are caused by low memory.
errors" from GCC which are caused by low memory.

# Bazel
[![Bazel Build](https://github.com/p4lang/p4c/actions/workflows/ci-bazel.yml/badge.svg)](https://github.com/p4lang/p4c/actions/workflows/ci-bazel.yml)
Expand All @@ -467,9 +467,9 @@ We run continuous integration to ensure this works with the latest version of
Bazel.

We also provide a [`p4_library` rule](bazel/p4_library.bzl) for invoking
p4c during the build process of 3rd party Bazel projects.
P4C during the build process of 3rd party Bazel projects.

See [bazel/example](bazel/example) for an example of how to use or extend p4c in
See [bazel/example](bazel/example) for an example of how to use or extend P4C in
your own Bazel project. You may use it as a template to get you started.

# Build system
Expand Down Expand Up @@ -518,15 +518,15 @@ Python files should be added to the black and isort target using the following r
add_black_files (${CMAKE_CURRENT_SOURCE_DIR} "${MY_SOURCES_AND_HEADERS}")
```

The p4c CMakeLists.txt will use that name to figure the full path of the files to lint.
The P4C CMakeLists.txt will use that name to figure the full path of the files to lint.

clang-format, black, and isort need to be installed before the linter can be used. They can be installed with the following command:
```
pip3 install --user "clang-format==18.1.0" "black==24.3.0" "isort==5.13.2"
```
clang-format can be checked using the `make clang-format` command. Complaints can be fixed by running `make clang-format-fix-errors`. black and isort can be checked using the `make black` or `make isort` command respectively. Complaints can be fixed by running `make black-fix-errors` or `make isort-fix-errors`.

cpplint, clang-format, and black/isort run as checks as port of p4c's continuous integration process. To make sure that these tests pass, we recommend installing the appropriate git hooks. This can be done by running
cpplint, clang-format, and black/isort run as checks as port of P4C's continuous integration process. To make sure that these tests pass, we recommend installing the appropriate git hooks. This can be done by running
```
./tools/install_git_hooks.sh
```
Expand Down Expand Up @@ -584,14 +584,14 @@ See the documentation for
[`p4c_add_tests`](cmake/P4CUtils.cmake) for more information on the
arguments to these macros.

To pass custom arguments to p4c, you can set the environment variable `P4C_ARGS`:
To pass custom arguments to P4C, you can set the environment variable `P4C_ARGS`:
```
make check P4C_ARGS="-Xp4c=MY_CUSTOM_FLAG"
```

When making changes to p4c, it is sometimes useful to be able to run
When making changes to P4C, it is sometimes useful to be able to run
the tests while overwriting the expected output files that are saved
in this repository. One such situation is when your changes to p4c
in this repository. One such situation is when your changes to P4C
cause the names of compiler-generated local variables to change. To
force the expected output files to be rewritten while running the
tests, assign a value to the shell environment variable
Expand All @@ -605,7 +605,7 @@ P4TEST_REPLACE=1 make check

Define rules to install your backend. Typically you need to install
the binary, the additional architecture headers, and the configuration
file for the p4c driver.
file for the P4C driver.

```
install (TARGETS p4c-mybackend
Expand Down Expand Up @@ -672,7 +672,7 @@ Educational material on P4:
- Introduction to P4Runtime: [Next-Gen SDN Tutorial - Session 1: P4 and P4Runtime Basics](https://www.youtube.com/watch?v=KRx92qSLgo4)

# Contact
We appreciate your contributions and look forward to working with you to improve the P4 Compiler Project (p4c)!
We appreciate your contributions and look forward to working with you to improve the P4 Compiler Project (P4C)!
- For further assistance or questions regarding contributions, reach out to us in our [community chat](https://p4-lang.slack.com/). [Joining link](https://join.slack.com/t/p4-lang/shared_invite/zt-a9pe96br-Th73ueaBAwJw1ZbD_z1Rpg) .
- For general P4-related questions, use the [P4 forum](https://forum.p4.org/).
- For other communication channels click [here](https://p4.org/join/).
Expand Down
2 changes: 1 addition & 1 deletion backends/bmv2/common/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct CounterlikeTraits;
/// be a definition. If the declaration is not a definition, the specialization
/// may be defined later (7.3.1.2).
///
/// gcc reports an error when trying so specialize CounterlikeTraits<> for
/// GCC reports an error when trying so specialize CounterlikeTraits<> for
/// Standard::CounterExtern & Standard::MeterExtern outside of the Helpers
/// namespace, even when qualifying CounterlikeTraits<> with Helpers::. It seems
/// to be related to this bug:
Expand Down
3 changes: 3 additions & 0 deletions backends/dpdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ set(DPDK_PTF_DRIVER "${CMAKE_CURRENT_SOURCE_DIR}/run-dpdk-ptf-test.py")
set(DPDK_COMPILER_DRIVER "${CMAKE_CURRENT_SOURCE_DIR}/run-dpdk-test.py")

set (P4_16_SUITES
# TODO (issue #4614): Consider moving dpdk pna and psa tests to their own
# subdirectories (e.g. p4_16_psa_samples/), similar to what is done for the
# dpdk/psa/pna errors tests.
"${P4C_SOURCE_DIR}/testdata/p4_16_samples/psa-*.p4"
"${P4C_SOURCE_DIR}/testdata/p4_16_samples/pna-*.p4"
"${P4C_SOURCE_DIR}/testdata/p4_16_psa_errors/*.p4"
Expand Down
29 changes: 14 additions & 15 deletions backends/ebpf/codeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ bool CodeGenInspector::preorder(const IR::BlockStatement *s) {
return false;
}

// This is correct only after inlining
/// This is correct only after inlining.
bool CodeGenInspector::preorder(const IR::ExitStatement *) {
builder->append("return");
builder->endOfStatement();
Expand Down Expand Up @@ -590,25 +590,24 @@ void CodeGenInspector::emitTCAssignmentEndianessConversion(const IR::Expression
return;
}
if (rByteOrder == "NETWORK") {
/*
If left side of assignment is not annotated field i.e host endian and right expression
is annotated field i.e network endian, we need to convert rexp to host order.
Example -
select_0 = hdr.ipv4.diffserv
select_0 = bntoh(hdr.ipv4.diffserv)
*/
// If left side of assignment is not annotated field i.e host endian and right expression
// is annotated field i.e network endian, we need to convert rexp to host order.
// Example -
// select_0 = hdr.ipv4.diffserv
// select_0 = bntoh(hdr.ipv4.diffserv)
//
emitAndConvertByteOrder(rexpr, "HOST");
}
if (lByteOrder == "NETWORK") {
/*
If left side of assignment is annotated field i.e network endian, we need to convert
right expression to network order.
Example -
hdr.opv4.diffserv = 0x1;
hdr.opv4.diffserv = bhton(0x1)
*/
// If left side of assignment is annotated field i.e network endian, we need to convert
// right expression to network order.
// Example -
// hdr.opv4.diffserv = 0x1;
// hdr.opv4.diffserv = bhton(0x1)
//
emitAndConvertByteOrder(rexpr, "NETWORK");
}

return;
}

Expand Down
Loading

0 comments on commit 5790cb4

Please sign in to comment.