blob: 87bfd959fdd46fa6c3184dbb8a599b9721f57480 [file] [log] [blame]
Carmelo Cascone228092b2018-06-15 20:41:10 +02001#!/usr/bin/env bash
2
Carmelo Casconeb5324e72018-11-25 02:26:32 -08003set -e
Carmelo Cascone228092b2018-06-15 20:41:10 +02004
5BMV2_CPU_PORT="255"
Daniele Moro5a2de712019-09-24 14:34:07 -07006BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER -DWITH_DEBUG"
Carmelo Cascone228092b2018-06-15 20:41:10 +02007
8PROFILE=$1
9OTHER_PP_FLAGS=$2
Carmelo Cascone228092b2018-06-15 20:41:10 +020010
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070011SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12OUT_DIR=${SRC_DIR}/p4c-out/${PROFILE}/bmv2/default
Carmelo Cascone228092b2018-06-15 20:41:10 +020013
Carmelo Casconeb5324e72018-11-25 02:26:32 -080014mkdir -p ${OUT_DIR}
15mkdir -p ${OUT_DIR}/graphs
16
17echo
18echo "## Compiling profile ${PROFILE} in ${OUT_DIR}..."
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070019
Carmelo Cascone2388cc12021-05-26 19:30:30 +020020dockerImage=opennetworking/p4c:stable-20210108
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070021dockerRun="docker run --rm -w ${SRC_DIR} -v ${SRC_DIR}:${SRC_DIR} -v ${OUT_DIR}:${OUT_DIR} ${dockerImage}"
22
23# Generate preprocessed P4 source (for debugging).
24(set -x; ${dockerRun} p4c-bm2-ss --arch v1model \
Carmelo Cascone228092b2018-06-15 20:41:10 +020025 ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070026 --pp ${OUT_DIR}/_pp.p4 fabric.p4)
27
28# Generate BMv2 JSON and P4Info.
29(set -x; ${dockerRun} p4c-bm2-ss --arch v1model -o ${OUT_DIR}/bmv2.json \
30 ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \
31 --p4runtime-files ${OUT_DIR}/p4info.txt fabric.p4)
32
33# Graphs.
34(set -x; ${dockerRun} p4c-graphs ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \
35 --graphs-dir ${OUT_DIR}/graphs fabric.p4)
36
37# Convert .dot graphs to PDFs.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080038for f in ${OUT_DIR}/graphs/*.dot; do
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070039 (set -x; ${dockerRun} dot -Tpdf ${f} > ${f}.pdf)
Carmelo Casconeb5324e72018-11-25 02:26:32 -080040 rm -f ${f}
41done
Carmelo Cascone6880ba62018-09-06 00:04:34 -070042
Carmelo Cascone4d8785b2019-05-31 17:11:26 -070043# CPU port.
Carmelo Casconeb5324e72018-11-25 02:26:32 -080044(set -x; echo ${BMV2_CPU_PORT} > ${OUT_DIR}/cpu_port.txt)