Carmelo Cascone | 228092b | 2018-06-15 20:41:10 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 3 | set -e |
Carmelo Cascone | 228092b | 2018-06-15 20:41:10 +0200 | [diff] [blame] | 4 | |
| 5 | BMV2_CPU_PORT="255" |
Daniele Moro | 5a2de71 | 2019-09-24 14:34:07 -0700 | [diff] [blame] | 6 | BMV2_PP_FLAGS="-DTARGET_BMV2 -DCPU_PORT=${BMV2_CPU_PORT} -DWITH_PORT_COUNTER -DWITH_DEBUG" |
Carmelo Cascone | 228092b | 2018-06-15 20:41:10 +0200 | [diff] [blame] | 7 | |
| 8 | PROFILE=$1 |
| 9 | OTHER_PP_FLAGS=$2 |
Carmelo Cascone | 228092b | 2018-06-15 20:41:10 +0200 | [diff] [blame] | 10 | |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 11 | SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 12 | OUT_DIR=${SRC_DIR}/p4c-out/${PROFILE}/bmv2/default |
Carmelo Cascone | 228092b | 2018-06-15 20:41:10 +0200 | [diff] [blame] | 13 | |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 14 | mkdir -p ${OUT_DIR} |
| 15 | mkdir -p ${OUT_DIR}/graphs |
| 16 | |
| 17 | echo |
| 18 | echo "## Compiling profile ${PROFILE} in ${OUT_DIR}..." |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 19 | |
Carmelo Cascone | 2388cc1 | 2021-05-26 19:30:30 +0200 | [diff] [blame] | 20 | dockerImage=opennetworking/p4c:stable-20210108 |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 21 | dockerRun="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 Cascone | 228092b | 2018-06-15 20:41:10 +0200 | [diff] [blame] | 25 | ${BMV2_PP_FLAGS} ${OTHER_PP_FLAGS} \ |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 26 | --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 Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 38 | for f in ${OUT_DIR}/graphs/*.dot; do |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 39 | (set -x; ${dockerRun} dot -Tpdf ${f} > ${f}.pdf) |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 40 | rm -f ${f} |
| 41 | done |
Carmelo Cascone | 6880ba6 | 2018-09-06 00:04:34 -0700 | [diff] [blame] | 42 | |
Carmelo Cascone | 4d8785b | 2019-05-31 17:11:26 -0700 | [diff] [blame] | 43 | # CPU port. |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 44 | (set -x; echo ${BMV2_CPU_PORT} > ${OUT_DIR}/cpu_port.txt) |