From 39d9d44473baf387e4b7ce1cdc1d176718733ded Mon Sep 17 00:00:00 2001 From: Bili Dong Date: Wed, 14 Aug 2024 23:56:46 -0700 Subject: [PATCH] Promote `P4` to be THE project-wise top-level namespace (#4825) * Introduce top-level namespace p4c to the lib/ dir Signed-off-by: Bili Dong * Change top-level namespace Util to p4c::Util Signed-off-by: Bili Dong * Change top-level namespace Test to p4c::Test Signed-off-by: Bili Dong * Change top-level namespace IR to p4c::IR Signed-off-by: Bili Dong * Change top-level namespace P4 to p4c::P4 Signed-off-by: Bili Dong * Make sure all midend/ C++ code is under namespace p4c Signed-off-by: Bili Dong * Make sure all frontend/ code is under namespace p4c Signed-off-by: Bili Dong * Make sure all ir/ code is under namespace p4c Signed-off-by: Bili Dong * Change top-level namespace BMV2 to p4c::BMV2 Signed-off-by: Bili Dong * Change top-level namespace DPDK to p4c::DPDK Signed-off-by: Bili Dong * Change top-level namespace EBPF to p4c::EBPF Signed-off-by: Bili Dong * Change top-level namespace graphs to p4c::graphs Signed-off-by: Bili Dong * Change top-level namespace TC to p4c::TC Signed-off-by: Bili Dong * Change top-level namespace UBPF to p4c::UBPF Signed-off-by: Bili Dong * Fully qualify `using namespace p4c` to be `using namespace ::p4c` Signed-off-by: Bili Dong * Make sure all backends/ code is under namespace p4c Signed-off-by: Bili Dong * Address some compiling issues Signed-off-by: Bili Dong * Address remaining compiling issues Signed-off-by: Bili Dong * Apply clang-format Signed-off-by: Bili Dong * Address cpplint issues Signed-off-by: Bili Dong * Update bazel/example/ code Signed-off-by: Bili Dong * Address remaining namespace issues Signed-off-by: Bili Dong * Try fixing the macOS compiling issue Signed-off-by: Bili Dong * Address linter issues Signed-off-by: Bili Dong * Revert the past few changes as they didn't work Signed-off-by: Bili Dong * Change namespace naming from p4c to P4C Signed-off-by: Bili Dong * Fix wrong replacements Signed-off-by: Bili Dong * Add namespace P4C to newly added code Signed-off-by: Bili Dong * Resolve some #include within namespace issues Signed-off-by: Bili Dong * Switch to use `P4` as THE top-level namespace And avoid nested `P4::P4` namespace. Signed-off-by: Bili Dong * Recover Ubuntu 18.04 support Signed-off-by: Bili Dong * Avoid introducing new symbols into `namespace std` Signed-off-by: Bili Dong * Resolve compiling issues for newly updated code Signed-off-by: Bili Dong * Address review comments Signed-off-by: Bili Dong * Further address compiling issues Signed-off-by: Bili Dong * Apply namespace updates to newly added code Signed-off-by: Bili Dong * Convert `using namespace ::P4` back to `using namespace P4` Signed-off-by: Bili Dong * Use `::P4` consistently in macros under lib/ Signed-off-by: Bili Dong * Fix more `P4` namespace usage in macros Signed-off-by: Bili Dong --------- Signed-off-by: Bili Dong --- backends/bmv2/common/JsonObjects.cpp | 4 +- backends/bmv2/common/JsonObjects.h | 4 +- backends/bmv2/common/action.cpp | 10 +- backends/bmv2/common/action.h | 4 +- backends/bmv2/common/annotations.h | 4 +- backends/bmv2/common/backend.h | 4 +- backends/bmv2/common/check_unsupported.h | 4 +- backends/bmv2/common/control.h | 168 ++++++------- backends/bmv2/common/controlFlowGraph.cpp | 23 +- backends/bmv2/common/controlFlowGraph.h | 4 +- backends/bmv2/common/deparser.cpp | 13 +- backends/bmv2/common/deparser.h | 4 +- backends/bmv2/common/expression.cpp | 59 ++--- backends/bmv2/common/expression.h | 4 +- backends/bmv2/common/extern.cpp | 18 +- backends/bmv2/common/extern.h | 4 +- backends/bmv2/common/globals.cpp | 4 +- backends/bmv2/common/globals.h | 4 +- backends/bmv2/common/header.cpp | 28 +-- backends/bmv2/common/header.h | 4 +- backends/bmv2/common/helpers.cpp | 8 +- backends/bmv2/common/helpers.h | 4 +- backends/bmv2/common/lower.cpp | 16 +- backends/bmv2/common/lower.h | 4 +- backends/bmv2/common/midend.h | 4 +- backends/bmv2/common/options.h | 4 +- backends/bmv2/common/parser.cpp | 42 ++-- backends/bmv2/common/parser.h | 4 +- .../bmv2/common/sharedActionSelectorCheck.h | 20 +- backends/bmv2/pna_nic/main.cpp | 23 +- backends/bmv2/pna_nic/midend.cpp | 4 +- backends/bmv2/pna_nic/midend.h | 4 +- backends/bmv2/pna_nic/options.cpp | 2 +- backends/bmv2/pna_nic/options.h | 4 +- backends/bmv2/pna_nic/pnaNic.cpp | 23 +- backends/bmv2/pna_nic/pnaNic.h | 9 +- backends/bmv2/pna_nic/pnaProgramStructure.cpp | 14 +- backends/bmv2/pna_nic/pnaProgramStructure.h | 10 +- backends/bmv2/portable_common/midend.cpp | 4 +- backends/bmv2/portable_common/midend.h | 4 +- backends/bmv2/portable_common/options.cpp | 4 +- backends/bmv2/portable_common/options.h | 4 +- backends/bmv2/portable_common/portable.cpp | 24 +- backends/bmv2/portable_common/portable.h | 4 +- backends/bmv2/psa_switch/main.cpp | 23 +- backends/bmv2/psa_switch/midend.cpp | 4 +- backends/bmv2/psa_switch/midend.h | 4 +- backends/bmv2/psa_switch/options.cpp | 2 +- backends/bmv2/psa_switch/options.h | 4 +- backends/bmv2/psa_switch/psaSwitch.cpp | 23 +- backends/bmv2/psa_switch/psaSwitch.h | 9 +- backends/bmv2/simple_switch/main.cpp | 23 +- backends/bmv2/simple_switch/midend.cpp | 4 +- backends/bmv2/simple_switch/midend.h | 4 +- backends/bmv2/simple_switch/options.h | 4 +- backends/bmv2/simple_switch/simpleSwitch.cpp | 154 ++++++------ backends/bmv2/simple_switch/simpleSwitch.h | 8 +- backends/common/metermap.cpp | 26 +- backends/common/psaProgramStructure.cpp | 10 +- backends/common/psaProgramStructure.h | 6 +- backends/dpdk/backend.cpp | 6 +- backends/dpdk/backend.h | 4 +- backends/dpdk/constants.h | 4 + .../control-plane/bfruntime_arch_handler.h | 31 +-- backends/dpdk/control-plane/bfruntime_ext.cpp | 8 +- backends/dpdk/control-plane/bfruntime_ext.h | 4 +- backends/dpdk/dbprint-dpdk.cpp | 4 + backends/dpdk/dpdk.def | 4 +- backends/dpdk/dpdkArch.cpp | 230 +++++++++--------- backends/dpdk/dpdkArch.h | 51 ++-- backends/dpdk/dpdkAsmOpt.cpp | 35 +-- backends/dpdk/dpdkAsmOpt.h | 4 +- backends/dpdk/dpdkCheckExternInvocation.h | 4 +- backends/dpdk/dpdkContext.cpp | 57 ++--- backends/dpdk/dpdkContext.h | 6 +- backends/dpdk/dpdkHelpers.cpp | 121 ++++----- backends/dpdk/dpdkHelpers.h | 8 +- backends/dpdk/dpdkMetadata.cpp | 8 +- backends/dpdk/dpdkMetadata.h | 4 +- backends/dpdk/dpdkProgram.cpp | 52 ++-- backends/dpdk/dpdkProgram.h | 4 +- backends/dpdk/dpdkProgramStructure.cpp | 45 ++-- backends/dpdk/dpdkProgramStructure.h | 4 + backends/dpdk/dpdkUtils.cpp | 4 +- backends/dpdk/dpdkUtils.h | 4 +- backends/dpdk/main.cpp | 26 +- backends/dpdk/midend.cpp | 4 +- backends/dpdk/midend.h | 4 +- backends/dpdk/options.cpp | 4 +- backends/dpdk/options.h | 4 +- backends/dpdk/printUtils.cpp | 8 +- backends/dpdk/printUtils.h | 4 +- backends/dpdk/spec.cpp | 41 ++-- backends/dpdk/tdiConf.cpp | 18 +- backends/dpdk/tdiConf.h | 4 +- backends/ebpf/codeGen.cpp | 14 +- backends/ebpf/codeGen.h | 6 +- backends/ebpf/ebpfBackend.cpp | 18 +- backends/ebpf/ebpfBackend.h | 4 +- backends/ebpf/ebpfControl.cpp | 37 +-- backends/ebpf/ebpfControl.h | 8 +- backends/ebpf/ebpfDeparser.cpp | 33 +-- backends/ebpf/ebpfDeparser.h | 4 +- backends/ebpf/ebpfModel.cpp | 4 +- backends/ebpf/ebpfModel.h | 40 +-- backends/ebpf/ebpfObject.h | 4 +- backends/ebpf/ebpfOptions.cpp | 4 + backends/ebpf/ebpfOptions.h | 4 + backends/ebpf/ebpfParser.cpp | 53 ++-- backends/ebpf/ebpfParser.h | 6 +- backends/ebpf/ebpfProgram.cpp | 21 +- backends/ebpf/ebpfProgram.h | 4 +- backends/ebpf/ebpfTable.cpp | 115 ++++----- backends/ebpf/ebpfTable.h | 4 +- backends/ebpf/ebpfType.cpp | 16 +- backends/ebpf/ebpfType.h | 4 +- backends/ebpf/lower.cpp | 14 +- backends/ebpf/lower.h | 4 +- backends/ebpf/midend.cpp | 6 +- backends/ebpf/midend.h | 4 +- backends/ebpf/p4c-ebpf.cpp | 20 +- backends/ebpf/psa/backend.cpp | 12 +- backends/ebpf/psa/backend.h | 4 +- backends/ebpf/psa/ebpfPipeline.cpp | 6 +- backends/ebpf/psa/ebpfPipeline.h | 4 +- backends/ebpf/psa/ebpfPsaControl.cpp | 10 +- backends/ebpf/psa/ebpfPsaControl.h | 12 +- backends/ebpf/psa/ebpfPsaDeparser.cpp | 7 +- backends/ebpf/psa/ebpfPsaDeparser.h | 8 +- backends/ebpf/psa/ebpfPsaGen.cpp | 21 +- backends/ebpf/psa/ebpfPsaGen.h | 4 +- backends/ebpf/psa/ebpfPsaParser.cpp | 4 +- backends/ebpf/psa/ebpfPsaParser.h | 6 +- backends/ebpf/psa/ebpfPsaTable.cpp | 62 ++--- backends/ebpf/psa/ebpfPsaTable.h | 8 +- backends/ebpf/psa/externs/ebpfPsaChecksum.cpp | 16 +- backends/ebpf/psa/externs/ebpfPsaChecksum.h | 4 +- backends/ebpf/psa/externs/ebpfPsaCounter.cpp | 43 ++-- backends/ebpf/psa/externs/ebpfPsaCounter.h | 4 +- backends/ebpf/psa/externs/ebpfPsaDigest.cpp | 8 +- backends/ebpf/psa/externs/ebpfPsaDigest.h | 4 +- .../ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp | 42 ++-- .../ebpf/psa/externs/ebpfPsaHashAlgorithm.h | 4 +- backends/ebpf/psa/externs/ebpfPsaMeter.cpp | 14 +- backends/ebpf/psa/externs/ebpfPsaMeter.h | 4 +- backends/ebpf/psa/externs/ebpfPsaRandom.cpp | 30 +-- backends/ebpf/psa/externs/ebpfPsaRandom.h | 4 +- backends/ebpf/psa/externs/ebpfPsaRegister.cpp | 15 +- backends/ebpf/psa/externs/ebpfPsaRegister.h | 4 +- .../externs/ebpfPsaTableImplementation.cpp | 99 ++++---- .../psa/externs/ebpfPsaTableImplementation.h | 4 +- backends/ebpf/psa/xdpHelpProgram.h | 4 +- backends/ebpf/target.cpp | 17 +- backends/ebpf/target.h | 12 +- backends/graphs/controls.cpp | 8 +- backends/graphs/controls.h | 4 +- backends/graphs/graph_visitor.cpp | 6 +- backends/graphs/graph_visitor.h | 4 +- backends/graphs/graphs.cpp | 4 +- backends/graphs/graphs.h | 4 +- backends/graphs/p4c-graphs.cpp | 20 +- backends/graphs/parsers.cpp | 4 +- backends/graphs/parsers.h | 4 +- backends/p4fmt/main.cpp | 10 +- backends/p4fmt/options.cpp | 4 +- backends/p4fmt/options.h | 4 +- backends/p4fmt/p4fmt.cpp | 12 +- backends/p4fmt/p4fmt.h | 4 + backends/p4fmt/refcheck.cpp | 29 ++- backends/p4test/midend.cpp | 4 +- backends/p4test/midend.h | 4 +- backends/p4test/p4test.cpp | 14 +- .../common/compiler/compiler_result.cpp | 4 +- .../p4tools/common/compiler/compiler_result.h | 4 +- .../common/compiler/compiler_target.cpp | 10 +- .../p4tools/common/compiler/compiler_target.h | 4 +- .../p4tools/common/compiler/configuration.h | 4 +- backends/p4tools/common/compiler/context.h | 4 +- .../common/compiler/convert_hs_index.cpp | 4 +- .../common/compiler/convert_hs_index.h | 4 +- .../common/compiler/convert_struct_expr.cpp | 4 +- .../common/compiler/convert_struct_expr.h | 4 +- .../common/compiler/convert_varbits.cpp | 4 +- .../p4tools/common/compiler/convert_varbits.h | 4 +- backends/p4tools/common/compiler/midend.cpp | 4 +- backends/p4tools/common/compiler/midend.h | 4 +- .../p4tools/common/compiler/reachability.cpp | 4 +- .../p4tools/common/compiler/reachability.h | 4 +- .../control_plane/symbolic_variables.cpp | 4 +- .../common/control_plane/symbolic_variables.h | 4 +- .../common/core/abstract_execution_state.cpp | 4 +- .../common/core/abstract_execution_state.h | 4 +- backends/p4tools/common/core/target.cpp | 4 +- backends/p4tools/common/core/target.h | 4 +- backends/p4tools/common/core/z3_solver.cpp | 4 +- backends/p4tools/common/core/z3_solver.h | 4 +- backends/p4tools/common/lib/arch_spec.cpp | 4 +- backends/p4tools/common/lib/arch_spec.h | 4 +- backends/p4tools/common/lib/constants.h | 4 +- backends/p4tools/common/lib/format_int.cpp | 10 +- backends/p4tools/common/lib/format_int.h | 4 +- backends/p4tools/common/lib/formulae.h | 4 +- backends/p4tools/common/lib/gen_eq.cpp | 4 +- backends/p4tools/common/lib/gen_eq.h | 4 +- backends/p4tools/common/lib/ir_compare.h | 5 +- backends/p4tools/common/lib/logging.cpp | 10 +- backends/p4tools/common/lib/logging.h | 4 +- backends/p4tools/common/lib/model.cpp | 4 +- backends/p4tools/common/lib/model.h | 4 +- .../p4tools/common/lib/namespace_context.cpp | 4 +- .../p4tools/common/lib/namespace_context.h | 4 +- backends/p4tools/common/lib/symbolic_env.cpp | 4 +- backends/p4tools/common/lib/symbolic_env.h | 4 +- backends/p4tools/common/lib/table_utils.cpp | 4 +- backends/p4tools/common/lib/table_utils.h | 4 +- backends/p4tools/common/lib/taint.cpp | 4 +- backends/p4tools/common/lib/taint.h | 4 +- backends/p4tools/common/lib/trace_event.cpp | 4 +- backends/p4tools/common/lib/trace_event.h | 4 +- .../p4tools/common/lib/trace_event_types.cpp | 4 +- .../p4tools/common/lib/trace_event_types.h | 4 +- backends/p4tools/common/lib/util.cpp | 4 +- backends/p4tools/common/lib/util.h | 4 +- backends/p4tools/common/lib/variables.cpp | 4 +- backends/p4tools/common/lib/variables.h | 4 +- backends/p4tools/common/options.cpp | 20 +- backends/p4tools/common/options.h | 4 +- backends/p4tools/common/p4ctool.h | 4 +- .../modules/smith/common/declarations.cpp | 4 +- .../modules/smith/common/declarations.h | 4 +- .../modules/smith/common/expressions.cpp | 4 +- .../modules/smith/common/expressions.h | 4 +- .../p4tools/modules/smith/common/generator.h | 4 +- .../p4tools/modules/smith/common/parser.cpp | 4 +- .../p4tools/modules/smith/common/parser.h | 4 +- .../p4tools/modules/smith/common/scope.cpp | 4 +- backends/p4tools/modules/smith/common/scope.h | 4 +- .../modules/smith/common/statements.cpp | 4 +- .../p4tools/modules/smith/common/statements.h | 4 +- .../p4tools/modules/smith/common/table.cpp | 4 +- backends/p4tools/modules/smith/common/table.h | 4 +- .../p4tools/modules/smith/core/target.cpp | 4 +- backends/p4tools/modules/smith/core/target.h | 4 +- backends/p4tools/modules/smith/main.cpp | 2 + backends/p4tools/modules/smith/options.cpp | 8 +- backends/p4tools/modules/smith/options.h | 4 +- backends/p4tools/modules/smith/register.h.in | 4 +- backends/p4tools/modules/smith/smith.cpp | 6 +- backends/p4tools/modules/smith/smith.h | 4 +- .../modules/smith/targets/bmv2/psa.cpp | 4 +- .../p4tools/modules/smith/targets/bmv2/psa.h | 4 +- .../modules/smith/targets/bmv2/register.h | 4 +- .../modules/smith/targets/bmv2/target.cpp | 4 +- .../modules/smith/targets/bmv2/target.h | 4 +- .../modules/smith/targets/bmv2/v1model.cpp | 4 +- .../modules/smith/targets/bmv2/v1model.h | 4 +- .../modules/smith/targets/generic/register.h | 4 +- .../modules/smith/targets/generic/target.cpp | 4 +- .../modules/smith/targets/generic/target.h | 4 +- .../generic/test/smith_for_in_loop_test.cpp | 4 +- .../generic/test/smith_for_loop_test.cpp | 4 +- .../modules/smith/targets/nic/register.h | 4 +- .../modules/smith/targets/nic/target.cpp | 4 +- .../modules/smith/targets/nic/target.h | 4 +- .../modules/smith/targets/tofino/register.h | 4 +- .../modules/smith/targets/tofino/target.cpp | 4 +- .../modules/smith/targets/tofino/target.h | 4 +- backends/p4tools/modules/smith/toolname.h | 4 +- backends/p4tools/modules/smith/util/util.cpp | 4 +- backends/p4tools/modules/smith/util/util.h | 4 +- .../p4tools/modules/smith/util/wordlist.cpp | 4 +- .../p4tools/modules/smith/util/wordlist.h | 4 +- .../modules/testgen/core/compiler_result.cpp | 4 +- .../modules/testgen/core/compiler_result.h | 4 +- .../modules/testgen/core/extern_info.h | 4 +- .../modules/testgen/core/program_info.cpp | 4 +- .../modules/testgen/core/program_info.h | 4 +- .../core/small_step/abstract_stepper.cpp | 4 +- .../core/small_step/abstract_stepper.h | 4 +- .../testgen/core/small_step/cmd_stepper.cpp | 4 +- .../testgen/core/small_step/cmd_stepper.h | 4 +- .../testgen/core/small_step/expr_stepper.cpp | 4 +- .../testgen/core/small_step/expr_stepper.h | 4 +- .../core/small_step/extern_stepper.cpp | 4 +- .../testgen/core/small_step/small_step.cpp | 6 +- .../testgen/core/small_step/small_step.h | 4 +- .../testgen/core/small_step/table_stepper.cpp | 4 +- .../testgen/core/small_step/table_stepper.h | 4 +- .../core/symbolic_executor/depth_first.cpp | 6 +- .../core/symbolic_executor/depth_first.h | 4 +- .../symbolic_executor/greedy_node_cov.cpp | 6 +- .../core/symbolic_executor/greedy_node_cov.h | 4 +- .../core/symbolic_executor/path_selection.h | 4 +- .../symbolic_executor/random_backtrack.cpp | 6 +- .../core/symbolic_executor/random_backtrack.h | 4 +- .../symbolic_executor/selected_branches.cpp | 10 +- .../symbolic_executor/selected_branches.h | 4 +- .../symbolic_executor/symbolic_executor.cpp | 10 +- .../symbolic_executor/symbolic_executor.h | 4 +- .../p4tools/modules/testgen/core/target.cpp | 4 +- .../p4tools/modules/testgen/core/target.h | 4 +- .../testgen/lib/collect_coverable_nodes.cpp | 4 +- .../testgen/lib/collect_coverable_nodes.h | 4 +- .../p4tools/modules/testgen/lib/concolic.cpp | 4 +- .../p4tools/modules/testgen/lib/concolic.h | 4 +- .../modules/testgen/lib/continuation.cpp | 4 +- .../modules/testgen/lib/continuation.h | 8 +- .../p4tools/modules/testgen/lib/exceptions.h | 4 +- .../modules/testgen/lib/execution_state.cpp | 4 +- .../modules/testgen/lib/execution_state.h | 4 +- .../modules/testgen/lib/final_state.cpp | 8 +- .../p4tools/modules/testgen/lib/final_state.h | 4 +- .../p4tools/modules/testgen/lib/logging.cpp | 10 +- .../p4tools/modules/testgen/lib/logging.h | 4 +- .../modules/testgen/lib/packet_vars.cpp | 4 +- .../p4tools/modules/testgen/lib/packet_vars.h | 4 +- .../modules/testgen/lib/test_backend.cpp | 4 +- .../modules/testgen/lib/test_backend.h | 4 +- .../testgen/lib/test_backend_configuration.h | 4 +- .../modules/testgen/lib/test_framework.cpp | 4 +- .../modules/testgen/lib/test_framework.h | 4 +- .../p4tools/modules/testgen/lib/test_object.h | 4 +- .../p4tools/modules/testgen/lib/test_spec.cpp | 4 +- .../p4tools/modules/testgen/lib/test_spec.h | 4 +- backends/p4tools/modules/testgen/main.cpp | 2 + backends/p4tools/modules/testgen/options.cpp | 37 +-- backends/p4tools/modules/testgen/options.h | 4 +- .../p4tools/modules/testgen/register.h.in | 4 +- .../testgen/targets/bmv2/cmd_stepper.cpp | 6 +- .../testgen/targets/bmv2/cmd_stepper.h | 4 +- .../testgen/targets/bmv2/compiler_result.cpp | 4 +- .../testgen/targets/bmv2/compiler_result.h | 4 +- .../modules/testgen/targets/bmv2/concolic.cpp | 4 +- .../modules/testgen/targets/bmv2/concolic.h | 4 +- .../testgen/targets/bmv2/constants.cpp | 2 +- .../modules/testgen/targets/bmv2/constants.h | 4 +- .../testgen/targets/bmv2/expr_stepper.cpp | 24 +- .../testgen/targets/bmv2/expr_stepper.h | 4 +- .../targets/bmv2/map_direct_externs.cpp | 12 +- .../testgen/targets/bmv2/map_direct_externs.h | 4 +- .../targets/bmv2/p4_asserts_parser.cpp | 8 +- .../testgen/targets/bmv2/p4_asserts_parser.h | 4 +- .../targets/bmv2/p4_refers_to_parser.cpp | 4 +- .../targets/bmv2/p4_refers_to_parser.h | 4 +- .../targets/bmv2/p4runtime_translation.cpp | 6 +- .../targets/bmv2/p4runtime_translation.h | 4 +- .../testgen/targets/bmv2/program_info.cpp | 4 +- .../testgen/targets/bmv2/program_info.h | 4 +- .../modules/testgen/targets/bmv2/register.h | 4 +- .../testgen/targets/bmv2/table_stepper.cpp | 12 +- .../testgen/targets/bmv2/table_stepper.h | 4 +- .../modules/testgen/targets/bmv2/target.cpp | 16 +- .../modules/testgen/targets/bmv2/target.h | 4 +- .../targets/bmv2/test/small-step/binary.cpp | 4 +- .../small-step/p4_asserts_parser_test.cpp | 4 +- .../bmv2/test/small-step/reachability.cpp | 4 +- .../targets/bmv2/test/small-step/unary.cpp | 4 +- .../targets/bmv2/test/small-step/value.cpp | 4 +- .../targets/bmv2/test/test_backend/ptf.cpp | 4 +- .../targets/bmv2/test/test_backend/ptf.h | 4 +- .../targets/bmv2/test/test_backend/stf.cpp | 4 +- .../targets/bmv2/test/test_backend/stf.h | 4 +- .../bmv2/test/testgen_api/api_test.cpp | 4 +- .../bmv2/test/testgen_api/benchmark.cpp | 4 +- .../testgen_api/control_plane_filter_test.cpp | 4 +- .../test/testgen_api/output_option_test.cpp | 4 +- .../transformations/saturation_arithm.cpp | 4 +- .../bmv2/test/z3-solver/asrt_model.cpp | 4 +- .../bmv2/test/z3-solver/expressions.cpp | 4 +- .../testgen/targets/bmv2/test_backend.cpp | 6 +- .../testgen/targets/bmv2/test_backend.h | 4 +- .../targets/bmv2/test_backend/common.cpp | 4 +- .../targets/bmv2/test_backend/common.h | 4 +- .../targets/bmv2/test_backend/metadata.cpp | 4 +- .../targets/bmv2/test_backend/metadata.h | 4 +- .../targets/bmv2/test_backend/protobuf.cpp | 4 +- .../targets/bmv2/test_backend/protobuf.h | 4 +- .../targets/bmv2/test_backend/protobuf_ir.cpp | 4 +- .../targets/bmv2/test_backend/protobuf_ir.h | 4 +- .../testgen/targets/bmv2/test_backend/ptf.cpp | 4 +- .../testgen/targets/bmv2/test_backend/ptf.h | 4 +- .../testgen/targets/bmv2/test_backend/stf.cpp | 4 +- .../testgen/targets/bmv2/test_backend/stf.h | 4 +- .../testgen/targets/bmv2/test_spec.cpp | 4 +- .../modules/testgen/targets/bmv2/test_spec.h | 4 +- .../testgen/targets/ebpf/backend/stf/stf.cpp | 4 +- .../testgen/targets/ebpf/backend/stf/stf.h | 4 +- .../testgen/targets/ebpf/cmd_stepper.cpp | 4 +- .../testgen/targets/ebpf/cmd_stepper.h | 4 +- .../modules/testgen/targets/ebpf/concolic.cpp | 4 +- .../modules/testgen/targets/ebpf/concolic.h | 4 +- .../testgen/targets/ebpf/constants.cpp | 4 +- .../modules/testgen/targets/ebpf/constants.h | 4 +- .../testgen/targets/ebpf/expr_stepper.cpp | 8 +- .../testgen/targets/ebpf/expr_stepper.h | 4 +- .../testgen/targets/ebpf/program_info.cpp | 4 +- .../testgen/targets/ebpf/program_info.h | 4 +- .../modules/testgen/targets/ebpf/register.h | 4 +- .../testgen/targets/ebpf/table_stepper.cpp | 6 +- .../testgen/targets/ebpf/table_stepper.h | 4 +- .../modules/testgen/targets/ebpf/target.cpp | 8 +- .../modules/testgen/targets/ebpf/target.h | 4 +- .../testgen/targets/ebpf/test_backend.cpp | 6 +- .../testgen/targets/ebpf/test_backend.h | 4 +- .../testgen/targets/ebpf/test_spec.cpp | 2 +- .../modules/testgen/targets/ebpf/test_spec.h | 2 +- .../targets/pna/backend/metadata/metadata.cpp | 4 +- .../targets/pna/backend/metadata/metadata.h | 4 +- .../testgen/targets/pna/backend/ptf/ptf.cpp | 4 +- .../testgen/targets/pna/backend/ptf/ptf.h | 4 +- .../modules/testgen/targets/pna/concolic.cpp | 4 +- .../modules/testgen/targets/pna/concolic.h | 4 +- .../modules/testgen/targets/pna/constants.cpp | 4 +- .../modules/testgen/targets/pna/constants.h | 4 +- .../testgen/targets/pna/dpdk/cmd_stepper.cpp | 4 +- .../testgen/targets/pna/dpdk/cmd_stepper.h | 4 +- .../testgen/targets/pna/dpdk/expr_stepper.cpp | 4 +- .../testgen/targets/pna/dpdk/expr_stepper.h | 4 +- .../testgen/targets/pna/dpdk/program_info.cpp | 4 +- .../testgen/targets/pna/dpdk/program_info.h | 4 +- .../targets/pna/dpdk/table_stepper.cpp | 4 +- .../testgen/targets/pna/dpdk/table_stepper.h | 4 +- .../modules/testgen/targets/pna/register.h | 4 +- .../targets/pna/shared_cmd_stepper.cpp | 4 +- .../testgen/targets/pna/shared_cmd_stepper.h | 4 +- .../targets/pna/shared_expr_stepper.cpp | 4 +- .../testgen/targets/pna/shared_expr_stepper.h | 4 +- .../targets/pna/shared_program_info.cpp | 4 +- .../testgen/targets/pna/shared_program_info.h | 4 +- .../targets/pna/shared_table_stepper.cpp | 12 +- .../targets/pna/shared_table_stepper.h | 4 +- .../modules/testgen/targets/pna/target.cpp | 4 +- .../modules/testgen/targets/pna/target.h | 4 +- .../testgen/targets/pna/test_backend.cpp | 6 +- .../testgen/targets/pna/test_backend.h | 4 +- .../modules/testgen/targets/pna/test_spec.cpp | 4 +- .../modules/testgen/targets/pna/test_spec.h | 4 +- .../modules/testgen/test/gtest_utils.cpp | 4 +- .../modules/testgen/test/gtest_utils.h | 4 +- .../modules/testgen/test/lib/format_int.cpp | 4 +- .../modules/testgen/test/lib/format_int.h | 4 +- .../modules/testgen/test/lib/p4info_api.cpp | 4 +- .../modules/testgen/test/lib/p4info_api.h | 4 +- .../modules/testgen/test/lib/taint.cpp | 4 +- .../p4tools/modules/testgen/test/lib/taint.h | 4 +- .../modules/testgen/test/small-step/util.cpp | 4 +- .../modules/testgen/test/small-step/util.h | 4 +- .../modules/testgen/test/z3-solver/accessor.h | 4 +- .../testgen/test/z3-solver/constraints.cpp | 4 +- backends/p4tools/modules/testgen/testgen.cpp | 30 +-- backends/p4tools/modules/testgen/testgen.h | 4 +- backends/p4tools/modules/testgen/toolname.h | 4 +- backends/tc/backend.cpp | 175 ++++++------- backends/tc/backend.h | 4 +- backends/tc/ebpfCodeGen.cpp | 122 +++++----- backends/tc/ebpfCodeGen.h | 10 +- backends/tc/introspection.cpp | 16 +- backends/tc/introspection.h | 4 +- backends/tc/midend.cpp | 6 +- backends/tc/midend.h | 4 +- backends/tc/options.h | 4 +- backends/tc/pnaProgramStructure.cpp | 14 +- backends/tc/pnaProgramStructure.h | 10 +- backends/tc/tc.cpp | 20 +- backends/tc/tcAnnotations.cpp | 4 +- backends/tc/tcAnnotations.h | 4 +- backends/tc/tcExterns.cpp | 34 +-- backends/tc/tcExterns.h | 16 +- backends/tc/tc_defines.h | 4 +- backends/ubpf/codeGen.h | 4 +- backends/ubpf/midend.cpp | 6 +- backends/ubpf/midend.h | 4 +- backends/ubpf/p4c-ubpf.cpp | 16 +- backends/ubpf/target.cpp | 4 +- backends/ubpf/target.h | 4 +- backends/ubpf/ubpfBackend.cpp | 13 +- backends/ubpf/ubpfBackend.h | 4 +- backends/ubpf/ubpfControl.cpp | 34 +-- backends/ubpf/ubpfControl.h | 8 +- backends/ubpf/ubpfDeparser.cpp | 30 +-- backends/ubpf/ubpfDeparser.h | 10 +- backends/ubpf/ubpfHelpers.h | 4 +- backends/ubpf/ubpfModel.cpp | 4 +- backends/ubpf/ubpfModel.h | 54 ++-- backends/ubpf/ubpfParser.cpp | 26 +- backends/ubpf/ubpfParser.h | 4 +- backends/ubpf/ubpfProgram.cpp | 16 +- backends/ubpf/ubpfProgram.h | 4 +- backends/ubpf/ubpfRegister.cpp | 4 +- backends/ubpf/ubpfRegister.h | 4 +- backends/ubpf/ubpfTable.cpp | 43 ++-- backends/ubpf/ubpfTable.h | 4 +- backends/ubpf/ubpfType.cpp | 14 +- backends/ubpf/ubpfType.h | 4 +- bazel/example/main.cc | 2 +- control-plane/bfruntime.cpp | 55 +++-- control-plane/bfruntime.h | 2 +- control-plane/bytestrings.cpp | 2 +- control-plane/bytestrings.h | 4 +- control-plane/p4RuntimeArchHandler.cpp | 44 ++-- control-plane/p4RuntimeArchHandler.h | 26 +- control-plane/p4RuntimeArchStandard.cpp | 20 +- control-plane/p4RuntimeArchStandard.h | 99 ++++---- control-plane/p4RuntimeSerializer.cpp | 224 +++++++++-------- control-plane/p4RuntimeSerializer.h | 6 +- control-plane/p4RuntimeSymbolTable.cpp | 10 +- control-plane/p4RuntimeSymbolTable.h | 4 +- control-plane/p4infoApi.cpp | 2 +- control-plane/typeSpecConverter.cpp | 15 +- docs/README.md | 2 +- frontends/common/applyOptionsPragmas.cpp | 14 +- frontends/common/constantFolding.cpp | 141 ++++++----- frontends/common/constantParsing.cpp | 13 +- frontends/common/constantParsing.h | 12 +- frontends/common/copySrcInfo.h | 4 +- frontends/common/model.h | 4 +- frontends/common/name_gateways.h | 4 + frontends/common/options.cpp | 18 +- frontends/common/options.h | 5 + frontends/common/parseInput.cpp | 6 +- frontends/common/parseInput.h | 18 +- frontends/common/parser_options.cpp | 39 +-- frontends/common/parser_options.h | 13 +- .../resolveReferences/resolveReferences.cpp | 46 ++-- frontends/p4-14/header_type.cpp | 4 + frontends/p4-14/header_type.h | 4 + frontends/p4-14/inline_control_flow.h | 4 + frontends/p4-14/typecheck.cpp | 7 +- frontends/p4-14/typecheck.h | 4 + frontends/p4/actionsInlining.cpp | 12 +- frontends/p4/actionsInlining.h | 4 +- frontends/p4/alias.h | 32 +-- frontends/p4/callGraph.h | 4 +- frontends/p4/checkConstants.cpp | 2 +- frontends/p4/checkNamedArgs.cpp | 20 +- frontends/p4/commonInlining.h | 2 +- frontends/p4/coreLibrary.h | 19 +- frontends/p4/createBuiltins.cpp | 28 +-- frontends/p4/def_use.cpp | 12 +- frontends/p4/def_use.h | 12 +- frontends/p4/defaultValues.cpp | 2 +- frontends/p4/deprecated.cpp | 4 +- frontends/p4/dontcareArgs.cpp | 2 +- frontends/p4/entryPriorities.cpp | 23 +- frontends/p4/evaluator/evaluator.cpp | 4 +- frontends/p4/externInstance.h | 4 +- frontends/p4/fromv1.0/converters.cpp | 32 +-- frontends/p4/fromv1.0/converters.h | 56 ++--- frontends/p4/fromv1.0/programStructure.cpp | 168 +++++++------ frontends/p4/fromv1.0/programStructure.h | 10 +- frontends/p4/fromv1.0/v1model.h | 194 +++++++-------- frontends/p4/functionsInlining.cpp | 4 +- frontends/p4/inlining.cpp | 50 ++-- frontends/p4/inlining.h | 4 +- frontends/p4/localizeActions.cpp | 4 +- frontends/p4/localizeActions.h | 2 +- frontends/p4/modelInstances.cpp | 4 +- frontends/p4/optimizeExpressions.h | 2 +- frontends/p4/parameterSubstitution.cpp | 2 +- frontends/p4/parseAnnotations.cpp | 2 +- frontends/p4/removeParameters.cpp | 4 +- frontends/p4/removeParameters.h | 6 +- frontends/p4/resetHeaders.cpp | 4 +- frontends/p4/sideEffects.cpp | 2 +- frontends/p4/sideEffects.h | 4 +- frontends/p4/simplifyDefUse.cpp | 12 +- frontends/p4/simplifyParsers.cpp | 9 +- frontends/p4/specialize.h | 2 +- frontends/p4/specializeGenericFunctions.h | 2 +- frontends/p4/specializeGenericTypes.cpp | 8 +- frontends/p4/staticAssert.h | 10 +- frontends/p4/strengthReduction.cpp | 6 +- frontends/p4/symbol_table.cpp | 16 +- frontends/p4/symbol_table.h | 4 +- frontends/p4/tableKeyNames.cpp | 4 +- frontends/p4/tableKeyNames.h | 2 +- frontends/p4/typeChecking/bindVariables.cpp | 6 +- .../typeChecking/constantTypeSubstitution.h | 2 +- frontends/p4/typeChecking/typeCheckDecl.cpp | 2 +- frontends/p4/typeChecking/typeCheckExpr.cpp | 12 +- frontends/p4/typeChecking/typeCheckTypes.cpp | 9 +- frontends/p4/typeChecking/typeChecker.cpp | 18 +- frontends/p4/typeChecking/typeChecker.h | 2 +- frontends/p4/typeChecking/typeConstraints.cpp | 12 +- frontends/p4/typeChecking/typeConstraints.h | 6 +- .../p4/typeChecking/typeSubstitution.cpp | 7 +- frontends/p4/typeChecking/typeSubstitution.h | 4 +- .../p4/typeChecking/typeSubstitutionVisitor.h | 1 + frontends/p4/typeMap.cpp | 14 +- frontends/p4/uniqueNames.cpp | 2 +- frontends/p4/validateMatchAnnotations.h | 6 +- frontends/p4/validateParsedProgram.cpp | 118 ++++----- frontends/p4/validateParsedProgram.h | 2 +- frontends/p4/validateValueSets.h | 4 +- frontends/parsers/p4/p4lexer.ll | 2 + frontends/parsers/p4/p4parser.ypp | 22 +- frontends/parsers/parserDriver.cpp | 10 +- frontends/parsers/parserDriver.h | 4 +- frontends/parsers/v1/v1lexer.ll | 2 + frontends/parsers/v1/v1lexer_internal.hpp | 4 +- frontends/parsers/v1/v1parser.ypp | 49 ++-- ir/base.cpp | 8 +- ir/bitrange.cpp | 4 +- ir/compare.h | 5 +- ir/configuration.h | 4 + ir/dbprint-expression.cpp | 4 + ir/dbprint-p4.cpp | 4 + ir/dbprint-stmt.cpp | 4 + ir/dbprint-type.cpp | 4 + ir/dbprint.cpp | 6 +- ir/dbprint.h | 4 +- ir/declaration.h | 4 +- ir/dump.cpp | 4 + ir/dump.h | 4 + ir/expression.cpp | 15 +- ir/expression.def | 10 +- ir/id.h | 8 +- ir/indexed_vector.h | 8 +- ir/ir-inline.h | 8 +- ir/ir-tree-macros.h | 2 +- ir/ir.cpp | 35 +-- ir/ir.def | 8 +- ir/irutils.cpp | 10 +- ir/irutils.h | 4 +- ir/json_generator.h | 4 + ir/json_loader.h | 12 +- ir/json_parser.cpp | 4 + ir/json_parser.h | 4 + ir/loop-visitor.cpp | 4 + ir/namemap.h | 10 +- ir/node.cpp | 4 + ir/node.h | 18 +- ir/nodemap.h | 4 +- ir/pass_manager.cpp | 13 +- ir/pass_manager.h | 4 + ir/pattern.h | 4 + ir/solver.h | 4 + ir/type.cpp | 14 +- ir/type.def | 4 + ir/v1.cpp | 4 + ir/v1.def | 6 +- ir/vector.h | 9 +- ir/visitor.cpp | 18 +- ir/visitor.h | 8 +- ir/write_context.cpp | 4 + lib/algorithm.h | 3 + lib/alloc_trace.cpp | 4 + lib/alloc_trace.h | 4 + lib/backtrace_exception.cpp | 29 ++- lib/backtrace_exception.h | 4 + lib/big_int.h | 4 + lib/big_int_fwd.h | 4 + lib/big_int_util.cpp | 8 +- lib/big_int_util.h | 8 +- lib/bitops.h | 4 + lib/bitrange.cpp | 4 + lib/bitrange.h | 24 +- lib/bitvec.cpp | 4 + lib/bitvec.h | 3 + lib/bug_helper.h | 3 + lib/castable.h | 4 + lib/compile_context.cpp | 4 + lib/compile_context.h | 10 +- lib/crash.cpp | 13 +- lib/crash.h | 4 + lib/cstring.cpp | 3 + lib/cstring.h | 15 +- lib/enumerator.h | 5 +- lib/error.h | 10 +- lib/error_catalog.cpp | 4 + lib/error_catalog.h | 4 + lib/error_helper.h | 9 +- lib/error_message.cpp | 4 + lib/error_message.h | 10 +- lib/error_reporter.h | 22 +- lib/exceptions.h | 24 +- lib/exename.cpp | 4 + lib/exename.h | 4 + lib/gc.cpp | 2 + lib/gc.h | 3 +- lib/hash.cpp | 4 +- lib/hash.h | 8 +- lib/hashvec.cpp | 10 +- lib/hashvec.h | 4 + lib/hex.cpp | 4 + lib/hex.h | 4 + lib/hvec_map.h | 4 + lib/hvec_set.h | 4 + lib/indent.cpp | 4 + lib/indent.h | 5 +- lib/iterator_range.h | 4 +- lib/json.cpp | 4 +- lib/json.h | 10 +- lib/log.cpp | 2 + lib/log.h | 38 +-- lib/ltbitmatrix.h | 4 + lib/map.h | 4 + lib/match.cpp | 4 + lib/match.h | 4 + lib/n4.h | 4 + lib/nethash.cpp | 4 +- lib/nethash.h | 4 +- lib/nullstream.cpp | 9 +- lib/nullstream.h | 4 + lib/options.cpp | 13 +- lib/options.h | 4 +- lib/ordered_map.h | 4 + lib/ordered_set.h | 4 + lib/range.h | 4 + lib/rtti.h | 52 ++-- lib/rtti_utils.h | 4 +- lib/safe_vector.h | 4 + lib/set.h | 3 + lib/sourceCodeBuilder.h | 4 +- lib/source_file.cpp | 12 +- lib/source_file.h | 10 +- lib/string_map.h | 4 + lib/stringify.cpp | 4 +- lib/stringify.h | 4 + lib/stringref.h | 4 + lib/symbitmatrix.h | 4 + lib/timer.cpp | 4 +- lib/timer.h | 4 +- midend/checkExternInvocationCommon.h | 8 +- midend/compileTimeOps.h | 4 +- midend/convertEnums.cpp | 4 +- midend/convertEnums.h | 2 +- midend/convertErrors.cpp | 4 +- midend/copyStructures.cpp | 8 +- midend/def_use.cpp | 8 + midend/eliminateInvalidHeaders.cpp | 4 +- midend/eliminateSwitch.cpp | 8 +- midend/expandEmit.cpp | 3 +- midend/expandLookahead.cpp | 2 +- midend/expr_uses.h | 4 + midend/flattenHeaders.cpp | 7 +- midend/flattenHeaders.h | 2 +- midend/flattenInterfaceStructs.cpp | 10 +- midend/flattenInterfaceStructs.h | 6 +- midend/flattenLogMsg.h | 4 +- midend/flattenUnions.cpp | 11 +- midend/has_side_effects.h | 4 + midend/interpreter.cpp | 2 +- midend/interpreter.h | 6 +- midend/local_copyprop.cpp | 12 +- midend/local_copyprop.h | 2 +- midend/nestedStructs.cpp | 7 +- midend/nestedStructs.h | 6 +- midend/noMatch.cpp | 10 +- midend/parserUnroll.cpp | 35 +-- midend/parserUnroll.h | 2 +- midend/predication.cpp | 7 +- midend/predication.h | 5 +- midend/replaceSelectRange.cpp | 16 +- midend/replaceSelectRange.h | 1 + midend/simplifyKey.cpp | 2 +- midend/simplifySelectCases.cpp | 2 +- midend/singleArgumentSelect.cpp | 5 +- midend/unrollLoops.cpp | 4 + test/gtest/arch_test.cpp | 36 +-- test/gtest/bitrange.cpp | 8 +- test/gtest/bitvec_test.cpp | 4 +- test/gtest/call_graph_test.cpp | 4 +- test/gtest/complex_bitwise.cpp | 4 +- test/gtest/constant_expr_test.cpp | 4 +- test/gtest/constant_folding.cpp | 6 +- test/gtest/cstring.cpp | 4 +- test/gtest/diagnostics.cpp | 64 ++--- test/gtest/dumpjson.cpp | 2 + test/gtest/enumerator_test.cpp | 4 +- test/gtest/equiv_test.cpp | 1 + test/gtest/exception_test.cpp | 4 +- test/gtest/expr_uses_test.cpp | 1 + test/gtest/format_test.cpp | 4 +- test/gtest/frontend_test.cpp | 24 +- test/gtest/gtestp4c.cpp | 2 + test/gtest/hash.cpp | 4 +- test/gtest/helpers.cpp | 30 ++- test/gtest/helpers.h | 18 +- test/gtest/hvec_map.cpp | 4 +- test/gtest/hvec_set.cpp | 4 +- test/gtest/indexed_vector.cpp | 6 +- test/gtest/json_test.cpp | 4 +- test/gtest/load_ir_from_json.cpp | 4 +- test/gtest/map.cpp | 4 +- test/gtest/midend_def_use.cpp | 6 +- test/gtest/midend_pass.cpp | 4 +- test/gtest/midend_pass.h | 6 +- test/gtest/midend_test.cpp | 14 +- test/gtest/nethash.cpp | 6 +- test/gtest/opeq_test.cpp | 2 + test/gtest/ordered_map.cpp | 4 +- test/gtest/ordered_set.cpp | 4 +- test/gtest/p4runtime.cpp | 76 +++--- test/gtest/parser_unroll.cpp | 15 +- test/gtest/remove_dontcare_args_test.cpp | 8 +- test/gtest/rtti_test.cpp | 4 +- test/gtest/source_file_test.cpp | 4 +- test/gtest/strength_reduction.cpp | 4 +- test/gtest/string_map.cpp | 4 +- test/gtest/transforms.cpp | 4 +- test/gtest/visitor.cpp | 4 +- testdata/p4_14_errors/issue747.p4 | 2 +- tools/ir-generator/generator.cpp | 2 + tools/ir-generator/ir-generator.h | 4 + tools/ir-generator/ir-generator.ypp | 9 +- tools/ir-generator/irclass.cpp | 17 +- tools/ir-generator/irclass.h | 8 +- tools/ir-generator/methods.cpp | 4 + tools/ir-generator/type.cpp | 6 +- tools/ir-generator/type.h | 4 + 811 files changed, 4642 insertions(+), 3899 deletions(-) diff --git a/backends/bmv2/common/JsonObjects.cpp b/backends/bmv2/common/JsonObjects.cpp index 8f0c741e3c..2bb140a190 100644 --- a/backends/bmv2/common/JsonObjects.cpp +++ b/backends/bmv2/common/JsonObjects.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "helpers.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { const int JSON_MAJOR_VERSION = 2; const int JSON_MINOR_VERSION = 23; @@ -387,4 +387,4 @@ void JsonObjects::add_extern(const cstring &name, const cstring &type, externs->append(extn); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/JsonObjects.h b/backends/bmv2/common/JsonObjects.h index 212a68e85c..054a09f755 100644 --- a/backends/bmv2/common/JsonObjects.h +++ b/backends/bmv2/common/JsonObjects.h @@ -22,7 +22,7 @@ limitations under the License. #include "lib/json.h" #include "lib/ordered_map.h" -namespace BMV2 { +namespace P4::BMV2 { class JsonObjects { public: @@ -227,6 +227,6 @@ class JsonObjects { Util::JsonArray *field_aliases; }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_JSONOBJECTS_H_ */ diff --git a/backends/bmv2/common/action.cpp b/backends/bmv2/common/action.cpp index fb1d0a3769..62bdb5ddf1 100644 --- a/backends/bmv2/common/action.cpp +++ b/backends/bmv2/common/action.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "extern.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -181,7 +181,7 @@ void ActionConverter::convertActionBody(const IR::Vector *body, continue; } } - ::error(ErrorType::ERR_UNSUPPORTED, "%1% not yet supported on this target", s); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% not yet supported on this target", s); } } @@ -197,8 +197,8 @@ void ActionConverter::convertActionParams(const IR::ParameterList *parameters, // TODO: added IR::Type_Enum here to support PSA_MeterColor_t // should re-consider how to support action parameters that is neither bit<> nor int<> if (!(type->is() || type->is())) - ::error(ErrorType::ERR_INVALID, - "%1%: action parameters must be bit<> or int<> on this target", p); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: action parameters must be bit<> or int<> on this target", p); param->emplace("bitwidth", type->width_bits()); params->append(param); } @@ -215,4 +215,4 @@ void ActionConverter::postorder(const IR::P4Action *action) { ctxt->structure->ids.emplace(action, id); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/action.h b/backends/bmv2/common/action.h index d01a933e19..12a0756d37 100644 --- a/backends/bmv2/common/action.h +++ b/backends/bmv2/common/action.h @@ -20,7 +20,7 @@ limitations under the License. #include "helpers.h" #include "ir/ir.h" -namespace BMV2 { +namespace P4::BMV2 { class ActionConverter : public Inspector { ConversionContext *ctxt; @@ -38,6 +38,6 @@ class ActionConverter : public Inspector { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_ACTION_H_ */ diff --git a/backends/bmv2/common/annotations.h b/backends/bmv2/common/annotations.h index f2354d8268..288076ed73 100644 --- a/backends/bmv2/common/annotations.h +++ b/backends/bmv2/common/annotations.h @@ -20,7 +20,7 @@ limitations under the License. #include "frontends/p4/parseAnnotations.h" #include "ir/ir.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -39,6 +39,6 @@ class ParseAnnotations : public P4::ParseAnnotations { }) {} }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_ANNOTATIONS_H_ */ diff --git a/backends/bmv2/common/backend.h b/backends/bmv2/common/backend.h index 2723069e7d..2b2c583bc2 100644 --- a/backends/bmv2/common/backend.h +++ b/backends/bmv2/common/backend.h @@ -38,7 +38,7 @@ limitations under the License. #include "options.h" #include "sharedActionSelectorCheck.h" -namespace BMV2 { +namespace P4::BMV2 { enum gress_t { INGRESS, EGRESS }; enum block_t { @@ -194,6 +194,6 @@ class RenameUserMetadata : public Transform { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_BACKEND_H_ */ diff --git a/backends/bmv2/common/check_unsupported.h b/backends/bmv2/common/check_unsupported.h index f8601dc8e5..2cc6881488 100644 --- a/backends/bmv2/common/check_unsupported.h +++ b/backends/bmv2/common/check_unsupported.h @@ -22,7 +22,7 @@ limitations under the License. #include "lower.h" #include "midend/convertEnums.h" -namespace BMV2 { +namespace P4::BMV2 { class CheckUnsupported : public Inspector { bool preorder(const IR::ForStatement *fs) override { @@ -35,6 +35,6 @@ class CheckUnsupported : public Inspector { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_CHECK_UNSUPPORTED_H_ */ diff --git a/backends/bmv2/common/control.h b/backends/bmv2/common/control.h index b6af2178aa..d9a8d196a6 100644 --- a/backends/bmv2/common/control.h +++ b/backends/bmv2/common/control.h @@ -31,7 +31,7 @@ limitations under the License. #include "midend/convertEnums.h" #include "sharedActionSelectorCheck.h" -namespace BMV2 { +namespace P4::BMV2 { static constexpr unsigned INVALID_ACTION_ID = 0xffffffff; @@ -63,10 +63,10 @@ class ControlConverter : public Inspector { auto ket = ctxt->typeMap->getType(expr, true); if (!ket->is() && !ket->is() && !ket->is()) - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: unsupporded key type %2%. " - "Supported key types are be bit<> or boolean, or error.", - expr, ket); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupporded key type %2%. " + "Supported key types are be bit<> or boolean, or error.", + expr, ket); auto match_type = getKeyMatchType(ke); if (match_type == BMV2::MatchImplementation::selectorMatchTypeName) continue; @@ -78,8 +78,8 @@ class ControlConverter : public Inspector { // 4) otherwise the table is EXACT if (match_type == corelib.lpmMatch.name) count_lpm++; if (count_lpm > 1) - ::error(ErrorType::ERR_UNSUPPORTED, - "multiple LPM keys in table %1% not supported", table); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "multiple LPM keys in table %1% not supported", table); if (match_type != table_match_type) { if (match_type == BMV2::MatchImplementation::rangeMatchTypeName) table_match_type = BMV2::MatchImplementation::rangeMatchTypeName; @@ -101,7 +101,7 @@ class ControlConverter : public Inspector { mask = mexp->left->to()->value; expr = mexp->right; } else { - ::error(ErrorType::ERR_EXPECTED, "%1% must be a constant", expr); + ::P4::error(ErrorType::ERR_EXPECTED, "%1% must be a constant", expr); } } else if (auto slice = expr->to()) { expr = slice->e0; @@ -152,13 +152,13 @@ class ControlConverter : public Inspector { if (sz->value->is()) { auto expr = sz->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1% must be a constant", sz); + ::P4::error(ErrorType::ERR_EXPECTED, "%1% must be a constant", sz); size = 0; } else { size = expr->to()->asInt(); } } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a number", sz); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a number", sz); } } if (auto entries = table->getEntries()) { @@ -178,18 +178,18 @@ class ControlConverter : public Inspector { auto type = ctxt->typeMap->getType(expr, true); if (type == nullptr) return result; if (!type->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: Unexpected type %2% for property. " - "Must be extern.", - ctrs, type); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: Unexpected type %2% for property. " + "Must be extern.", + ctrs, type); return result; } auto te = type->to(); if (te->name != "direct_counter" && te->name != "counter") { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: Unexpected type %2% for property. " - "Must be 'counter' or 'direct_counter'.", - ctrs, type); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: Unexpected type %2% for property. " + "Must be 'counter' or 'direct_counter'.", + ctrs, type); return result; } auto jctr = new Util::JsonObject(); @@ -207,23 +207,23 @@ class ControlConverter : public Inspector { auto pe = expr->to(); auto decl = ctxt->refMap->getDeclaration(pe->path, true); if (!decl->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an instance", - decl->getNode()); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an instance", + decl->getNode()); return result; } cstring ctrname = decl->controlPlaneName(); auto it = ctxt->structure->directCounterMap.find(ctrname); LOG3("Looking up " << ctrname); if (it != ctxt->structure->directCounterMap.end()) { - ::error(ErrorType::ERR_INVALID, - "%1%: Direct counters cannot be attached to multiple tables" - " %2% and %3%", - decl, it->second, table); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Direct counters cannot be attached to multiple tables" + " %2% and %3%", + decl, it->second, table); return result; } ctxt->structure->directCounterMap.emplace(ctrname, table); } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a counter", ctrs); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a counter", ctrs); } } result->emplace("with_counters", true); @@ -237,12 +237,12 @@ class ControlConverter : public Inspector { if (timeout->value->is()) { auto expr = timeout->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: must true/false", timeout); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: must true/false", timeout); } else { sup_to = expr->to()->value; } } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a Boolean", timeout); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a Boolean", timeout); } } result->emplace("support_timeout", sup_to); @@ -252,8 +252,8 @@ class ControlConverter : public Inspector { if (dm->value->is()) { auto expr = dm->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected a reference to a meter declaration", expr); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected a reference to a meter declaration", expr); } else { auto pe = expr->to(); auto decl = ctxt->refMap->getDeclaration(pe->path, true); @@ -262,19 +262,19 @@ class ControlConverter : public Inspector { if (type->is()) type = type->to()->baseType; if (!type->is()) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: Unexpected type %2% for property", - dm, type); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: Unexpected type %2% for property", dm, type); return result; } auto te = type->to(); if (te->name != "direct_meter") { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: Unexpected type %2% for property", - dm, type); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: Unexpected type %2% for property", dm, type); return result; } if (!decl->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an instance", - decl->getNode()); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an instance", + decl->getNode()); return result; } ctxt->structure->directMeterMap.setTable(decl, table); @@ -285,7 +285,7 @@ class ControlConverter : public Inspector { result->emplace("direct_meters", name); } } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a meter", dm); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a meter", dm); } } else { result->emplace("direct_meters", Util::JsonValue::null); @@ -300,8 +300,8 @@ class ControlConverter : public Inspector { if (a->expression->is()) { auto mce = a->expression->to(); if (mce->arguments->size() > 0) - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: actions in action list with arguments not supported", a); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: actions in action list with arguments not supported", a); } auto decl = ctxt->refMap->getDeclaration(a->getPath(), true); BUG_CHECK(decl->is(), "%1%: should be an action name", a); @@ -357,7 +357,7 @@ class ControlConverter : public Inspector { } else { label = s->label; if (label == "default") continue; - label = ::get(useActionName, label); + label = ::P4::get(useActionName, label); } next_tables->emplace(label, nodeName(s->endpoint)); labelsDone.emplace(label); @@ -368,7 +368,7 @@ class ControlConverter : public Inspector { if (!hitMiss) { for (auto a : al->actionList) { cstring name = a->getName().name; - cstring label = ::get(useActionName, name); + cstring label = ::P4::get(useActionName, name); if (labelsDone.find(label) == labelsDone.end()) next_tables->emplace(label, nextLabel); } @@ -379,14 +379,15 @@ class ControlConverter : public Inspector { table->properties->getProperty(IR::TableProperties::defaultActionPropertyName); if (defact != nullptr) { if (!simple) { - ::warning(ErrorType::WARN_UNSUPPORTED, - "Target does not support default_action for %1% (due to action profiles)", - table); + ::P4::warning( + ErrorType::WARN_UNSUPPORTED, + "Target does not support default_action for %1% (due to action profiles)", + table); return result; } if (!defact->value->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an action", defact); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an action", defact); return result; } auto expr = defact->value->to()->expression; @@ -421,8 +422,8 @@ class ControlConverter : public Inspector { cstring repr = stringRepr(a->expression->to()->value); fields->append(repr); } else { - ::error(ErrorType::ERR_EXPECTED, - "%1%: argument must evaluate to a constant integer", a); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: argument must evaluate to a constant integer", a); return result; } } @@ -474,8 +475,8 @@ class ControlConverter : public Inspector { key->emplace("key", stringRepr(k->to()->value ? 1 : 0, k8)); else - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: unsupported exact key expression", - k); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupported exact key expression", k); } else if (matchType == corelib.ternaryMatch.name) { if (k->is()) { auto km = k->to(); @@ -488,8 +489,8 @@ class ControlConverter : public Inspector { key->emplace("key", stringRepr(0, k8)); key->emplace("mask", stringRepr(0, k8)); } else { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: unsupported ternary key expression", k); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupported ternary key expression", k); } } else if (matchType == corelib.lpmMatch.name) { if (k->is()) { @@ -505,7 +506,7 @@ class ControlConverter : public Inspector { static_cast(km->right->to()->value); auto len = trailing_zeros(mask, keyWidth); if (len + count_ones(mask) != keyWidth) // any remaining 0s in the prefix? - ::error(ErrorType::ERR_INVALID, "%1%: invalid mask for LPM key", k); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid mask for LPM key", k); else key->emplace("prefix_length", keyWidth - len); } else if (k->is()) { @@ -515,8 +516,8 @@ class ControlConverter : public Inspector { key->emplace("key", stringRepr(0, k8)); key->emplace("prefix_length", 0); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: unsupported LPM key expression", - k); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupported LPM key expression", k); } } else if (matchType == "range") { if (k->is()) { @@ -530,8 +531,8 @@ class ControlConverter : public Inspector { key->emplace("start", stringRepr(0, k8)); key->emplace("end", stringRepr((1 << keyWidth) - 1, k8)); // 2^N -1 } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported range key expression", - k); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1% unsupported range key expression", k); } } else if (matchType == "optional") { // Table key fields with match_kind optional with @@ -548,12 +549,12 @@ class ControlConverter : public Inspector { key->emplace("key", stringRepr(0, k8)); key->emplace("mask", stringRepr(0, k8)); } else { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: unsupported optional key expression", k); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupported optional key expression", k); } } else { - ::error(ErrorType::ERR_UNKNOWN, "unknown key match type '%2%' for key %1%", k, - matchType); + ::P4::error(ErrorType::ERR_UNKNOWN, "unknown key match type '%2%' for key %1%", + k, matchType); } matchKeys->append(key); keyIndex++; @@ -562,7 +563,8 @@ class ControlConverter : public Inspector { auto action = new Util::JsonObject(); auto actionRef = e->getAction(); if (!actionRef->is()) - ::error(ErrorType::ERR_INVALID, "Invalid action '%1%' in entries list.", actionRef); + ::P4::error(ErrorType::ERR_INVALID, "Invalid action '%1%' in entries list.", + actionRef); auto actionCall = actionRef->to(); auto method = actionCall->method->to()->path; auto decl = ctxt->refMap->getDeclaration(method, true); @@ -579,12 +581,13 @@ class ControlConverter : public Inspector { auto priorityAnnotation = e->getAnnotation("priority"_cs); if (priorityAnnotation != nullptr) { if (priorityAnnotation->expr.size() > 1) - ::error(ErrorType::ERR_INVALID, "Invalid priority value %1%", - priorityAnnotation->expr); + ::P4::error(ErrorType::ERR_INVALID, "Invalid priority value %1%", + priorityAnnotation->expr); auto priValue = priorityAnnotation->expr.front(); if (!priValue->is()) - ::error(ErrorType::ERR_INVALID, "Invalid priority value %1%; must be constant.", - priorityAnnotation->expr); + ::P4::error(ErrorType::ERR_INVALID, + "Invalid priority value %1%; must be constant.", + priorityAnnotation->expr); entry->emplace("priority", priValue->to()->value); } else { entry->emplace("priority", entryPriority); @@ -605,7 +608,7 @@ class ControlConverter : public Inspector { return mt->name.name; } - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: match type not supported on this target", mt); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: match type not supported on this target", mt); return "invalid"_cs; } /// Return 'true' if the table is 'simple' @@ -618,8 +621,8 @@ class ControlConverter : public Inspector { } if (!implementation->value->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected expression for property", - implementation); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected expression for property", + implementation); return false; } auto propv = implementation->value->to(); @@ -633,8 +636,8 @@ class ControlConverter : public Inspector { P4::ConstructorCall::resolve(propv->expression->to(), ctxt->refMap, ctxt->typeMap); if (!cc->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected extern object for property", - implementation); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected extern object for property", + implementation); return false; } auto ecc = cc->to(); @@ -654,7 +657,7 @@ class ControlConverter : public Inspector { auto size_expr = arguments->at(arg_index)->expression; int size; if (!size_expr->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1% must be a constant", size_expr); + ::P4::error(ErrorType::ERR_EXPECTED, "%1% must be a constant", size_expr); size = 0; } else { size = size_expr->to()->asInt(); @@ -673,8 +676,8 @@ class ControlConverter : public Inspector { auto hash = arguments->at(0)->expression; auto ei = P4::EnumInstance::resolve(hash, ctxt->typeMap); if (ei == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: hash must be a constant on this target", - hash); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: hash must be a constant on this target", hash); } else { cstring algo = ei->name; selector->emplace("algo", algo); @@ -696,20 +699,21 @@ class ControlConverter : public Inspector { table->emplace("type", "indirect"); add_size(0); } else { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: expected value for property", propv); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: expected value for property", propv); } } else if (propv->expression->is()) { auto pathe = propv->expression->to(); auto decl = ctxt->refMap->getDeclaration(pathe->path, true); if (!decl->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a reference to an instance", pathe); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a reference to an instance", + pathe); return false; } apname = decl->controlPlaneName(); auto dcltype = ctxt->typeMap->getType(pathe, true); if (!dcltype->is()) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type for implementation", - dcltype); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type for implementation", + dcltype); return false; } auto type_extern_name = dcltype->to()->name; @@ -720,8 +724,8 @@ class ControlConverter : public Inspector { } else if (type_extern_name == actionSelectorName) { table->emplace("type", "indirect_ws"); } else { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type for implementation", - dcltype); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type for implementation", + dcltype); return false; } isSimpleTable = false; @@ -732,7 +736,7 @@ class ControlConverter : public Inspector { eb->to(), emitExterns); } } else { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected value for property", propv); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected value for property", propv); return false; } table->emplace("action_profile", apname); @@ -801,11 +805,11 @@ class ControlConverter : public Inspector { continue; done.emplace(tn->table); auto j = convertTable(tn, action_profiles, selector_check); - if (::errorCount() > 0) return false; + if (::P4::errorCount() > 0) return false; tables->append(j); } else if (node->is()) { auto j = convertIf(node->to(), cont->name); - if (::errorCount() > 0) return false; + if (::P4::errorCount() > 0) return false; conditionals->append(j); } } @@ -843,6 +847,6 @@ class ControlConverter : public Inspector { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_CONTROL_H_ */ diff --git a/backends/bmv2/common/controlFlowGraph.cpp b/backends/bmv2/common/controlFlowGraph.cpp index d532f88161..3c56b0eee8 100644 --- a/backends/bmv2/common/controlFlowGraph.cpp +++ b/backends/bmv2/common/controlFlowGraph.cpp @@ -25,7 +25,7 @@ limitations under the License. #include "lib/ordered_map.h" #include "lib/ordered_set.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -81,10 +81,11 @@ bool CFG::dfs(Node *node, std::set &visited, std::setis()) { table = node->to()->table; if (stack.find(table) != stack.end()) { - ::error(ErrorType::ERR_INVALID, - "Program can not be implemented on this target since it contains a path from " - "table %1% back to itself", - table); + ::P4::error( + ErrorType::ERR_INVALID, + "Program can not be implemented on this target since it contains a path from " + "table %1% back to itself", + table); return false; } } @@ -134,10 +135,10 @@ bool CFG::checkMergeable(std::set nodes) const { } bool same = first->successors.checkSame(tn->successors); if (!same) { - ::error(ErrorType::ERR_INVALID, - "Program is not supported by this target, because " - "table %1% has multiple successors", - tn->table); + ::P4::error(ErrorType::ERR_INVALID, + "Program is not supported by this target, because " + "table %1% has multiple successors", + tn->table); return false; } } @@ -192,7 +193,7 @@ class CFGBuilder : public Inspector { if (!instance->is()) return false; auto am = instance->to(); if (!am->object->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: apply method must be on a table", statement); + ::P4::error(ErrorType::ERR_INVALID, "%1%: apply method must be on a table", statement); return false; } auto tc = am->object->to(); @@ -310,4 +311,4 @@ void CFG::build(const IR::P4Control *cc, P4::ReferenceMap *refMap, P4::TypeMap * LOG2(this); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/controlFlowGraph.h b/backends/bmv2/common/controlFlowGraph.h index 4c55c1dff3..712b73b763 100644 --- a/backends/bmv2/common/controlFlowGraph.h +++ b/backends/bmv2/common/controlFlowGraph.h @@ -23,7 +23,7 @@ limitations under the License. #include "lib/castable.h" #include "lib/ordered_set.h" -namespace BMV2 { +namespace P4::BMV2 { /// This CFG models the BMV2 notion of control-flow graph. /// In BMv2 there are only 2 types of nodes: If and Table. @@ -192,6 +192,6 @@ class CFG final : public IHasDbPrint { bool checkMergeable(std::set nodes) const; }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_CONTROLFLOWGRAPH_H_ */ diff --git a/backends/bmv2/common/deparser.cpp b/backends/bmv2/common/deparser.cpp index 5ecc06482c..9257fc5e08 100644 --- a/backends/bmv2/common/deparser.cpp +++ b/backends/bmv2/common/deparser.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "backend.h" #include "extern.h" -namespace BMV2 { +namespace P4::BMV2 { void DeparserConverter::convertDeparserBody(const IR::Vector *body, Util::JsonArray *order, Util::JsonArray *primitives) { @@ -91,8 +91,9 @@ void DeparserConverter::convertDeparserBody(const IR::Vector *bo // We don't need to handle other types, // like header unions or stacks; they were // expanded by the expandEmit pass. - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: emit only supports header arguments, not %2%", arg, type); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: emit only supports header arguments, not %2%", arg, + type); } } continue; @@ -124,8 +125,8 @@ void DeparserConverter::convertDeparserBody(const IR::Vector *bo continue; } } - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported within a deparser on this target", - s); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: not supported within a deparser on this target", s); } ctxt->conv->simpleExpressionsOnly = false; } @@ -162,4 +163,4 @@ bool DeparserConverter::preorder(const IR::P4Control *control) { return false; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/deparser.h b/backends/bmv2/common/deparser.h index f273199454..5d3a157d43 100644 --- a/backends/bmv2/common/deparser.h +++ b/backends/bmv2/common/deparser.h @@ -24,7 +24,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { class DeparserConverter : public Inspector { ConversionContext *ctxt; @@ -45,6 +45,6 @@ class DeparserConverter : public Inspector { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_DEPARSER_H_ */ diff --git a/backends/bmv2/common/expression.cpp b/backends/bmv2/common/expression.cpp index d1cd111383..92deef8222 100644 --- a/backends/bmv2/common/expression.cpp +++ b/backends/bmv2/common/expression.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "helpers.h" #include "lib/algorithm.h" -namespace BMV2 { +namespace P4::BMV2 { class ArithmeticFixup; @@ -84,7 +84,7 @@ void ExpressionConverter::mapExpression(const IR::Expression *expression, Util:: } Util::IJson *ExpressionConverter::get(const IR::Expression *expression) const { - auto result = ::get(map, expression); + auto result = ::P4::get(map, expression); if (result == nullptr) { LOG3("Looking up " << expression); for (auto it : map) { @@ -92,8 +92,8 @@ Util::IJson *ExpressionConverter::get(const IR::Expression *expression) const { } } if (result == nullptr) - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: could not convert expression to Json", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: could not convert expression to Json", + expression); return result; } @@ -110,7 +110,8 @@ void ExpressionConverter::postorder(const IR::MethodCallExpression *expression) if (em->originalExternType->name == corelib.packetIn.name && em->method->name == corelib.packetIn.lookahead.name) { if (expression->typeArguments->size() != 1) - ::error(ErrorType::ERR_INVALID, "Expected 1 type parameter for %1%", em->method); + ::P4::error(ErrorType::ERR_INVALID, "Expected 1 type parameter for %1%", + em->method); auto targ = expression->typeArguments->at(0); auto typearg = typeMap->getTypeType(targ, true); int width = typearg->width_bits(); @@ -163,7 +164,7 @@ void ExpressionConverter::postorder(const IR::MethodCallExpression *expression) } } - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported", expression); } void ExpressionConverter::postorder(const IR::Cast *expression) { @@ -204,7 +205,7 @@ void ExpressionConverter::postorder(const IR::ArrayIndex *expression) { if (!expression->right->is()) { const IR::Expression *ex = expression->right; - auto fresult = ::get(map, ex); + auto fresult = ::P4::get(map, ex); if (fresult == nullptr) { LOG2("Looking up " << ex); for (auto it : map) { @@ -314,7 +315,7 @@ void ExpressionConverter::postorder(const IR::Member *expression) { auto field = parentType->to()->getField(expression->member); LOG3("looking up field " << field); CHECK_NULL(field); - auto name = ::get(structure->scalarMetadataFields, field); + auto name = ::P4::get(structure->scalarMetadataFields, field); BUG_CHECK((name != nullptr), "NULL name: %1%", field->name); if (type->is() || type->is() || leftValue || simpleExpressionsOnly) { @@ -354,7 +355,7 @@ void ExpressionConverter::postorder(const IR::Member *expression) { auto mem = expression->expr->to(); auto memtype = typeMap->getType(mem->expr, true); if (memtype->is() && mem->member == IR::Type_Stack::next) - ::error(ErrorType::ERR_UNINITIALIZED, "%1% uninitialized: next field read", mem); + ::P4::error(ErrorType::ERR_UNINITIALIZED, "%1% uninitialized: next field read", mem); // array.last.field => type: "stack_field", value: [ array, field ] if (memtype->is() && mem->member == IR::Type_Stack::last) { auto l = get(mem->expr); @@ -431,10 +432,10 @@ void ExpressionConverter::postorder(const IR::Member *expression) { } else if (auto jo = l->to()) { if (st) { if (index_pos < 0) { - ::error(ErrorType::ERR_INVALID, - "BMV2: Struct has no field " - "for runtime index computation %1%", - st); + ::P4::error(ErrorType::ERR_INVALID, + "BMV2: Struct has no field " + "for runtime index computation %1%", + st); } result->emplace("type", "expression"); auto e = new Util::JsonObject(); @@ -485,8 +486,8 @@ void ExpressionConverter::postorder(const IR::Mux *expression) { auto result = new Util::JsonObject(); mapExpression(expression, result); if (simpleExpressionsOnly) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: expression too complex for this target", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: expression too complex for this target", expression); return; } @@ -528,8 +529,8 @@ void ExpressionConverter::binary(const IR::Operation_Binary *expression) { auto result = new Util::JsonObject(); mapExpression(expression, result); if (simpleExpressionsOnly) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: expression too complex for this target", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: expression too complex for this target", expression); return; } @@ -586,8 +587,8 @@ void ExpressionConverter::postorder(const IR::ListExpression *expression) { auto result = new Util::JsonArray(); mapExpression(expression, result); if (simpleExpressionsOnly) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: expression too complex for this target", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: expression too complex for this target", expression); return; } @@ -603,8 +604,8 @@ void ExpressionConverter::postorder(const IR::StructExpression *expression) { auto result = new Util::JsonArray(); mapExpression(expression, result); if (simpleExpressionsOnly) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: expression too complex for this target", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: expression too complex for this target", expression); return; } @@ -619,8 +620,8 @@ void ExpressionConverter::postorder(const IR::Operation_Unary *expression) { auto result = new Util::JsonObject(); mapExpression(expression, result); if (simpleExpressionsOnly) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: expression too complex for this target", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: expression too complex for this target", expression); return; } @@ -658,7 +659,7 @@ void ExpressionConverter::postorder(const IR::PathExpression *expression) { } auto result = new Util::JsonObject(); result->emplace("type", "runtime_data"); - unsigned paramIndex = ::get(&structure->index, param); + unsigned paramIndex = ::P4::get(&structure->index, param); result->emplace("value", paramIndex); mapExpression(expression, result); } else if (auto var = decl->to()) { @@ -775,10 +776,10 @@ Util::IJson *ExpressionConverter::convert(const IR::Expression *e, bool doFixup, CHECK_NULL(expr); } expr->apply(*this); - auto result = ::get(map, expr->to()); + auto result = ::P4::get(map, expr->to()); if (result == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Could not generate code for expression", - e); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Could not generate code for expression", e); return new Util::JsonValue(); } @@ -824,7 +825,7 @@ Util::IJson *ExpressionConverter::convertLeftValue(const IR::Expression *e) { expr = r->to(); CHECK_NULL(expr); expr->apply(*this); - auto result = ::get(map, expr->to()); + auto result = ::P4::get(map, expr->to()); if (result == nullptr) BUG("%1%: Could not convert expression", e); leftValue = false; return result; @@ -837,4 +838,4 @@ Util::IJson *ExpressionConverter::convertWithConstantWidths(const IR::Expression return result; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/expression.h b/backends/bmv2/common/expression.h index b1e9c73fbc..0764577b8e 100644 --- a/backends/bmv2/common/expression.h +++ b/backends/bmv2/common/expression.h @@ -28,7 +28,7 @@ limitations under the License. #include "lib/json.h" #include "lower.h" -namespace BMV2 { +namespace P4::BMV2 { /// Inserts casts and narrowing operations to implement correctly the semantics of /// P4-16 arithmetic on top of unbounded precision arithmetic. For example, @@ -134,6 +134,6 @@ class ExpressionConverter : public Inspector { void saturated_binary(const IR::Operation_Binary *expression); }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_EXPRESSION_H_ */ diff --git a/backends/bmv2/common/extern.cpp b/backends/bmv2/common/extern.cpp index a21331cbd0..0d4f9cdeb0 100644 --- a/backends/bmv2/common/extern.cpp +++ b/backends/bmv2/common/extern.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "frontends/p4/fromv1.0/v1model.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { std::map *ExternConverter::cvtForType = nullptr; @@ -72,8 +72,8 @@ Util::IJson *ExternConverter::convertExternObject(ConversionContext *ctxt, } return primitive; } else { - ::error(ErrorType::ERR_UNKNOWN, "Unknown extern method %1% from type %2%", em->method->name, - em->originalExternType->name); + ::P4::error(ErrorType::ERR_UNKNOWN, "Unknown extern method %1% from type %2%", + em->method->name, em->originalExternType->name); return nullptr; } } @@ -83,7 +83,7 @@ Util::IJson *ExternConverter::convertExternObject(ConversionContext *ctxt, void ExternConverter::convertExternInstance(ConversionContext *ctxt, const IR::Declaration *decl, const IR::ExternBlock *eb, const bool &emitExterns) { if (!emitExterns) { - ::error(ErrorType::ERR_UNKNOWN, "%1%: unknown extern instance", eb->type->name); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown extern instance", eb->type->name); return; } auto attrs = new Util::JsonArray(); @@ -113,7 +113,7 @@ Util::IJson *ExternConverter::convertExternFunction(ConversionContext *ctxt, const IR::StatOrDecl *s, const bool emitExterns) { if (!emitExterns) { - ::error(ErrorType::ERR_UNKNOWN, "%1%: unknown extern function", ef->method->name); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown extern function", ef->method->name); return nullptr; } auto primitive = mkPrimitive(ef->method->name); @@ -128,7 +128,7 @@ Util::IJson *ExternConverter::convertExternFunction(ConversionContext *ctxt, void ExternConverter::modelError(const char *format, const IR::Node *node) const { cstring errMsg = cstring(format) + ". Are you using an up-to-date v1model.p4?"; - ::error(ErrorType::ERR_MODEL, errMsg.c_str(), node); + ::P4::error(ErrorType::ERR_MODEL, errMsg.c_str(), node); } void ExternConverter::addToFieldList(ConversionContext *ctxt, const IR::Expression *expr, @@ -231,7 +231,7 @@ cstring ExternConverter::convertHashAlgorithm(cstring algorithm) { if (algorithm == P4V1::V1Model::instance.algorithm.csum16.name) return "csum16"_cs; if (algorithm == P4V1::V1Model::instance.algorithm.xor16.name) return "xor16"_cs; - ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported algorithm %1%", algorithm); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unsupported algorithm %1%", algorithm); return cstring::empty; } @@ -242,7 +242,7 @@ Util::IJson *ExternConverter::convertAssertAssume(ConversionContext *ctxt, const IR::MethodCallExpression *methodCall, const P4::ExternFunction *ef) { if (methodCall->arguments->size() != 1) { - ::error(ErrorType::ERR_EXPECTED, "Expected 1 arguments for %1%", methodCall); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected 1 arguments for %1%", methodCall); return nullptr; } auto primitive = mkPrimitive(ef->method->name.name); @@ -270,4 +270,4 @@ Util::IJson *ExternConverter_assume::convertExternFunction( return ExternConverter::convertAssertAssume(ctxt, mc, ef); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/extern.h b/backends/bmv2/common/extern.h index 79e63a0d1e..2ecac3f8af 100644 --- a/backends/bmv2/common/extern.h +++ b/backends/bmv2/common/extern.h @@ -22,7 +22,7 @@ limitations under the License. #include "helpers.h" #include "ir/ir.h" -namespace BMV2 { +namespace P4::BMV2 { class ExternConverter { static std::map *cvtForType; @@ -142,6 +142,6 @@ class ExternConverter { EXTERN_CONVERTER_W_FUNCTION(assert) EXTERN_CONVERTER_W_FUNCTION(assume) -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_EXTERN_H_ */ diff --git a/backends/bmv2/common/globals.cpp b/backends/bmv2/common/globals.cpp index af1213d721..973894d75c 100644 --- a/backends/bmv2/common/globals.cpp +++ b/backends/bmv2/common/globals.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "extern.h" #include "sharedActionSelectorCheck.h" -namespace BMV2 { +namespace P4::BMV2 { bool ConvertGlobals::preorder(const IR::ExternBlock *block) { LOG2("Converting " << block); @@ -33,4 +33,4 @@ bool ConvertGlobals::preorder(const IR::ExternBlock *block) { return false; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/globals.h b/backends/bmv2/common/globals.h index b30d788e51..af444df628 100644 --- a/backends/bmv2/common/globals.h +++ b/backends/bmv2/common/globals.h @@ -20,7 +20,7 @@ limitations under the License. #include "backend.h" #include "ir/ir.h" -namespace BMV2 { +namespace P4::BMV2 { class ConvertGlobals : public Inspector { ConversionContext *ctxt; @@ -42,6 +42,6 @@ class ConvertGlobals : public Inspector { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_GLOBALS_H_ */ diff --git a/backends/bmv2/common/header.cpp b/backends/bmv2/common/header.cpp index ff1b158a3d..4b34ebdd3c 100644 --- a/backends/bmv2/common/header.cpp +++ b/backends/bmv2/common/header.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "backend.h" #include "ir/ir.h" -namespace BMV2 { +namespace P4::BMV2 { /// TODO(hanw): remove. Util::JsonArray *HeaderConverter::pushNewArray(Util::JsonArray *parent) { @@ -43,9 +43,9 @@ void HeaderConverter::addTypesAndInstances(const IR::Type_StructLike *type, bool if (ft->is()) { // The headers struct can not contain nested structures. if (!meta && ft->is()) { - ::error(ErrorType::ERR_INVALID, - "%1%: type should only contain headers, header stacks, or header unions", - type); + ::P4::error( + ErrorType::ERR_INVALID, + "%1%: type should only contain headers, header stacks, or header unions", type); return; } auto st = ft->to(); @@ -236,8 +236,8 @@ void HeaderConverter::addHeaderType(const IR::Type_StructLike *st) { max_length += type->size; field->append("*"); if (varbitFound) - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: headers with multiple varbit fields not supported", st); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: headers with multiple varbit fields not supported", st); varbitFound = true; } else if (ftype->is()) { // treat as bit<32> @@ -257,11 +257,11 @@ void HeaderConverter::addHeaderType(const IR::Type_StructLike *st) { unsigned padding = max_length % 8; if (padding != 0) { if (st->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Found header with fields totaling %2% bits." - " BMv2 target only supports headers with fields" - " totaling a multiple of 8 bits.", - st, max_length); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Found header with fields totaling %2% bits." + " BMv2 target only supports headers with fields" + " totaling a multiple of 8 bits.", + st, max_length); } else if (st->is()) { cstring name = ctxt->refMap->newName("_padding"); auto field = pushNewArray(fields); @@ -298,8 +298,8 @@ void HeaderConverter::addHeaderType(const IR::Type_StructLike *st) { target_name = aliasAnnotation->body.at(0)->text; } else { // aliasAnnotation->body is empty or not saved correctly - ::error(ErrorType::ERR_INVALID, - "There is no saved data for aliases target_name."); + ::P4::error(ErrorType::ERR_INVALID, + "There is no saved data for aliases target_name."); } } LOG2("field alias " << target_name); @@ -458,4 +458,4 @@ bool HeaderConverter::preorder(const IR::Parameter *param) { return false; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/header.h b/backends/bmv2/common/header.h index 6cd1ba72cd..a36114c292 100644 --- a/backends/bmv2/common/header.h +++ b/backends/bmv2/common/header.h @@ -28,7 +28,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { class Backend; @@ -61,6 +61,6 @@ class HeaderConverter : public Inspector { HeaderConverter(ConversionContext *ctxt, cstring scalarsName); }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_HEADER_H_ */ diff --git a/backends/bmv2/common/helpers.cpp b/backends/bmv2/common/helpers.cpp index e2e2afd7de..68a5bb2daf 100644 --- a/backends/bmv2/common/helpers.cpp +++ b/backends/bmv2/common/helpers.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { /// constant definition for bmv2 const cstring MatchImplementation::selectorMatchTypeName = "selector"_cs; @@ -146,8 +146,8 @@ int ConversionContext::createFieldList(const IR::Expression *expr, cstring listN } void ConversionContext::modelError(const char *format, const IR::Node *node) { - ::error(format, node); - ::error("Are you using an up-to-date v1model.p4?"); + ::P4::error(format, node); + ::P4::error("Are you using an up-to-date v1model.p4?"); } cstring ConversionContext::createCalculation(cstring algo, const IR::Expression *fields, @@ -205,4 +205,4 @@ const IR::ListExpression *convertToList(const IR::Expression *expr, P4::TypeMap return list; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/helpers.h b/backends/bmv2/common/helpers.h index 11662d8853..d158c0718d 100644 --- a/backends/bmv2/common/helpers.h +++ b/backends/bmv2/common/helpers.h @@ -28,7 +28,7 @@ limitations under the License. #include "lib/json.h" #include "lib/ordered_map.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -347,6 +347,6 @@ unsigned nextId(cstring group); /// Converts expr into a ListExpression or returns nullptr if not possible const IR::ListExpression *convertToList(const IR::Expression *expr, P4::TypeMap *typeMap); -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_HELPERS_H_ */ diff --git a/backends/bmv2/common/lower.cpp b/backends/bmv2/common/lower.cpp index 0ce31798df..962f4813c2 100644 --- a/backends/bmv2/common/lower.cpp +++ b/backends/bmv2/common/lower.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "lib/big_int_util.h" -namespace BMV2 { +namespace P4::BMV2 { /// We make an effort to update the typeMap as we proceed /// since parent expression trees may need the information @@ -33,15 +33,15 @@ const IR::Expression *LowerExpressions::shift(const IR::Operation_Binary *expres auto cst = rhs->checkedTo(); big_int maxShift = Util::shift_left(1, LowerExpressions::maxShiftWidth); if (cst->value > maxShift) - ::error(ErrorType::ERR_OVERLIMIT, "%1%: shift amount limited to %2% on this target", - expression, maxShift); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: shift amount limited to %2% on this target", + expression, maxShift); } else { BUG_CHECK(rhstype->is(), "%1%: expected a bit<> type", rhstype); auto bs = rhstype->to(); if (bs->size > LowerExpressions::maxShiftWidth) - ::error(ErrorType::ERR_OVERLIMIT, - "%1%: shift amount limited to %2% bits on this target", expression, - LowerExpressions::maxShiftWidth); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "%1%: shift amount limited to %2% bits on this target", expression, + LowerExpressions::maxShiftWidth); } auto ltype = typeMap->getType(getOriginal(), true); typeMap->setType(expression, ltype); @@ -186,7 +186,7 @@ const IR::Node *RemoveComplexExpressions::postorder(IR::MethodCallExpression *ex // one knew of this feature, since it was not very clearly // documented. if (expression->arguments->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected 2 arguments", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected 2 arguments", expression); return expression; } auto vec = new IR::Vector(); @@ -218,4 +218,4 @@ const IR::Node *RemoveComplexExpressions::postorder(IR::MethodCallExpression *ex return expression; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/lower.h b/backends/bmv2/common/lower.h index e439bb5169..ae1ecbabf4 100644 --- a/backends/bmv2/common/lower.h +++ b/backends/bmv2/common/lower.h @@ -22,7 +22,7 @@ limitations under the License. #include "ir/ir.h" #include "midend/removeComplexExpressions.h" -namespace BMV2 { +namespace P4::BMV2 { /// This pass rewrites expressions which are not supported natively on BMv2. class LowerExpressions : public Transform { @@ -61,6 +61,6 @@ class RemoveComplexExpressions : public P4::RemoveComplexExpressions { const IR::Node *postorder(IR::MethodCallExpression *expression) override; }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_LOWER_H_ */ diff --git a/backends/bmv2/common/midend.h b/backends/bmv2/common/midend.h index 1a4d7e73b2..4983c61e44 100644 --- a/backends/bmv2/common/midend.h +++ b/backends/bmv2/common/midend.h @@ -22,7 +22,7 @@ limitations under the License. #include "lower.h" #include "midend/convertEnums.h" -namespace BMV2 { +namespace P4::BMV2 { /// This class implements a policy suitable for the ConvertEnums pass. /// The policy is: convert all enums that are not part of the v1model. @@ -66,6 +66,6 @@ class MidEnd : public PassManager { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_MIDEND_H_ */ diff --git a/backends/bmv2/common/options.h b/backends/bmv2/common/options.h index 931aec7bda..bb92148e92 100644 --- a/backends/bmv2/common/options.h +++ b/backends/bmv2/common/options.h @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/common/options.h" -namespace BMV2 { +namespace P4::BMV2 { class BMV2Options : public CompilerOptions { public: @@ -62,6 +62,6 @@ class BMV2Options : public CompilerOptions { using BMV2Context = P4CContextWithOptions; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_OPTIONS_H_ */ diff --git a/backends/bmv2/common/parser.cpp b/backends/bmv2/common/parser.cpp index 59b85a3295..9dfa150cb0 100644 --- a/backends/bmv2/common/parser.cpp +++ b/backends/bmv2/common/parser.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "frontends/p4/fromv1.0/v1model.h" #include "lib/algorithm.h" -namespace BMV2 { +namespace P4::BMV2 { cstring ParserConverter::jsonAssignment(const IR::Type *type) { if (type->is()) return "assign_union"_cs; @@ -129,8 +129,8 @@ Util::IJson *ParserConverter::convertParserStatement(const IR::StatOrDecl *stat) if (extmeth->method->name.name == corelib.packetIn.extract.name) { int argCount = mce->arguments->size(); if (argCount < 1 || argCount > 2) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: unknown extract method", - mce); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: unknown extract method", + mce); return result; } @@ -139,9 +139,9 @@ Util::IJson *ParserConverter::convertParserStatement(const IR::StatOrDecl *stat) auto arg = mce->arguments->at(0); auto argtype = ctxt->typeMap->getType(arg->expression, true); if (!argtype->is()) { - ::error(ErrorType::ERR_INVALID, - "%1%: extract only accepts arguments with header types, not %2%", arg, - argtype); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: extract only accepts arguments with header types, not %2%", + arg, argtype); return result; } auto param = new Util::JsonObject(); @@ -213,7 +213,7 @@ Util::IJson *ParserConverter::convertParserStatement(const IR::StatOrDecl *stat) return nullptr; } else if (extmeth->method->name.name == corelib.packetIn.advance.name) { if (mce->arguments->size() != 1) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: expected 1 argument", mce); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: expected 1 argument", mce); return result; } auto arg = mce->arguments->at(0); @@ -326,7 +326,7 @@ Util::IJson *ParserConverter::convertParserStatement(const IR::StatOrDecl *stat) return result; } } - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in parser on this target", stat); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in parser on this target", stat); return result; } @@ -336,13 +336,13 @@ void ParserConverter::convertSimpleKey(const IR::Expression *keySet, big_int &va if (keySet->is()) { auto mk = keySet->to(); if (!mk->left->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must evaluate to a compile-time constant", - mk->left); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must evaluate to a compile-time constant", + mk->left); return; } if (!mk->right->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must evaluate to a compile-time constant", - mk->right); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must evaluate to a compile-time constant", + mk->right); return; } value = mk->left->to()->value; @@ -357,7 +357,8 @@ void ParserConverter::convertSimpleKey(const IR::Expression *keySet, big_int &va value = 0; mask = 0; } else { - ::error(ErrorType::ERR_INVALID, "%1%: must evaluate to a compile-time constant", keySet); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must evaluate to a compile-time constant", + keySet); value = 0; mask = 0; } @@ -441,8 +442,8 @@ Util::IJson *ParserConverter::stateName(IR::ID state) { if (state.name == IR::ParserState::accept) { return Util::JsonValue::null; } else if (state.name == IR::ParserState::reject) { - ::warning(ErrorType::WARN_UNSUPPORTED, - "Explicit transition to %1% not supported on this target", state); + ::P4::warning(ErrorType::WARN_UNSUPPORTED, + "Explicit transition to %1% not supported on this target", state); return Util::JsonValue::null; } else { return new Util::JsonValue(state.name); @@ -531,10 +532,11 @@ void ParserConverter::addValueSets(const IR::P4Parser *parser) { if (auto st = etype->to()) { for (auto f : st->fields) { if (isExactMatch(f)) continue; - ::warning(ErrorType::WARN_UNSUPPORTED, - "This backend only supports exact matches in value_sets but the match " - "on '%1%' is not exact; the annotation will be ignored", - f); + ::P4::warning( + ErrorType::WARN_UNSUPPORTED, + "This backend only supports exact matches in value_sets but the match " + "on '%1%' is not exact; the annotation will be ignored", + f); } } @@ -602,4 +604,4 @@ bool ParserConverter::preorder(const IR::P4Parser *parser) { return false; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/common/parser.h b/backends/bmv2/common/parser.h index d2c6fe0ee4..b900ec056f 100644 --- a/backends/bmv2/common/parser.h +++ b/backends/bmv2/common/parser.h @@ -24,7 +24,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { class JsonObjects; @@ -54,6 +54,6 @@ class ParserConverter : public Inspector { } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_PARSER_H_ */ diff --git a/backends/bmv2/common/sharedActionSelectorCheck.h b/backends/bmv2/common/sharedActionSelectorCheck.h index 0cb68d570b..3ebbd05cd6 100644 --- a/backends/bmv2/common/sharedActionSelectorCheck.h +++ b/backends/bmv2/common/sharedActionSelectorCheck.h @@ -29,7 +29,7 @@ limitations under the License. #include "lib/error.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { using SelectorInput = std::vector; @@ -72,8 +72,8 @@ class SharedActionSelectorCheck : public Inspector { auto implementation = table->properties->getProperty("implementation"); if (implementation == nullptr) return false; if (!implementation->value->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected expression for property", - implementation); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected expression for property", + implementation); return false; } auto propv = implementation->value->to(); @@ -81,12 +81,13 @@ class SharedActionSelectorCheck : public Inspector { auto pathe = propv->expression->to(); auto decl = refMap->getDeclaration(pathe->path, true); if (!decl->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a reference to an instance", pathe); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a reference to an instance", pathe); return false; } auto dcltype = typeMap->getType(pathe, true); if (!dcltype->is()) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type for implementation", dcltype); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type for implementation", + dcltype); return false; } auto type_extern_name = dcltype->to()->name; @@ -114,15 +115,16 @@ class SharedActionSelectorCheck : public Inspector { }; if (!cmp_inputs(it->second, input)) { - ::error(ErrorType::ERR_INVALID, - "Action selector %1% is used by multiple tables with different selector inputs", - decl); + ::P4::error( + ErrorType::ERR_INVALID, + "Action selector %1% is used by multiple tables with different selector inputs", + decl); } return false; } }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_COMMON_SHAREDACTIONSELECTORCHECK_H_ */ diff --git a/backends/bmv2/pna_nic/main.cpp b/backends/bmv2/pna_nic/main.cpp index 9ac9b2bf1f..2f6872ec86 100644 --- a/backends/bmv2/pna_nic/main.cpp +++ b/backends/bmv2/pna_nic/main.cpp @@ -37,6 +37,8 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" +using namespace P4; + int main(int argc, char *const argv[]) { setup_gc_logging(); @@ -48,7 +50,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto hook = options.getDebugHook(); @@ -61,7 +63,7 @@ int main(int argc, char *const argv[]) { if (options.loadIRFromJson == false) { program = P4::parseP4File(options); - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; try { P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); @@ -73,17 +75,17 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; } else { std::filebuf fb; if (fb.open(options.file, std::ios::in) == nullptr) { - ::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); return 1; } std::istream inJson(&fb); JSONLoader jsonFileLoader(inJson); if (jsonFileLoader.json == nullptr) { - ::error(ErrorType::ERR_IO, "%s: Not valid input file", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: Not valid input file", options.file); return 1; } program = new IR::P4Program(jsonFileLoader); @@ -91,20 +93,21 @@ int main(int argc, char *const argv[]) { } P4::serializeP4RuntimeIfRequired(program, options); - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; BMV2::PnaNicMidEnd midEnd(options); midEnd.addDebugHook(hook); try { toplevel = midEnd.process(program); - if (::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) return 1; + if (::P4::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) + return 1; if (options.dumpJsonFile.empty()) JSONGenerator(*openFile(options.dumpJsonFile, true), true) << program << std::endl; } catch (const std::exception &bug) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto backend = new BMV2::PnaNicBackend(options, &midEnd.refMap, &midEnd.typeMap, &midEnd.enumMap); @@ -117,7 +120,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; if (!options.outputFile.empty()) { std::ostream *out = openFile(options.outputFile, false); @@ -127,5 +130,5 @@ int main(int argc, char *const argv[]) { } } - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/bmv2/pna_nic/midend.cpp b/backends/bmv2/pna_nic/midend.cpp index eefa751227..ac096f0984 100644 --- a/backends/bmv2/pna_nic/midend.cpp +++ b/backends/bmv2/pna_nic/midend.cpp @@ -62,7 +62,7 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/validateProperties.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -181,4 +181,4 @@ PnaNicMidEnd::PnaNicMidEnd(CompilerOptions &options, std::ostream *outStream) } } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/pna_nic/midend.h b/backends/bmv2/pna_nic/midend.h index 70b2a04ee8..ac083c7ec3 100644 --- a/backends/bmv2/pna_nic/midend.h +++ b/backends/bmv2/pna_nic/midend.h @@ -19,7 +19,7 @@ limitations under the License. #include "backends/bmv2/portable_common/midend.h" -namespace BMV2 { +namespace P4::BMV2 { class PnaNicMidEnd : public PortableMidEnd { public: @@ -27,6 +27,6 @@ class PnaNicMidEnd : public PortableMidEnd { explicit PnaNicMidEnd(CompilerOptions &options, std::ostream *outStream = nullptr); }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PNA_NIC_MIDEND_H_ */ diff --git a/backends/bmv2/pna_nic/options.cpp b/backends/bmv2/pna_nic/options.cpp index 792802db58..2d07e432eb 100644 --- a/backends/bmv2/pna_nic/options.cpp +++ b/backends/bmv2/pna_nic/options.cpp @@ -3,4 +3,4 @@ #include "frontends/common/parser_options.h" #include "lib/exename.h" -namespace BMV2 {} // namespace BMV2 +namespace P4::BMV2 {} // namespace P4::BMV2 diff --git a/backends/bmv2/pna_nic/options.h b/backends/bmv2/pna_nic/options.h index be5547178c..9165572042 100644 --- a/backends/bmv2/pna_nic/options.h +++ b/backends/bmv2/pna_nic/options.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/bmv2/pna_nic/midend.h" #include "backends/bmv2/portable_common/options.h" -namespace BMV2 { +namespace P4::BMV2 { class PnaNicOptions : public PortableOptions { public: @@ -40,6 +40,6 @@ class PnaNicOptions : public PortableOptions { using PnaNicContext = P4CContextWithOptions; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PNA_NIC_OPTIONS_H_ */ diff --git a/backends/bmv2/pna_nic/pnaNic.cpp b/backends/bmv2/pna_nic/pnaNic.cpp index b7283a3493..ea94b45269 100644 --- a/backends/bmv2/pna_nic/pnaNic.cpp +++ b/backends/bmv2/pna_nic/pnaNic.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "frontends/common/model.h" #include "frontends/p4/cloner.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -69,10 +69,10 @@ void PnaNicBackend::convert(const IR::ToplevelBlock *tlb) { if (!main) return; if (main->type->name != "PNA_NIC") - ::warning(ErrorType::WARN_INVALID, - "%1%: the main package should be called PNA_NIC" - "; are you using the wrong architecture?", - main->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main package should be called PNA_NIC" + "; are you using the wrong architecture?", + main->type->name); main->apply(*parsePnaArch); @@ -112,7 +112,7 @@ void PnaNicBackend::convert(const IR::ToplevelBlock *tlb) { main = toplevel->getMain(); if (!main) return; // no main main->apply(*parsePnaArch); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; program = toplevel->getProgram(); PassManager toJson = {new P4::DiscoverStructure(&structure), @@ -324,7 +324,8 @@ void ExternConverter_InternetChecksum::convertExternInstance(UNUSED ConversionCo auto mainParser = pnaStructure->parsers.at("main_parser"_cs)->controlPlaneName(); auto mainDeparser = pnaStructure->deparsers.at("main_deparser"_cs)->controlPlaneName(); if (block != mainParser && block != mainDeparser) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in pipeline on this target", eb); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in pipeline on this target", + eb); } // add checksum instance auto jcksum = new Util::JsonObject(); @@ -369,17 +370,17 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c } auto regType = st->arguments->at(0); if (!regType->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: registers with types other than bit<> or int<> are not suppoted", eb); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: registers with types other than bit<> or int<> are not suppoted", eb); return; } unsigned width = regType->width_bits(); if (width == 0) { - ::error(ErrorType::ERR_UNKNOWN, "%1%: unknown width", st->arguments->at(0)); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown width", st->arguments->at(0)); return; } jreg->emplace("bitwidth"_cs, width); ctxt->json->register_arrays->append(jreg); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/pna_nic/pnaNic.h b/backends/bmv2/pna_nic/pnaNic.h index 53e61db2aa..51aea20646 100644 --- a/backends/bmv2/pna_nic/pnaNic.h +++ b/backends/bmv2/pna_nic/pnaNic.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/bmv2/portable_common/portable.h" #include "pnaProgramStructure.h" -namespace BMV2 { +namespace P4::BMV2 { class PnaNicExpressionConverter : public ExpressionConverter { public: @@ -29,8 +29,9 @@ class PnaNicExpressionConverter : public ExpressionConverter { : BMV2::ExpressionConverter(refMap, typeMap, structure, scalarsName) {} void modelError(const char *format, const cstring field) { - ::error(ErrorType::ERR_MODEL, - (cstring(format) + "\nInvalid metadata parameter value for PNA").c_str(), field); + ::P4::error(ErrorType::ERR_MODEL, + (cstring(format) + "\nInvalid metadata parameter value for PNA").c_str(), + field); } Util::IJson *convertParam(UNUSED const IR::Parameter *param, cstring fieldName) override { @@ -129,6 +130,6 @@ EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash) EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(InternetChecksum) EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Register) -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PNA_NIC_PNANIC_H_ */ diff --git a/backends/bmv2/pna_nic/pnaProgramStructure.cpp b/backends/bmv2/pna_nic/pnaProgramStructure.cpp index b43e94de09..8561705685 100644 --- a/backends/bmv2/pna_nic/pnaProgramStructure.cpp +++ b/backends/bmv2/pna_nic/pnaProgramStructure.cpp @@ -16,7 +16,7 @@ limitations under the License. #include "pnaProgramStructure.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -69,9 +69,9 @@ void InspectPnaProgram::addTypesAndInstances(const IR::Type_StructLike *type, bo if (ft->is()) { // The headers struct can not contain nested structures. if (isHeader && ft->is()) { - ::error(ErrorType::ERR_INVALID, - "Type %1% should only contain headers, header stacks, or header unions", - type); + ::P4::error(ErrorType::ERR_INVALID, + "Type %1% should only contain headers, header stacks, or header unions", + type); return; } auto st = ft->to(); @@ -92,8 +92,8 @@ void InspectPnaProgram::addTypesAndInstances(const IR::Type_StructLike *type, bo if (auto h_type = uft->to()) { addHeaderInstance(h_type, uf->controlPlaneName()); } else { - ::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, - uft); + ::P4::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, + uft); return; } } @@ -255,4 +255,4 @@ bool ParsePnaArchitecture::preorder(const IR::PackageBlock *block) { return false; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/pna_nic/pnaProgramStructure.h b/backends/bmv2/pna_nic/pnaProgramStructure.h index 00ac37a6f0..9f6b80bdfe 100644 --- a/backends/bmv2/pna_nic/pnaProgramStructure.h +++ b/backends/bmv2/pna_nic/pnaProgramStructure.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/common/portableProgramStructure.h" /// TODO: this is not really specific to BMV2, it should reside somewhere else -namespace BMV2 { +namespace P4::BMV2 { enum pna_block_t { MAIN_PARSER, @@ -59,9 +59,9 @@ class ParsePnaArchitecture : public P4::ParsePortableArchitecture { } void modelError(const char *format, const IR::INode *node) { - ::error(ErrorType::ERR_MODEL, - (cstring(format) + "\nAre you using an up-to-date 'pna.p4'?").c_str(), - node->getNode()); + ::P4::error(ErrorType::ERR_MODEL, + (cstring(format) + "\nAre you using an up-to-date 'pna.p4'?").c_str(), + node->getNode()); } bool preorder(const IR::PackageBlock *block) override; @@ -95,6 +95,6 @@ class InspectPnaProgram : public P4::InspectPortableProgram { bool preorder(const IR::Parameter *parameter) override; }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PNA_NIC_PNAPROGRAMSTRUCTURE_H_ */ diff --git a/backends/bmv2/portable_common/midend.cpp b/backends/bmv2/portable_common/midend.cpp index 74aeb88cbc..7878a1a16e 100644 --- a/backends/bmv2/portable_common/midend.cpp +++ b/backends/bmv2/portable_common/midend.cpp @@ -62,8 +62,8 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/validateProperties.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/portable_common/midend.h b/backends/bmv2/portable_common/midend.h index 2c5bba40de..83281a1afd 100644 --- a/backends/bmv2/portable_common/midend.h +++ b/backends/bmv2/portable_common/midend.h @@ -23,13 +23,13 @@ limitations under the License. #include "ir/ir.h" #include "midend/convertEnums.h" -namespace BMV2 { +namespace P4::BMV2 { class PortableMidEnd : public MidEnd { public: explicit PortableMidEnd(CompilerOptions &options) : MidEnd(options) {} }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PORTABLE_COMMON_MIDEND_H_ */ diff --git a/backends/bmv2/portable_common/options.cpp b/backends/bmv2/portable_common/options.cpp index 8d88c4810e..564e254763 100644 --- a/backends/bmv2/portable_common/options.cpp +++ b/backends/bmv2/portable_common/options.cpp @@ -3,7 +3,7 @@ #include "frontends/common/parser_options.h" #include "lib/exename.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -17,4 +17,4 @@ std::vector *PortableOptions::process(int argc, char *const argv[] return remainingOptions; } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/portable_common/options.h b/backends/bmv2/portable_common/options.h index 4e6727f75d..c3478fb50d 100644 --- a/backends/bmv2/portable_common/options.h +++ b/backends/bmv2/portable_common/options.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/bmv2/common/options.h" #include "backends/bmv2/portable_common/midend.h" -namespace BMV2 { +namespace P4::BMV2 { class PortableOptions : public BMV2Options { public: @@ -28,6 +28,6 @@ class PortableOptions : public BMV2Options { std::vector *process(int argc, char *const argv[]) override; }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PORTABLE_COMMON_OPTIONS_H_ */ diff --git a/backends/bmv2/portable_common/portable.cpp b/backends/bmv2/portable_common/portable.cpp index 8589591f65..6d8f98d691 100644 --- a/backends/bmv2/portable_common/portable.cpp +++ b/backends/bmv2/portable_common/portable.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "frontends/common/model.h" #include "frontends/p4/cloner.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -52,8 +52,8 @@ void PortableCodeGenerator::createStructLike(ConversionContext *ctxt, const IR:: max_length += type->size; field->append("*"); if (varbitFound) - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: headers with multiple varbit fields are not supported", st); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: headers with multiple varbit fields are not supported", st); varbitFound = true; } else if (ftype->is()) { field->append(f->name.name); @@ -448,7 +448,7 @@ void ExternConverter_DirectCounter::convertExternInstance(UNUSED ConversionConte cstring name = inst->controlPlaneName(); auto it = ctxt->structure->directCounterMap.find(name); if (it == ctxt->structure->directCounterMap.end()) { - ::warning(ErrorType::WARN_UNUSED, "%1%: Direct counter not used; ignoring", inst); + ::P4::warning(ErrorType::WARN_UNUSED, "%1%: Direct counter not used; ignoring", inst); } else { auto jctr = new Util::JsonObject(); jctr->emplace("name"_cs, name); @@ -556,7 +556,7 @@ void ExternConverter_Meter::convertExternInstance(UNUSED ConversionContext *ctxt else if (mkind_name == "BYTES") type = "bytes"_cs; else - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected meter type", mkind->getNode()); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected meter type", mkind->getNode()); auto k = new Util::JsonObject(); k->emplace("name"_cs, "type"); k->emplace("type"_cs, "string"); @@ -630,7 +630,7 @@ void ExternConverter_ActionProfile::convertExternInstance(UNUSED ConversionConte eb->constructor->srcInfo); if (!sz->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); } action_profile->emplace("max_size"_cs, sz->to()->value); @@ -655,7 +655,7 @@ void ExternConverter_ActionSelector::convertExternInstance(UNUSED ConversionCont BUG_CHECK(sz, "%1%Invalid declaration of extern ActionSelector: no size param", eb->constructor->srcInfo); if (!sz->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); return; } action_profile->emplace("max_size"_cs, sz->to()->value); @@ -673,10 +673,10 @@ void ExternConverter_ActionSelector::convertExternInstance(UNUSED ConversionCont if (input == nullptr) { // the selector is never used by any table, we cannot figure out its // input and therefore cannot include it in the JSON - ::warning(ErrorType::WARN_UNUSED, - "Action selector '%1%' is never referenced by a table " - "and cannot be included in bmv2 JSON", - c); + ::P4::warning(ErrorType::WARN_UNUSED, + "Action selector '%1%' is never referenced by a table " + "and cannot be included in bmv2 JSON", + c); return; } auto j_input = mkArrayField(selector, "input"_cs); @@ -694,4 +694,4 @@ void ExternConverter_Digest::convertExternInstance(UNUSED ConversionContext *ctx UNUSED const IR::ExternBlock *eb, UNUSED const bool &emitExterns) { /* TODO */ } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/portable_common/portable.h b/backends/bmv2/portable_common/portable.h index b0b1972eab..6d931f0cf4 100644 --- a/backends/bmv2/portable_common/portable.h +++ b/backends/bmv2/portable_common/portable.h @@ -41,7 +41,7 @@ limitations under the License. #include "lib/big_int_util.h" #include "lib/json.h" -namespace BMV2 { +namespace P4::BMV2 { class PortableCodeGenerator { public: @@ -68,6 +68,6 @@ EXTERN_CONVERTER_W_INSTANCE(ActionProfile) EXTERN_CONVERTER_W_INSTANCE(ActionSelector) EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Digest) -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PORTABLE_COMMON_PORTABLE_H_ */ diff --git a/backends/bmv2/psa_switch/main.cpp b/backends/bmv2/psa_switch/main.cpp index 9df0897a54..767fa31221 100644 --- a/backends/bmv2/psa_switch/main.cpp +++ b/backends/bmv2/psa_switch/main.cpp @@ -37,6 +37,8 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" +using namespace P4; + int main(int argc, char *const argv[]) { setup_gc_logging(); @@ -48,7 +50,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto hook = options.getDebugHook(); @@ -61,7 +63,7 @@ int main(int argc, char *const argv[]) { if (options.loadIRFromJson == false) { program = P4::parseP4File(options); - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; try { P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); @@ -73,17 +75,17 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; } else { std::filebuf fb; if (fb.open(options.file, std::ios::in) == nullptr) { - ::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); return 1; } std::istream inJson(&fb); JSONLoader jsonFileLoader(inJson); if (jsonFileLoader.json == nullptr) { - ::error(ErrorType::ERR_IO, "%s: Not valid input file", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: Not valid input file", options.file); return 1; } program = new IR::P4Program(jsonFileLoader); @@ -91,20 +93,21 @@ int main(int argc, char *const argv[]) { } P4::serializeP4RuntimeIfRequired(program, options); - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; BMV2::PsaSwitchMidEnd midEnd(options); midEnd.addDebugHook(hook); try { toplevel = midEnd.process(program); - if (::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) return 1; + if (::P4::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) + return 1; if (!options.dumpJsonFile.empty()) JSONGenerator(*openFile(options.dumpJsonFile, true), true) << program << std::endl; } catch (const std::exception &bug) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto backend = new BMV2::PsaSwitchBackend(options, &midEnd.refMap, &midEnd.typeMap, &midEnd.enumMap); @@ -117,7 +120,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; if (!options.outputFile.empty()) { std::ostream *out = openFile(options.outputFile, false); @@ -127,5 +130,5 @@ int main(int argc, char *const argv[]) { } } - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/bmv2/psa_switch/midend.cpp b/backends/bmv2/psa_switch/midend.cpp index ed0a5108b8..6a3a14bfb9 100644 --- a/backends/bmv2/psa_switch/midend.cpp +++ b/backends/bmv2/psa_switch/midend.cpp @@ -62,7 +62,7 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/validateProperties.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -187,4 +187,4 @@ PsaSwitchMidEnd::PsaSwitchMidEnd(CompilerOptions &options, std::ostream *outStre } } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/psa_switch/midend.h b/backends/bmv2/psa_switch/midend.h index 8c1bc35958..21cb67efe3 100644 --- a/backends/bmv2/psa_switch/midend.h +++ b/backends/bmv2/psa_switch/midend.h @@ -19,7 +19,7 @@ limitations under the License. #include "backends/bmv2/portable_common/midend.h" -namespace BMV2 { +namespace P4::BMV2 { class PsaSwitchMidEnd : public PortableMidEnd { public: @@ -27,6 +27,6 @@ class PsaSwitchMidEnd : public PortableMidEnd { explicit PsaSwitchMidEnd(CompilerOptions &options, std::ostream *outStream = nullptr); }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PSA_SWITCH_MIDEND_H_ */ diff --git a/backends/bmv2/psa_switch/options.cpp b/backends/bmv2/psa_switch/options.cpp index 29b71e3110..7a74947e9d 100644 --- a/backends/bmv2/psa_switch/options.cpp +++ b/backends/bmv2/psa_switch/options.cpp @@ -1,3 +1,3 @@ #include "options.h" -namespace BMV2 {} // namespace BMV2 +namespace P4::BMV2 {} // namespace P4::BMV2 diff --git a/backends/bmv2/psa_switch/options.h b/backends/bmv2/psa_switch/options.h index 3f42e347d6..910d3e247c 100644 --- a/backends/bmv2/psa_switch/options.h +++ b/backends/bmv2/psa_switch/options.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/bmv2/portable_common/options.h" #include "backends/bmv2/psa_switch/midend.h" -namespace BMV2 { +namespace P4::BMV2 { class PsaSwitchOptions : public PortableOptions { public: @@ -40,6 +40,6 @@ class PsaSwitchOptions : public PortableOptions { using PsaSwitchContext = P4CContextWithOptions; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PSA_SWITCH_OPTIONS_H_ */ diff --git a/backends/bmv2/psa_switch/psaSwitch.cpp b/backends/bmv2/psa_switch/psaSwitch.cpp index 6566b2ab1f..b5550d0e6f 100644 --- a/backends/bmv2/psa_switch/psaSwitch.cpp +++ b/backends/bmv2/psa_switch/psaSwitch.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "frontends/common/model.h" #include "frontends/p4/cloner.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -83,10 +83,10 @@ void PsaSwitchBackend::convert(const IR::ToplevelBlock *tlb) { if (!main) return; if (main->type->name != "PSA_Switch") - ::warning(ErrorType::WARN_INVALID, - "%1%: the main package should be called PSA_Switch" - "; are you using the wrong architecture?", - main->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main package should be called PSA_Switch" + "; are you using the wrong architecture?", + main->type->name); main->apply(*parsePsaArch); @@ -128,7 +128,7 @@ void PsaSwitchBackend::convert(const IR::ToplevelBlock *tlb) { main = toplevel->getMain(); if (!main) return; // no main main->apply(*parsePsaArch); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; program = toplevel->getProgram(); PassManager toJson = {new P4::DiscoverStructure(&structure), @@ -343,7 +343,8 @@ void ExternConverter_InternetChecksum::convertExternInstance(UNUSED ConversionCo auto egressDeparser = psaStructure->deparsers.at("egress"_cs)->controlPlaneName(); if (block != ingressParser && block != ingressDeparser && block != egressParser && block != egressDeparser) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in pipeline on this target", eb); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in pipeline on this target", + eb); } // add checksum instance auto jcksum = new Util::JsonObject(); @@ -388,17 +389,17 @@ void ExternConverter_Register::convertExternInstance(UNUSED ConversionContext *c } auto regType = st->arguments->at(0); if (!regType->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: registers with types other than bit<> or int<> are not suppoted", eb); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: registers with types other than bit<> or int<> are not suppoted", eb); return; } unsigned width = regType->width_bits(); if (width == 0) { - ::error(ErrorType::ERR_UNKNOWN, "%1%: unknown width", st->arguments->at(0)); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown width", st->arguments->at(0)); return; } jreg->emplace("bitwidth", width); ctxt->json->register_arrays->append(jreg); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/psa_switch/psaSwitch.h b/backends/bmv2/psa_switch/psaSwitch.h index dce1d9ba1d..17837c9029 100644 --- a/backends/bmv2/psa_switch/psaSwitch.h +++ b/backends/bmv2/psa_switch/psaSwitch.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/bmv2/portable_common/portable.h" #include "backends/common/psaProgramStructure.h" -namespace BMV2 { +namespace P4::BMV2 { class PsaSwitchExpressionConverter : public ExpressionConverter { public: @@ -29,8 +29,9 @@ class PsaSwitchExpressionConverter : public ExpressionConverter { : BMV2::ExpressionConverter(refMap, typeMap, structure, scalarsName) {} void modelError(const char *format, const cstring field) { - ::error(ErrorType::ERR_MODEL, - (cstring(format) + "\nInvalid metadata parameter value for PSA").c_str(), field); + ::P4::error(ErrorType::ERR_MODEL, + (cstring(format) + "\nInvalid metadata parameter value for PSA").c_str(), + field); } Util::IJson *convertParam(UNUSED const IR::Parameter *param, cstring fieldName) override { @@ -132,6 +133,6 @@ EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Hash) EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(InternetChecksum) EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE(Register) -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_PSA_SWITCH_PSASWITCH_H_ */ diff --git a/backends/bmv2/simple_switch/main.cpp b/backends/bmv2/simple_switch/main.cpp index 2b64e505d2..0458cc2caa 100644 --- a/backends/bmv2/simple_switch/main.cpp +++ b/backends/bmv2/simple_switch/main.cpp @@ -38,6 +38,8 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" +using namespace P4; + int main(int argc, char *const argv[]) { setup_gc_logging(); @@ -49,7 +51,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto hook = options.getDebugHook(); @@ -62,7 +64,7 @@ int main(int argc, char *const argv[]) { if (options.loadIRFromJson == false) { program = P4::parseP4File(options); - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; try { P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); @@ -74,17 +76,17 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; } else { std::filebuf fb; if (fb.open(options.file, std::ios::in) == nullptr) { - ::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); return 1; } std::istream inJson(&fb); JSONLoader jsonFileLoader(inJson); if (jsonFileLoader.json == nullptr) { - ::error(ErrorType::ERR_IO, "%s: Not valid json input file", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: Not valid json input file", options.file); return 1; } program = new IR::P4Program(jsonFileLoader); @@ -92,20 +94,21 @@ int main(int argc, char *const argv[]) { } P4::serializeP4RuntimeIfRequired(program, options); - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; BMV2::SimpleSwitchMidEnd midEnd(options); midEnd.addDebugHook(hook); try { toplevel = midEnd.process(program); - if (::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) return 1; + if (::P4::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) + return 1; if (!options.dumpJsonFile.empty() && !options.loadIRFromJson) JSONGenerator(*openFile(options.dumpJsonFile, true), true) << program << std::endl; } catch (const std::exception &bug) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto backend = new BMV2::SimpleSwitchBackend(options, &midEnd.refMap, &midEnd.typeMap, &midEnd.enumMap); @@ -118,7 +121,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; if (!options.outputFile.empty()) { std::ostream *out = openFile(options.outputFile, false); @@ -128,5 +131,5 @@ int main(int argc, char *const argv[]) { } } - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/bmv2/simple_switch/midend.cpp b/backends/bmv2/simple_switch/midend.cpp index 78bb398574..ba04ca2779 100644 --- a/backends/bmv2/simple_switch/midend.cpp +++ b/backends/bmv2/simple_switch/midend.cpp @@ -66,7 +66,7 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/validateProperties.h" -namespace BMV2 { +namespace P4::BMV2 { using namespace P4::literals; @@ -161,4 +161,4 @@ SimpleSwitchMidEnd::SimpleSwitchMidEnd(CompilerOptions &options, std::ostream *o } } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/simple_switch/midend.h b/backends/bmv2/simple_switch/midend.h index 6424a8ea45..22fc0e834d 100644 --- a/backends/bmv2/simple_switch/midend.h +++ b/backends/bmv2/simple_switch/midend.h @@ -23,7 +23,7 @@ limitations under the License. #include "ir/ir.h" #include "midend/convertEnums.h" -namespace BMV2 { +namespace P4::BMV2 { class SimpleSwitchMidEnd : public MidEnd { public: @@ -31,6 +31,6 @@ class SimpleSwitchMidEnd : public MidEnd { explicit SimpleSwitchMidEnd(CompilerOptions &options, std::ostream *outStream = nullptr); }; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_SIMPLE_SWITCH_MIDEND_H_ */ diff --git a/backends/bmv2/simple_switch/options.h b/backends/bmv2/simple_switch/options.h index 1b4a28ea46..1009e3e643 100644 --- a/backends/bmv2/simple_switch/options.h +++ b/backends/bmv2/simple_switch/options.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/bmv2/common/options.h" #include "backends/bmv2/simple_switch/midend.h" -namespace BMV2 { +namespace P4::BMV2 { class SimpleSwitchOptions : public BMV2Options { public: @@ -40,6 +40,6 @@ class SimpleSwitchOptions : public BMV2Options { using SimpleSwitchContext = P4CContextWithOptions; -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_SIMPLE_SWITCH_OPTIONS_H_ */ diff --git a/backends/bmv2/simple_switch/simpleSwitch.cpp b/backends/bmv2/simple_switch/simpleSwitch.cpp index 6f977ab42c..5634bee00e 100644 --- a/backends/bmv2/simple_switch/simpleSwitch.cpp +++ b/backends/bmv2/simple_switch/simpleSwitch.cpp @@ -28,17 +28,17 @@ limitations under the License. #include "lib/json.h" #include "midend/flattenLogMsg.h" -using BMV2::mkArrayField; -using BMV2::mkParameters; -using BMV2::mkPrimitive; -using BMV2::nextId; -using BMV2::stringRepr; +using ::P4::BMV2::mkArrayField; +using ::P4::BMV2::mkParameters; +using ::P4::BMV2::mkPrimitive; +using ::P4::BMV2::nextId; +using ::P4::BMV2::stringRepr; -namespace BMV2 { +namespace P4::BMV2 { void ParseV1Architecture::modelError(const char *format, const IR::Node *node) { - ::error(ErrorType::ERR_MODEL, - (cstring(format) + "\nAre you using an up-to-date v1model.p4?").c_str(), node); + ::P4::error(ErrorType::ERR_MODEL, + (cstring(format) + "\nAre you using an up-to-date v1model.p4?").c_str(), node); } bool ParseV1Architecture::preorder(const IR::PackageBlock *main) { @@ -138,15 +138,15 @@ Util::IJson *ExternConverter_clone::convertExternFunction(ConversionContext *ctx if (ei->name == "I2E") { prim = "clone_ingress_pkt_to_egress"_cs; if (ctxt->blockConverted != BlockConverted::Ingress) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "'clone(I2E, ...) not invoked in ingress %1%", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "'clone(I2E, ...) not invoked in ingress %1%", mc); return nullptr; } } else { prim = "clone_egress_pkt_to_egress"_cs; if (ctxt->blockConverted != BlockConverted::Egress) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "'clone(E2E, ...) not invoked in egress %1%", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "'clone(E2E, ...) not invoked in egress %1%", mc); return nullptr; } } @@ -180,8 +180,8 @@ static unsigned getFieldListById(ConversionContext *ctxt, unsigned index) { } } if (id == -1) { - ::warning(ErrorType::WARN_INVALID, "no user metadata fields tagged with @field_list(%1%)", - index); + ::P4::warning(ErrorType::WARN_INVALID, + "no user metadata fields tagged with @field_list(%1%)", index); // Create an empty list. cstring name = ctxt->refMap->newName("empty"); id = ctxt->createFieldList(new IR::ListExpression({}), name); @@ -209,15 +209,15 @@ Util::IJson *ExternConverter_clone_preserving_field_list::convertExternFunction( if (ei->name == "I2E") { prim = "clone_ingress_pkt_to_egress"_cs; if (ctxt->blockConverted != BlockConverted::Ingress) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "'clone_preserving_field_list(I2E, ...) not invoked in ingress %1%", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "'clone_preserving_field_list(I2E, ...) not invoked in ingress %1%", mc); return nullptr; } } else { prim = "clone_egress_pkt_to_egress"_cs; if (ctxt->blockConverted != BlockConverted::Egress) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "'clone_preserving_field_list(E2E, ...) not invoked in egress %1%", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "'clone_preserving_field_list(E2E, ...) not invoked in egress %1%", mc); return nullptr; } } @@ -268,7 +268,7 @@ Util::IJson *ExternConverter_hash::convertExternFunction(ConversionContext *ctxt auto ei = P4::EnumInstance::resolve(mc->arguments->at(1)->expression, ctxt->typeMap); CHECK_NULL(ei); if (supportedHashAlgorithms.find(ei->name) == supportedHashAlgorithms.end()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: unexpected algorithm", ei->name); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: unexpected algorithm", ei->name); return nullptr; } auto fields = mc->arguments->at(3); @@ -324,8 +324,8 @@ Util::IJson *ExternConverter_resubmit_preserving_field_list::convertExternFuncti const IR::MethodCallExpression *mc, UNUSED const IR::StatOrDecl *s, UNUSED const bool emitExterns) { if (ctxt->blockConverted != BlockConverted::Ingress) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "'resubmit' can only be invoked in ingress %1%", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "'resubmit' can only be invoked in ingress %1%", mc); return nullptr; } if (mc->arguments->size() == 1) { @@ -355,8 +355,8 @@ Util::IJson *ExternConverter_recirculate_preserving_field_list::convertExternFun const IR::MethodCallExpression *mc, UNUSED const IR::StatOrDecl *s, UNUSED const bool emitExterns) { if (ctxt->blockConverted != BlockConverted::Egress) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "'resubmit' can only be invoked in egress %1%", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "'resubmit' can only be invoked in egress %1%", mc); return nullptr; } if (mc->arguments->size() == 1) { @@ -532,8 +532,8 @@ void ExternConverter_meter::convertExternInstance(ConversionContext *ctxt, const else if (mkind_name == v1model.meter.meterType.bytes.name) type = "bytes"_cs; else - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Unexpected meter type %1%", - mkind->getNode()); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Unexpected meter type %1%", + mkind->getNode()); jmtr->emplace("type", type); ctxt->json->meter_arrays->append(jmtr); } @@ -602,13 +602,13 @@ void ExternConverter_register::convertExternInstance(ConversionContext *ctxt, } auto regType = st->arguments->at(0); if (!regType->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Only registers with bit or int types are currently supported", eb); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Only registers with bit or int types are currently supported", eb); return; } unsigned width = regType->width_bits(); if (width == 0) { - ::error(ErrorType::ERR_EXPRESSION, "%1%: unknown width", st->arguments->at(0)); + ::P4::error(ErrorType::ERR_EXPRESSION, "%1%: unknown width", st->arguments->at(0)); return; } jreg->emplace("bitwidth", width); @@ -639,7 +639,7 @@ void ExternConverter_direct_counter::convertExternInstance(ConversionContext *ct cstring name = inst->controlPlaneName(); auto it = ctxt->structure->directCounterMap.find(name); if (it == ctxt->structure->directCounterMap.end()) { - ::warning(ErrorType::WARN_UNUSED, "%1%: Direct counter not used; ignoring", inst); + ::P4::warning(ErrorType::WARN_UNUSED, "%1%: Direct counter not used; ignoring", inst); } else { auto jctr = new Util::JsonObject(); jctr->emplace("name", name); @@ -688,10 +688,10 @@ void ExternConverter_direct_meter::convertExternInstance(ConversionContext *ctxt // property. // + the meter is incorrectly associated with a table via a // property like 'counters = my_meter;'. - ::error(ErrorType::ERR_INVALID, - "%1%: direct meter is not associated with any table" - " via 'meters' table property", - inst); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: direct meter is not associated with any table" + " via 'meters' table property", + inst); return; } CHECK_NULL(info->destinationField); @@ -746,7 +746,7 @@ void ExternConverter_action_profile::convertExternInstance(ConversionContext *ct BUG_CHECK(sz, "%1%Invalid declaration of extern ctor: no size param", eb->constructor->srcInfo); if (!sz->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); return; } action_profile->emplace("max_size", sz->to()->value); @@ -768,10 +768,10 @@ void ExternConverter_action_profile::convertExternInstance(ConversionContext *ct if (input == nullptr) { // the selector is never used by any table, we cannot figure out its // input and therefore cannot include it in the JSON - ::warning(ErrorType::WARN_UNUSED, - "Action selector '%1%' is never referenced by a table " - "and cannot be included in bmv2 JSON", - c); + ::P4::warning(ErrorType::WARN_UNUSED, + "Action selector '%1%' is never referenced by a table " + "and cannot be included in bmv2 JSON", + c); return; } auto j_input = mkArrayField(selector, "input"_cs); @@ -805,7 +805,7 @@ void ExternConverter_action_selector::convertExternInstance(ConversionContext *c BUG_CHECK(sz, "%1%Invalid declaration of extern ctor: no size param", eb->constructor->srcInfo); if (!sz->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", sz); return; } action_profile->emplace("max_size", sz->to()->value); @@ -827,10 +827,10 @@ void ExternConverter_action_selector::convertExternInstance(ConversionContext *c if (input == nullptr) { // the selector is never used by any table, we cannot figure out its // input and therefore cannot include it in the JSON - ::warning(ErrorType::WARN_UNUSED, - "Action selector '%1%' is never referenced by a table " - "and cannot be included in bmv2 JSON", - c); + ::P4::warning(ErrorType::WARN_UNUSED, + "Action selector '%1%' is never referenced by a table " + "and cannot be included in bmv2 JSON", + c); return; } auto j_input = mkArrayField(selector, "input"_cs); @@ -866,8 +866,8 @@ Util::IJson *ExternConverter_log_msg::convertExternFunction(ConversionContext *c // evaluating to integral types. auto le = convertToList(arg1, ctxt->typeMap); if (!le) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Second argument must be a list expression: %2%", mc, arg1); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Second argument must be a list expression: %2%", mc, arg1); return primitive; } @@ -876,8 +876,8 @@ Util::IJson *ExternConverter_log_msg::convertExternFunction(ConversionContext *c auto tf = ctxt->typeMap->getType(v); if (!tf->is() && !tf->is() && !tf->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: only integral values supported for logged values", mc); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: only integral values supported for logged values", mc); return primitive; } auto val = ctxt->conv->convert(v, false, true, true); @@ -893,8 +893,8 @@ Util::IJson *ExternConverter_log_msg::convertExternFunction(ConversionContext *c } void SimpleSwitchBackend::modelError(const char *format, const IR::Node *node) const { - ::errorWithSuffix(ErrorType::ERR_MODEL, format, "\nAre you using an up-to-date v1model.p4?", - node); + ::P4::errorWithSuffix(ErrorType::ERR_MODEL, format, "\nAre you using an up-to-date v1model.p4?", + node); } cstring SimpleSwitchBackend::createCalculation(cstring algo, const IR::Expression *fields, @@ -935,8 +935,8 @@ class EnsureExpressionIsSimple : public Inspector { setName("EnsureExpressionIsSimple"); } bool preorder(const IR::Expression *expression) override { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Computations are not supported in %2%", - expression, block); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Computations are not supported in %2%", + expression, block); return false; } bool preorder(const IR::StructExpression *) override { return true; } @@ -996,10 +996,10 @@ void SimpleSwitchBackend::convertChecksum(const IR::BlockStatement *block, } } } - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Only calls to %2% or %3% allowed", stat, - verify ? v1model.verify_checksum.name : v1model.update_checksum.name, - verify ? v1model.verify_checksum_with_payload.name - : v1model.update_checksum_with_payload.name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Only calls to %2% or %3% allowed", stat, + verify ? v1model.verify_checksum.name : v1model.update_checksum.name, + verify ? v1model.verify_checksum_with_payload.name + : v1model.update_checksum_with_payload.name); } } @@ -1044,14 +1044,14 @@ void SimpleSwitchBackend::createRecirculateFieldsList(ConversionContext *ctxt, for (auto e : anno->expr) { auto cst = e->to(); if (cst == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Annotation must be a constant integer", e); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Annotation must be a constant integer", e); continue; } unsigned index = cst->asUnsigned(); Util::JsonArray *elements; - auto fl = ::get(fieldLists, index); + auto fl = ::P4::get(fieldLists, index); if (fl == nullptr) { fl = new Util::JsonObject(); ctxt->json->field_lists->append(fl); @@ -1070,7 +1070,7 @@ void SimpleSwitchBackend::createRecirculateFieldsList(ConversionContext *ctxt, field->emplace("type", "field"); auto value = new Util::JsonArray(); value->append(scalarName); - auto name = ::get(ctxt->structure->scalarMetadataFields, f); + auto name = ::P4::get(ctxt->structure->scalarMetadataFields, f); value->append(name); field->emplace("value"_cs, value); elements->append(field); @@ -1086,13 +1086,13 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { if (!main) return; // no main if (main->type->name != "V1Switch") - ::warning(ErrorType::WARN_INVALID, - "%1%: the main package should be called V1Switch" - "; are you using the wrong architecture?", - main->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main package should be called V1Switch" + "; are you using the wrong architecture?", + main->type->name); main->apply(*parseV1Arch); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; /// Declaration which introduces the user metadata. /// We expect this to be a struct type. @@ -1111,14 +1111,14 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { auto metaParam = params->parameters.at(2); auto paramType = metaParam->type; if (!paramType->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected the user metadata type to be a struct", - paramType); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected the user metadata type to be a struct", + paramType); return; } auto decl = refMap->getDeclaration(paramType->to()->path); if (!decl->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected the user metadata type to be a struct", - paramType); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected the user metadata type to be a struct", + paramType); return; } userMetaType = decl->to(); @@ -1129,15 +1129,15 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { auto headersParam = params->parameters.at(1); auto headersType = headersParam->type; if (!headersType->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected type to be a struct", - headersParam->type); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected type to be a struct", + headersParam->type); return; } decl = refMap->getDeclaration(headersType->to()->path); auto st = decl->to(); if (st == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected type to be a struct", - headersParam->type); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected type to be a struct", + headersParam->type); return; } LOG2("Headers type is " << st); @@ -1145,9 +1145,9 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { auto t = typeMap->getType(f, true); if (!t->is() && !t->is() && !t->is()) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: the type should be a struct of headers, stacks, or unions", - headersParam->type); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: the type should be a struct of headers, stacks, or unions", + headersParam->type); return; } } @@ -1218,7 +1218,7 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { json->add_enum(name, pEntry.first, pEntry.second); } } - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; main = toplevel->getMain(); if (!main) return; // no main @@ -1271,4 +1271,4 @@ void SimpleSwitchBackend::convert(const IR::ToplevelBlock *tlb) { (void)toplevel->apply(ConvertGlobals(ctxt, options.emitExterns)); } -} // namespace BMV2 +} // namespace P4::BMV2 diff --git a/backends/bmv2/simple_switch/simpleSwitch.h b/backends/bmv2/simple_switch/simpleSwitch.h index 3a2e7b541c..681276a388 100644 --- a/backends/bmv2/simple_switch/simpleSwitch.h +++ b/backends/bmv2/simple_switch/simpleSwitch.h @@ -38,7 +38,7 @@ limitations under the License. #include "frontends/p4/unusedDeclarations.h" #include "midend/convertEnums.h" -namespace BMV2 { +namespace P4::BMV2 { class V1ProgramStructure : public P4::ProgramStructure { public: @@ -79,8 +79,8 @@ class SimpleSwitchExpressionConverter : public ExpressionConverter { : ExpressionConverter(refMap, typeMap, structure, scalarsName), structure(structure) {} void modelError(const char *format, const IR::Node *node) { - ::errorWithSuffix(ErrorType::ERR_MODEL, format, "\nAre you using an up-to-date v1model.p4?", - node); + ::P4::errorWithSuffix(ErrorType::ERR_MODEL, format, + "\nAre you using an up-to-date v1model.p4?", node); } bool isStandardMetadataParameter(const IR::Parameter *param) { @@ -181,6 +181,6 @@ EXTERN_CONVERTER_W_OBJECT_AND_INSTANCE_AND_MODEL(direct_meter, P4V1::V1Model, v1 EXTERN_CONVERTER_W_INSTANCE_AND_MODEL(action_profile, P4V1::V1Model, v1model) EXTERN_CONVERTER_W_INSTANCE_AND_MODEL(action_selector, P4V1::V1Model, v1model) -} // namespace BMV2 +} // namespace P4::BMV2 #endif /* BACKENDS_BMV2_SIMPLE_SWITCH_SIMPLESWITCH_H_ */ diff --git a/backends/common/metermap.cpp b/backends/common/metermap.cpp index 05f1717332..3ffb75e2b4 100644 --- a/backends/common/metermap.cpp +++ b/backends/common/metermap.cpp @@ -20,7 +20,7 @@ namespace P4 { /// @returns direct meter information from the direct meter map. DirectMeterMap::DirectMeterInfo *DirectMeterMap::createInfo(const IR::IDeclaration *meter) { - auto prev = ::get(directMeter, meter); + auto prev = ::P4::get(directMeter, meter); BUG_CHECK(prev == nullptr, "Already created"); auto result = new DirectMeterMap::DirectMeterInfo(); directMeter.emplace(meter, result); @@ -28,22 +28,22 @@ DirectMeterMap::DirectMeterInfo *DirectMeterMap::createInfo(const IR::IDeclarati } DirectMeterMap::DirectMeterInfo *DirectMeterMap::getInfo(const IR::IDeclaration *meter) { - return ::get(directMeter, meter); + return ::P4::get(directMeter, meter); } /// Set the table that a direct meter is attached to. void DirectMeterMap::setTable(const IR::IDeclaration *meter, const IR::P4Table *table) { auto info = getInfo(meter); if (info == nullptr) { - ::error(ErrorType::ERR_INVALID, - "%1%: table with direct meter %2% must have" - " at least one action with a read method call", - table, meter); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: table with direct meter %2% must have" + " at least one action with a read method call", + table, meter); return; } if (info->table != nullptr) - ::error(ErrorType::ERR_INVALID, - "%1%: Direct meters cannot be attached to multiple tables %2% and %3%", meter, - table, info->table); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Direct meters cannot be attached to multiple tables %2% and %3%", meter, + table, info->table); info->table = table; } /// Helper function to check if two expressions are syntactically identical. @@ -69,10 +69,10 @@ void DirectMeterMap::setDestination(const IR::IDeclaration *meter, } else { bool same = checkSame(destination, info->destinationField); if (!same) - ::error(ErrorType::ERR_INVALID, - "all meter operations must write to the same destination," - " however %1% and %2% are different", - destination, info->destinationField); + ::P4::error(ErrorType::ERR_INVALID, + "all meter operations must write to the same destination," + " however %1% and %2% are different", + destination, info->destinationField); } } diff --git a/backends/common/psaProgramStructure.cpp b/backends/common/psaProgramStructure.cpp index d4e096badc..dc738da754 100644 --- a/backends/common/psaProgramStructure.cpp +++ b/backends/common/psaProgramStructure.cpp @@ -70,9 +70,9 @@ void InspectPsaProgram::addTypesAndInstances(const IR::Type_StructLike *type, bo if (ft->is()) { // The headers struct can not contain nested structures. if (isHeader && ft->is()) { - ::error(ErrorType::ERR_INVALID, - "Type %1% should only contain headers, header stacks, or header unions", - type); + ::P4::error(ErrorType::ERR_INVALID, + "Type %1% should only contain headers, header stacks, or header unions", + type); return; } auto st = ft->to(); @@ -93,8 +93,8 @@ void InspectPsaProgram::addTypesAndInstances(const IR::Type_StructLike *type, bo if (auto h_type = uft->to()) { addHeaderInstance(h_type, uf->controlPlaneName()); } else { - ::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, - uft); + ::P4::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, + uft); return; } } diff --git a/backends/common/psaProgramStructure.h b/backends/common/psaProgramStructure.h index 6677b957c5..00527ebb56 100644 --- a/backends/common/psaProgramStructure.h +++ b/backends/common/psaProgramStructure.h @@ -64,9 +64,9 @@ class ParsePsaArchitecture : public ParsePortableArchitecture { } void modelError(const char *format, const IR::INode *node) { - ::error(ErrorType::ERR_MODEL, - (cstring(format) + "\nAre you using an up-to-date 'psa.p4'?").c_str(), - node->getNode()); + ::P4::error(ErrorType::ERR_MODEL, + (cstring(format) + "\nAre you using an up-to-date 'psa.p4'?").c_str(), + node->getNode()); } bool preorder(const IR::PackageBlock *block) override; diff --git a/backends/dpdk/backend.cpp b/backends/dpdk/backend.cpp index 7fdd13946e..4baff0cf25 100644 --- a/backends/dpdk/backend.cpp +++ b/backends/dpdk/backend.cpp @@ -33,7 +33,7 @@ limitations under the License. #include "midend/removeComplexExpressions.h" #include "midend/simplifyKey.h" -namespace DPDK { +namespace P4::DPDK { void DpdkBackend::convert(const IR::ToplevelBlock *tlb) { CHECK_NULL(tlb); @@ -121,7 +121,7 @@ void DpdkBackend::convert(const IR::ToplevelBlock *tlb) { genContextJson->serializeContextJson(out); out->flush(); } else - ::error(ErrorType::ERR_IO, "Could not open file: %1%", options.ctxtFile); + ::P4::error(ErrorType::ERR_IO, "Could not open file: %1%", options.ctxtFile); } }), new ReplaceHdrMetaField(), @@ -166,4 +166,4 @@ void DpdkBackend::convert(const IR::ToplevelBlock *tlb) { void DpdkBackend::codegen(std::ostream &out) const { dpdk_program->toSpec(out) << std::endl; } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/backend.h b/backends/dpdk/backend.h index 45314f18d2..6db74f647d 100644 --- a/backends/dpdk/backend.h +++ b/backends/dpdk/backend.h @@ -35,7 +35,7 @@ namespace p4configv1 = ::p4::config::v1; #include "lib/json.h" #include "options.h" -namespace DPDK { +namespace P4::DPDK { class DpdkBackend { DpdkOptions &options; P4::ReferenceMap *refMap; @@ -51,6 +51,6 @@ class DpdkBackend { void codegen(std::ostream &) const; }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_BACKEND_H_ */ diff --git a/backends/dpdk/constants.h b/backends/dpdk/constants.h index 03fe6aa731..53c611f906 100644 --- a/backends/dpdk/constants.h +++ b/backends/dpdk/constants.h @@ -19,6 +19,8 @@ limitations under the License. #include "lib/cstring.h" +namespace P4 { + /// Unique handle for action and table. const unsigned table_handle_prefix = 0x00010000; const unsigned action_handle_prefix = 0x00020000; @@ -62,4 +64,6 @@ const unsigned initial_group_id = 0xFFFFFFFF; /// Maximum operand size for unary, binary and ternary operations const int dpdk_max_operand_size = 64; +} // namespace P4 + #endif /* BACKENDS_DPDK_CONSTANTS_H_ */ diff --git a/backends/dpdk/control-plane/bfruntime_arch_handler.h b/backends/dpdk/control-plane/bfruntime_arch_handler.h index d3721f4908..a5d8190680 100644 --- a/backends/dpdk/control-plane/bfruntime_arch_handler.h +++ b/backends/dpdk/control-plane/bfruntime_arch_handler.h @@ -38,10 +38,10 @@ limitations under the License. #include "frontends/p4/typeMap.h" #include "midend/eliminateTypedefs.h" -using P4::ReferenceMap; -using P4::TypeMap; -using P4::ControlPlaneAPI::Helpers::getExternInstanceFromProperty; -using P4::ControlPlaneAPI::Helpers::isExternPropertyConstructedInPlace; +using ::P4::ReferenceMap; +using ::P4::TypeMap; +using ::P4::ControlPlaneAPI::Helpers::getExternInstanceFromProperty; +using ::P4::ControlPlaneAPI::Helpers::isExternPropertyConstructedInPlace; namespace p4configv1 = ::p4::config::v1; @@ -92,7 +92,8 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon { template void forAllPipeBlocks(const IR::ToplevelBlock *evaluatedProgram, Func function) { auto main = evaluatedProgram->getMain(); - if (!main) ::error(ErrorType::ERR_NOT_FOUND, "Program does not contain a `main` module"); + if (!main) + ::P4::error(ErrorType::ERR_NOT_FOUND, "Program does not contain a `main` module"); auto cparams = main->getConstructorParameters(); int index = -1; for (auto param : main->constantValue) { @@ -331,21 +332,21 @@ class BFRuntimeArchHandler : public P4RuntimeArchHandlerCommon { return false; } } else if (expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "Unresolved value %1% for psa_idle_timeout " - "property on table %2%. Must be a constant and one of " - "{ NOTIFY_CONTROL, NO_TIMEOUT }", - timeout, table); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unresolved value %1% for psa_idle_timeout " + "property on table %2%. Must be a constant and one of " + "{ NOTIFY_CONTROL, NO_TIMEOUT }", + timeout, table); return false; } } } - ::error(ErrorType::ERR_UNEXPECTED, - "Unexpected value %1% for psa_idle_timeout " - "property on table %2%. Supported values are " - "{ NOTIFY_CONTROL, NO_TIMEOUT }", - timeout, table); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unexpected value %1% for psa_idle_timeout " + "property on table %2%. Supported values are " + "{ NOTIFY_CONTROL, NO_TIMEOUT }", + timeout, table); return false; } }; diff --git a/backends/dpdk/control-plane/bfruntime_ext.cpp b/backends/dpdk/control-plane/bfruntime_ext.cpp index 809a5be53d..0f13c9ef52 100644 --- a/backends/dpdk/control-plane/bfruntime_ext.cpp +++ b/backends/dpdk/control-plane/bfruntime_ext.cpp @@ -37,8 +37,8 @@ struct BFRuntimeSchemaGenerator::ActionSelector { const auto &pre = externInstance.preamble(); ::dpdk::ActionSelector actionSelector; if (!externInstance.info().UnpackTo(&actionSelector)) { - ::error(ErrorType::ERR_NOT_FOUND, - "Extern instance %1% does not pack an ActionSelector object", pre.name()); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "Extern instance %1% does not pack an ActionSelector object", pre.name()); return std::nullopt; } auto selectorId = makeBFRuntimeId(pre.id(), ::dpdk::P4Ids::ACTION_SELECTOR); @@ -167,8 +167,8 @@ bool BFRuntimeSchemaGenerator::addActionProfIds(const p4configv1::Table &table, if (implementationId > 0) { auto hasSelector = actProfHasSelector(implementationId); if (hasSelector == std::nullopt) { - ::error(ErrorType::ERR_INVALID, "Invalid implementation id in p4info: %1%", - implementationId); + ::P4::error(ErrorType::ERR_INVALID, "Invalid implementation id in p4info: %1%", + implementationId); return false; } cstring tableType; diff --git a/backends/dpdk/control-plane/bfruntime_ext.h b/backends/dpdk/control-plane/bfruntime_ext.h index aa3a2a0144..14e25215c9 100644 --- a/backends/dpdk/control-plane/bfruntime_ext.h +++ b/backends/dpdk/control-plane/bfruntime_ext.h @@ -82,8 +82,8 @@ class BFRuntimeSchemaGenerator : public BFRuntimeGenerator { const auto &pre = externInstance.preamble(); p4configv1::ActionProfile actionProfile; if (!externInstance.info().UnpackTo(&actionProfile)) { - ::error(ErrorType::ERR_NOT_FOUND, - "Extern instance %1% does not pack an ActionProfile object", pre.name()); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "Extern instance %1% does not pack an ActionProfile object", pre.name()); return std::nullopt; } auto tableIds = collectTableIds(p4info, actionProfile.table_ids().begin(), diff --git a/backends/dpdk/dbprint-dpdk.cpp b/backends/dpdk/dbprint-dpdk.cpp index 8349d0db93..50b9e5e80b 100644 --- a/backends/dpdk/dbprint-dpdk.cpp +++ b/backends/dpdk/dbprint-dpdk.cpp @@ -1,5 +1,7 @@ #include "ir/ir.h" +namespace P4 { + void IR::DpdkJmpLabelStatement::dbprint(std::ostream &out) const { out << "jmp " << label << std::endl; } @@ -67,3 +69,5 @@ void IR::DpdkJmpEqualStatement::dbprint(std::ostream &out) const { void IR::DpdkMovStatement::dbprint(std::ostream &out) const { out << "mov " << dst << " " << src << std::endl; } + +} // namespace P4 diff --git a/backends/dpdk/dpdk.def b/backends/dpdk/dpdk.def index 3e59bb6ff8..511c2bcd8f 100644 --- a/backends/dpdk/dpdk.def +++ b/backends/dpdk/dpdk.def @@ -48,7 +48,7 @@ class DpdkTable { if (kp == nullptr) return nullptr; if (!kp->value->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be a key", kp); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a key", kp); return nullptr; } return kp->value->to(); } EntriesList getEntries() const { @@ -56,7 +56,7 @@ class DpdkTable { if (ep == nullptr) return nullptr; if (!ep->value->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be a list of entries", ep); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a list of entries", ep); return nullptr; } return ep->value->to(); diff --git a/backends/dpdk/dpdkArch.cpp b/backends/dpdk/dpdkArch.cpp index a61fd8a752..7c08130022 100644 --- a/backends/dpdk/dpdkArch.cpp +++ b/backends/dpdk/dpdkArch.cpp @@ -31,7 +31,7 @@ limitations under the License. #include "frontends/p4/typeMap.h" #include "lib/cstring.h" -namespace DPDK { +namespace P4::DPDK { cstring TypeStruct2Name(const cstring s) { if (isStandardMetadata(s)) { @@ -465,8 +465,8 @@ const IR::Node *AlignHdrMetaField::preorder(IR::Type_StructLike *st) { } } if ((size_sum_so_far & 0x7) != 0) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "'%1%' is not 8-bit aligned", - st->name.name); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "'%1%' is not 8-bit aligned", + st->name.name); return st; } if (all_hdr_field_aligned) { @@ -559,11 +559,11 @@ const IR::Node *AlignHdrMetaField::preorder(IR::Type_StructLike *st) { } // Throw error if there is non-aligned field present at the end in header. if (size_sum_so_far != 0) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "8-bit Alignment for Header Structure '%1%' is not possible as no more header" - " fields available in header to combine. DPDK does not support non-aligned" - " header fields.", - st->name.name); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "8-bit Alignment for Header Structure '%1%' is not possible as no more header" + " fields available in header to combine. DPDK does not support non-aligned" + " header fields.", + st->name.name); return st; } return new IR::Type_Header(IR::ID(st->name), st->annotations, *fields); @@ -1462,8 +1462,8 @@ bool CopyMatchKeysToSingleStruct::isLearnerTable(const IR::P4Table *t) { if (add_on_miss->value->is()) { auto expr = add_on_miss->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: expected boolean for 'add_on_miss' property", - add_on_miss); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: expected boolean for 'add_on_miss' property", add_on_miss); return false; } else { use_add_on_miss = expr->to()->value; @@ -1547,8 +1547,8 @@ cstring CopyMatchKeysToSingleStruct::getTableKeyName(const IR::Expression *e) { keyName = "m." + mem->member; } } else { - ::error(ErrorType::ERR_INVALID, "Invalid member expression '%1%' used as table key", - mem); + ::P4::error(ErrorType::ERR_INVALID, "Invalid member expression '%1%' used as table key", + mem); } } else if (auto m = e->to()) { BUG_CHECK(isValidCall(m), @@ -1560,8 +1560,8 @@ cstring CopyMatchKeysToSingleStruct::getTableKeyName(const IR::Expression *e) { CHECK_NULL(mem); keyName = "h." + mem->expr->to()->member + "." + IR::Type_Header::isValid; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Unsupported key expression %1%", - e->toString()); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Unsupported key expression %1%", + e->toString()); } return keyName; } @@ -1641,8 +1641,8 @@ const IR::Node *CopyMatchKeysToSingleStruct::preorder(IR::Key *keys) { if (keyInfoInstance->isLearner) { if (!keyInfoInstance->isExact) { - ::error(ErrorType::ERR_EXPECTED, "Learner table %1% must have all exact match keys", - table->name); + ::P4::error(ErrorType::ERR_EXPECTED, "Learner table %1% must have all exact match keys", + table->name); return keys; } structure->table_type_map.emplace(table->name.name, InternalTableType::LEARNER); @@ -1664,10 +1664,10 @@ const IR::Node *CopyMatchKeysToSingleStruct::preorder(IR::Key *keys) { // This prune will prevent the postorder(IR::KeyElement*) below from executing prune(); } else { - ::warning(ErrorType::WARN_MISMATCH, - "Mismatched header/metadata struct for key " - "elements in table %1%. Copying all match fields to metadata", - findOrigCtxt()->name.toString()); + ::P4::warning(ErrorType::WARN_MISMATCH, + "Mismatched header/metadata struct for key " + "elements in table %1%. Copying all match fields to metadata", + findOrigCtxt()->name.toString()); LOG3("Will pull out " << keys); } return keys; @@ -1748,9 +1748,9 @@ std::optional getExternInstanceFromProperty( auto property = table->properties->getProperty(propertyName); if (property == nullptr) return std::nullopt; if (!property->value->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected %1% property value for table %2% to be an expression: %3%", propertyName, - table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected %1% property value for table %2% to be an expression: %3%", + propertyName, table->controlPlaneName(), property); return std::nullopt; } @@ -1759,19 +1759,19 @@ std::optional getExternInstanceFromProperty( if (isConstructedInPlace) *isConstructedInPlace = expr->is(); if (expr->is() && property->getAnnotation(IR::Annotation::nameAnnotation) == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Table '%1%' has an anonymous table property '%2%' with no name annotation, " - "which is not supported by P4Runtime", - table->controlPlaneName(), propertyName); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Table '%1%' has an anonymous table property '%2%' with no name annotation, " + "which is not supported by P4Runtime", + table->controlPlaneName(), propertyName); return std::nullopt; } auto name = property->controlPlaneName(); auto externInstance = P4::ExternInstance::resolve(expr, refMap, typeMap, name); if (!externInstance) { - ::error(ErrorType::ERR_INVALID, - "Expected %1% property value for table %2% to resolve to an " - "extern instance: %3%", - propertyName, table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_INVALID, + "Expected %1% property value for table %2% to resolve to an " + "extern instance: %3%", + propertyName, table->controlPlaneName(), property); return std::nullopt; } return externInstance; @@ -1929,10 +1929,10 @@ const IR::Node *SplitActionSelectorTable::postorder(IR::P4Table *tbl) { tbl->properties->getProperty(structure->isPNA() ? "pna_direct_meter" : "psa_direct_meter"); if (property != nullptr && (counterProperty != nullptr || meterProperty != nullptr)) { - ::error(ErrorType::ERR_UNEXPECTED, - "implementation property cannot co-exist with direct counter and direct meter " - "property for table %1%", - tbl->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "implementation property cannot co-exist with direct counter and direct meter " + "property for table %1%", + tbl->name); return tbl; } @@ -1943,29 +1943,30 @@ const IR::Node *SplitActionSelectorTable::postorder(IR::P4Table *tbl) { if (instance->type->name != "ActionSelector") return tbl; if (instance->arguments->size() != 3) { - ::error(ErrorType::ERR_UNEXPECTED, "Incorrect number of argument on action selector %1%", - *instance->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Incorrect number of argument on action selector %1%", *instance->name); return tbl; } if (!instance->arguments->at(1)->expression->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "The 'size' argument of ActionSelector %1% must be a constant", *instance->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "The 'size' argument of ActionSelector %1% must be a constant", + *instance->name); return tbl; } int n_groups_max = instance->arguments->at(1)->expression->to()->asUnsigned(); if (!instance->arguments->at(2)->expression->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "The 'outputWidth' argument of ActionSelector %1% must be a constant", - *instance->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "The 'outputWidth' argument of ActionSelector %1% must be a constant", + *instance->name); return tbl; } auto outputWidth = instance->arguments->at(2)->expression->to()->asUnsigned(); if (outputWidth >= 32) { - ::error(ErrorType::ERR_UNEXPECTED, - "The 'outputWidth' argument of ActionSelector %1% must be smaller than 32", - *instance->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "The 'outputWidth' argument of ActionSelector %1% must be smaller than 32", + *instance->name); return tbl; } int n_members_per_group_max = 1 << outputWidth; @@ -2060,14 +2061,14 @@ const IR::Node *SplitActionProfileTable::postorder(IR::P4Table *tbl) { if (!instance || instance->type->name != "ActionProfile") return tbl; if (instance->arguments->size() != 1) { - ::error(ErrorType::ERR_MODEL, "Incorrect number of argument on action profile %1%", - *instance->name); + ::P4::error(ErrorType::ERR_MODEL, "Incorrect number of argument on action profile %1%", + *instance->name); return tbl; } if (!instance->arguments->at(0)->expression->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "The 'size' argument of ActionProfile %1% must be a constant", *instance->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "The 'size' argument of ActionProfile %1% must be a constant", *instance->name); return tbl; } @@ -2175,7 +2176,7 @@ const IR::Node *SplitP4TableCommon::postorder(IR::MethodCallStatement *statement auto tableName = apply->object->getName().name; group_id_expr = initializeMemberAndGroupId(tableName, decls); if (member_tables.count(tableName) == 0) { - ::error(ErrorType::ERR_NOT_FOUND, "Unable to find member table %1%", tableName); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Unable to find member table %1%", tableName); return statement; } // an action selector t.apply() is converted to @@ -2192,7 +2193,7 @@ const IR::Node *SplitP4TableCommon::postorder(IR::MethodCallStatement *statement IR::Expression *t0stat = nullptr; if (implementation == TableImplementation::ACTION_SELECTOR) { if (group_tables.count(tableName) == 0) { - ::error(ErrorType::ERR_NOT_FOUND, "Unable to find group table %1%", tableName); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Unable to find group table %1%", tableName); return statement; } auto selectorTable = group_tables.at(tableName); @@ -2259,7 +2260,7 @@ const IR::Node *SplitP4TableCommon::postorder(IR::IfStatement *statement) { auto tableName = apply->object->getName().name; group_id_expr = initializeMemberAndGroupId(tableName, decls); if (member_tables.count(tableName) == 0) { - ::error(ErrorType::ERR_NOT_FOUND, "Unable to find member table %1%", tableName); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Unable to find member table %1%", tableName); return statement; } if (member_tables.count(tableName) == 0) return statement; @@ -2364,7 +2365,7 @@ const IR::Node *SplitP4TableCommon::postorder(IR::SwitchStatement *statement) { group_id_expr = initializeMemberAndGroupId(tableName, decls); if (member_tables.count(tableName) == 0) { - ::error(ErrorType::ERR_NOT_FOUND, "Unable to find member table %1%", tableName); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Unable to find member table %1%", tableName); return statement; } auto ifBaseTableHit = new IR::IndexedVector(); @@ -2376,7 +2377,7 @@ const IR::Node *SplitP4TableCommon::postorder(IR::SwitchStatement *statement) { if (implementation == TableImplementation::ACTION_SELECTOR) { if (group_tables.count(tableName) == 0) { - ::error(ErrorType::ERR_NOT_FOUND, "Unable to find group table %1%", tableName); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Unable to find group table %1%", tableName); return statement; } auto selectorTable = group_tables.at(tableName); @@ -2458,10 +2459,10 @@ void CollectDirectCounterMeter::checkMethodCallInAction(const P4::ExternMethod * // error if more than one count method found with different instance name if (oneInstance != instanceName) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1% method for different %2% " - "instances (%3% and %4%) called within same action", - method, externName, oneInstance, instanceName); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1% method for different %2% " + "instances (%3% and %4%) called within same action", + method, externName, oneInstance, instanceName); return; } } @@ -2524,14 +2525,14 @@ bool CollectDirectCounterMeter::preorder(const IR::P4Table *tbl) { auto meterInstance = Helpers::getExternInstanceFromProperty( tbl, direct_meter, refMap, typeMap, &isConstructedInPlace, meterExternName); int table_size = getTableSize(tbl); - auto table_type = ::get(structure->table_type_map, tbl->name.name); + auto table_type = ::P4::get(structure->table_type_map, tbl->name.name); // Direct Counter and Meter are not supported with Wildcard match tables. if (table_type == InternalTableType::WILDCARD && (counterInstance || meterInstance)) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Direct counters and direct meters are" - " unsupported for wildcard match table %1%", - tbl->name); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Direct counters and direct meters are" + " unsupported for wildcard match table %1%", + tbl->name); return false; } @@ -2549,19 +2550,20 @@ bool CollectDirectCounterMeter::preorder(const IR::P4Table *tbl) { if (defaultActionDecl->name.originalName != "NoAction") { if (!ifMethodFound(defaultActionDecl, "count"_cs, counterExternName)) { if (counterInstance) { - ::error(ErrorType::ERR_EXPECTED, - "Expected default action %1% to have " - "'count' method call for DirectCounter extern instance %2%", - defaultActionDecl->name, *counterInstance->name); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected default action %1% to have " + "'count' method call for DirectCounter extern instance %2%", + defaultActionDecl->name, *counterInstance->name); return false; } } if (!ifMethodFound(defaultActionDecl, "dpdk_execute"_cs, meterExternName)) { if (meterInstance) { - ::error(ErrorType::ERR_EXPECTED, - "Expected default action %1% to have " - "'dpdk_execute' method call for DirectMeter extern instance %2%", - defaultActionDecl->name, *meterInstance->name); + ::P4::error( + ErrorType::ERR_EXPECTED, + "Expected default action %1% to have " + "'dpdk_execute' method call for DirectMeter extern instance %2%", + defaultActionDecl->name, *meterInstance->name); return false; } } @@ -2589,20 +2591,20 @@ void ValidateDirectCounterMeter::validateMethodInvocation(P4::ExternMethod *a) { if ((externName == "DirectCounter" && methodName != "count") || (externName == "DirectMeter" && methodName != "dpdk_execute")) { - ::error(ErrorType::ERR_UNEXPECTED, "%1% method not supported for %2% extern", methodName, - externName); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1% method not supported for %2% extern", + methodName, externName); return; } if (auto di = a->object->to()) { - auto ownerTable = ::get(structure->direct_resource_map, di->name.name); + auto ownerTable = ::P4::get(structure->direct_resource_map, di->name.name); bool invokedFromOwnerTable = false; auto act = findOrigCtxt(); if (!act) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1% method of %2% extern " - "must only be called from within an action", - a->method->getName().name, di->name.originalName); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1% method of %2% extern " + "must only be called from within an action", + a->method->getName().name, di->name.originalName); return; } @@ -2615,10 +2617,10 @@ void ValidateDirectCounterMeter::validateMethodInvocation(P4::ExternMethod *a) { } if (!invokedFromOwnerTable) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1% method of %2% extern " - "can only be invoked from within action of ownertable", - a->method->getName(), di->name.originalName); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1% method of %2% extern " + "can only be invoked from within action of ownertable", + a->method->getName(), di->name.originalName); return; } } @@ -2648,8 +2650,8 @@ void CollectAddOnMissTable::postorder(const IR::P4Table *t) { if (add_on_miss->value->is()) { auto expr = add_on_miss->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: expected boolean for 'add_on_miss' property", - add_on_miss); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: expected boolean for 'add_on_miss' property", add_on_miss); return; } else { use_add_on_miss = expr->to()->value; @@ -2660,10 +2662,10 @@ void CollectAddOnMissTable::postorder(const IR::P4Table *t) { // sanity checks auto default_action = t->properties->getProperty("default_action"); if (use_add_on_miss && default_action == nullptr) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: add_on_miss property is defined, " - "but default_action not specificed for table %2%", - add_on_miss, t->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: add_on_miss property is defined, " + "but default_action not specificed for table %2%", + add_on_miss, t->name); return; } if (default_action->value->is()) { @@ -2676,9 +2678,9 @@ void CollectAddOnMissTable::postorder(const IR::P4Table *t) { default_action); auto ac = mi->to()->action; if (mi->to()->action->parameters->parameters.size() != 0) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: action cannot have action argument when used with add_on_miss", - default_action); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: action cannot have action argument when used with add_on_miss", + default_action); } default_actname = ac->name.name; } @@ -2735,7 +2737,7 @@ void ValidateAddOnMissExterns::postorder(const IR::MethodCallStatement *mcs) { return; auto act = findOrigCtxt(); BUG_CHECK(act != nullptr, "%1%: %2% extern can only be used in an action", mcs, externFuncName); - auto tbl = ::get(structure->learner_action_table, act->externalName()); + auto tbl = ::P4::get(structure->learner_action_table, act->externalName()); if (externFuncName == "restart_expire_timer" || externFuncName == "set_entry_expire_time") { bool use_idle_timeout_with_auto_delete = false; if (tbl) { @@ -2747,7 +2749,7 @@ void ValidateAddOnMissExterns::postorder(const IR::MethodCallStatement *mcs) { auto expr = idle_timeout_with_auto_delete->value->to()->expression; if (!expr->is()) { - ::error( + ::P4::error( ErrorType::ERR_UNEXPECTED, "%1%: expected boolean for 'idle_timeout_with_auto_delete' property", idle_timeout_with_auto_delete); @@ -2772,8 +2774,9 @@ void ValidateAddOnMissExterns::postorder(const IR::MethodCallStatement *mcs) { if (add_on_miss->value->is()) { auto expr = add_on_miss->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: expected boolean for 'add_on_miss' property", add_on_miss); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: expected boolean for 'add_on_miss' property", + add_on_miss); return; } else { auto use_add_on_miss = expr->to()->value; @@ -2781,20 +2784,20 @@ void ValidateAddOnMissExterns::postorder(const IR::MethodCallStatement *mcs) { isValidExternCall = true; cstring st = getDefActionName(tbl); if (st != act->name.name) { // checks caller - ::error(ErrorType::ERR_UNEXPECTED, - "%1% is not called from a default action: %2% ", mcs, - act->name.name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1% is not called from a default action: %2% ", mcs, + act->name.name); return; } else if (st == an) { // checks arg0 - ::error(ErrorType::ERR_UNEXPECTED, - "%1% action cannot be default action: %2%:", mcs, an); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1% action cannot be default action: %2%:", mcs, an); return; } for (auto action : tbl->getActionList()->actionList) { if (action->getName().originalName == an) found = true; } if (!found) { - ::error( + ::P4::error( ErrorType::ERR_UNEXPECTED, "%1% first arg action name %2% is not any action in table %3%", mcs, an, tbl->name.name); @@ -2807,10 +2810,10 @@ void ValidateAddOnMissExterns::postorder(const IR::MethodCallStatement *mcs) { } } if (!isValidExternCall) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1% must only be called from within an action with '%2% %3%'" - " property equal to true", - mcs, propName, act->name.name); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1% must only be called from within an action with '%2% %3%'" + " property equal to true", + mcs, propName, act->name.name); } return; } @@ -2969,9 +2972,10 @@ const IR::Node *MoveNonHeaderFieldsToPseudoHeader::postorder(IR::AssignmentState if (auto base = assn->right->to()) expr = base->expr; if (auto cst = assn->right->to()) { if (!cst->fitsUint64()) { - ::error(ErrorType::ERR_OVERLIMIT, - "DPDK target supports up-to 64-bit immediate values, %1% exceeds the limit", - cst); + ::P4::error( + ErrorType::ERR_OVERLIMIT, + "DPDK target supports up-to 64-bit immediate values, %1% exceeds the limit", + cst); return assn; } } @@ -3232,8 +3236,8 @@ const IR::Node *InsertReqDeclForIPSec::preorder(IR::P4Program *program) { if (!is_ipsec_used) return program; cstring resName = cstring::empty; if (!reservedNames(refMap, registerInstanceNames, resName)) { - ::error(ErrorType::ERR_RESERVED, "%1% name is reserved for DPDK IPSec port register", - resName); + ::P4::error(ErrorType::ERR_RESERVED, "%1% name is reserved for DPDK IPSec port register", + resName); return program; } bool ipsecHdrAdded = false; @@ -3246,8 +3250,8 @@ const IR::Node *InsertReqDeclForIPSec::preorder(IR::P4Program *program) { newHeaderFields.push_back( new IR::StructField(newHeaderFieldName, IR::Type_Bits::get(sa_id_width))); if (!reservedNames(refMap, {newHeaderName}, resName)) { - ::error(ErrorType::ERR_RESERVED, "%1% type name is reserved for DPDK platform header", - newHeaderName); + ::P4::error(ErrorType::ERR_RESERVED, "%1% type name is reserved for DPDK platform header", + newHeaderName); return program; } ipsecHeader = new IR::Type_Header(IR::ID(newHeaderName), newHeaderFields); @@ -3362,4 +3366,4 @@ const IR::Node *InsertReqDeclForIPSec::preorder(IR::P4Control *c) { return c; } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkArch.h b/backends/dpdk/dpdkArch.h index 8a2ff90c34..ab1da45030 100644 --- a/backends/dpdk/dpdkArch.h +++ b/backends/dpdk/dpdkArch.h @@ -29,7 +29,7 @@ limitations under the License. #include "midend/flattenInterfaceStructs.h" #include "midend/removeLeftSlices.h" -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -638,8 +638,8 @@ class CollectExternDeclaration : public Inspector { auto externTypeName = type->path->name.name; if (externTypeName == "DirectMeter") { if (d->arguments->size() != 1) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected type of meter as the only argument", d); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected type of meter as the only argument", d); } else { /* Check if the Direct meter is of PACKETS (0) type */ if (d->arguments->at(0)->expression->to()->asUnsigned() == 0) @@ -657,8 +657,8 @@ class CollectExternDeclaration : public Inspector { auto externTypeName = type->baseType->path->name.name; if (externTypeName == "Meter") { if (d->arguments->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected number of meters and type of meter as arguments", d); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected number of meters and type of meter as arguments", d); } else { /* Check if the meter is of PACKETS (0) type */ if (d->arguments->at(1)->expression->to()->asUnsigned() == 0) @@ -669,23 +669,24 @@ class CollectExternDeclaration : public Inspector { } } else if (externTypeName == "Counter") { if (d->arguments->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected number of counters and type of counter as arguments", d); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected number of counters and type of counter as arguments", + d); } } else if (externTypeName == "DirectCounter") { if (d->arguments->size() != 1) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected type of counter as the only argument", d); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected type of counter as the only argument", d); } } else if (externTypeName == "Register") { if (d->arguments->size() != 1 && d->arguments->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected size and optionally init_val as arguments", d); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected size and optionally init_val as arguments", d); } } else if (externTypeName == "Hash") { if (d->arguments->size() != 1) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: expected hash algorithm as the only argument", d); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: expected hash algorithm as the only argument", d); } } else { // unsupported extern type @@ -1092,8 +1093,8 @@ class ValidateOperandSize : public Inspector { void isValidOperandSize(const IR::Expression *e) { if (auto t = e->type->to()) { if (t->width_bits() > dpdk_max_operand_size) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Unsupported bitwidth %1% in %2%", - t->width_bits(), e); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Unsupported bitwidth %1% in %2%", + t->width_bits(), e); return; } } @@ -1389,9 +1390,9 @@ class CollectProgramStructure : public PassManager { auto toplevel = evaluator->getToplevelBlock(); auto main = toplevel->getMain(); if (main == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, - "Could not locate top-level block; is there a %1% module?", - IR::P4Program::main); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "Could not locate top-level block; is there a %1% module?", + IR::P4Program::main); return; } main->apply(*parseDpdk); @@ -1467,8 +1468,8 @@ class CollectIPSecInfo : public Inspector { if (auto a = mi->to()) { if (a->originalExternType->getName().name == "ipsec_accelerator") { if (structure->isPSA()) { - ::error(ErrorType::ERR_MODEL, "%1% is not available for PSA programs", - a->originalExternType->getName().name); + ::P4::error(ErrorType::ERR_MODEL, "%1% is not available for PSA programs", + a->originalExternType->getName().name); return false; } if (a->method->getName().name == "enable") { @@ -1476,14 +1477,14 @@ class CollectIPSecInfo : public Inspector { } else if (a->method->getName().name == "set_sa_index") { auto typeArgs = a->expr->typeArguments; if (typeArgs->size() != 1) { - ::error(ErrorType::ERR_MODEL, "Unexpected number of type arguments for %1%", - a->method->name); + ::P4::error(ErrorType::ERR_MODEL, + "Unexpected number of type arguments for %1%", a->method->name); return false; } auto width = typeArgs->at(0); if (!width->is()) { - ::error(ErrorType::ERR_MODEL, "Unexpected width type %1% for sa_index", - width); + ::P4::error(ErrorType::ERR_MODEL, "Unexpected width type %1% for sa_index", + width); return false; } sa_id_width = width->to()->width_bits(); @@ -1545,5 +1546,5 @@ struct DpdkHandleIPSec : public PassManager { } }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKARCH_H_ */ diff --git a/backends/dpdk/dpdkAsmOpt.cpp b/backends/dpdk/dpdkAsmOpt.cpp index 4267c9521f..f0c1d037fb 100644 --- a/backends/dpdk/dpdkAsmOpt.cpp +++ b/backends/dpdk/dpdkAsmOpt.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "dpdkUtils.h" -namespace DPDK { +namespace P4::DPDK { /// The assumption is compiler can only produce forward jumps. const IR::IndexedVector *RemoveRedundantLabel::removeRedundantLabel( const IR::IndexedVector &s) { @@ -400,10 +400,10 @@ big_int EmitDpdkTableConfig::convertSimpleKeyExpressionToBigInt(const IR::Expres BUG_CHECK(w == keyWidth, "SerEnum bitwidth mismatch"); return type->value; } - ::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); return -1; } else { - ::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); return -1; } } @@ -450,7 +450,8 @@ void EmitDpdkTableConfig::addAction(const IR::Expression *actionRef, P4::Referen auto argValue = sei->value->to(); argVals.push_back(argValue->value); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported argument expression", arg); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported argument expression", + arg); continue; } } @@ -488,14 +489,14 @@ void EmitDpdkTableConfig::addLpm(const IR::Expression *k, int keyWidth, P4::Type mask = km->right->to()->value; auto len = trailing_zeros(mask); if (len + count_ones(mask) != keyWidth) { // any remaining 0s in the prefix? - ::error(ErrorType::ERR_INVALID, "%1% invalid mask for LPM key", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid mask for LPM key", k); return; } if ((value & mask) != value) { - ::warning(ErrorType::WARN_MISMATCH, - "P4Runtime requires that LPM matches have masked-off bits set to 0, " - "updating value %1% to conform to the P4Runtime specification", - km->left); + ::P4::warning(ErrorType::WARN_MISMATCH, + "P4Runtime requires that LPM matches have masked-off bits set to 0, " + "updating value %1% to conform to the P4Runtime specification", + km->left); value &= mask; } valueStr = value; @@ -517,10 +518,10 @@ void EmitDpdkTableConfig::addTernary(const IR::Expression *k, int keyWidth, P4:: auto value = convertSimpleKeyExpressionToBigInt(km->left, keyWidth, typeMap); auto mask = convertSimpleKeyExpressionToBigInt(km->right, keyWidth, typeMap); if ((value & mask) != value) { - ::warning(ErrorType::WARN_MISMATCH, - "P4Runtime requires that Ternary matches have masked-off bits set to 0, " - "updating value %1% to conform to the P4Runtime specification", - km->left); + ::P4::warning(ErrorType::WARN_MISMATCH, + "P4Runtime requires that Ternary matches have masked-off bits set to 0, " + "updating value %1% to conform to the P4Runtime specification", + km->left); value &= mask; } valueStr = value; @@ -551,7 +552,7 @@ void EmitDpdkTableConfig::addRange(const IR::Expression *k, int keyWidth, P4::Ty // For e.g. 16 bit key has a max value of 65535, Range of (1..65536) // will be converted to (1..0) and will fail below check. if (start > end) - ::error(ErrorType::ERR_INVALID, "%s Invalid range for table entry", kr->srcInfo); + ::P4::error(ErrorType::ERR_INVALID, "%s Invalid range for table entry", kr->srcInfo); startStr = start; endStr = end; } else { @@ -590,8 +591,8 @@ void EmitDpdkTableConfig::addMatchKey(const IR::DpdkTable *table, const IR::List addOptional(k, keyWidth, typeMap); } else { if (!k->is()) - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: match type not supported by P4Runtime serializer", matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: match type not supported by P4Runtime serializer", matchType); continue; } } @@ -640,4 +641,4 @@ void EmitDpdkTableConfig::postorder(const IR::DpdkTable *table) { dpdkTableConfigFile.close(); } size_t ShortenTokenLength::count = 0; -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkAsmOpt.h b/backends/dpdk/dpdkAsmOpt.h index 25c95e642d..471eaaabed 100644 --- a/backends/dpdk/dpdkAsmOpt.h +++ b/backends/dpdk/dpdkAsmOpt.h @@ -35,7 +35,7 @@ limitations under the License. #define DPDK_TABLE_MAX_KEY_SIZE 64 * 8 -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -653,5 +653,5 @@ class DpdkAsmOptimization : public PassRepeated { } }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKASMOPT_H_ */ diff --git a/backends/dpdk/dpdkCheckExternInvocation.h b/backends/dpdk/dpdkCheckExternInvocation.h index 5599470fef..5b998a47c4 100644 --- a/backends/dpdk/dpdkCheckExternInvocation.h +++ b/backends/dpdk/dpdkCheckExternInvocation.h @@ -31,7 +31,7 @@ class ReferenceMap; class TypeMap; } // namespace P4 -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -171,6 +171,6 @@ class CheckExternInvocation : public Inspector { } }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKCHECKEXTERNINVOCATION_H_ */ diff --git a/backends/dpdk/dpdkContext.cpp b/backends/dpdk/dpdkContext.cpp index 908d116c8a..8390b0fbbb 100644 --- a/backends/dpdk/dpdkContext.cpp +++ b/backends/dpdk/dpdkContext.cpp @@ -20,7 +20,7 @@ limitations under the License. #include "control-plane/bfruntime_ext.h" #include "dpdkUtils.h" #include "printUtils.h" -namespace DPDK { +namespace P4::DPDK { cstring DpdkContextGenerator::removePipePrefix(cstring tableName) { if (!options.bfRtSchema.empty() || !options.tdiFile.empty()) { @@ -61,9 +61,9 @@ void DpdkContextGenerator::CollectTablesAndSetAttributes() { if (add_on_miss->value->is()) { auto expr = add_on_miss->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: expected boolean for 'add_on_miss' property", - add_on_miss); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: expected boolean for 'add_on_miss' property", + add_on_miss); return; } else { tblAttr.is_add_on_miss = expr->to()->value; @@ -77,10 +77,10 @@ void DpdkContextGenerator::CollectTablesAndSetAttributes() { auto expr = idle_timeout_with_auto_delete->value->to() ->expression; if (!expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: expected boolean for 'idle_timeout_with_auto_delete' " - "property", - idle_timeout_with_auto_delete); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: expected boolean for 'idle_timeout_with_auto_delete' " + "property", + idle_timeout_with_auto_delete); return; } else { tblAttr.idle_timeout_with_auto_delete = @@ -94,8 +94,9 @@ void DpdkContextGenerator::CollectTablesAndSetAttributes() { } else { tblAttr.isHidden = false; tblAttr.tableType = "match"_cs; - tblAttr.tableKeys = ::get(structure->key_map, kv.second->name.originalName + - "_" + tbl->name.originalName); + tblAttr.tableKeys = + ::P4::get(structure->key_map, + kv.second->name.originalName + "_" + tbl->name.originalName); } if (!hidden) tables.push_back(d); @@ -126,10 +127,10 @@ void DpdkContextGenerator::CollectTablesAndSetAttributes() { unsigned maxArgNum = externTypeName == "Counter" ? 2 : 1; int typeArgNum = maxArgNum - 1; if (ed->arguments->size() != maxArgNum) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: expected %2% arguments, number of counters and type" - "of counter", - ed, maxArgNum); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: expected %2% arguments, number of counters and type" + "of counter", + ed, maxArgNum); } auto counter_type = ed->arguments->at(typeArgNum)->expression; BUG_CHECK(counter_type->is(), "Expected counter type to be constant"); @@ -147,8 +148,8 @@ void DpdkContextGenerator::CollectTablesAndSetAttributes() { } } if (externTypeName == "DirectMeter" || externTypeName == "DirectCounter") { - auto ownerTable = ::get(structure->direct_resource_map, ed->name.name); - auto tableAttr = ::get(tableAttrmap, ownerTable->name.originalName); + auto ownerTable = ::P4::get(structure->direct_resource_map, ed->name.name); + auto tableAttr = ::P4::get(tableAttrmap, ownerTable->name.originalName); externAttr.table_id = tableAttr.tableHandle; } externAttrMap.emplace(ed->name.name, externAttr); @@ -282,7 +283,7 @@ void DpdkContextGenerator::setActionAttributes(const IR::P4Table *tbl) { // DPDK target takes a structure as parameter for Actions. So, all action // parameters are collected into a structure by an earlier pass. - auto params = ::get(structure->args_struct_map, act->getPath()->name.name + "_arg_t"); + auto params = ::P4::get(structure->args_struct_map, act->getPath()->name.name + "_arg_t"); if (params) attr.params = params->clone(); else @@ -304,9 +305,9 @@ void DpdkContextGenerator::setDefaultActionHandle(const IR::P4Table *table) { cstring default_action_name = cstring::empty; if (table->getDefaultAction()) default_action_name = toStr(table->getDefaultAction()); - auto tableAttr = ::get(tableAttrmap, table->name.originalName); + auto tableAttr = ::P4::get(tableAttrmap, table->name.originalName); for (auto action : table->getActionList()->actionList) { - struct actionAttributes attr = ::get(actionAttrMap, action->getName()); + struct actionAttributes attr = ::P4::get(actionAttrMap, action->getName()); if (toStr(action->expression) == default_action_name) { tableAttr.default_action_handle = attr.actionHandle; // Update default table handle in existing table attribute map @@ -329,14 +330,14 @@ void DpdkContextGenerator::addImmediateField(Util::JsonArray *paramJson, const c /// This functions creates JSON object for match attributes of a table. Util::JsonObject *DpdkContextGenerator::addMatchAttributes(const IR::P4Table *table, const cstring ctrlName) { - auto tableAttr = ::get(tableAttrmap, table->name.originalName); + auto tableAttr = ::P4::get(tableAttrmap, table->name.originalName); auto *match_attributes = new Util::JsonObject(); auto *actFmtArray = new Util::JsonArray(); auto *stageTblArray = new Util::JsonArray(); auto *oneStageTbl = new Util::JsonObject(); for (auto action : table->getActionList()->actionList) { auto *oneAction = new Util::JsonObject(); - struct actionAttributes attr = ::get(actionAttrMap, action->getName()); + struct actionAttributes attr = ::P4::get(actionAttrMap, action->getName()); auto name = action->externalName(); if (name != "NoAction") { name = ctrlName + "." + name; @@ -384,7 +385,7 @@ Util::JsonArray *DpdkContextGenerator::addActions(const IR::P4Table *table, const cstring controlName, bool isMatch) { auto *actArray = new Util::JsonArray(); for (auto action : table->getActionList()->actionList) { - struct actionAttributes attr = ::get(actionAttrMap, action->getName()); + struct actionAttributes attr = ::P4::get(actionAttrMap, action->getName()); // Printing compiler added actions is curently not required if (!attr.is_compiler_added_action) { auto *act = new Util::JsonObject(); @@ -446,7 +447,7 @@ bool DpdkContextGenerator::addRefTables(const cstring tbl_name, const IR::P4Tabl hasActionProfileSelector = true; *memberTable = structure->member_tables.at(tbl_name); auto *actionDataField = new Util::JsonObject(); - auto tableAttr = ::get(tableAttrmap, (*memberTable)->name.originalName); + auto tableAttr = ::P4::get(tableAttrmap, (*memberTable)->name.originalName); auto tableName = tableAttr.controlName + "." + (*memberTable)->name.originalName; actionDataField->emplace("name", tableName); actionDataField->emplace("handle", tableAttr.tableHandle); @@ -460,7 +461,7 @@ bool DpdkContextGenerator::addRefTables(const cstring tbl_name, const IR::P4Tabl hasActionProfileSelector = true; auto groupTable = structure->group_tables.at(tbl_name); auto *selectField = new Util::JsonObject(); - auto tableAttr = ::get(tableAttrmap, groupTable->name.originalName); + auto tableAttr = ::P4::get(tableAttrmap, groupTable->name.originalName); auto tableName = tableAttr.controlName + "." + groupTable->name.originalName; selectField->emplace("name", tableName); selectField->emplace("handle", tableAttr.tableHandle); @@ -478,7 +479,7 @@ bool DpdkContextGenerator::addRefTables(const cstring tbl_name, const IR::P4Tabl void DpdkContextGenerator::addMatchTables(Util::JsonArray *tablesJson) { for (auto t : tables) { auto tbl = t->to(); - auto tableAttr = ::get(tableAttrmap, tbl->name.originalName); + auto tableAttr = ::P4::get(tableAttrmap, tbl->name.originalName); auto *tableJson = initTableCommonJson(tbl->name.originalName, tableAttr); bool hasActionProfileSelector = false; bool isMatchTable = tableAttr.tableType == "match"; @@ -510,7 +511,7 @@ void DpdkContextGenerator::addMatchTables(Util::JsonArray *tablesJson) { setActionAttributes(table); setDefaultActionHandle(table); - tableAttr = ::get(tableAttrmap, table->name.originalName); + tableAttr = ::P4::get(tableAttrmap, table->name.originalName); tableJson->emplace("actions", addActions(table, tableAttr.controlName, isMatchTable)); if (isMatchTable) { tableJson->emplace("match_attributes", @@ -532,7 +533,7 @@ void DpdkContextGenerator::addMatchTables(Util::JsonArray *tablesJson) { /// Add extern information to the context json. void DpdkContextGenerator::addExternInfo(Util::JsonArray *externsJson) { for (auto t : externs) { - auto externAttr = ::get(externAttrMap, t->name.name); + auto externAttr = ::P4::get(externAttrMap, t->name.name); auto *externJson = new Util::JsonObject(); externJson->emplace("name", externAttr.externalName); externJson->emplace("target_name", t->name.name); @@ -576,4 +577,4 @@ void DpdkContextGenerator::serializeContextJson(std::ostream *destination) { destination->flush(); } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkContext.h b/backends/dpdk/dpdkContext.h index 6b1fabe799..e232261ffa 100644 --- a/backends/dpdk/dpdkContext.h +++ b/backends/dpdk/dpdkContext.h @@ -35,7 +35,7 @@ namespace p4configv1 = ::p4::config::v1; /// actions. It contains all relevant information regarding the tables and actions. /// The context JSON is based on the JSON Schema defined in DPDK_context_schema.json. -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -115,7 +115,7 @@ struct SelectionTable { } // Fetch associated member table handle cstring actionDataTableName = tbl->name.originalName.replace("_sel", ""); - auto actionTableAttr = ::get(tableAttrmap, actionDataTableName); + auto actionTableAttr = ::P4::get(tableAttrmap, actionDataTableName); bound_to_action_data_table_handle = actionTableAttr.tableHandle; } }; @@ -166,6 +166,6 @@ class DpdkContextGenerator : public Inspector { cstring removePipePrefix(cstring); }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKCONTEXT_H_ */ diff --git a/backends/dpdk/dpdkHelpers.cpp b/backends/dpdk/dpdkHelpers.cpp index e8955d2d0f..79d2475a2d 100644 --- a/backends/dpdk/dpdkHelpers.cpp +++ b/backends/dpdk/dpdkHelpers.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/cstring.h" -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -241,8 +241,8 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { auto di = e->object->to(); auto declArgs = di->arguments; if (declArgs->size() == 0) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected 1 argument for %1%", - e->object->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected 1 argument for %1%", + e->object->getName()); return false; } auto hash_alg = declArgs->at(0)->expression; @@ -305,11 +305,12 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { // If not, throw an error. if (auto b = base->expression->to()) { if (!b->is()) - ::error(ErrorType::ERR_UNEXPECTED, - "Expecting const expression '%1%'" - " for 'base' value in get_hash method of Hash extern in DPDK " - "Target", - base); + ::P4::error( + ErrorType::ERR_UNEXPECTED, + "Expecting const expression '%1%'" + " for 'base' value in get_hash method of Hash extern in DPDK " + "Target", + base); } if (auto b = max_val->expression->to()) { @@ -317,14 +318,14 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { maxValue = b->to()->asUnsigned(); // Check whether max value is power of 2 or not if (maxValue == 0 || ((maxValue & (maxValue - 1)) != 0)) { - ::error(ErrorType::ERR_UNEXPECTED, - "Invalid Max value '%1%'. DPDK" - " Target expect 'Max' value to be power of 2", - maxValue); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Invalid Max value '%1%'. DPDK" + " Target expect 'Max' value to be power of 2", + maxValue); return false; } } else { - ::error( + ::P4::error( ErrorType::ERR_UNEXPECTED, "Expecting const expression '%1%'" " for 'Max' value in get_hash method of Hash extern in DPDK Target", @@ -358,10 +359,10 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { } } else if (e->originalExternType->getName().name == "Meter") { if (e->method->getName().name == "execute") { - ::error(ErrorType::ERR_UNEXPECTED, - "use dpdk specific `dpdk_execute` method, `%1%`" - " not supported by dpdk", - e->method->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "use dpdk specific `dpdk_execute` method, `%1%`" + " not supported by dpdk", + e->method->getName()); return false; } if (e->method->getName().name == "dpdk_execute") { @@ -369,8 +370,8 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { // DPDK target needs index and packet length as mandatory parameters if (argSize < 2) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected atleast 2 arguments for %1%", - e->object->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Expected atleast 2 arguments for %1%", e->object->getName()); return false; } const IR::Expression *color_in = nullptr; @@ -392,10 +393,10 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { // DPDK target needs packet length as mandatory parameters if (argSize < 1) { - ::error(ErrorType::ERR_UNEXPECTED, - "Expected atleast 1 argument " - "(packet length) for %1%", - e->object->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Expected atleast 1 argument " + "(packet length) for %1%", + e->object->getName()); return false; } const IR::Expression *color_in = nullptr; @@ -426,9 +427,9 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { if (e->method->getName().name == "from_ipsec") { auto argSize = e->expr->arguments->size(); if (argSize != 1) { - ::error(ErrorType::ERR_MODEL, - "Expected 1 argument for status of ipsec encryption", - e->object->getName()); + ::P4::error(ErrorType::ERR_MODEL, + "Expected 1 argument for status of ipsec encryption", + e->object->getName()); return false; } auto status = (*e->expr->arguments)[0]->expression; @@ -576,8 +577,8 @@ bool ConvertStatementToDpdk::preorder(const IR::AssignmentStatement *a) { i = new IR::DpdkCastStatement(left, ca->expr, ca->destType); } else if (auto n = right->to()) { if (!n->expr->type->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Negate operation is only supported on BIT types"); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Negate operation is only supported on BIT types"); return false; } BUG_CHECK(metadataStruct, "Metadata structure missing unexpectedly!"); @@ -1059,7 +1060,7 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { header->expression->is()) { add_instr(new IR::DpdkEmitStatement(header->expression)); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% is not supported", s); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% is not supported", s); } } } else if (a->originalExternType->getName().name == "packet_in") { @@ -1070,7 +1071,7 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { if (!(header->expression->is() || header->expression->is() || header->expression->is())) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% is not supported", s); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% is not supported", s); } if (args->size() == 1) { add_instr(new IR::DpdkExtractStatement(header->expression)); @@ -1090,7 +1091,7 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { } else if (length->expression->is()) { baseName = length->expression->to()->member.name; } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% is not supported", s); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% is not supported", s); } IR::ID tmpName(refmap->newName(baseName + "_extract_tmp")); @@ -1122,19 +1123,19 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { if (a->method->getName().name == "count") { auto args = a->expr->arguments; if (args->size() > 1) { - ::error(ErrorType::ERR_UNEXPECTED, - "Expected at most 1 argument for %1%," - "provided %2%", - a->method->getName(), args->size()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Expected at most 1 argument for %1%," + "provided %2%", + a->method->getName(), args->size()); } else { const IR::Expression *incr = nullptr; auto counter = a->object->getName(); if (args->size() == 1) incr = args->at(0)->expression; if (!incr && value > 0) { - ::error(ErrorType::ERR_UNEXPECTED, - "Expected packet length argument for %1% " - "method of direct counter", - a->method->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Expected packet length argument for %1% " + "method of direct counter", + a->method->getName()); return false; } auto metaIndex = new IR::Member(new IR::PathExpression(IR::ID("m")), @@ -1165,18 +1166,18 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { if (a->method->getName().name == "count") { auto args = a->expr->arguments; if (args->size() < 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected atleast 1 arguments for %1%", - a->method->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected atleast 1 arguments for %1%", + a->method->getName()); } else { const IR::Expression *incr = nullptr; auto index = args->at(0)->expression; auto counter = a->object->getName(); if (args->size() == 2) incr = args->at(1)->expression; if (!incr && value > 0) { - ::error(ErrorType::ERR_UNEXPECTED, - "Expected packet length argument for %1% " - "method of indirect counter", - a->method->getName()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Expected packet length argument for %1% " + "method of indirect counter", + a->method->getName()); return false; } if (value == 2) { @@ -1207,8 +1208,8 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { } else if (a->method->getName().name == "set_sa_index") { auto args = a->expr->arguments; if (args->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected number of arguments for %1%", - a->method->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected number of arguments for %1%", + a->method->name); return false; } auto index = args->at(0)->expression; @@ -1220,13 +1221,13 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { BUG("ipsec_accelerator function %1% not implemented", a->method->getName().name); } } else { - ::error(ErrorType::ERR_UNKNOWN, "%1%: Unknown extern function.", s); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: Unknown extern function.", s); } } else if (auto a = mi->to()) { LOG3("extern function: " << dbp(s) << std::endl << s); if (a->method->name == "verify") { if (parser == nullptr) - ::error(ErrorType::ERR_INVALID, "%1%: verify must be used in parser", s); + ::P4::error(ErrorType::ERR_INVALID, "%1%: verify must be used in parser", s); auto args = a->expr->arguments; auto condition = args->at(0); auto error_id = args->at(1); @@ -1257,8 +1258,8 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { auto args = a->expr->arguments; auto argSize = args->size(); if (argSize != 3) { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected number of arguments for %1%", - a->method->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected number of arguments for %1%", + a->method->name); return false; } auto action = a->expr->arguments->at(0)->expression; @@ -1266,7 +1267,7 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { auto act = parent->to(); cstring parent_act = act->name.name; action_name = - ::get(structure->learner_action_map, std::make_pair(action_name, parent_act)); + ::P4::get(structure->learner_action_map, std::make_pair(action_name, parent_act)); auto param = a->expr->arguments->at(1)->expression; auto timeout_id = a->expr->arguments->at(2)->expression; if (timeout_id->is()) { @@ -1296,14 +1297,15 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { add_instr(new IR::DpdkMovStatement(learnMember, param)); add_instr(new IR::DpdkLearnStatement(action_name, timeout_id, learnMember)); } else { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unhandled function", s); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unhandled function", s); } } else if (a->method->name == "restart_expire_timer") { add_instr(new IR::DpdkRearmStatement()); } else if (a->method->name == "set_entry_expire_time") { auto args = a->expr->arguments; if (args->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected 1 argument for %1%", a->method->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected 1 argument for %1%", + a->method->name); return false; } auto timeout = a->expr->arguments->at(0)->expression; @@ -1321,7 +1323,8 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { } else if (a->method->name == "mirror_packet") { auto args = a->expr->arguments; if (args->size() != 2) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected 2 arguments for %1%", a->method->name); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected 2 arguments for %1%", + a->method->name); return false; } auto slotId = a->expr->arguments->at(0)->expression; @@ -1340,8 +1343,8 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { if (sessionId->is()) { unsigned value = sessionId->to()->asUnsigned(); if (value == 0) { - ::error(ErrorType::ERR_INVALID, - "Mirror session ID 0 is reserved for use by Architecture"); + ::P4::error(ErrorType::ERR_INVALID, + "Mirror session ID 0 is reserved for use by Architecture"); return false; } } @@ -1364,7 +1367,7 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) { } else if (a->method->name == "drop_packet") { add_instr(new IR::DpdkDropStatement()); } else { - ::error(ErrorType::ERR_UNKNOWN, "%1%: Unknown extern function", s); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: Unknown extern function", s); } } else if (auto a = mi->to()) { LOG3("builtin method: " << dbp(s) << std::endl << s); @@ -1457,4 +1460,4 @@ bool ConvertStatementToDpdk::preorder(const IR::SwitchStatement *s) { return false; } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkHelpers.h b/backends/dpdk/dpdkHelpers.h index df8a822894..91d1cafdf1 100644 --- a/backends/dpdk/dpdkHelpers.h +++ b/backends/dpdk/dpdkHelpers.h @@ -35,7 +35,7 @@ limitations under the License. #define TOSTR_DECLA(NAME) std::ostream &toStr(std::ostream &, IR::NAME *) -namespace DPDK { +namespace P4::DPDK { /// @brief Name of the metadata used as output port. /// @@ -136,8 +136,8 @@ class TypeWidthValidator : public Inspector { void postorder(const IR::Type_Varbits *type) override { LOG3("Validating Type_Varbits: " << type); if (type->size % 8 != 0) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% varbit width (%2%) not aligned to 8 bits", - type->srcInfo, type->size); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% varbit width (%2%) not aligned to 8 bits", + type->srcInfo, type->size); } } }; @@ -201,5 +201,5 @@ class ProcessControls : public P4::RemoveComplexExpressionsPolicy { } }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKHELPERS_H_ */ diff --git a/backends/dpdk/dpdkMetadata.cpp b/backends/dpdk/dpdkMetadata.cpp index 749942e6cd..70116b8f48 100644 --- a/backends/dpdk/dpdkMetadata.cpp +++ b/backends/dpdk/dpdkMetadata.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "dpdkUtils.h" -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -32,8 +32,8 @@ void DirectionToRegRead::uniqueNames(IR::DpdkAsmProgram *p) { } if (usedNames.count(registerInstanceName)) - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "decl name %s is reserved for dpdk pna", - registerInstanceName); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "decl name %s is reserved for dpdk pna", + registerInstanceName); } const IR::Node *DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) { @@ -137,4 +137,4 @@ IR::IndexedVector PrependPassRecircId::prependPassWithReci return newStmts; } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkMetadata.h b/backends/dpdk/dpdkMetadata.h index b1e67bcd94..a4e6c4aa0e 100644 --- a/backends/dpdk/dpdkMetadata.h +++ b/backends/dpdk/dpdkMetadata.h @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/common/resolveReferences/referenceMap.h" #include "ir/ir.h" -namespace DPDK { +namespace P4::DPDK { class IsDirectionMetadataUsed : public Inspector { bool &is_direction_used; @@ -93,5 +93,5 @@ class PrependPassRecircId : public Transform { IR::IndexedVector stmts); }; -} // namespace DPDK +} // namespace P4::DPDK #endif // BACKENDS_DPDK_DPDKMETADATA_H_ diff --git a/backends/dpdk/dpdkProgram.cpp b/backends/dpdk/dpdkProgram.cpp index 971a13012b..3896a35f4e 100644 --- a/backends/dpdk/dpdkProgram.cpp +++ b/backends/dpdk/dpdkProgram.cpp @@ -24,7 +24,7 @@ limitations under the License. #include "ir/ir.h" #include "lib/stringify.h" -namespace DPDK { +namespace P4::DPDK { /// Insert the metadata structure updated with tmp variables created during parser conversion /// Add all the structures to DPDK structtype. IR::IndexedVector ConvertToDpdkProgram::UpdateHeaderMetadata( @@ -269,13 +269,13 @@ IR::Declaration_Variable *ConvertToDpdkParser::addNewTmpVarToMetadata(cstring na void ConvertToDpdkParser::getCondVars(const IR::Expression *sv, const IR::Expression *ce, IR::Expression **leftExpr, IR::Expression **rightExpr) { if (sv->is() && sv->type->width_bits() > 32) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%, Constant expression wider than 32-bit is not permitted", sv); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%, Constant expression wider than 32-bit is not permitted", sv); return; } if (sv->type->width_bits() > 64) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%, Select expression wider than 64-bit is not permitted", sv); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%, Select expression wider than 64-bit is not permitted", sv); return; } auto width = sv->type->width_bits(); @@ -527,16 +527,16 @@ bool ConvertToDpdkControl::checkTableValid(const IR::P4Table *a) { } if (lpmCount > 1) { - ::error(ErrorType::ERR_UNEXPECTED, - "Only one LPM match field is permitted per table, " - "more than one lpm field found in table (%1%)", - a->name.toString()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Only one LPM match field is permitted per table, " + "more than one lpm field found in table (%1%)", + a->name.toString()); return false; } else if (lpmCount == 1 && nonExactCount > 0) { - ::error(ErrorType::ERR_UNEXPECTED, - "Non 'exact' match kind not permitted in table (%1%) " - "with 'lpm' match kind", - a->name.toString()); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Non 'exact' match kind not permitted in table (%1%) " + "with 'lpm' match kind", + a->name.toString()); return false; } return true; @@ -547,16 +547,16 @@ std::optional ConvertToDpdkControl::getMemExprFromProperty( auto property = table->properties->getProperty(propertyName); if (property == nullptr) return std::nullopt; if (!property->value->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected %1% property value for table %2% to be an expression: %3%", propertyName, - table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected %1% property value for table %2% to be an expression: %3%", + propertyName, table->controlPlaneName(), property); return std::nullopt; } auto expr = property->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Exprected %1% property value for table %2% to be a member", propertyName, - table->controlPlaneName()); + ::P4::error(ErrorType::ERR_EXPECTED, + "Exprected %1% property value for table %2% to be a member", propertyName, + table->controlPlaneName()); return std::nullopt; } @@ -568,16 +568,16 @@ std::optional ConvertToDpdkControl::getNumberFromProperty(const IR::P4Table auto property = table->properties->getProperty(propertyName); if (property == nullptr) return std::nullopt; if (!property->value->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected %1% property value for table %2% to be an expression: %3%", propertyName, - table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected %1% property value for table %2% to be an expression: %3%", + propertyName, table->controlPlaneName(), property); return std::nullopt; } auto expr = property->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Exprected %1% property value for table %2% to be a constant", propertyName, - table->controlPlaneName()); + ::P4::error(ErrorType::ERR_EXPECTED, + "Exprected %1% property value for table %2% to be a constant", propertyName, + table->controlPlaneName()); return std::nullopt; } @@ -640,4 +640,4 @@ bool ConvertToDpdkControl::preorder(const IR::P4Control *c) { return true; } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkProgram.h b/backends/dpdk/dpdkProgram.h index 9a14aa3472..fa41f72285 100644 --- a/backends/dpdk/dpdkProgram.h +++ b/backends/dpdk/dpdkProgram.h @@ -33,7 +33,7 @@ limitations under the License. #include "lib/json.h" #include "options.h" -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -174,5 +174,5 @@ class EliminateUnusedAction : public PassManager { } }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKPROGRAM_H_ */ diff --git a/backends/dpdk/dpdkProgramStructure.cpp b/backends/dpdk/dpdkProgramStructure.cpp index 5173f265df..ea24ae238c 100644 --- a/backends/dpdk/dpdkProgramStructure.cpp +++ b/backends/dpdk/dpdkProgramStructure.cpp @@ -3,6 +3,8 @@ #include "ir/ir.h" #include "options.h" +namespace P4 { + using namespace P4::literals; bool ParseDpdkArchitecture::preorder(const IR::ToplevelBlock *block) { @@ -17,7 +19,8 @@ void ParseDpdkArchitecture::parse_pna_block(const IR::PackageBlock *block) { structure->p4arch = "pna"_cs; auto p = block->findParameterValue("main_parser"_cs); if (p == nullptr) { - ::error(ErrorType::ERR_MODEL, "Package %1% has no parameter named 'main_parser'", block); + ::P4::error(ErrorType::ERR_MODEL, "Package %1% has no parameter named 'main_parser'", + block); return; } auto parser = p->to(); @@ -39,22 +42,22 @@ void ParseDpdkArchitecture::parse_psa_block(const IR::PackageBlock *block) { structure->p4arch = "psa"_cs; auto pkg = block->findParameterValue("ingress"_cs); if (pkg == nullptr) { - ::error(ErrorType::ERR_MODEL, "Package %1% has no parameter named 'ingress'", block); + ::P4::error(ErrorType::ERR_MODEL, "Package %1% has no parameter named 'ingress'", block); return; } if (auto ingress = pkg->to()) { auto p = ingress->findParameterValue("ip"_cs); if (!p) { - ::error(ErrorType::ERR_MODEL, "'ingress' package %1% has no parameter named 'ip'", - block); + ::P4::error(ErrorType::ERR_MODEL, "'ingress' package %1% has no parameter named 'ip'", + block); return; } auto parser = p->to(); structure->parsers.emplace("IngressParser"_cs, parser->container); p = ingress->findParameterValue("ig"_cs); if (!p) { - ::error(ErrorType::ERR_MODEL, "'ingress' package %1% has no parameter named 'ig'", - block); + ::P4::error(ErrorType::ERR_MODEL, "'ingress' package %1% has no parameter named 'ig'", + block); return; } auto pipeline = p->to(); @@ -62,8 +65,8 @@ void ParseDpdkArchitecture::parse_psa_block(const IR::PackageBlock *block) { structure->pipeline_controls.emplace(pipeline->container->name); p = ingress->findParameterValue("id"_cs); if (!p) { - ::error(ErrorType::ERR_MODEL, "'ingress' package %1% has no parameter named 'id'", - block); + ::P4::error(ErrorType::ERR_MODEL, "'ingress' package %1% has no parameter named 'id'", + block); return; } auto deparser = p->to(); @@ -74,16 +77,16 @@ void ParseDpdkArchitecture::parse_psa_block(const IR::PackageBlock *block) { if (auto egress = pkg->to()) { auto p = egress->findParameterValue("ep"_cs); if (!p) { - ::error(ErrorType::ERR_MODEL, "'egress' package %1% has no parameter named 'ep'", - block); + ::P4::error(ErrorType::ERR_MODEL, "'egress' package %1% has no parameter named 'ep'", + block); return; } auto parser = p->to(); structure->parsers.emplace("EgressParser"_cs, parser->container); p = egress->findParameterValue("eg"_cs); if (!p) { - ::error(ErrorType::ERR_MODEL, "'egress' package %1% has no parameter named 'eg'", - block); + ::P4::error(ErrorType::ERR_MODEL, "'egress' package %1% has no parameter named 'eg'", + block); return; } auto pipeline = p->to(); @@ -91,8 +94,8 @@ void ParseDpdkArchitecture::parse_psa_block(const IR::PackageBlock *block) { structure->pipeline_controls.emplace(pipeline->container->name); p = egress->findParameterValue("ed"_cs); if (!p) { - ::error(ErrorType::ERR_MODEL, "'egress' package %1% has no parameter named 'ed'", - block); + ::P4::error(ErrorType::ERR_MODEL, "'egress' package %1% has no parameter named 'ed'", + block); return; } auto deparser = p->to(); @@ -110,7 +113,7 @@ bool ParseDpdkArchitecture::preorder(const IR::PackageBlock *block) { block->instanceType->to()->name == "PNA_NIC") { parse_pna_block(block); } else { - ::error(ErrorType::ERR_MODEL, "Unknown architecture %1%", options.arch); + ::P4::error(ErrorType::ERR_MODEL, "Unknown architecture %1%", options.arch); } return false; } @@ -164,9 +167,9 @@ void InspectDpdkProgram::addTypesAndInstances(const IR::Type_StructLike *type, b if (ft->is()) { // The headers struct can not contain nested structures. if (isHeader && ft->is()) { - ::error(ErrorType::ERR_INVALID, - "Type %1% should only contain headers, header stacks, or header unions", - type); + ::P4::error(ErrorType::ERR_INVALID, + "Type %1% should only contain headers, header stacks, or header unions", + type); return; } auto st = ft->to(); @@ -187,8 +190,8 @@ void InspectDpdkProgram::addTypesAndInstances(const IR::Type_StructLike *type, b if (auto h_type = uft->to()) { addHeaderInstance(h_type, uf->controlPlaneName()); } else { - ::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, - uft); + ::P4::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, + uft); return; } } @@ -298,3 +301,5 @@ bool InspectDpdkProgram::preorder(const IR::P4Action *action) { structure->actions.emplace(action->name, action); return false; } + +} // namespace P4 diff --git a/backends/dpdk/dpdkProgramStructure.h b/backends/dpdk/dpdkProgramStructure.h index 5f05dbd606..85fbedfb00 100644 --- a/backends/dpdk/dpdkProgramStructure.h +++ b/backends/dpdk/dpdkProgramStructure.h @@ -5,6 +5,8 @@ #include "frontends/p4/typeMap.h" #include "ir/ir.h" +namespace P4 { + /// DPDK target implementation treats tables with keys lying non-contiguous in underlying /// structure as wildcard even if all keys are exact match keys. /// Learner tables are special table with contiguous and exact match keys. @@ -161,4 +163,6 @@ class InspectDpdkProgram : public Inspector { bool isStandardMetadata(cstring); }; +} // namespace P4 + #endif /* BACKENDS_DPDK_DPDKPROGRAMSTRUCTURE_H_ */ diff --git a/backends/dpdk/dpdkUtils.cpp b/backends/dpdk/dpdkUtils.cpp index 1d90f09512..62f2ffda0a 100644 --- a/backends/dpdk/dpdkUtils.cpp +++ b/backends/dpdk/dpdkUtils.cpp @@ -15,7 +15,7 @@ limitations under the License. #include "dpdkUtils.h" -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; bool isSimpleExpression(const IR::Expression *e) { @@ -170,4 +170,4 @@ int getMetadataFieldWidth(int width) { return width; } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/dpdkUtils.h b/backends/dpdk/dpdkUtils.h index cc9c98ff39..fbcf95d6aa 100644 --- a/backends/dpdk/dpdkUtils.h +++ b/backends/dpdk/dpdkUtils.h @@ -19,7 +19,7 @@ limitations under the License. #include "frontends/common/resolveReferences/resolveReferences.h" #include "ir/ir.h" -namespace DPDK { +namespace P4::DPDK { bool isSimpleExpression(const IR::Expression *e); bool isNonConstantSimpleExpression(const IR::Expression *e); bool isCommutativeBinaryOperation(const IR::Operation_Binary *bin); @@ -41,5 +41,5 @@ bool reservedNames(P4::ReferenceMap *refMap, const std::vector &names, /// Creates Register extern declaration for holding persistent information. IR::Declaration_Instance *createRegDeclarationInstance(cstring instanceName, int regSize, int indexBitWidth, int initValBitwidth); -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_DPDKUTILS_H_ */ diff --git a/backends/dpdk/main.cpp b/backends/dpdk/main.cpp index f332a7d9cb..6feba25385 100644 --- a/backends/dpdk/main.cpp +++ b/backends/dpdk/main.cpp @@ -40,6 +40,7 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" +using namespace P4; using namespace P4::literals; void generateTDIBfrtJson(bool isTDI, const IR::P4Program *program, DPDK::DpdkOptions &options) { @@ -56,7 +57,7 @@ void generateTDIBfrtJson(bool isTDI, const IR::P4Program *program, DPDK::DpdkOpt auto p4rt = new P4::BFRT::BFRuntimeSchemaGenerator(*p4Runtime.p4Info, isTDI, options); std::ostream *out = openFile(filename, false); if (!out) { - ::error(ErrorType::ERR_IO, "Could not open file: %1%", filename); + ::P4::error(ErrorType::ERR_IO, "Could not open file: %1%", filename); return; } p4rt->serializeBFRuntimeSchema(out); @@ -73,7 +74,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto hook = options.getDebugHook(); @@ -83,7 +84,7 @@ int main(int argc, char *const argv[]) { if (options.loadIRFromJson == false) { program = P4::parseP4File(options); - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; try { P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); @@ -95,17 +96,17 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; } else { std::filebuf fb; if (fb.open(options.file, std::ios::in) == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%s: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%s: No such file or directory.", options.file); return 1; } std::istream inJson(&fb); JSONLoader jsonFileLoader(inJson); if (jsonFileLoader.json == nullptr) { - ::error(ErrorType::ERR_INVALID, "Not valid input file"); + ::P4::error(ErrorType::ERR_INVALID, "Not valid input file"); return 1; } program = new IR::P4Program(jsonFileLoader); @@ -113,7 +114,7 @@ int main(int argc, char *const argv[]) { } P4::serializeP4RuntimeIfRequired(program, options); - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; if (!options.tdiBuilderConf.empty()) { DPDK::TdiBfrtConf::generate(program, options); @@ -126,25 +127,26 @@ int main(int argc, char *const argv[]) { generateTDIBfrtJson(true, program, options); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto p4info = *P4::generateP4Runtime(program, options.arch).p4Info; DPDK::DpdkMidEnd midEnd(options); midEnd.addDebugHook(hook); try { toplevel = midEnd.process(program); - if (::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) return 1; + if (::P4::errorCount() > 1 || toplevel == nullptr || toplevel->getMain() == nullptr) + return 1; if (!options.dumpJsonFile.empty()) JSONGenerator(*openFile(options.dumpJsonFile, true), true) << program << std::endl; } catch (const std::exception &bug) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto backend = new DPDK::DpdkBackend(options, &midEnd.refMap, &midEnd.typeMap, p4info); backend->convert(toplevel); - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; if (!options.outputFile.empty()) { std::ostream *out = openFile(options.outputFile, false); @@ -154,5 +156,5 @@ int main(int argc, char *const argv[]) { } } - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/dpdk/midend.cpp b/backends/dpdk/midend.cpp index a439e8c0dd..87d1f3d319 100644 --- a/backends/dpdk/midend.cpp +++ b/backends/dpdk/midend.cpp @@ -71,7 +71,7 @@ limitations under the License. #include "midend/validateProperties.h" #include "options.h" -namespace DPDK { +namespace P4::DPDK { /// This class implements a policy suitable for the ConvertEnums pass. /// The policy is: convert all enums to bit<32> @@ -249,4 +249,4 @@ DpdkMidEnd::DpdkMidEnd(CompilerOptions &options, std::ostream *outStream) { } } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/midend.h b/backends/dpdk/midend.h index 87657e38b6..90cedffae6 100644 --- a/backends/dpdk/midend.h +++ b/backends/dpdk/midend.h @@ -21,7 +21,7 @@ limitations under the License. #include "ir/ir.h" #include "midend/convertEnums.h" -namespace DPDK { +namespace P4::DPDK { class DpdkMidEnd : public PassManager { public: @@ -41,6 +41,6 @@ class DpdkMidEnd : public PassManager { } }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_MIDEND_H_ */ diff --git a/backends/dpdk/options.cpp b/backends/dpdk/options.cpp index 5de853393d..bddcef0df2 100644 --- a/backends/dpdk/options.cpp +++ b/backends/dpdk/options.cpp @@ -3,7 +3,7 @@ #include "frontends/common/parser_options.h" #include "lib/exename.h" -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -28,4 +28,4 @@ const char *DpdkOptions::getIncludePath() const { return path.c_str(); } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/options.h b/backends/dpdk/options.h index 954d861d9d..8cd53c26a2 100644 --- a/backends/dpdk/options.h +++ b/backends/dpdk/options.h @@ -19,7 +19,7 @@ limitations under the License. #include "backends/dpdk/midend.h" -namespace DPDK { +namespace P4::DPDK { class DpdkOptions : public CompilerOptions { public: @@ -109,6 +109,6 @@ class DpdkOptions : public CompilerOptions { using DpdkContext = P4CContextWithOptions; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_OPTIONS_H_ */ diff --git a/backends/dpdk/printUtils.cpp b/backends/dpdk/printUtils.cpp index 036ff20573..36f61d842b 100644 --- a/backends/dpdk/printUtils.cpp +++ b/backends/dpdk/printUtils.cpp @@ -15,7 +15,7 @@ limitations under the License. #include "printUtils.h" -namespace DPDK { +namespace P4::DPDK { bool ConvertToString::preorder(const IR::Expression *e) { BUG("%1% not implemented", e); @@ -66,7 +66,7 @@ bool ConvertToString::preorder(const IR::MethodCallExpression *e) { if (auto path = e->method->to()) { out << path->path->name.name; } else { - ::error(ErrorType::ERR_INVALID, "%1% is not a PathExpression", e->toString()); + ::P4::error(ErrorType::ERR_INVALID, "%1% is not a PathExpression", e->toString()); } return false; } @@ -80,7 +80,7 @@ bool ConvertToString::preorder(const IR::ArrayIndex *e) { if (auto cst = e->right->to()) { out << toStr(e->left) << "_" << cst->value; } else { - ::error(ErrorType::ERR_INVALID, "%1% is not a constant", e->right); + ::P4::error(ErrorType::ERR_INVALID, "%1% is not a constant", e->right); } return false; } @@ -120,4 +120,4 @@ cstring toStr(const IR::Node *const n) { BUG("not implemented type"); } } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/printUtils.h b/backends/dpdk/printUtils.h index bc7a88bffe..b19c4e0efe 100644 --- a/backends/dpdk/printUtils.h +++ b/backends/dpdk/printUtils.h @@ -22,7 +22,7 @@ limitations under the License. #include "ir/ir.h" #include "ir/visitor.h" -namespace DPDK { +namespace P4::DPDK { /// This function translates nodes of different subclass of Expression, Type /// and PropertyValue in desired format. For example, for PathExpression, it returns /// PathExpression->path->name For Member, it returns toStr(Member->expr).Member->member etc. @@ -48,6 +48,6 @@ class ConvertToString : public Inspector { bool preorder(const IR::Type_Bits *type); bool preorder(const IR::ExpressionValue *property); }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_PRINTUTILS_H_ */ diff --git a/backends/dpdk/spec.cpp b/backends/dpdk/spec.cpp index 2d531060e3..6051023351 100644 --- a/backends/dpdk/spec.cpp +++ b/backends/dpdk/spec.cpp @@ -4,7 +4,10 @@ #include "dpdkHelpers.h" #include "ir/dbprint.h" #include "printUtils.h" -using namespace DBPrint; + +namespace P4 { + +using namespace P4::DBPrint; ordered_map DPDK::CollectDirectCounterMeter::directMeterCounterSizeMap = {}; auto &directMeterCounterSizeMap = DPDK::CollectDirectCounterMeter::directMeterCounterSizeMap; @@ -73,8 +76,8 @@ std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const { if (DPDK::toStr(getType()) == "Hash") { auto args = arguments; if (args->size() == 0) { - ::error(ErrorType::ERR_INVALID, - "Hash extern declaration %1% must contain hash algorithm \n", Name()); + ::P4::error(ErrorType::ERR_INVALID, + "Hash extern declaration %1% must contain hash algorithm \n", Name()); } else { auto hashAlg = args->at(0)->expression; unsigned hashAlgValue = CRC1; @@ -89,8 +92,8 @@ std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const { } else if (DPDK::toStr(getType()) == "Register") { auto args = arguments; if (args->size() == 0) { - ::error(ErrorType::ERR_INVALID, - "Register extern declaration %1% must contain a size parameter\n", Name()); + ::P4::error(ErrorType::ERR_INVALID, + "Register extern declaration %1% must contain a size parameter\n", Name()); } else { auto size = args->at(0)->expression; auto init_val = args->size() == 2 ? args->at(1)->expression : nullptr; @@ -101,8 +104,8 @@ std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const { auto args = arguments; unsigned value = 0; if (args->size() < 2) { - ::error(ErrorType::ERR_INVALID, - "Counter extern declaration %1% must contain 2 parameters\n", Name()); + ::P4::error(ErrorType::ERR_INVALID, + "Counter extern declaration %1% must contain 2 parameters\n", Name()); } else { auto n_counters = args->at(0)->expression; auto counter_type = args->at(1)->expression; @@ -127,8 +130,8 @@ std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const { auto args = arguments; unsigned value = 0; if (args->size() != 1) { - ::error(ErrorType::ERR_INVALID, - "Counter extern declaration %1% must contain 1 parameters\n", Name()); + ::P4::error(ErrorType::ERR_INVALID, + "Counter extern declaration %1% must contain 1 parameters\n", Name()); } else { IR::Expression *n_counters = nullptr; if (directMeterCounterSizeMap.count(Name())) { @@ -158,10 +161,10 @@ std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const { } else if (DPDK::toStr(getType()) == "Meter") { auto args = arguments; if (args->size() < 2) { - ::error(ErrorType::ERR_INVALID, - "Meter extern declaration %1% must contain a size parameter" - " and meter type parameter", - Name()); + ::P4::error(ErrorType::ERR_INVALID, + "Meter extern declaration %1% must contain a size parameter" + " and meter type parameter", + Name()); } else { auto n_meters = args->at(0)->expression; auto metDecl = new IR::DpdkMeterDeclStatement(Name(), n_meters); @@ -170,10 +173,10 @@ std::ostream &IR::DpdkExternDeclaration::toSpec(std::ostream &out) const { } else if (DPDK::toStr(getType()) == "DirectMeter") { auto args = arguments; if (args->size() < 1) { - ::error(ErrorType::ERR_INVALID, - "Meter extern declaration %1% must have " - "meter type parameter", - Name()); + ::P4::error(ErrorType::ERR_INVALID, + "Meter extern declaration %1% must have " + "meter type parameter", + Name()); } else { IR::Expression *n_meters = nullptr; if (directMeterCounterSizeMap.count(Name())) { @@ -571,7 +574,7 @@ std::ostream &IR::DpdkGetHashStatement::toSpec(std::ostream &out) const { out << " " << DPDK::toStr(l->components.at(l->components.size() - 1)); } } else { - ::error(ErrorType::ERR_INVALID, "%1%: get_hash's arg is not a ListExpression.", this); + ::P4::error(ErrorType::ERR_INVALID, "%1%: get_hash's arg is not a ListExpression.", this); } return out; } @@ -655,3 +658,5 @@ std::ostream &IR::DpdkDropStatement::toSpec(std::ostream &out) const { out << "drop"; return out; } + +} // namespace P4 diff --git a/backends/dpdk/tdiConf.cpp b/backends/dpdk/tdiConf.cpp index 199fcdfaa0..6577229f9b 100644 --- a/backends/dpdk/tdiConf.cpp +++ b/backends/dpdk/tdiConf.cpp @@ -19,7 +19,7 @@ limitations under the License. #include #include -namespace DPDK { +namespace P4::DPDK { using namespace P4::literals; @@ -54,7 +54,7 @@ std::optional TdiBfrtConf::findPipeName(const IR::P4Program *prog, main = decl->checkedTo(); } if (main == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "Program does not contain a `main` module"); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Program does not contain a `main` module"); return std::nullopt; } // We then get the list of constructor and type names in this call and return the first. @@ -63,14 +63,14 @@ std::optional TdiBfrtConf::findPipeName(const IR::P4Program *prog, BUG_CHECK(!pipeNames.empty(), "Program main does not have any pipe arguments."); return pipeNames.at(0); } - ::error("Unsupported target %1% for TDI Builder config generation.", options.arch); + ::P4::error("Unsupported target %1% for TDI Builder config generation.", options.arch); return std::nullopt; } void TdiBfrtConf::generate(const IR::P4Program *prog, DPDK::DpdkOptions &options) { if (options.outputFile.empty()) { - ::error(ErrorType::ERR_UNEXPECTED, - "No output file provided. Unable to generate correct TDI builder config file."); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "No output file provided. Unable to generate correct TDI builder config file."); return; } auto inputFile = std::filesystem::absolute(options.file); @@ -81,14 +81,14 @@ void TdiBfrtConf::generate(const IR::P4Program *prog, DPDK::DpdkOptions &options if (options.bfRtSchema.empty()) { options.bfRtSchema = (outDir / programName).replace_filename("json"); - ::warning( + ::P4::warning( "BF-Runtime Schema file name not provided, but is required for the TDI builder " "configuration. Generating file %1%", options.bfRtSchema); } if (options.ctxtFile.empty()) { options.ctxtFile = outDir / "context.json"; - ::warning( + ::P4::warning( "DPDK context file name not provided, but is required for the TDI builder " "configuration. Generating file %1%", options.ctxtFile); @@ -150,9 +150,9 @@ void TdiBfrtConf::generate(const IR::P4Program *prog, DPDK::DpdkOptions &options if (out.is_open()) { out << ss; } else { - ::error(ErrorType::ERR_IO, "Could not open file: %1%", tdiFile); + ::P4::error(ErrorType::ERR_IO, "Could not open file: %1%", tdiFile); return; } out.close(); } -} // namespace DPDK +} // namespace P4::DPDK diff --git a/backends/dpdk/tdiConf.h b/backends/dpdk/tdiConf.h index 95dae31f5f..651c2bf45f 100644 --- a/backends/dpdk/tdiConf.h +++ b/backends/dpdk/tdiConf.h @@ -19,7 +19,7 @@ limitations under the License. #include #include "backends/dpdk/options.h" -namespace DPDK { +namespace P4::DPDK { class TdiBfrtConf { private: @@ -36,6 +36,6 @@ class TdiBfrtConf { static void generate(const IR::P4Program *prog, DPDK::DpdkOptions &options); }; -} // namespace DPDK +} // namespace P4::DPDK #endif /* BACKENDS_DPDK_TDICONF_H_ */ diff --git a/backends/ebpf/codeGen.cpp b/backends/ebpf/codeGen.cpp index 1fd82e232d..83b9459f2b 100644 --- a/backends/ebpf/codeGen.cpp +++ b/backends/ebpf/codeGen.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "frontends/p4/enumInstance.h" #include "frontends/p4/methodInstance.h" -namespace EBPF { +namespace P4::EBPF { void CodeGenInspector::substitute(const IR::Parameter *p, const IR::Parameter *with) { substitution.emplace(p, with); @@ -231,7 +231,7 @@ bool CodeGenInspector::preorder(const IR::PathExpression *expression) { } bool CodeGenInspector::preorder(const IR::Path *p) { - if (p->absolute) ::error(ErrorType::ERR_EXPECTED, "%1%: Unexpected absolute path", p); + if (p->absolute) ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Unexpected absolute path", p); builder->append(p->name); return false; } @@ -467,11 +467,11 @@ void CodeGenInspector::widthCheck(const IR::Node *node) const { if (tb->size <= 64) { if (!tb->isSigned) return; - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Computations on signed %2% bits not yet supported", node, tb->size); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Computations on signed %2% bits not yet supported", node, tb->size); } - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Computations on %2% bits not supported", - node, tb->size); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Computations on %2% bits not supported", + node, tb->size); } void CodeGenInspector::emitAndConvertByteOrder(const IR::Expression *expr, cstring byte_order) { @@ -640,4 +640,4 @@ cstring EBPFInitializerUtils::genHexStr(const big_int &value, unsigned width, return str; } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/codeGen.h b/backends/ebpf/codeGen.h index e015b66f37..ebc4b8eb40 100644 --- a/backends/ebpf/codeGen.h +++ b/backends/ebpf/codeGen.h @@ -28,7 +28,7 @@ class ReferenceMap; } -namespace EBPF { +namespace P4::EBPF { class CodeBuilder : public Util::SourceCodeBuilder { public: @@ -83,7 +83,7 @@ class CodeGenInspector : public Inspector { bool isPointerVariable(cstring name) { return asPointerVariables.count(name) > 0; } bool notSupported(const IR::Expression *expression) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: not yet implemented", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: not yet implemented", expression); return false; } @@ -141,6 +141,6 @@ class EBPFInitializerUtils { static cstring genHexStr(const big_int &value, unsigned width, const IR::Expression *expr); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_CODEGEN_H_ */ diff --git a/backends/ebpf/ebpfBackend.cpp b/backends/ebpf/ebpfBackend.cpp index 910f85cc43..86477f4513 100644 --- a/backends/ebpf/ebpfBackend.cpp +++ b/backends/ebpf/ebpfBackend.cpp @@ -25,7 +25,7 @@ limitations under the License. #include "psa/ebpfPsaGen.h" #include "target.h" -namespace EBPF { +namespace P4::EBPF { void emitFilterModel(const EbpfOptions &options, Target *target, const IR::ToplevelBlock *toplevel, P4::ReferenceMap *refMap, P4::TypeMap *typeMap) { @@ -60,8 +60,9 @@ void run_ebpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *tople auto main = toplevel->getMain(); if (main == nullptr) { - ::warning(ErrorType::WARN_MISSING, - "Could not locate top-level block; is there a %1% module?", IR::P4Program::main); + ::P4::warning(ErrorType::WARN_MISSING, + "Could not locate top-level block; is there a %1% module?", + IR::P4Program::main); return; } @@ -79,8 +80,9 @@ void run_ebpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *tople } else if (options.target == "test") { target = new TestTarget(); } else { - ::error(ErrorType::ERR_UNKNOWN, - "Unknown target %s; legal choices are 'bcc', 'kernel', and test", options.target); + ::P4::error(ErrorType::ERR_UNKNOWN, + "Unknown target %s; legal choices are 'bcc', 'kernel', and test", + options.target); return; } @@ -98,10 +100,10 @@ void run_ebpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *tople backend->codegen(*cstream); cstream->flush(); } else { - ::error(ErrorType::ERR_UNKNOWN, - "Unknown architecture %s; legal choices are 'filter', and 'psa'", options.arch); + ::P4::error(ErrorType::ERR_UNKNOWN, + "Unknown architecture %s; legal choices are 'filter', and 'psa'", options.arch); return; } } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfBackend.h b/backends/ebpf/ebpfBackend.h index 45638bfeab..d37b6a11b8 100644 --- a/backends/ebpf/ebpfBackend.h +++ b/backends/ebpf/ebpfBackend.h @@ -22,11 +22,11 @@ limitations under the License. #include "frontends/p4/evaluator/evaluator.h" #include "ir/ir.h" -namespace EBPF { +namespace P4::EBPF { void run_ebpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *toplevel, P4::ReferenceMap *refMap, P4::TypeMap *typeMap); -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFBACKEND_H_ */ diff --git a/backends/ebpf/ebpfControl.cpp b/backends/ebpf/ebpfControl.cpp index 8e4fdc3b85..968ec5da44 100644 --- a/backends/ebpf/ebpfControl.cpp +++ b/backends/ebpf/ebpfControl.cpp @@ -25,7 +25,7 @@ limitations under the License. #include "lib/cstring.h" #include "lib/error.h" -namespace EBPF { +namespace P4::EBPF { ControlBodyTranslator::ControlBodyTranslator(const EBPFControl *control) : CodeGenInspector(control->program->refMap, control->program->typeMap), @@ -39,7 +39,7 @@ bool ControlBodyTranslator::preorder(const IR::PathExpression *expression) { auto param = decl->getNode()->to(); if (param != nullptr) { if (toDereference.count(param) > 0) builder->append("*"); - auto subst = ::get(substitution, param); + auto subst = ::P4::get(substitution, param); if (subst != nullptr) { builder->append(subst->name); return false; @@ -52,7 +52,7 @@ bool ControlBodyTranslator::preorder(const IR::PathExpression *expression) { void ControlBodyTranslator::processCustomExternFunction(const P4::ExternFunction *function, EBPFTypeFactory *typeFactory) { if (!control->emitExterns) - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Not supported", function->method); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Not supported", function->method); visit(function->expr->method); builder->append("("); @@ -149,7 +149,7 @@ bool ControlBodyTranslator::preorder(const IR::MethodCallExpression *expression) return false; } - ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported method invocation %1%", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unsupported method invocation %1%", expression); return false; } @@ -222,7 +222,7 @@ void ControlBodyTranslator::compileEmit(const IR::Vector *args) { auto type = typeMap->getType(expr); auto ht = type->to(); if (ht == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, "Cannot emit a non-header type %1%", expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Cannot emit a non-header type %1%", expr); return; } @@ -236,8 +236,8 @@ void ControlBodyTranslator::compileEmit(const IR::Vector *args) { // We expect all headers to start on a byte boundary. unsigned width = ht->width_bits(); if (width % 8 != 0) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Header %1% size %2% is not a multiple of 8 bits.", expr, width); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Header %1% size %2% is not a multiple of 8 bits.", expr, width); return; } @@ -261,8 +261,8 @@ void ControlBodyTranslator::compileEmit(const IR::Vector *args) { auto etype = EBPFTypeFactory::instance->create(ftype); auto et = etype->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", f); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", f); return; } compileEmitField(expr, f->name, hdrOffsetBits, etype); @@ -295,7 +295,7 @@ void ControlBodyTranslator::processMethod(const P4::ExternMethod *method) { return; } } - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unexpected method call", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unexpected method call", method->expr); } void ControlBodyTranslator::processApply(const P4::ApplyMethod *method) { @@ -534,8 +534,8 @@ void EBPFControl::scanConstants() { counters.emplace(name, ctr); } } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", - b->toString()); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", + b->toString()); } } } @@ -547,9 +547,9 @@ bool EBPFControl::build() { if (program->model.arch == ModelArchitecture::XdpSwitch) { if (pl->size() != 3) { - ::error(ErrorType::ERR_EXPECTED, - "Expected control block %s to have exactly 3 parameters", - controlBlock->getName()); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected control block %s to have exactly 3 parameters", + controlBlock->getName()); return false; } headers = *it; @@ -559,7 +559,8 @@ bool EBPFControl::build() { xdpOutputMeta = *it; } else { if (pl->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, "Expected control block to have exactly 2 parameters"); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected control block to have exactly 2 parameters"); return false; } headers = *it; @@ -571,7 +572,7 @@ bool EBPFControl::build() { codeGen->substitute(headers, parserHeaders); scanConstants(); - return ::errorCount() == 0; + return ::P4::errorCount() == 0; } void EBPFControl::emitDeclaration(CodeBuilder *builder, const IR::Declaration *decl) { @@ -639,4 +640,4 @@ void EBPFControl::emitTableInitializers(CodeBuilder *builder) { for (auto it : tables) it.second->emitInitializer(builder); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfControl.h b/backends/ebpf/ebpfControl.h index 9e0702287b..1341372572 100644 --- a/backends/ebpf/ebpfControl.h +++ b/backends/ebpf/ebpfControl.h @@ -21,7 +21,7 @@ limitations under the License. #include "ebpfTable.h" #include "ebpfType.h" -namespace EBPF { +namespace P4::EBPF { class EBPFControl; @@ -81,12 +81,12 @@ class EBPFControl : public EBPFObject { virtual void emitTableInstances(CodeBuilder *builder); virtual bool build(); EBPFTable *getTable(cstring name) const { - auto result = ::get(tables, name); + auto result = ::P4::get(tables, name); BUG_CHECK(result != nullptr, "No table named %1%", name); return result; } EBPFCounterTable *getCounter(cstring name) const { - auto result = ::get(counters, name); + auto result = ::P4::get(counters, name); BUG_CHECK(result != nullptr, "No counter named %1%", name); return result; } @@ -97,6 +97,6 @@ class EBPFControl : public EBPFObject { DECLARE_TYPEINFO(EBPFControl, EBPFObject); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFCONTROL_H_ */ diff --git a/backends/ebpf/ebpfDeparser.cpp b/backends/ebpf/ebpfDeparser.cpp index 64a53004b5..8569955732 100644 --- a/backends/ebpf/ebpfDeparser.cpp +++ b/backends/ebpf/ebpfDeparser.cpp @@ -17,7 +17,7 @@ limitations under the License. #include "ebpfDeparser.h" -namespace EBPF { +namespace P4::EBPF { DeparserBodyTranslator::DeparserBodyTranslator(const EBPFDeparser *deparser) : CodeGenInspector(deparser->program->refMap, deparser->program->typeMap), @@ -72,16 +72,16 @@ void DeparserPrepareBufferTranslator::processMethod(const P4::ExternMethod *meth auto decl = method->object; if (decl == deparser->packet_out) { if (method->expr->arguments->size() != 1) { - ::error(ErrorType::ERR_MODEL, - "Not enough arguments to emit() method, exactly 1 required"); + ::P4::error(ErrorType::ERR_MODEL, + "Not enough arguments to emit() method, exactly 1 required"); } auto expr = method->expr->arguments->at(0)->expression; auto exprType = deparser->program->typeMap->getType(expr); auto headerToEmit = exprType->to(); if (headerToEmit == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", - expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Cannot emit a non-header type %1%", expr); return; } @@ -115,8 +115,8 @@ void DeparserHdrEmitTranslator::processMethod(const P4::ExternMethod *method) { auto exprType = deparser->program->typeMap->getType(expr); auto headerToEmit = exprType->to(); if (headerToEmit == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", - expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Cannot emit a non-header type %1%", expr); } cstring msgStr; @@ -129,8 +129,8 @@ void DeparserHdrEmitTranslator::processMethod(const P4::ExternMethod *method) { // We expect all headers to start on a byte boundary. unsigned width = headerToEmit->width_bits(); if ((width % 8) != 0) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Header %1% size %2% is not a multiple of 8 bits.", expr, width); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Header %1% size %2% is not a multiple of 8 bits.", expr, width); return; } msgStr = absl::StrFormat("Deparser: emitting header %s", expr->toString().c_str()); @@ -156,8 +156,8 @@ void DeparserHdrEmitTranslator::processMethod(const P4::ExternMethod *method) { auto etype = EBPFTypeFactory::instance->create(ftype); auto et = etype->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", f); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", f); return; } emitField(builder, f->name, expr, hdrOffsetBits, etype); @@ -184,8 +184,8 @@ void DeparserHdrEmitTranslator::emitField(CodeBuilder *builder, cstring field, auto et = type->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", hdrExpr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", hdrExpr); return; } unsigned widthToEmit = et->widthInBits(); @@ -295,7 +295,8 @@ bool EBPFDeparser::build() { hitVariable = program->refMap->newName("hit"); auto pl = controlBlock->container->type->applyParams; if (pl->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, "Expected deparser block to have exactly 2 parameters"); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected deparser block to have exactly 2 parameters"); return false; } @@ -308,7 +309,7 @@ bool EBPFDeparser::build() { codeGen->substitute(headers, parserHeaders); scanConstants(); - return ::errorCount() == 0; + return ::P4::errorCount() == 0; } void EBPFDeparser::emitBufferAdjusts(CodeBuilder *builder) const { @@ -391,4 +392,4 @@ void EBPFDeparser::emit(CodeBuilder *builder) { builder->newline(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfDeparser.h b/backends/ebpf/ebpfDeparser.h index d1a2a3b69e..fba3b18430 100644 --- a/backends/ebpf/ebpfDeparser.h +++ b/backends/ebpf/ebpfDeparser.h @@ -19,7 +19,7 @@ limitations under the License. #include "ebpfControl.h" -namespace EBPF { +namespace P4::EBPF { class EBPFDeparser; @@ -91,6 +91,6 @@ class EBPFDeparser : public EBPFControl { DECLARE_TYPEINFO(EBPFDeparser, EBPFControl); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFDEPARSER_H_ */ diff --git a/backends/ebpf/ebpfModel.cpp b/backends/ebpf/ebpfModel.cpp index 7476c373be..5d8c3a8657 100644 --- a/backends/ebpf/ebpfModel.cpp +++ b/backends/ebpf/ebpfModel.cpp @@ -16,9 +16,9 @@ limitations under the License. #include "ebpfModel.h" -namespace EBPF { +namespace P4::EBPF { cstring EBPFModel::reservedPrefix = "ebpf_"_cs; EBPFModel EBPFModel::instance; -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfModel.h b/backends/ebpf/ebpfModel.h index 9f819e325d..657dbaca81 100644 --- a/backends/ebpf/ebpfModel.h +++ b/backends/ebpf/ebpfModel.h @@ -22,26 +22,26 @@ limitations under the License. #include "ir/ir.h" #include "lib/cstring.h" -namespace EBPF { +namespace P4::EBPF { using namespace P4::literals; -struct TableImpl_Model : public ::Model::Extern_Model { +struct TableImpl_Model : public ::P4::Model::Extern_Model { explicit TableImpl_Model(cstring name) : Extern_Model(name), size("size"_cs) {} - ::Model::Elem size; + ::P4::Model::Elem size; }; -struct CounterArray_Model : public ::Model::Extern_Model { +struct CounterArray_Model : public ::P4::Model::Extern_Model { CounterArray_Model() : Extern_Model("CounterArray"_cs), increment("increment"_cs), add("add"_cs), max_index("max_index"_cs), sparse("sparse"_cs) {} - ::Model::Elem increment; - ::Model::Elem add; - ::Model::Elem max_index; - ::Model::Elem sparse; + ::P4::Model::Elem increment; + ::P4::Model::Elem add; + ::P4::Model::Elem max_index; + ::P4::Model::Elem sparse; }; enum ModelArchitecture { @@ -49,21 +49,21 @@ enum ModelArchitecture { XdpSwitch, }; -struct Xdp_Model : public ::Model::Elem { +struct Xdp_Model : public ::P4::Model::Elem { Xdp_Model() : Elem("xdp"_cs), parser("p"_cs), switch_("s"_cs), deparser("d"_cs) {} - ::Model::Elem parser; - ::Model::Elem switch_; - ::Model::Elem deparser; + ::P4::Model::Elem parser; + ::P4::Model::Elem switch_; + ::P4::Model::Elem deparser; }; -struct Filter_Model : public ::Model::Elem { +struct Filter_Model : public ::P4::Model::Elem { Filter_Model() : Elem("ebpf_filter"_cs), parser("prs"_cs), filter("filt"_cs) {} - ::Model::Elem parser; - ::Model::Elem filter; + ::P4::Model::Elem parser; + ::P4::Model::Elem filter; }; /// Keep this in sync with ebpf_model.p4 and xdp_model.p4 -class EBPFModel : public ::Model::Model { +class EBPFModel : public ::P4::Model::Model { protected: EBPFModel() : counterArray(), @@ -85,9 +85,9 @@ class EBPFModel : public ::Model::Model { CounterArray_Model counterArray; TableImpl_Model array_table; TableImpl_Model hash_table; - ::Model::Elem tableImplProperty; - ::Model::Elem CPacketName; - ::Model::Param_Model packet; + ::P4::Model::Elem tableImplProperty; + ::P4::Model::Elem CPacketName; + ::P4::Model::Param_Model packet; ModelArchitecture arch; /// Only one of these should be used, depending on arch value. Filter_Model filter; @@ -99,6 +99,6 @@ class EBPFModel : public ::Model::Model { static cstring reserved(cstring name) { return reservedPrefix + name; } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFMODEL_H_ */ diff --git a/backends/ebpf/ebpfObject.h b/backends/ebpf/ebpfObject.h index 32d8960a98..b86efa6bdb 100644 --- a/backends/ebpf/ebpfObject.h +++ b/backends/ebpf/ebpfObject.h @@ -25,7 +25,7 @@ limitations under the License. #include "lib/castable.h" #include "target.h" -namespace EBPF { +namespace P4::EBPF { /// Base class for EBPF objects. class EBPFObject : public ICastable { @@ -58,6 +58,6 @@ class EBPFObject : public ICastable { DECLARE_TYPEINFO(EBPFObject); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFOBJECT_H_ */ diff --git a/backends/ebpf/ebpfOptions.cpp b/backends/ebpf/ebpfOptions.cpp index 315fbb2160..a5b4096f7b 100644 --- a/backends/ebpf/ebpfOptions.cpp +++ b/backends/ebpf/ebpfOptions.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "midend.h" +namespace P4 { + EbpfOptions::EbpfOptions() { langVersion = CompilerOptions::FrontendVersion::P4_16; registerOption( @@ -99,3 +101,5 @@ EbpfOptions::EbpfOptions() { }, "[psa only] Compile and generate the P4 prog for XDP hook"); } + +} // namespace P4 diff --git a/backends/ebpf/ebpfOptions.h b/backends/ebpf/ebpfOptions.h index 2aab050ab2..09e2bf3889 100644 --- a/backends/ebpf/ebpfOptions.h +++ b/backends/ebpf/ebpfOptions.h @@ -19,6 +19,8 @@ limitations under the License. #include "frontends/common/options.h" +namespace P4 { + enum XDP2TC { XDP2TC_NONE, XDP2TC_META, XDP2TC_HEAD, XDP2TC_CPUMAP }; class EbpfOptions : public CompilerOptions { @@ -69,4 +71,6 @@ class EbpfOptions : public CompilerOptions { using EbpfContext = P4CContextWithOptions; +} // namespace P4 + #endif /* BACKENDS_EBPF_EBPFOPTIONS_H_ */ diff --git a/backends/ebpf/ebpfParser.cpp b/backends/ebpf/ebpfParser.cpp index 99edaba6e8..d72be76836 100644 --- a/backends/ebpf/ebpfParser.cpp +++ b/backends/ebpf/ebpfParser.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/p4/coreLibrary.h" #include "frontends/p4/methodInstance.h" -namespace EBPF { +namespace P4::EBPF { void StateTranslationVisitor::compileLookahead(const IR::Expression *destination) { cstring msgStr = absl::StrFormat("Parser: lookahead for %s %s", @@ -57,15 +57,15 @@ void StateTranslationVisitor::compileAdvance(const P4::ExternMethod *extMethod) 2, state->parser->program->lengthVar.c_str(), offsetStr.c_str()); } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "packet_in.advance() method with non-constant argument is not supported yet"); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "packet_in.advance() method with non-constant argument is not supported yet"); return; } int advanceVal = cnst->asInt(); if (advanceVal % 8 != 0) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "packet_in.advance(%1%) must be byte-aligned in eBPF backend", advanceVal); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "packet_in.advance(%1%) must be byte-aligned in eBPF backend", advanceVal); return; } @@ -100,7 +100,7 @@ void StateTranslationVisitor::compileVerify(const IR::MethodCallExpression *expr auto errorMember = errorExpr->to(); auto type = typeMap->getType(errorExpr, true); if (!type->is() || errorMember == nullptr) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: not accessing a member error type", errorExpr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: not accessing a member error type", errorExpr); return; } @@ -209,7 +209,8 @@ bool StateTranslationVisitor::preorder(const IR::SelectExpression *expression) { if (pvs != nullptr) pvs->emitKeyInitializer(builder, expression, pvsKeyVarName); else - ::error(ErrorType::ERR_UNKNOWN, "%1%: expected a value_set instance", e->keyset); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: expected a value_set instance", + e->keyset); } } @@ -338,10 +339,11 @@ void StateTranslationVisitor::compileExtractField(const IR::Expression *expr, // To correctly insert that padding, the length of field must be known, but tools like // nikss-ctl (and the nikss library) don't consume P4info.txtpb to have such knowledge. // There is also a bug in (de)parser causing such fields to be deparsed incorrectly. - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: fields wider than 64 bits must have a size multiple of 8 bits (1 byte) " - "due to ambiguous padding in the LSB byte when the condition is not met", - field); + ::P4::error( + ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: fields wider than 64 bits must have a size multiple of 8 bits (1 byte) " + "due to ambiguous padding in the LSB byte when the condition is not met", + field); } // wide values; read all bytes one by one. @@ -405,16 +407,16 @@ void StateTranslationVisitor::compileExtract(const IR::Expression *destination) auto type = state->parser->typeMap->getType(destination); auto ht = type->to(); if (ht == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot extract to a non-struct type %1%", - destination); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot extract to a non-struct type %1%", + destination); return; } // We expect all headers to start on a byte boundary. unsigned width = ht->width_bits(); if ((width % 8) != 0) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Header %1% size %2% is not a multiple of 8 bits.", destination, width); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Header %1% size %2% is not a multiple of 8 bits.", destination, width); return; } @@ -474,8 +476,8 @@ void StateTranslationVisitor::compileExtract(const IR::Expression *destination) auto etype = EBPFTypeFactory::instance->create(ftype); auto et = etype->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", f); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", f); return; } compileExtractField(destination, f, hdrOffsetBits, etype); @@ -504,8 +506,8 @@ void StateTranslationVisitor::processFunction(const P4::ExternFunction *function if (function->method->name.name == IR::ParserState::verify) { compileVerify(function->expr); } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected extern function call in parser %1%", - function->expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected extern function call in parser %1%", + function->expr); } } @@ -516,8 +518,8 @@ void StateTranslationVisitor::processMethod(const P4::ExternMethod *method) { if (decl == state->parser->packet) { if (method->method->name.name == p4lib.packetIn.extract.name) { if (expression->arguments->size() != 1) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Variable-sized header fields not yet supported %1%", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Variable-sized header fields not yet supported %1%", expression); return; } compileExtract(expression->arguments->at(0)->expression); @@ -532,7 +534,8 @@ void StateTranslationVisitor::processMethod(const P4::ExternMethod *method) { BUG("Unhandled packet method %1%", expression->method); } - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected extern method call in parser %1%", expression); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected extern method call in parser %1%", + expression); } bool StateTranslationVisitor::preorder(const IR::MethodCallExpression *expression) { @@ -588,7 +591,7 @@ bool StateTranslationVisitor::preorder(const IR::MethodCallExpression *expressio } } - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in parser %1%", expression); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in parser %1%", expression); return false; } @@ -667,7 +670,7 @@ void EBPFParser::emit(CodeBuilder *builder) { bool EBPFParser::build() { auto pl = parserBlock->container->type->applyParams; if (pl->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly 2 parameters"); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly 2 parameters"); return false; } @@ -713,4 +716,4 @@ void EBPFParser::emitRejectState(CodeBuilder *builder) { builder->newline(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfParser.h b/backends/ebpf/ebpfParser.h index 5e9e1a982f..42b645a2e8 100644 --- a/backends/ebpf/ebpfParser.h +++ b/backends/ebpf/ebpfParser.h @@ -23,7 +23,7 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "ir/ir.h" -namespace EBPF { +namespace P4::EBPF { class EBPFParser; class EBPFParserState; @@ -101,11 +101,11 @@ class EBPFParser : public EBPFObject { virtual void emitValueSetInstances(CodeBuilder *builder); virtual void emitRejectState(CodeBuilder *builder); - EBPFValueSet *getValueSet(cstring name) const { return ::get(valueSets, name); } + EBPFValueSet *getValueSet(cstring name) const { return ::P4::get(valueSets, name); } DECLARE_TYPEINFO(EBPFParser, EBPFObject); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFPARSER_H_ */ diff --git a/backends/ebpf/ebpfProgram.cpp b/backends/ebpf/ebpfProgram.cpp index 721fe10869..e57a6c55a1 100644 --- a/backends/ebpf/ebpfProgram.cpp +++ b/backends/ebpf/ebpfProgram.cpp @@ -27,28 +27,29 @@ limitations under the License. #include "frontends/common/options.h" #include "frontends/p4/coreLibrary.h" -namespace EBPF { +namespace P4::EBPF { bool EBPFProgram::build() { auto pack = toplevel->getMain(); if (pack->type->name == "xdp") { if (pack->getConstructorParameters()->size() != 3) { - ::error(ErrorType::ERR_EXPECTED, - "Expected toplevel xdp package %1% to have 3 parameters", pack->type); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected toplevel xdp package %1% to have 3 parameters", pack->type); return false; } model.arch = ModelArchitecture::XdpSwitch; progTarget = new XdpTarget(options.emitTraceMessages); } else { if (pack->type->name != "ebpfFilter") - ::warning(ErrorType::WARN_INVALID, - "%1%: the main ebpf package should be called ebpfFilter or xdp" - "; are you using the wrong architecture?", - pack->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main ebpf package should be called ebpfFilter or xdp" + "; are you using the wrong architecture?", + pack->type->name); if (pack->getConstructorParameters()->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, - "Expected toplevel ebpfFilter package %1% to have 2 parameters", pack->type); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected toplevel ebpfFilter package %1% to have 2 parameters", + pack->type); return false; } model.arch = ModelArchitecture::EbpfFilter; @@ -357,4 +358,4 @@ bool EBPFProgram::isLibraryMethod(cstring methodName) { return XDP_METHODS.find(methodName) != XDP_METHODS.end(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfProgram.h b/backends/ebpf/ebpfProgram.h index 6abe2fdddf..9f6d75dedc 100644 --- a/backends/ebpf/ebpfProgram.h +++ b/backends/ebpf/ebpfProgram.h @@ -27,7 +27,7 @@ limitations under the License. #include "ir/ir.h" #include "target.h" -namespace EBPF { +namespace P4::EBPF { class EBPFProgram; class EBPFParser; @@ -111,6 +111,6 @@ class EBPFProgram : public EBPFObject { DECLARE_TYPEINFO(EBPFProgram, EBPFObject); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFPROGRAM_H_ */ diff --git a/backends/ebpf/ebpfTable.cpp b/backends/ebpf/ebpfTable.cpp index 428781dafe..3fe9dd0fef 100644 --- a/backends/ebpf/ebpfTable.cpp +++ b/backends/ebpf/ebpfTable.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "ir/ir.h" -namespace EBPF { +namespace P4::EBPF { bool ActionTranslationVisitor::preorder(const IR::PathExpression *expression) { if (isActionParameter(expression)) { @@ -90,7 +90,8 @@ void EBPFTable::initKey() { auto type = program->typeMap->getType(c->expression); auto ebpfType = EBPFTypeFactory::instance->create(type); if (!ebpfType->is()) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: illegal type %2% for key field", c, type); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: illegal type %2% for key field", c, + type); return; } @@ -121,10 +122,10 @@ void EBPFTable::validateKeys() const { unsigned width = ebpfType->to()->widthInBits(); if (width > last_key_size) { - ::error(ErrorType::WARN_ORDERING, - "%1%: key field larger than previous key, move it before previous key " - "to avoid padding between these keys", - it->expression); + ::P4::error(ErrorType::WARN_ORDERING, + "%1%: key field larger than previous key, move it before previous key " + "to avoid padding between these keys", + it->expression); return; } last_key_size = width; @@ -141,8 +142,8 @@ void EBPFTable::validateKeys() const { auto matchType = mtdecl->getNode()->to(); if (matchType->name.name == P4::P4CoreLibrary::instance().lpmMatch.name) { if (it != *lastKey) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1% field key must be at the end of whole key", it->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1% field key must be at the end of whole key", it->matchType); } } } @@ -172,8 +173,8 @@ void EBPFTable::emitKeyType(CodeBuilder *builder) { auto matchType = mtdecl->getNode()->to(); if (!isMatchTypeSupported(matchType)) { - ::error(ErrorType::ERR_UNSUPPORTED, "Match of type %1% not supported", - c->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Match of type %1% not supported", + c->matchType); } if (matchType->name.name == "selector") { @@ -185,8 +186,8 @@ void EBPFTable::emitKeyType(CodeBuilder *builder) { continue; } - auto ebpfType = ::get(keyTypes, c); - cstring fieldName = ::get(keyFieldNames, c); + auto ebpfType = ::P4::get(keyTypes, c); + cstring fieldName = ::P4::get(keyFieldNames, c); if (ebpfType->is() && ebpfType->to()->alignment() > structAlignment) { @@ -365,29 +366,29 @@ void EBPFTable::emitInstance(CodeBuilder *builder) { auto impl = table->container->properties->getProperty(program->model.tableImplProperty.name); if (impl == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "Table %1% does not have an %2% property", - table->container, program->model.tableImplProperty.name); + ::P4::error(ErrorType::ERR_EXPECTED, "Table %1% does not have an %2% property", + table->container, program->model.tableImplProperty.name); return; } // Some type checking... if (!impl->value->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected property to be an `extern` block", - impl); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: Expected property to be an `extern` block", impl); return; } auto expr = impl->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected property to be an `extern` block", - impl); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: Expected property to be an `extern` block", impl); return; } auto block = table->getValue(expr); if (block == nullptr || !block->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected property to be an `extern` block", - impl); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: Expected property to be an `extern` block", impl); return; } @@ -398,8 +399,9 @@ void EBPFTable::emitInstance(CodeBuilder *builder) { } else if (extBlock->type->name.name == program->model.hash_table.name) { tableKind = TableHash; } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: implementation must be one of %2% or %3%", - impl, program->model.array_table.name, program->model.hash_table.name); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: implementation must be one of %2% or %3%", impl, + program->model.array_table.name, program->model.hash_table.name); return; } @@ -409,8 +411,8 @@ void EBPFTable::emitInstance(CodeBuilder *builder) { auto matchType = mtdecl->getNode()->to(); if (matchType->name.name == P4::P4CoreLibrary::instance().lpmMatch.name) { if (tableKind == TableLPMTrie) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: only one LPM field allowed", - it->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: only one LPM field allowed", + it->matchType); return; } tableKind = TableLPMTrie; @@ -419,18 +421,18 @@ void EBPFTable::emitInstance(CodeBuilder *builder) { auto sz = extBlock->getParameterValue(program->model.array_table.size.name); if (sz == nullptr || !sz->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: Expected an integer argument; is the model corrupted?", expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: Expected an integer argument; is the model corrupted?", expr); return; } auto cst = sz->to(); if (!cst->fitsInt()) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: size too large", cst); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: size too large", cst); return; } int size = cst->asInt(); if (size <= 0) { - ::error(ErrorType::ERR_INVALID, "%1%: negative size", cst); + ::P4::error(ErrorType::ERR_INVALID, "%1%: negative size", cst); return; } @@ -457,8 +459,8 @@ void EBPFTable::emitKey(CodeBuilder *builder, cstring keyName) { } for (auto c : keyGenerator->keyElements) { - auto ebpfType = ::get(keyTypes, c); - cstring fieldName = ::get(keyFieldNames, c); + auto ebpfType = ::P4::get(keyTypes, c); + cstring fieldName = ::P4::get(keyFieldNames, c); if (fieldName == nullptr || ebpfType == nullptr) continue; bool memcpy = false; EBPFScalarType *scalar = nullptr; @@ -482,8 +484,8 @@ void EBPFTable::emitKey(CodeBuilder *builder, cstring keyName) { // preserved for filter model because existing tests expect it. // TODO: handle width > 64 bits for filter model if (program->options.arch.isNullOrEmpty() || program->options.arch == "filter") { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: fields wider than 64 bits are not supported yet", fieldName); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: fields wider than 64 bits are not supported yet", fieldName); } } } @@ -905,27 +907,27 @@ EBPFCounterTable::EBPFCounterTable(const EBPFProgram *program, const IR::ExternB : EBPFTableBase(program, name, codeGen) { auto sz = block->getParameterValue(program->model.counterArray.max_index.name); if (sz == nullptr || !sz->is()) { - ::error(ErrorType::ERR_INVALID, - "%1% (%2%): expected an integer argument; is the model corrupted?", - program->model.counterArray.max_index, name); + ::P4::error(ErrorType::ERR_INVALID, + "%1% (%2%): expected an integer argument; is the model corrupted?", + program->model.counterArray.max_index, name); return; } auto cst = sz->to(); if (!cst->fitsInt()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", cst); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", cst); return; } size = cst->asInt(); if (size <= 0) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: negative size", cst); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: negative size", cst); return; } auto sprs = block->getParameterValue(program->model.counterArray.sparse.name); if (sprs == nullptr || !sprs->is()) { - ::error(ErrorType::ERR_INVALID, - "%1% (%2%): Expected an integer argument; is the model corrupted?", - program->model.counterArray.sparse, name); + ::P4::error(ErrorType::ERR_INVALID, + "%1% (%2%): Expected an integer argument; is the model corrupted?", + program->model.counterArray.sparse, name); return; } @@ -1060,8 +1062,8 @@ void EBPFCounterTable::emitMethodInvocation(CodeBuilder *builder, const P4::Exte emitCounterAdd(builder, method->expr); return; } - ::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1% for %2%", method->expr, - program->model.counterArray.name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1% for %2%", method->expr, + program->model.counterArray.name); } void EBPFCounterTable::emitTypes(CodeBuilder *builder) { @@ -1088,11 +1090,11 @@ EBPFValueSet::EBPFValueSet(const EBPFProgram *program, const IR::P4ValueSet *p4v auto sc = pvs->size->to(); if (sc->fitsUint()) size = sc->asUnsigned(); if (size == 0) - ::error(ErrorType::ERR_OVERLIMIT, - "Size must be a positive value less than 2^32, got %1% entries", pvs->size); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "Size must be a positive value less than 2^32, got %1% entries", pvs->size); } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Size of value_set must be know at compilation time: %1%", pvs->size); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Size of value_set must be know at compilation time: %1%", pvs->size); } // validate type @@ -1104,11 +1106,11 @@ EBPFValueSet::EBPFValueSet(const EBPFProgram *program, const IR::P4ValueSet *p4v } else if (auto h = elemType->to()) { keyTypeName = h->name.name; - ::warning("Header type may contain additional shadow data: %1%", pvs->elementType); - ::warning("Header defined here: %1%", h); + ::P4::warning("Header type may contain additional shadow data: %1%", pvs->elementType); + ::P4::warning("Header defined here: %1%", h); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported type with value_set: %1%", - pvs->elementType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unsupported type with value_set: %1%", + pvs->elementType); } keyTypeName = "struct " + keyTypeName; @@ -1163,8 +1165,8 @@ void EBPFValueSet::emitInstance(CodeBuilder *builder) { void EBPFValueSet::emitKeyInitializer(CodeBuilder *builder, const IR::SelectExpression *expression, cstring varName) { if (fieldNames.size() != expression->select->components.size()) { - ::error(ErrorType::ERR_EXPECTED, - "Fields number of value_set do not match number of arguments: %1%", expression); + ::P4::error(ErrorType::ERR_EXPECTED, + "Fields number of value_set do not match number of arguments: %1%", expression); return; } keyVarName = varName; @@ -1182,9 +1184,10 @@ void EBPFValueSet::emitKeyInitializer(CodeBuilder *builder, const IR::SelectExpr auto keyExpr = expression->select->components.at(i); if (useMemcpy) { if (keyExpr->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: mask not supported for fields larger than 64 bits within value_set", - keyExpr); + ::P4::error( + ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: mask not supported for fields larger than 64 bits within value_set", + keyExpr); continue; } @@ -1214,4 +1217,4 @@ void EBPFValueSet::emitLookup(CodeBuilder *builder) { builder->target->emitTableLookup(builder, instanceName, keyVarName, cstring::empty); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfTable.h b/backends/ebpf/ebpfTable.h index 8bfaa93e45..0a54fec758 100644 --- a/backends/ebpf/ebpfTable.h +++ b/backends/ebpf/ebpfTable.h @@ -21,7 +21,7 @@ limitations under the License. #include "ebpfProgram.h" #include "frontends/p4/methodInstance.h" -namespace EBPF { +namespace P4::EBPF { class ActionTranslationVisitor : public virtual CodeGenInspector { protected: @@ -188,6 +188,6 @@ class EBPFValueSet : public EBPFTableBase { DECLARE_TYPEINFO(EBPFValueSet, EBPFTableBase); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFTABLE_H_ */ diff --git a/backends/ebpf/ebpfType.cpp b/backends/ebpf/ebpfType.cpp index 4305d74a06..c3a18d1ac8 100644 --- a/backends/ebpf/ebpfType.cpp +++ b/backends/ebpf/ebpfType.cpp @@ -16,7 +16,7 @@ limitations under the License. #include "ebpfType.h" -namespace EBPF { +namespace P4::EBPF { EBPFTypeFactory *EBPFTypeFactory::instance; @@ -53,7 +53,7 @@ EBPFType *EBPFTypeFactory::create(const IR::Type *type) { // Implement error type as scalar of width 8 bits result = new EBPFScalarType(IR::Type_Bits::get(8, false)); } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% not supported", type); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% not supported", type); } return result; @@ -183,8 +183,8 @@ EBPFStructType::EBPFStructType(const IR::Type_StructLike *strct) : EBPFType(strc auto type = EBPFTypeFactory::instance->create(f->type); auto wt = type->to(); if (wt == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "EBPF: Unsupported type in struct: %s", - f->type); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "EBPF: Unsupported type in struct: %s", f->type); } else { width += wt->widthInBits(); implWidth += wt->implementationWidthInBits(); @@ -282,7 +282,8 @@ void EBPFTypeName::emitInitializer(CodeBuilder *builder) { unsigned EBPFTypeName::widthInBits() const { auto wt = canonical->to(); if (wt == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% does not have a fixed witdh", type); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% does not have a fixed witdh", + type); return 0; } return wt->widthInBits(); @@ -291,7 +292,8 @@ unsigned EBPFTypeName::widthInBits() const { unsigned EBPFTypeName::implementationWidthInBits() const { auto wt = canonical->to(); if (wt == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% does not have a fixed witdh", type); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% does not have a fixed witdh", + type); return 0; } return wt->implementationWidthInBits(); @@ -382,4 +384,4 @@ void EBPFMethodDeclaration::emit(CodeBuilder *builder) { builder->newline(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/ebpfType.h b/backends/ebpf/ebpfType.h index 703738b59a..c3493b6aff 100644 --- a/backends/ebpf/ebpfType.h +++ b/backends/ebpf/ebpfType.h @@ -23,7 +23,7 @@ limitations under the License. #include "lib/rtti.h" #include "lib/sourceCodeBuilder.h" -namespace EBPF { +namespace P4::EBPF { /// Base class for EBPF types class EBPFType : public EBPFObject { @@ -223,6 +223,6 @@ class EBPFMethodDeclaration : public EBPFObject { DECLARE_TYPEINFO(EBPFMethodDeclaration, EBPFObject); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_EBPFTYPE_H_ */ diff --git a/backends/ebpf/lower.cpp b/backends/ebpf/lower.cpp index 454840f50d..875403a94d 100644 --- a/backends/ebpf/lower.cpp +++ b/backends/ebpf/lower.cpp @@ -16,7 +16,7 @@ limitations under the License. #include "lower.h" -namespace EBPF { +namespace P4::EBPF { const IR::Expression *LowerExpressions::shift(const IR::Operation_Binary *expression) const { auto rhs = expression->right; @@ -25,15 +25,15 @@ const IR::Expression *LowerExpressions::shift(const IR::Operation_Binary *expres auto cst = rhs->to(); big_int maxShift = Util::shift_left(1, LowerExpressions::maxShiftWidth); if (cst->value > maxShift) - ::error(ErrorType::ERR_OVERLIMIT, "%1%: shift amount limited to %2% on this target", - expression, maxShift); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: shift amount limited to %2% on this target", + expression, maxShift); } else { BUG_CHECK(rhstype->is(), "%1%: expected a bit<> type", rhstype); auto bs = rhstype->to(); if (bs->size > LowerExpressions::maxShiftWidth) - ::error(ErrorType::ERR_OVERLIMIT, - "%1%: shift amount limited to %2% bits on this target", expression, - LowerExpressions::maxShiftWidth); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "%1%: shift amount limited to %2% bits on this target", expression, + LowerExpressions::maxShiftWidth); } auto ltype = typeMap->getType(getOriginal(), true); typeMap->setType(expression, ltype); @@ -116,4 +116,4 @@ const IR::Node *LowerExpressions::postorder(IR::Cast *expression) { return expression; } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/lower.h b/backends/ebpf/lower.h index 2f498cca12..4da610a384 100644 --- a/backends/ebpf/lower.h +++ b/backends/ebpf/lower.h @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/p4/typeChecking/typeChecker.h" #include "ir/ir.h" -namespace EBPF { +namespace P4::EBPF { /// This pass rewrites expressions which are not supported natively on EBPF. class LowerExpressions : public Transform { @@ -53,6 +53,6 @@ class Lower : public PassManager { } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_LOWER_H_ */ diff --git a/backends/ebpf/midend.cpp b/backends/ebpf/midend.cpp index 8aed5a957c..ca4ed1e2ca 100644 --- a/backends/ebpf/midend.cpp +++ b/backends/ebpf/midend.cpp @@ -51,7 +51,7 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/validateProperties.h" -namespace EBPF { +namespace P4::EBPF { using namespace P4::literals; @@ -135,9 +135,9 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program * midEnd.setName("MidEnd"); midEnd.addDebugHooks(hooks); program = program->apply(midEnd); - if (::errorCount() > 0) return nullptr; + if (::P4::errorCount() > 0) return nullptr; return evaluator->getToplevelBlock(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/midend.h b/backends/ebpf/midend.h index c1a639a5cb..91f827cdde 100644 --- a/backends/ebpf/midend.h +++ b/backends/ebpf/midend.h @@ -22,7 +22,7 @@ limitations under the License. #include "frontends/p4/typeMap.h" #include "ir/ir.h" -namespace EBPF { +namespace P4::EBPF { class MidEnd { public: @@ -36,6 +36,6 @@ class MidEnd { std::ostream *outStream = nullptr); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_MIDEND_H_ */ diff --git a/backends/ebpf/p4c-ebpf.cpp b/backends/ebpf/p4c-ebpf.cpp index f497318a54..9c64fd411b 100644 --- a/backends/ebpf/p4c-ebpf.cpp +++ b/backends/ebpf/p4c-ebpf.cpp @@ -36,11 +36,13 @@ limitations under the License. #include "lib/nullstream.h" #include "midend.h" +using namespace P4; + void compile(EbpfOptions &options) { auto hook = options.getDebugHook(); bool isv1 = options.langVersion == CompilerOptions::FrontendVersion::P4_14; if (isv1) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "This compiler only handles P4-16"); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "This compiler only handles P4-16"); return; } const IR::P4Program *program = nullptr; @@ -48,21 +50,21 @@ void compile(EbpfOptions &options) { if (options.loadIRFromJson) { std::filebuf fb; if (fb.open(options.file, std::ios::in) == nullptr) { - ::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); return; } std::istream inJson(&fb); JSONLoader jsonFileLoader(inJson); if (jsonFileLoader.json == nullptr) { - ::error(ErrorType::ERR_IO, "%s: Not valid input file", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: Not valid input file", options.file); return; } program = new IR::P4Program(jsonFileLoader); fb.close(); } else { program = P4::parseP4File(options); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); @@ -70,12 +72,12 @@ void compile(EbpfOptions &options) { P4::FrontEnd frontend; frontend.addDebugHook(hook); program = frontend.run(options, program); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; } if (!options.arch.isNullOrEmpty() && options.arch != "filter") { P4::serializeP4RuntimeIfRequired(program, options); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; } EBPF::MidEnd midend; @@ -83,7 +85,7 @@ void compile(EbpfOptions &options) { auto toplevel = midend.run(options, program); if (!options.dumpJsonFile.empty()) JSONGenerator(*openFile(options.dumpJsonFile, true)) << program << std::endl; - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; EBPF::run_ebpf_backend(options, toplevel, &midend.refMap, &midend.typeMap); } @@ -99,7 +101,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) exit(1); + if (::P4::errorCount() > 0) exit(1); options.calculateXDP2TCMode(); try { @@ -110,5 +112,5 @@ int main(int argc, char *const argv[]) { } if (Log::verbose()) std::cerr << "Done." << std::endl; - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/ebpf/psa/backend.cpp b/backends/ebpf/psa/backend.cpp index 8a426eaaec..03293b1590 100644 --- a/backends/ebpf/psa/backend.cpp +++ b/backends/ebpf/psa/backend.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "backends/common/psaProgramStructure.h" -namespace EBPF { +namespace P4::EBPF { void PSASwitchBackend::convert(const IR::ToplevelBlock *tlb) { CHECK_NULL(tlb); @@ -30,10 +30,10 @@ void PSASwitchBackend::convert(const IR::ToplevelBlock *tlb) { } if (main->type->name != "PSA_Switch") { - ::warning(ErrorType::WARN_INVALID, - "%1%: the main package should be called PSA_Switch" - "; are you using the wrong architecture?", - main->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main package should be called PSA_Switch" + "; are you using the wrong architecture?", + main->type->name); return; } @@ -79,4 +79,4 @@ void PSASwitchBackend::convert(const IR::ToplevelBlock *tlb) { ebpf_program = convertToEbpfPSA->getPSAArchForEBPF(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/backend.h b/backends/ebpf/psa/backend.h index c9a1660ce0..0f3f1e1c99 100644 --- a/backends/ebpf/psa/backend.h +++ b/backends/ebpf/psa/backend.h @@ -19,7 +19,7 @@ limitations under the License. #include "ebpfPsaGen.h" -namespace EBPF { +namespace P4::EBPF { class PSASwitchBackend { public: @@ -51,6 +51,6 @@ class PSASwitchBackend { } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_BACKEND_H_ */ diff --git a/backends/ebpf/psa/ebpfPipeline.cpp b/backends/ebpf/psa/ebpfPipeline.cpp index fee84ee04f..2a3784194c 100644 --- a/backends/ebpf/psa/ebpfPipeline.cpp +++ b/backends/ebpf/psa/ebpfPipeline.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "backends/ebpf/ebpfParser.h" -namespace EBPF { +namespace P4::EBPF { bool EBPFPipeline::isEmpty() const { // Check if parser doesn't have any state @@ -95,7 +95,7 @@ void EBPFPipeline::emitUserMetadataInstance(CodeBuilder *builder) { builder->emitIndent(); auto user_md_type = typeMap->getType(control->user_metadata); if (user_md_type == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "cannot emit user metadata"); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "cannot emit user metadata"); } auto userMetadataType = EBPFTypeFactory::instance->create(user_md_type); userMetadataType->declare(builder, control->user_metadata->name.name, true); @@ -889,4 +889,4 @@ void TCTrafficManagerForXDP::emitReadXDP2TCMetadataFromCPUMAP(CodeBuilder *build builder->emitIndent(); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/ebpfPipeline.h b/backends/ebpf/psa/ebpfPipeline.h index 31d23629bf..0102f6f3a9 100644 --- a/backends/ebpf/psa/ebpfPipeline.h +++ b/backends/ebpf/psa/ebpfPipeline.h @@ -22,7 +22,7 @@ limitations under the License. #include "ebpfPsaControl.h" #include "ebpfPsaDeparser.h" -namespace EBPF { +namespace P4::EBPF { /// EBPFPipeline represents a single eBPF program in the TC/XDP hook. class EBPFPipeline : public EBPFProgram { @@ -279,6 +279,6 @@ class TCTrafficManagerForXDP : public TCIngressPipeline { DECLARE_TYPEINFO(TCTrafficManagerForXDP, TCIngressPipeline); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EBPFPIPELINE_H_ */ diff --git a/backends/ebpf/psa/ebpfPsaControl.cpp b/backends/ebpf/psa/ebpfPsaControl.cpp index 00aa9c5577..5095474805 100644 --- a/backends/ebpf/psa/ebpfPsaControl.cpp +++ b/backends/ebpf/psa/ebpfPsaControl.cpp @@ -17,7 +17,7 @@ limitations under the License. #include "ebpfPsaControl.h" -namespace EBPF { +namespace P4::EBPF { ControlBodyTranslatorPSA::ControlBodyTranslatorPSA(const EBPFControlPSA *control) : CodeGenInspector(control->program->refMap, control->program->typeMap), @@ -82,12 +82,14 @@ void ControlBodyTranslatorPSA::processMethod(const P4::ExternMethod *method) { if (method->method->type->name == "write") { reg->emitRegisterWrite(builder, method, this); } else if (method->method->type->name == "read") { - ::warning(ErrorType::WARN_UNUSED, "This Register(%1%) read value is not used!", name); + ::P4::warning(ErrorType::WARN_UNUSED, "This Register(%1%) read value is not used!", + name); reg->emitRegisterRead(builder, method, this, nullptr); } return; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unexpected method call", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unexpected method call", + method->expr); } } @@ -128,4 +130,4 @@ void EBPFControlPSA::emitTableInitializers(CodeBuilder *builder) { } } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/ebpfPsaControl.h b/backends/ebpf/psa/ebpfPsaControl.h index a5ad690a33..c6273f7a12 100644 --- a/backends/ebpf/psa/ebpfPsaControl.h +++ b/backends/ebpf/psa/ebpfPsaControl.h @@ -23,7 +23,7 @@ limitations under the License. #include "backends/ebpf/psa/externs/ebpfPsaRegister.h" #include "ebpfPsaTable.h" -namespace EBPF { +namespace P4::EBPF { class EBPFControlPSA; @@ -79,25 +79,25 @@ class EBPFControlPSA : public EBPFControl { void emitTableInitializers(CodeBuilder *builder) override; EBPFRandomPSA *getRandomExt(cstring name) const { - auto result = ::get(randoms, name); + auto result = ::P4::get(randoms, name); BUG_CHECK(result != nullptr, "No random generator named %1%", name); return result; } EBPFRegisterPSA *getRegister(cstring name) const { - auto result = ::get(registers, name); + auto result = ::P4::get(registers, name); BUG_CHECK(result != nullptr, "No register named %1%", name); return result; } EBPFHashPSA *getHash(cstring name) const { - auto result = ::get(hashes, name); + auto result = ::P4::get(hashes, name); BUG_CHECK(result != nullptr, "No hash named %1%", name); return result; } EBPFMeterPSA *getMeter(cstring name) const { - auto result = ::get(meters, name); + auto result = ::P4::get(meters, name); BUG_CHECK(result != nullptr, "No meter named %1%", name); return result; } @@ -105,6 +105,6 @@ class EBPFControlPSA : public EBPFControl { DECLARE_TYPEINFO(EBPFControlPSA, EBPFControl); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EBPFPSACONTROL_H_ */ diff --git a/backends/ebpf/psa/ebpfPsaDeparser.cpp b/backends/ebpf/psa/ebpfPsaDeparser.cpp index 97acfa34fb..42a235d3e6 100644 --- a/backends/ebpf/psa/ebpfPsaDeparser.cpp +++ b/backends/ebpf/psa/ebpfPsaDeparser.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "ebpfPipeline.h" -namespace EBPF { +namespace P4::EBPF { DeparserBodyTranslatorPSA::DeparserBodyTranslatorPSA(const EBPFDeparserPSA *deparser) : CodeGenInspector(deparser->program->refMap, deparser->program->typeMap), @@ -93,7 +93,8 @@ bool IngressDeparserPSA::build() { auto pl = controlBlock->container->type->applyParams; if (pl->size() != 7) { - ::error(ErrorType::ERR_EXPECTED, "Expected ingress deparser to have exactly 7 parameters"); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected ingress deparser to have exactly 7 parameters"); return false; } @@ -297,4 +298,4 @@ void XDPEgressDeparserPSA::emitPreDeparser(CodeBuilder *builder) { builder->blockEnd(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/ebpfPsaDeparser.h b/backends/ebpf/psa/ebpfPsaDeparser.h index b274c460ce..964513d7fc 100644 --- a/backends/ebpf/psa/ebpfPsaDeparser.h +++ b/backends/ebpf/psa/ebpfPsaDeparser.h @@ -24,7 +24,7 @@ limitations under the License. #include "ebpfPsaControl.h" #include "lib/rtti.h" -namespace EBPF { +namespace P4::EBPF { class EBPFDeparserPSA; @@ -55,13 +55,13 @@ class EBPFDeparserPSA : public EBPFDeparser { void emitDeclaration(CodeBuilder *builder, const IR::Declaration *decl) override; EBPFChecksumPSA *getChecksum(cstring name) const { - auto result = ::get(checksums, name); + auto result = ::P4::get(checksums, name); BUG_CHECK(result != nullptr, "No checksum named %1%", name); return result; } EBPFDigestPSA *getDigest(cstring name) const { - auto result = ::get(digests, name); + auto result = ::P4::get(digests, name); BUG_CHECK(result != nullptr, "No digest named %1%", name); return result; } @@ -154,6 +154,6 @@ class XDPEgressDeparserPSA : public EgressDeparserPSA { DECLARE_TYPEINFO(XDPEgressDeparserPSA, EgressDeparserPSA); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EBPFPSADEPARSER_H_ */ diff --git a/backends/ebpf/psa/ebpfPsaGen.cpp b/backends/ebpf/psa/ebpfPsaGen.cpp index e85f9454fb..f6ba5a7371 100644 --- a/backends/ebpf/psa/ebpfPsaGen.cpp +++ b/backends/ebpf/psa/ebpfPsaGen.cpp @@ -27,7 +27,7 @@ limitations under the License. #include "externs/ebpfPsaTableImplementation.h" #include "xdpHelpProgram.h" -namespace EBPF { +namespace P4::EBPF { class PSAErrorCodesGen : public Inspector { CodeBuilder *builder; @@ -51,8 +51,8 @@ class PSAErrorCodesGen : public Inspector { // Type ParserError_t is u8, which can have values from 0 to 255. if (id > 255) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: Reached maximum number of possible errors", - decl); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "%1%: Reached maximum number of possible errors", decl); } } builder->newline(); @@ -719,7 +719,7 @@ bool ConvertToEbpfPipeline::preorder(const IR::PackageBlock *block) { } else if (type == TC_TRAFFIC_MANAGER) { pipeline = new TCTrafficManagerForXDP(name, options, refmap, typemap); } else { - ::error(ErrorType::ERR_INVALID, "unknown type of pipeline"); + ::P4::error(ErrorType::ERR_INVALID, "unknown type of pipeline"); return false; } @@ -757,8 +757,8 @@ bool ConvertToEBPFParserPSA::preorder(const IR::ParserBlock *prsr) { } if (pl->size() != numOfParams) { - ::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly %1% parameters", - numOfParams); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly %1% parameters", + numOfParams); return false; } @@ -901,7 +901,8 @@ bool ConvertToEBPFControlPSA::preorder(const IR::ExternBlock *instance) { auto met = new EBPFMeterPSA(program, name, di, control->codeGen); control->meters.emplace(name, met); } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", instance); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", + instance); } return false; @@ -947,8 +948,8 @@ bool ConvertToEBPFDeparserPSA::preorder(const IR::Declaration_Instance *di) { if (typeName == "Digest") { if (pipelineType == TC_EGRESS || pipelineType == XDP_EGRESS) { - ::error(ErrorType::ERR_UNEXPECTED, - "Digests are only supported at ingress, got an instance at egress"); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Digests are only supported at ingress, got an instance at egress"); } cstring instance = EBPFObject::externalName(di); auto digest = new EBPFDigestPSA(program, di); @@ -959,4 +960,4 @@ bool ConvertToEBPFDeparserPSA::preorder(const IR::Declaration_Instance *di) { return false; } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/ebpfPsaGen.h b/backends/ebpf/psa/ebpfPsaGen.h index b4eff15340..9d2fb070f1 100644 --- a/backends/ebpf/psa/ebpfPsaGen.h +++ b/backends/ebpf/psa/ebpfPsaGen.h @@ -24,7 +24,7 @@ limitations under the License. #include "ebpfPsaParser.h" #include "xdpHelpProgram.h" -namespace EBPF { +namespace P4::EBPF { enum pipeline_type { TC_INGRESS, TC_EGRESS, XDP_INGRESS, XDP_EGRESS, TC_TRAFFIC_MANAGER }; @@ -227,6 +227,6 @@ class ConvertToEBPFDeparserPSA : public Inspector { EBPF::EBPFDeparserPSA *getEBPFDeparser() { return deparser; } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EBPFPSAGEN_H_ */ diff --git a/backends/ebpf/psa/ebpfPsaParser.cpp b/backends/ebpf/psa/ebpfPsaParser.cpp index 8c5549b3b1..b64d0d69c1 100644 --- a/backends/ebpf/psa/ebpfPsaParser.cpp +++ b/backends/ebpf/psa/ebpfPsaParser.cpp @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/psa/ebpfPipeline.h" #include "frontends/p4/enumInstance.h" -namespace EBPF { +namespace P4::EBPF { void PsaStateTranslationVisitor::processMethod(const P4::ExternMethod *ext) { auto externName = ext->originalExternType->name.name; @@ -113,4 +113,4 @@ void EBPFPsaParser::emitRejectState(CodeBuilder *builder) { builder->appendFormat("goto %s", IR::ParserState::accept.c_str()); builder->endOfStatement(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/ebpfPsaParser.h b/backends/ebpf/psa/ebpfPsaParser.h index d2764c5550..6f804f52b0 100644 --- a/backends/ebpf/psa/ebpfPsaParser.h +++ b/backends/ebpf/psa/ebpfPsaParser.h @@ -22,7 +22,7 @@ limitations under the License. #include "backends/ebpf/psa/ebpfPsaTable.h" #include "backends/ebpf/psa/externs/ebpfPsaChecksum.h" -namespace EBPF { +namespace P4::EBPF { class EBPFPsaParser; @@ -51,7 +51,7 @@ class EBPFPsaParser : public EBPFParser { void emitRejectState(CodeBuilder *builder) override; EBPFChecksumPSA *getChecksum(cstring name) const { - auto result = ::get(checksums, name); + auto result = ::P4::get(checksums, name); BUG_CHECK(result != nullptr, "No checksum named %1%", name); return result; } @@ -59,6 +59,6 @@ class EBPFPsaParser : public EBPFParser { DECLARE_TYPEINFO(EBPFPsaParser, EBPFParser); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EBPFPSAPARSER_H_ */ diff --git a/backends/ebpf/psa/ebpfPsaTable.cpp b/backends/ebpf/psa/ebpfPsaTable.cpp index 0044652234..517fbf2720 100644 --- a/backends/ebpf/psa/ebpfPsaTable.cpp +++ b/backends/ebpf/psa/ebpfPsaTable.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "ebpfPipeline.h" #include "externs/ebpfPsaTableImplementation.h" -namespace EBPF { +namespace P4::EBPF { class EBPFTablePSADirectCounterPropertyVisitor : public EBPFTablePsaPropertyVisitor { public: @@ -34,8 +34,8 @@ class EBPFTablePSADirectCounterPropertyVisitor : public EBPFTablePsaPropertyVisi auto di = decl->to(); CHECK_NULL(di); if (EBPFObject::getSpecializedTypeName(di) != "DirectCounter") { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: not a DirectCounter, see declaration of %2%", - pe, decl); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: not a DirectCounter, see declaration of %2%", pe, decl); return false; } @@ -61,8 +61,8 @@ class EBPFTablePSADirectMeterPropertyVisitor : public EBPFTablePsaPropertyVisito auto di = decl->to(); CHECK_NULL(di); if (EBPFObject::getTypeName(di) != "DirectMeter") { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: not a DirectMeter, see declaration of %2%", pe, - decl); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: not a DirectMeter, see declaration of %2%", + pe, decl); return false; } @@ -91,8 +91,8 @@ class EBPFTablePSAImplementationPropertyVisitor : public EBPFTablePsaPropertyVis cstring type = di->type->toString(); if (table->implementation != nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: Up to one implementation is supported in a table", pe); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: Up to one implementation is supported in a table", pe); return false; } @@ -104,7 +104,7 @@ class EBPFTablePSAImplementationPropertyVisitor : public EBPFTablePsaPropertyVis if (table->implementation != nullptr) table->implementation->registerTable(table); else - ::error(ErrorType::ERR_UNKNOWN, "%1%: unknown table implementation %2%", pe, decl); + ::P4::error(ErrorType::ERR_UNKNOWN, "%1%: unknown table implementation %2%", pe, decl); return false; } @@ -175,7 +175,7 @@ class EBPFTablePSAInitializerCodeGen : public CodeGenInspector { return true; } bool preorder(const IR::KeyElement *key) override { - cstring fieldName = ::get(table->keyFieldNames, key); + cstring fieldName = ::P4::get(table->keyFieldNames, key); cstring matchType = key->matchType->path->name.name; auto expr = currentEntry->keys->components[currentKeyEntryIndex]; unsigned width = EBPFInitializerUtils::ebpfTypeWidth(typeMap, key->expression); @@ -211,7 +211,7 @@ class EBPFTablePSAInitializerCodeGen : public CodeGenInspector { auto mask = km->right->to()->value; auto len = trailing_zeros(mask); if (len + count_ones(mask) != width) { // any remaining 0s in the prefix? - ::error(ErrorType::ERR_INVALID, "%1% invalid mask for LPM key", key); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid mask for LPM key", key); return false; } prefixLen = width - len; @@ -362,15 +362,17 @@ void ActionTranslationVisitorPSA::processMethod(const P4::ExternMethod *method) if (ctr != nullptr) ctr->emitDirectMethodInvocation(builder, method, valueName); else - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Table %2% does not own DirectCounter named %3%", - method->expr, table->table->container, instanceName); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: Table %2% does not own DirectCounter named %3%", method->expr, + table->table->container, instanceName); } else if (declType->name.name == "DirectMeter") { auto met = table->getMeter(instanceName); if (met != nullptr) { met->emitDirectExecute(builder, method, valueName); } else { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Table %2% does not own DirectMeter named %3%", - method->expr, table->table->container, instanceName); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: Table %2% does not own DirectMeter named %3%", method->expr, + table->table->container, instanceName); } } else { ControlBodyTranslatorPSA::processMethod(method); @@ -397,15 +399,15 @@ EBPFTablePSA::EBPFTablePSA(const EBPFProgram *program, const IR::TableBlock *tab : EBPFTable(program, table, codeGen), implementation(nullptr) { auto sizeProperty = table->container->properties->getProperty("size"); if (keyGenerator == nullptr && sizeProperty != nullptr) { - ::warning(ErrorType::WARN_IGNORE_PROPERTY, - "%1%: property ignored because table does not have a key", sizeProperty); + ::P4::warning(ErrorType::WARN_IGNORE_PROPERTY, + "%1%: property ignored because table does not have a key", sizeProperty); } if (keyFieldNames.empty() && size != 1) { if (sizeProperty != nullptr) { - ::warning(ErrorType::WARN_IGNORE, - "%1%: only one entry allowed with empty key or selector-only key", - sizeProperty); + ::P4::warning(ErrorType::WARN_IGNORE, + "%1%: only one entry allowed with empty key or selector-only key", + sizeProperty); } this->size = 1; } @@ -451,18 +453,18 @@ void EBPFTablePSA::initImplementation() { } if (hasActionSelector && selectorKey == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, - "%1%: ActionSelector provided but there is no selector key", table->container); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: ActionSelector provided but there is no selector key", table->container); } if (!hasActionSelector && selectorKey != nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, - "%1%: implementation not found, ActionSelector is required", - selectorKey->matchType); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: implementation not found, ActionSelector is required", + selectorKey->matchType); } auto emptyGroupAction = table->container->properties->getProperty("psa_empty_group_action"); if (!hasActionSelector && emptyGroupAction != nullptr) { - ::warning(ErrorType::WARN_UNUSED, "%1%: unused property (ActionSelector not provided)", - emptyGroupAction); + ::P4::warning(ErrorType::WARN_UNUSED, "%1%: unused property (ActionSelector not provided)", + emptyGroupAction); } } @@ -934,9 +936,9 @@ void EBPFTablePSA::tryEnableTableCache() { if (!program->options.enableTableCache) return; if (!isLPMTable() && !isTernaryTable()) return; if (!counters.empty() || !meters.empty()) { - ::warning(ErrorType::WARN_UNSUPPORTED, - "%1%: table cache can't be enabled due to direct extern(s)", - table->container->name); + ::P4::warning(ErrorType::WARN_UNSUPPORTED, + "%1%: table cache can't be enabled due to direct extern(s)", + table->container->name); return; } @@ -1056,4 +1058,4 @@ void EBPFTablePSA::emitCacheUpdate(CodeBuilder *builder, cstring key, cstring va builder->blockEnd(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/ebpfPsaTable.h b/backends/ebpf/psa/ebpfPsaTable.h index f12aa98245..2ed8144a79 100644 --- a/backends/ebpf/psa/ebpfPsaTable.h +++ b/backends/ebpf/psa/ebpfPsaTable.h @@ -22,7 +22,7 @@ limitations under the License. #include "backends/ebpf/psa/externs/ebpfPsaMeter.h" #include "frontends/p4/methodInstance.h" -namespace EBPF { +namespace P4::EBPF { class EBPFTableImplementationPSA; @@ -132,8 +132,8 @@ class EBPFTablePsaPropertyVisitor : public Inspector { /// precedence over it and throw error for whole list. bool preorder(const IR::ListExpression *) override { return true; } bool preorder(const IR::Expression *expr) override { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: unsupported expression, expected a named instance", expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupported expression, expected a named instance", expr); return false; } @@ -143,6 +143,6 @@ class EBPFTablePsaPropertyVisitor : public Inspector { } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EBPFPSATABLE_H_ */ diff --git a/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp b/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp index c90a9eecd5..c4ac2f56a2 100644 --- a/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaChecksum.cpp @@ -18,17 +18,17 @@ limitations under the License. #include "ebpfPsaHashAlgorithm.h" -namespace EBPF { +namespace P4::EBPF { void EBPFChecksumPSA::init(const EBPFProgram *program, cstring name, int type) { engine = EBPFHashAlgorithmTypeFactoryPSA::instance()->create(type, program, name); if (engine == nullptr) { if (declaration->arguments->empty()) - ::error(ErrorType::ERR_UNSUPPORTED, "InternetChecksum not yet implemented"); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "InternetChecksum not yet implemented"); else - ::error(ErrorType::ERR_UNSUPPORTED, "Hash algorithm not yet implemented: %1%", - declaration->arguments->at(0)); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Hash algorithm not yet implemented: %1%", + declaration->arguments->at(0)); } } @@ -37,7 +37,7 @@ EBPFChecksumPSA::EBPFChecksumPSA(const EBPFProgram *program, const IR::Declarati : engine(nullptr), declaration(block) { auto di = block->to(); if (di->arguments->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", block); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", block); return; } int type = di->arguments->at(0)->expression->checkedTo()->asInt(); @@ -63,7 +63,7 @@ void EBPFChecksumPSA::processMethod(CodeBuilder *builder, cstring method, } else if (method == "get") { engine->emitGet(builder); } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); } } @@ -92,7 +92,7 @@ void EBPFHashPSA::processMethod(CodeBuilder *builder, cstring method, if (method == "get_hash") { emitGetMethod(builder, expr, visitor); } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); } } @@ -130,4 +130,4 @@ void EBPFHashPSA::emitGetMethod(CodeBuilder *builder, const IR::MethodCallExpres } } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaChecksum.h b/backends/ebpf/psa/externs/ebpfPsaChecksum.h index 69aac07582..e755b79a46 100644 --- a/backends/ebpf/psa/externs/ebpfPsaChecksum.h +++ b/backends/ebpf/psa/externs/ebpfPsaChecksum.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/ebpfObject.h" #include "ebpfPsaHashAlgorithm.h" -namespace EBPF { +namespace P4::EBPF { class EBPFChecksumPSA : public EBPFObject { protected: @@ -70,6 +70,6 @@ class EBPFHashPSA : public EBPFChecksumPSA { Visitor *visitor); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EXTERNS_EBPFPSACHECKSUM_H_ */ diff --git a/backends/ebpf/psa/externs/ebpfPsaCounter.cpp b/backends/ebpf/psa/externs/ebpfPsaCounter.cpp index b0b37351b3..de06a581f3 100644 --- a/backends/ebpf/psa/externs/ebpfPsaCounter.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaCounter.cpp @@ -20,14 +20,14 @@ limitations under the License. #include "backends/ebpf/ebpfType.h" #include "backends/ebpf/psa/ebpfPipeline.h" -namespace EBPF { +namespace P4::EBPF { EBPFCounterPSA::EBPFCounterPSA(const EBPFProgram *program, const IR::Declaration_Instance *di, cstring name, CodeGenInspector *codeGen) : EBPFCounterTable(program, name, codeGen, 1, false) { CHECK_NULL(di); if (!di->type->is()) { - ::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); return; } auto ts = di->type->to(); @@ -37,45 +37,46 @@ EBPFCounterPSA::EBPFCounterPSA(const EBPFProgram *program, const IR::Declaration } else if (ts->baseType->toString() == "DirectCounter") { isDirect = true; } else { - ::error(ErrorType::ERR_UNKNOWN, "Unknown counter type extern: %1%", di); + ::P4::error(ErrorType::ERR_UNKNOWN, "Unknown counter type extern: %1%", di); return; } if (isDirect && di->arguments->size() != 1) { - ::error(ErrorType::ERR_MODEL, "Expected 1 argument: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Expected 1 argument: %1%", di); return; } else if (!isDirect && di->arguments->size() != 2) { - ::error(ErrorType::ERR_MODEL, "Expected 2 arguments: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Expected 2 arguments: %1%", di); return; } if (isDirect && ts->arguments->size() != 1) { - ::error(ErrorType::ERR_MODEL, "Expected a type specialized with one argument: %1%", ts); + ::P4::error(ErrorType::ERR_MODEL, "Expected a type specialized with one argument: %1%", ts); return; } else if (!isDirect && ts->arguments->size() != 2) { - ::error(ErrorType::ERR_MODEL, "Expected a type specialized with two arguments: %1%", ts); + ::P4::error(ErrorType::ERR_MODEL, "Expected a type specialized with two arguments: %1%", + ts); return; } // check dataplane counter width auto dpwtype = ts->arguments->at(0); if (!dpwtype->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", dpwtype); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", dpwtype); return; } dataplaneWidthType = EBPFTypeFactory::instance->create(dpwtype); unsigned dataplaneWidth = dpwtype->width_bits(); if (dataplaneWidth > 64) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Counters dataplane width up to 64 bits are supported: %1%", dpwtype); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Counters dataplane width up to 64 bits are supported: %1%", dpwtype); return; } if (dataplaneWidth < 8 || (dataplaneWidth & (dataplaneWidth - 1)) != 0) { - ::warning(ErrorType::WARN_UNSUPPORTED, - "Counter dataplane width will be extended to " - "nearest type (8, 16, 32 or 64 bits): %1%", - dpwtype); + ::P4::warning(ErrorType::WARN_UNSUPPORTED, + "Counter dataplane width will be extended to " + "nearest type (8, 16, 32 or 64 bits): %1%", + dpwtype); } // By default, use BPF array map for Counter @@ -87,14 +88,14 @@ EBPFCounterPSA::EBPFCounterPSA(const EBPFProgram *program, const IR::Declaration if (!isDirect) { auto istype = ts->arguments->at(1); if (!dpwtype->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", istype); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", istype); return; } if (!isHash && istype->width_bits() != 32) { // ARRAY_MAP can have only 32 bits key, so assume this and warn user - ::warning(ErrorType::WARN_UNSUPPORTED, - "Up to 32-bit type for index is supported, using 32 bit: %1%", istype); + ::P4::warning(ErrorType::WARN_UNSUPPORTED, + "Up to 32-bit type for index is supported, using 32 bit: %1%", istype); } if (isHash) { @@ -105,7 +106,7 @@ EBPFCounterPSA::EBPFCounterPSA(const EBPFProgram *program, const IR::Declaration auto declaredSize = di->arguments->at(0)->expression->to(); if (!declaredSize->fitsUint()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", declaredSize); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", declaredSize); return; } size = declaredSize->asUnsigned(); @@ -174,7 +175,7 @@ void EBPFCounterPSA::emitInstance(CodeBuilder *builder) { void EBPFCounterPSA::emitMethodInvocation(CodeBuilder *builder, const P4::ExternMethod *method, CodeGenInspector *codeGen) { if (method->method->name.name != "count") { - ::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); return; } BUG_CHECK(!isDirect, "DirectCounter used outside of table"); @@ -189,7 +190,7 @@ void EBPFCounterPSA::emitMethodInvocation(CodeBuilder *builder, const P4::Extern void EBPFCounterPSA::emitDirectMethodInvocation(CodeBuilder *builder, const P4::ExternMethod *method, cstring valuePtr) { if (method->method->name.name != "count") { - ::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); return; } BUG_CHECK(isDirect, "Bad Counter invocation"); @@ -315,4 +316,4 @@ void EBPFCounterPSA::emitCounterInitializer(CodeBuilder *builder) { builder->blockEnd(false); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaCounter.h b/backends/ebpf/psa/externs/ebpfPsaCounter.h index 7872b22b2e..70383fe377 100644 --- a/backends/ebpf/psa/externs/ebpfPsaCounter.h +++ b/backends/ebpf/psa/externs/ebpfPsaCounter.h @@ -19,7 +19,7 @@ limitations under the License. #include "backends/ebpf/ebpfTable.h" -namespace EBPF { +namespace P4::EBPF { class ControlBodyTranslatorPSA; @@ -55,6 +55,6 @@ class EBPFCounterPSA : public EBPFCounterTable { DECLARE_TYPEINFO(EBPFCounterPSA, EBPFCounterTable); }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EXTERNS_EBPFPSACOUNTER_H_ */ diff --git a/backends/ebpf/psa/externs/ebpfPsaDigest.cpp b/backends/ebpf/psa/externs/ebpfPsaDigest.cpp index 07d2888f07..03ef4d8ef3 100644 --- a/backends/ebpf/psa/externs/ebpfPsaDigest.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaDigest.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "backends/ebpf/ebpfType.h" #include "backends/ebpf/psa/ebpfPsaDeparser.h" -namespace EBPF { +namespace P4::EBPF { class EBPFDigestPSAValueVisitor : public CodeGenInspector { protected: @@ -143,8 +143,8 @@ void EBPFDigestPSA::processMethod(CodeBuilder *builder, cstring method, dg.setBuilder(builder); arg->apply(dg); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: unsupported method call for Digest", - expr->method); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: unsupported method call for Digest", + expr->method); } } @@ -163,4 +163,4 @@ void EBPFDigestPSA::emitPushElement(CodeBuilder *builder, cstring elem) const { builder->endOfStatement(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaDigest.h b/backends/ebpf/psa/externs/ebpfPsaDigest.h index 7a196eb780..c7e593e25f 100644 --- a/backends/ebpf/psa/externs/ebpfPsaDigest.h +++ b/backends/ebpf/psa/externs/ebpfPsaDigest.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/ebpfObject.h" #include "backends/ebpf/ebpfProgram.h" -namespace EBPF { +namespace P4::EBPF { class DeparserBodyTranslatorPSA; @@ -48,6 +48,6 @@ class EBPFDigestPSA : public EBPFObject { virtual void emitPushElement(CodeBuilder *builder, cstring elem) const; }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EXTERNS_EBPFPSADIGEST_H_ */ diff --git a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp index ef50b361ac..66091dd67b 100644 --- a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "backends/ebpf/ebpfProgram.h" #include "backends/ebpf/ebpfType.h" -namespace EBPF { +namespace P4::EBPF { EBPFHashAlgorithmPSA::ArgumentsList EBPFHashAlgorithmPSA::unpackArguments( const IR::MethodCallExpression *expr, int dataPos) { @@ -186,11 +186,11 @@ void CRCChecksumAlgorithm::emitVariables(CodeBuilder *builder, auto otype = ts->arguments->at(0); if (!otype->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", ts); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", ts); return; } if (otype->width_bits() != crcWidth) { - ::error(ErrorType::ERR_TYPE_ERROR, "Must be %1%-bits width: %2%", crcWidth, ts); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "Must be %1%-bits width: %2%", crcWidth, ts); return; } @@ -243,7 +243,7 @@ void CRCChecksumAlgorithm::emitAddData(CodeBuilder *builder, const ArgumentsList for (auto field : arguments) { auto fieldType = field->type->to(); if (fieldType == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, "Only bits types are supported %1%", field); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Only bits types are supported %1%", field); return; } const int width = fieldType->width_bits(); @@ -252,11 +252,11 @@ void CRCChecksumAlgorithm::emitAddData(CodeBuilder *builder, const ArgumentsList if (width < 8 || concatenateBits) { concatenateBits = true; if (width > remainingBits) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Unable to concatenate fields into one byte. " - "Last field(%1%) overflows one byte. " - "There are %2% remaining bits but field (%1%) has %3% bits width.", - field, remainingBits, width); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Unable to concatenate fields into one byte. " + "Last field(%1%) overflows one byte. " + "There are %2% remaining bits but field (%1%) has %3% bits width.", + field, remainingBits, width); return; } if (remainingBits == 8) { @@ -284,8 +284,8 @@ void CRCChecksumAlgorithm::emitAddData(CodeBuilder *builder, const ArgumentsList } else { // fields larger than 8 bits if (width % 8 != 0) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Fields larger than 8 bits have to be aligned to bytes %1%", field); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Fields larger than 8 bits have to be aligned to bytes %1%", field); return; } builder->emitIndent(); @@ -371,7 +371,7 @@ void InternetChecksumAlgorithm::updateChecksum(CodeBuilder *builder, const Argum for (auto field : arguments) { auto fieldType = field->type->to(); if (fieldType == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported field type: %1%", field->type); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unsupported field type: %1%", field->type); return; } const int width = fieldType->width_bits(); @@ -379,15 +379,17 @@ void InternetChecksumAlgorithm::updateChecksum(CodeBuilder *builder, const Argum if (width > 64) { if (remainingBits != 16) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: field wider than 64 bits must be aligned to 16 bits in input data", - field); + ::P4::error( + ErrorType::ERR_UNSUPPORTED, + "%1%: field wider than 64 bits must be aligned to 16 bits in input data", + field); continue; } if (width % 16 != 0) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: field wider than 64 bits must have size in bits multiply of 16 bits", - field); + ::P4::error( + ErrorType::ERR_UNSUPPORTED, + "%1%: field wider than 64 bits must have size in bits multiply of 16 bits", + field); continue; } @@ -516,7 +518,7 @@ void InternetChecksumAlgorithm::emitGetInternalState(CodeBuilder *builder) { void InternetChecksumAlgorithm::emitSetInternalState(CodeBuilder *builder, const IR::MethodCallExpression *expr) { if (expr->arguments->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", expr); return; } builder->emitIndent(); @@ -525,4 +527,4 @@ void InternetChecksumAlgorithm::emitSetInternalState(CodeBuilder *builder, builder->endOfStatement(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h index c56f1c9557..0d6f68aacb 100644 --- a/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h +++ b/backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h @@ -19,7 +19,7 @@ limitations under the License. #include "backends/ebpf/ebpfObject.h" -namespace EBPF { +namespace P4::EBPF { class EBPFProgram; @@ -195,6 +195,6 @@ class EBPFHashAlgorithmTypeFactoryPSA { } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAHASHALGORITHM_H_ */ diff --git a/backends/ebpf/psa/externs/ebpfPsaMeter.cpp b/backends/ebpf/psa/externs/ebpfPsaMeter.cpp index b967f4c953..c04296f1d4 100644 --- a/backends/ebpf/psa/externs/ebpfPsaMeter.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaMeter.cpp @@ -15,7 +15,7 @@ limitations under the License. #include "backends/ebpf/psa/ebpfPipeline.h" -namespace EBPF { +namespace P4::EBPF { EBPFMeterPSA::EBPFMeterPSA(const EBPFProgram *program, cstring instanceName, const IR::Declaration_Instance *di, CodeGenInspector *codeGen) @@ -32,12 +32,12 @@ EBPFMeterPSA::EBPFMeterPSA(const EBPFProgram *program, cstring instanceName, auto declaredSize = di->arguments->at(0)->expression->to(); if (!declaredSize->fitsUint()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", declaredSize); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", declaredSize); return; } size = declaredSize->asUnsigned(); } else { - ::error(ErrorType::ERR_INVALID, "Not known Meter type: %1%", di); + ::P4::error(ErrorType::ERR_INVALID, "Not known Meter type: %1%", di); return; } @@ -150,9 +150,9 @@ void EBPFMeterPSA::emitInstance(CodeBuilder *builder) const { builder->target->emitTableDeclSpinlock(builder, instanceName, TableHash, this->keyTypeName, "struct " + getIndirectStructName(), size); } else { - ::error(ErrorType::ERR_UNEXPECTED, - "Direct meter belongs to table " - "and cannot have own instance"); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Direct meter belongs to table " + "and cannot have own instance"); } } @@ -446,4 +446,4 @@ cstring EBPFMeterPSA::meterExecuteFunc(bool trace, P4::ReferenceMap *refMap) { return meterExecuteFunc; } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaMeter.h b/backends/ebpf/psa/externs/ebpfPsaMeter.h index 55973ad19c..107ab42eb3 100644 --- a/backends/ebpf/psa/externs/ebpfPsaMeter.h +++ b/backends/ebpf/psa/externs/ebpfPsaMeter.h @@ -16,7 +16,7 @@ limitations under the License. #include "backends/ebpf/ebpfTable.h" -namespace EBPF { +namespace P4::EBPF { class ControlBodyTranslatorPSA; @@ -62,6 +62,6 @@ class EBPFMeterPSA : public EBPFTableBase { static cstring meterExecuteFunc(bool trace, P4::ReferenceMap *refMap); }; -} // namespace EBPF +} // namespace P4::EBPF #endif // BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAMETER_H_ diff --git a/backends/ebpf/psa/externs/ebpfPsaRandom.cpp b/backends/ebpf/psa/externs/ebpfPsaRandom.cpp index 2730caf8ce..ec254bab79 100644 --- a/backends/ebpf/psa/externs/ebpfPsaRandom.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaRandom.cpp @@ -13,7 +13,7 @@ limitations under the License. */ #include "ebpfPsaRandom.h" -namespace EBPF { +namespace P4::EBPF { EBPFRandomPSA::EBPFRandomPSA(const IR::Declaration_Instance *di) : minValue(0), maxValue(0), range(0) { @@ -21,22 +21,22 @@ EBPFRandomPSA::EBPFRandomPSA(const IR::Declaration_Instance *di) // verify type if (!di->type->is()) { - ::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); return; } auto ts = di->type->to(); BUG_CHECK(ts->arguments->size() == 1, "%1%, Lack of specialization argument", ts); auto type = ts->arguments->at(0); if (!type->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", ts); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Must be bit or int type: %1%", ts); return; } if (type->width_bits() > 32) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: up to 32 bits width is supported", ts); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: up to 32 bits width is supported", ts); } if (di->arguments->size() != 2) { - ::error(ErrorType::ERR_MODEL, "Expected 2 arguments to: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Expected 2 arguments to: %1%", di); return; } @@ -47,11 +47,11 @@ EBPFRandomPSA::EBPFRandomPSA(const IR::Declaration_Instance *di) if (expr->fitsUint()) { tmp[i] = expr->asUnsigned(); } else { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", expr); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", expr); } } else { - ::error(ErrorType::ERR_UNSUPPORTED, "Must be constant value: %1%", - di->arguments->at(i)->expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Must be constant value: %1%", + di->arguments->at(i)->expression); } } @@ -61,13 +61,13 @@ EBPFRandomPSA::EBPFRandomPSA(const IR::Declaration_Instance *di) // verify constructor parameters if (minValue > maxValue) { - ::error(ErrorType::ERR_INVALID, "%1%: Max value lower than min value", di); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Max value lower than min value", di); } if (minValue == maxValue) { - ::warning(ErrorType::WARN_IGNORE, - "%1%: No randomness, will always return the same value " - "due to that the min value is equal to the max value", - di); + ::P4::warning(ErrorType::WARN_IGNORE, + "%1%: No randomness, will always return the same value " + "due to that the min value is equal to the max value", + di); } } @@ -75,7 +75,7 @@ void EBPFRandomPSA::processMethod(CodeBuilder *builder, const P4::ExternMethod * if (method->method->type->name == "read") { emitRead(builder); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Method not implemented yet", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Method not implemented yet", method->expr); } } @@ -100,4 +100,4 @@ void EBPFRandomPSA::emitRead(CodeBuilder *builder) const { if (minValue != 0) builder->append(")"); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaRandom.h b/backends/ebpf/psa/externs/ebpfPsaRandom.h index da562aae98..2d019df603 100644 --- a/backends/ebpf/psa/externs/ebpfPsaRandom.h +++ b/backends/ebpf/psa/externs/ebpfPsaRandom.h @@ -17,7 +17,7 @@ limitations under the License. #include "backends/ebpf/ebpfObject.h" #include "frontends/p4/methodInstance.h" -namespace EBPF { +namespace P4::EBPF { class EBPFRandomPSA : public EBPFObject { unsigned int minValue, maxValue; @@ -30,6 +30,6 @@ class EBPFRandomPSA : public EBPFObject { void emitRead(CodeBuilder *builder) const; }; -} // namespace EBPF +} // namespace P4::EBPF #endif // BACKENDS_EBPF_PSA_EXTERNS_EBPFPSARANDOM_H_ diff --git a/backends/ebpf/psa/externs/ebpfPsaRegister.cpp b/backends/ebpf/psa/externs/ebpfPsaRegister.cpp index 697324146a..5e36e9953a 100644 --- a/backends/ebpf/psa/externs/ebpfPsaRegister.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaRegister.cpp @@ -19,20 +19,21 @@ limitations under the License. #include "backends/ebpf/psa/ebpfPsaControl.h" -namespace EBPF { +namespace P4::EBPF { EBPFRegisterPSA::EBPFRegisterPSA(const EBPFProgram *program, cstring instanceName, const IR::Declaration_Instance *di, CodeGenInspector *codeGen) : EBPFTableBase(program, instanceName, codeGen) { CHECK_NULL(di); if (!di->type->is()) { - ::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); return; } auto ts = di->type->to(); if (ts->arguments->size() != 2) { - ::error(ErrorType::ERR_MODEL, "Expected a type specialized with two arguments: %1%", ts); + ::P4::error(ErrorType::ERR_MODEL, "Expected a type specialized with two arguments: %1%", + ts); return; } @@ -42,7 +43,7 @@ EBPFRegisterPSA::EBPFRegisterPSA(const EBPFProgram *program, cstring instanceNam this->valueType = EBPFTypeFactory::instance->create(valueArg); if (di->arguments->size() < 1) { - ::error(ErrorType::ERR_MODEL, "Expected at least 1 argument: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Expected at least 1 argument: %1%", di); return; } @@ -50,7 +51,7 @@ EBPFRegisterPSA::EBPFRegisterPSA(const EBPFProgram *program, cstring instanceNam CHECK_NULL(declaredSize); if (!declaredSize->fitsUint()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", declaredSize); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", declaredSize); return; } size = declaredSize->asUnsigned(); @@ -71,7 +72,7 @@ bool EBPFRegisterPSA::shouldUseArrayMap() { return (keyWidth > 0 && keyWidth <= 32); } - ::error(ErrorType::ERR_MODEL, "Unexpected key type: %1%", this->keyType->type); + ::P4::error(ErrorType::ERR_MODEL, "Unexpected key type: %1%", this->keyType->type); return false; } @@ -236,4 +237,4 @@ void EBPFRegisterPSA::emitRegisterWrite(CodeBuilder *builder, const P4::ExternMe builder->blockEnd(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaRegister.h b/backends/ebpf/psa/externs/ebpfPsaRegister.h index 048f79182e..e6cf31d774 100644 --- a/backends/ebpf/psa/externs/ebpfPsaRegister.h +++ b/backends/ebpf/psa/externs/ebpfPsaRegister.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/ebpfTable.h" #include "backends/ebpf/ebpfType.h" -namespace EBPF { +namespace P4::EBPF { class ControlBodyTranslatorPSA; @@ -54,6 +54,6 @@ class EBPFRegisterPSA : public EBPFTableBase { ControlBodyTranslatorPSA *translator); }; -} // namespace EBPF +} // namespace P4::EBPF #endif // BACKENDS_EBPF_PSA_EXTERNS_EBPFPSAREGISTER_H_ diff --git a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp index 72e2d56754..483907a565 100644 --- a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp +++ b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.cpp @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/psa/ebpfPsaControl.h" #include "ebpfPsaHashAlgorithm.h" -namespace EBPF { +namespace P4::EBPF { EBPFTableImplementationPSA::EBPFTableImplementationPSA(const EBPFProgram *program, CodeGenInspector *codeGen, @@ -81,11 +81,11 @@ void EBPFTableImplementationPSA::verifyTableActionList(const EBPFTablePSA *insta } if (printError) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: Action list differs from previous %2% " - "(tables use the same implementation %3%)", - instance->table->container->getActionList(), table->container->getActionList(), - declaration); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: Action list differs from previous %2% " + "(tables use the same implementation %3%)", + instance->table->container->getActionList(), table->container->getActionList(), + declaration); } } @@ -100,18 +100,18 @@ void EBPFTableImplementationPSA::verifyTableNoDefaultAction(const EBPFTablePSA * BUG_CHECK(ac != nullptr, "%1%: expected an action call", mi); if (ac->action->name.originalName != P4::P4CoreLibrary::instance().noAction.name) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: Default action cannot be defined for table %2% with implementation %3%", - defaultAction, instance->table->container->name, declaration); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: Default action cannot be defined for table %2% with implementation %3%", + defaultAction, instance->table->container->name, declaration); } } void EBPFTableImplementationPSA::verifyTableNoDirectObjects(const EBPFTablePSA *instance) { if (!instance->counters.empty() || !instance->meters.empty()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: DirectCounter and DirectMeter externs are not supported " - "with table implementation %2%", - instance->table->container->name, declaration->type->toString()); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: DirectCounter and DirectMeter externs are not supported " + "with table implementation %2%", + instance->table->container->name, declaration->type->toString()); } } @@ -121,22 +121,22 @@ void EBPFTableImplementationPSA::verifyTableNoEntries(const EBPFTablePSA *instan // I believe that this sentence forbids (const) entries in a table in P4 code at all. auto entries = instance->table->container->getEntries(); if (entries != nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: entries directly specified in a table %2% " - "with implementation %3% are not supported", - entries, instance->table->container->name, declaration); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: entries directly specified in a table %2% " + "with implementation %3% are not supported", + entries, instance->table->container->name, declaration); } } unsigned EBPFTableImplementationPSA::getUintFromExpression(const IR::Expression *expr, unsigned defaultValue) { if (!expr->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Must be constant value: %1%", expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Must be constant value: %1%", expr); return defaultValue; } auto c = expr->to(); if (!c->fitsUint()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", c); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: size too large", c); return defaultValue; } return c->asUnsigned(); @@ -214,26 +214,26 @@ EBPFActionSelectorPSA::EBPFActionSelectorPSA(const EBPFProgram *program, CodeGen if (hashEngine != nullptr) { hashEngine->setVisitor(codeGen); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "Algorithm not yet implemented: %1%", - decl->arguments->at(0)); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Algorithm not yet implemented: %1%", + decl->arguments->at(0)); } size = getUintFromExpression(decl->arguments->at(1)->expression, 1); unsigned outputHashWidth = getUintFromExpression(decl->arguments->at(2)->expression, 0); if (hashEngine != nullptr && outputHashWidth > hashEngine->getOutputWidth()) { - ::error(ErrorType::ERR_INVALID, "%1%: more bits requested than hash provides (%2%)", - decl->arguments->at(2)->expression, hashEngine->getOutputWidth()); + ::P4::error(ErrorType::ERR_INVALID, "%1%: more bits requested than hash provides (%2%)", + decl->arguments->at(2)->expression, hashEngine->getOutputWidth()); } if (outputHashWidth > 64) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: supported up to 64 bits", - decl->arguments->at(2)->expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: supported up to 64 bits", + decl->arguments->at(2)->expression); } if (outputHashWidth < 1) { - ::error(ErrorType::ERR_INVALID, - "%1%: invalid output width used for checksum " - "value truncation, must be at least 1 bit", - decl->arguments->at(2)->expression); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid output width used for checksum " + "value truncation, must be at least 1 bit", + decl->arguments->at(2)->expression); } outputHashMask = absl::StrFormat("0x%llx", (1ull << outputHashWidth) - 1); @@ -266,8 +266,9 @@ void EBPFActionSelectorPSA::emitInitializer(CodeBuilder *builder) { BUG_CHECK(action != nullptr, "%1%: not an action", ev); if (!action->getParameters()->empty()) { - ::error(ErrorType::ERR_UNINITIALIZED, "%1%: missing value for action parameters: %2%", - ev, action->getParameters()); + ::P4::error(ErrorType::ERR_UNINITIALIZED, + "%1%: missing value for action parameters: %2%", ev, + action->getParameters()); return; } @@ -579,10 +580,10 @@ void EBPFActionSelectorPSA::verifyTableSelectorKeySet(const EBPFTablePSA *instan } if (printError) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: selector type keys list differs from previous %2% " - "(tables use the same implementation %3%)", - instance->table->container, table->container, declaration); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: selector type keys list differs from previous %2% " + "(tables use the same implementation %3%)", + instance->table->container, table->container, declaration); } } @@ -591,18 +592,18 @@ void EBPFActionSelectorPSA::verifyTableEmptyGroupAction(const EBPFTablePSA *inst if (emptyGroupAction == nullptr && iega == nullptr) return; // nothing to do here if (emptyGroupAction == nullptr && iega != nullptr) { - ::error(ErrorType::ERR_UNEXPECTED, - "%1%: property not specified in previous table %2% " - "(tables use the same implementation %3%)", - iega, table->container, declaration); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: property not specified in previous table %2% " + "(tables use the same implementation %3%)", + iega, table->container, declaration); return; } if (emptyGroupAction != nullptr && iega == nullptr) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: missing property %2%, defined in previous table %3% " - "(tables use the same implementation %4%)", - instance->table->container, emptyGroupAction, table->container->toString(), - declaration); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: missing property %2%, defined in previous table %3% " + "(tables use the same implementation %4%)", + instance->table->container, emptyGroupAction, table->container->toString(), + declaration); return; } @@ -647,10 +648,10 @@ void EBPFActionSelectorPSA::verifyTableEmptyGroupAction(const EBPFTablePSA *inst } if (!same) { - ::error(ErrorType::ERR_EXPECTED, - "%1%: defined property value is different from %2%, defined in " - "previous table %3% (tables use the same implementation %4%)%5%", - rev, lev, table->container->toString(), declaration, additionalNote); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: defined property value is different from %2%, defined in " + "previous table %3% (tables use the same implementation %4%)%5%", + rev, lev, table->container->toString(), declaration, additionalNote); } } @@ -788,4 +789,4 @@ void EBPFActionSelectorPSA::emitCacheUpdate(CodeBuilder *builder, cstring key, c builder->blockEnd(true); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h index b546630ad6..b60dfe4605 100644 --- a/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h +++ b/backends/ebpf/psa/externs/ebpfPsaTableImplementation.h @@ -22,7 +22,7 @@ limitations under the License. #include "backends/ebpf/psa/ebpfPsaTable.h" #include "backends/ebpf/psa/externs/ebpfPsaHashAlgorithm.h" -namespace EBPF { +namespace P4::EBPF { /// Base class for ActionProfile and ActionSelector. class EBPFTableImplementationPSA : public EBPFTablePSA { @@ -109,6 +109,6 @@ class EBPFActionSelectorPSA : public EBPFTableImplementationPSA { DECLARE_TYPEINFO(EBPFActionSelectorPSA, EBPFTableImplementationPSA); }; -} // namespace EBPF +} // namespace P4::EBPF #endif // BACKENDS_EBPF_PSA_EXTERNS_EBPFPSATABLEIMPLEMENTATION_H_ diff --git a/backends/ebpf/psa/xdpHelpProgram.h b/backends/ebpf/psa/xdpHelpProgram.h index f8e44e9028..a1311fa8b0 100644 --- a/backends/ebpf/psa/xdpHelpProgram.h +++ b/backends/ebpf/psa/xdpHelpProgram.h @@ -19,7 +19,7 @@ limitations under the License. #include "backends/ebpf/ebpfProgram.h" -namespace EBPF { +namespace P4::EBPF { class XDPHelpProgram : public EBPFProgram { const char *XDPProgUsingMetaForXDP2TC = @@ -120,6 +120,6 @@ class XDPHelpProgram : public EBPFProgram { } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_PSA_XDPHELPPROGRAM_H_ */ diff --git a/backends/ebpf/target.cpp b/backends/ebpf/target.cpp index 78e78e1f90..f8eec4ad25 100644 --- a/backends/ebpf/target.cpp +++ b/backends/ebpf/target.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "ebpfType.h" -namespace EBPF { +namespace P4::EBPF { void Target::emitPreamble(Util::SourceCodeBuilder *builder) const { (void)builder; } @@ -75,14 +75,15 @@ void KernelSamplesTarget::emitTableDecl(Util::SourceCodeBuilder *builder, cstrin if (keyType != "u32" && (tableKind == TablePerCPUArray || tableKind == TableArray)) { // it's more safe to overwrite user-provided key type, // as array map must have u32 key type. - ::warning(ErrorType::WARN_INVALID, - "Invalid key type (%1%) for table kind %2%, replacing with u32", keyType, kind); + ::P4::warning(ErrorType::WARN_INVALID, + "Invalid key type (%1%) for table kind %2%, replacing with u32", keyType, + kind); keyType = "u32"_cs; } else if (tableKind == TableProgArray && (keyType != "u32" || valueType != "u32")) { - ::warning(ErrorType::WARN_INVALID, - "Invalid key type (%1%) or value type (%2%) for table kind %3%, " - "replacing with u32", - keyType, valueType, kind); + ::P4::warning(ErrorType::WARN_INVALID, + "Invalid key type (%1%) or value type (%2%) for table kind %3%, " + "replacing with u32", + keyType, valueType, kind); keyType = "u32"_cs; valueType = "u32"_cs; } @@ -281,4 +282,4 @@ void BccTarget::emitMain(Util::SourceCodeBuilder *builder, cstring functionName, builder->appendFormat("int %s(struct __sk_buff* %s)", functionName.c_str(), argName.c_str()); } -} // namespace EBPF +} // namespace P4::EBPF diff --git a/backends/ebpf/target.h b/backends/ebpf/target.h index d3c0573593..3bc414514c 100644 --- a/backends/ebpf/target.h +++ b/backends/ebpf/target.h @@ -27,7 +27,7 @@ limitations under the License. /// We are prepared to support code generation using multiple styles /// (e.g., using BCC or using CLANG). -namespace EBPF { +namespace P4::EBPF { using namespace P4::literals; @@ -73,8 +73,8 @@ class Target { (void)keyType; (void)valueType; (void)size; - ::error(ErrorType::ERR_UNSUPPORTED, "emitTableDeclSpinlock is not supported on %1% target", - name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "emitTableDeclSpinlock is not supported on %1% target", name); } /// map-in-map requires declaration of both inner and outer map, /// thus we define them together in a single method. @@ -93,8 +93,8 @@ class Target { (void)outerTableKind; (void)outerKeyType; (void)outerSize; - ::error(ErrorType::ERR_UNSUPPORTED, "emitMapInMapDecl is not supported on %1% target", - name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "emitMapInMapDecl is not supported on %1% target", + name); } virtual void emitMain(Util::SourceCodeBuilder *builder, cstring functionName, cstring argName) const = 0; @@ -316,6 +316,6 @@ class TestTarget : public EBPF::KernelSamplesTarget { cstring packetDescriptorType() const override { return "struct __sk_buff"_cs; } }; -} // namespace EBPF +} // namespace P4::EBPF #endif /* BACKENDS_EBPF_TARGET_H_ */ diff --git a/backends/graphs/controls.cpp b/backends/graphs/controls.cpp index ccc5f57a25..f49949316e 100644 --- a/backends/graphs/controls.cpp +++ b/backends/graphs/controls.cpp @@ -27,7 +27,7 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" -namespace graphs { +namespace P4::graphs { using Graph = ControlGraphs::Graph; @@ -203,8 +203,8 @@ bool ControlGraphs::preorder(const IR::MethodCallStatement *statement) { visit(am->object->to()); } else if (am->applyObject->is()) { if (am->object->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: control parameters are not supported by this target", am->object); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: control parameters are not supported by this target", am->object); return false; } BUG_CHECK(am->object->is(), @@ -328,4 +328,4 @@ bool ControlGraphs::preorder(const IR::P4Table *table) { return false; } -} // namespace graphs +} // namespace P4::graphs diff --git a/backends/graphs/controls.h b/backends/graphs/controls.h index 4fd0ac83cb..c16fc2f77d 100644 --- a/backends/graphs/controls.h +++ b/backends/graphs/controls.h @@ -19,7 +19,7 @@ limitations under the License. #include "graphs.h" -namespace graphs { +namespace P4::graphs { class ControlGraphs : public Graphs { public: @@ -66,6 +66,6 @@ class ControlGraphs : public Graphs { std::optional instanceName{}; }; -} // namespace graphs +} // namespace P4::graphs #endif /* BACKENDS_GRAPHS_CONTROLS_H_ */ diff --git a/backends/graphs/graph_visitor.cpp b/backends/graphs/graph_visitor.cpp index f36c691524..e032ca49e0 100644 --- a/backends/graphs/graph_visitor.cpp +++ b/backends/graphs/graph_visitor.cpp @@ -19,13 +19,13 @@ #include "graphs.h" #include "lib/nullstream.h" -namespace graphs { +namespace P4::graphs { void Graph_visitor::writeGraphToFile(const Graph &g, const std::string &name) { auto path = graphsDir / (name + ".dot"); auto out = openFile(path, false); if (out == nullptr) { - ::error(ErrorType::ERR_IO, "Failed to open file %1%", path); + ::P4::error(ErrorType::ERR_IO, "Failed to open file %1%", path); return; } // Custom label writers not supported with subgraphs, so we populate @@ -212,4 +212,4 @@ void Graph_visitor::process(std::vector &controlGraphsArray, } } -} // namespace graphs +} // namespace P4::graphs diff --git a/backends/graphs/graph_visitor.h b/backends/graphs/graph_visitor.h index e3385c9693..e955cf263d 100644 --- a/backends/graphs/graph_visitor.h +++ b/backends/graphs/graph_visitor.h @@ -25,7 +25,7 @@ #ifndef BACKENDS_GRAPHS_GRAPH_VISITOR_H_ #define BACKENDS_GRAPHS_GRAPH_VISITOR_H_ -namespace graphs { +namespace P4::graphs { /// "process" function of class is dependent on previous aplication of visitor /// classes Controls and Parsers onto IR, and can only be run after them. @@ -123,6 +123,6 @@ class Graph_visitor : public Graphs { const std::filesystem::path filename; }; -} // namespace graphs +} // namespace P4::graphs #endif /* BACKENDS_GRAPHS_GRAPH_VISITOR_H_ */ diff --git a/backends/graphs/graphs.cpp b/backends/graphs/graphs.cpp index 835bcc6c1a..a8c7e45c0e 100644 --- a/backends/graphs/graphs.cpp +++ b/backends/graphs/graphs.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" -namespace graphs { +namespace P4::graphs { Graphs::vertex_t Graphs::add_vertex(const cstring &name, VertexType type) { auto v = boost::add_vertex(*g); @@ -93,4 +93,4 @@ Graphs::vertex_t Graphs::add_and_connect_vertex(const cstring &name, VertexType return v; } -} // namespace graphs +} // namespace P4::graphs diff --git a/backends/graphs/graphs.h b/backends/graphs/graphs.h index db5446492e..8ac8d7e957 100644 --- a/backends/graphs/graphs.h +++ b/backends/graphs/graphs.h @@ -46,7 +46,7 @@ class TypeMap; } // namespace P4 -namespace graphs { +namespace P4::graphs { using namespace P4::literals; @@ -224,6 +224,6 @@ class Graphs : public Inspector { void limitStringSize(std::stringstream &sstream, std::stringstream &helper_sstream); }; -} // namespace graphs +} // namespace P4::graphs #endif /* BACKENDS_GRAPHS_GRAPHS_H_ */ diff --git a/backends/graphs/p4c-graphs.cpp b/backends/graphs/p4c-graphs.cpp index a695e4d418..d131ec0fa6 100644 --- a/backends/graphs/p4c-graphs.cpp +++ b/backends/graphs/p4c-graphs.cpp @@ -33,7 +33,7 @@ limitations under the License. #include "lib/nullstream.h" #include "parsers.h" -namespace graphs { +namespace P4::graphs { class MidEnd : public PassManager { public: @@ -120,7 +120,9 @@ class Options : public CompilerOptions { using GraphsContext = P4CContextWithOptions; -} // namespace graphs +} // namespace P4::graphs + +using namespace P4; int main(int argc, char *const argv[]) { setup_gc_logging(); @@ -134,7 +136,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; auto hook = options.getDebugHook(); @@ -143,21 +145,21 @@ int main(int argc, char *const argv[]) { if (options.loadIRFromJson) { std::filebuf fb; if (fb.open(options.file, std::ios::in) == nullptr) { - ::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_IO, "%s: No such file or directory.", options.file); return 1; } std::istream inJson(&fb); JSONLoader jsonFileLoader(inJson); if (jsonFileLoader.json == nullptr) { - ::error(ErrorType::ERR_IO, "Not valid input file"); + ::P4::error(ErrorType::ERR_IO, "Not valid input file"); return 1; } program = new IR::P4Program(jsonFileLoader); fb.close(); } else { program = P4::parseP4File(options); - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; try { P4::P4COptionPragmaParser optionsPragmaParser; @@ -170,7 +172,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (program == nullptr || ::errorCount() > 0) return 1; + if (program == nullptr || ::P4::errorCount() > 0) return 1; } graphs::MidEnd midEnd(options); @@ -184,7 +186,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; LOG2("Generating graphs under " << options.graphsDir); LOG2("Generating control graphs"); @@ -199,5 +201,5 @@ int main(int argc, char *const argv[]) { gvs.process(cgen.controlGraphsArray, pgg.parserGraphsArray); - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/graphs/parsers.cpp b/backends/graphs/parsers.cpp index 4e8d76ddc4..7e1c4ae392 100644 --- a/backends/graphs/parsers.cpp +++ b/backends/graphs/parsers.cpp @@ -21,7 +21,7 @@ #include "frontends/p4/toP4/toP4.h" #include "lib/nullstream.h" -namespace graphs { +namespace P4::graphs { using Graph = ParserGraphs::Graph; @@ -119,4 +119,4 @@ void ParserGraphs::postorder(const IR::SelectExpression *expression) { new TransitionEdge(state, reject->to(), "fallthrough"_cs)); } -} // namespace graphs +} // namespace P4::graphs diff --git a/backends/graphs/parsers.h b/backends/graphs/parsers.h index fa112f07cf..b9e6db2a3d 100644 --- a/backends/graphs/parsers.h +++ b/backends/graphs/parsers.h @@ -25,7 +25,7 @@ #include "lib/nullstream.h" #include "lib/safe_vector.h" -namespace graphs { +namespace P4::graphs { class ParserGraphs : public Graphs { protected: @@ -58,6 +58,6 @@ class ParserGraphs : public Graphs { std::optional instanceName{}; }; -} // namespace graphs +} // namespace P4::graphs #endif /* BACKENDS_GRAPHS_PARSERS_H_ */ diff --git a/backends/p4fmt/main.cpp b/backends/p4fmt/main.cpp index 5b775ee4e4..d86ef3c977 100644 --- a/backends/p4fmt/main.cpp +++ b/backends/p4fmt/main.cpp @@ -6,6 +6,8 @@ #include "options.h" #include "p4fmt.h" +using namespace P4; + int main(int argc, char *const argv[]) { AutoCompileContext autoP4FmtContext(new P4Fmt::P4FmtContext); auto &options = P4Fmt::P4FmtContext::get().options(); @@ -14,7 +16,7 @@ int main(int argc, char *const argv[]) { } options.setInputFile(); - std::stringstream formattedOutput = getFormattedOutput(options.file); + std::stringstream formattedOutput = P4Fmt::getFormattedOutput(options.file); if (formattedOutput.str().empty()) { return EXIT_FAILURE; }; @@ -26,8 +28,8 @@ int main(int argc, char *const argv[]) { } else { out = openFile(options.outputFile(), false); if ((out == nullptr) || !(*out)) { - ::error(ErrorType::ERR_NOT_FOUND, "%2%: No such file or directory.", - options.outputFile().string()); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%2%: No such file or directory.", + options.outputFile().string()); options.usage(); return EXIT_FAILURE; } @@ -36,7 +38,7 @@ int main(int argc, char *const argv[]) { (*out) << formattedOutput.str(); out->flush(); if (!(*out)) { - ::error(ErrorType::ERR_IO, "Failed to write to output file."); + ::P4::error(ErrorType::ERR_IO, "Failed to write to output file."); return EXIT_FAILURE; } diff --git a/backends/p4fmt/options.cpp b/backends/p4fmt/options.cpp index 0df95affe2..14cce860b4 100644 --- a/backends/p4fmt/options.cpp +++ b/backends/p4fmt/options.cpp @@ -1,6 +1,6 @@ #include "options.h" -namespace P4Fmt { +namespace P4::P4Fmt { P4fmtOptions::P4fmtOptions() { registerOption( @@ -14,4 +14,4 @@ P4fmtOptions::P4fmtOptions() { const std::filesystem::path &P4fmtOptions::outputFile() const { return outFile; } -} // namespace P4Fmt +} // namespace P4::P4Fmt diff --git a/backends/p4fmt/options.h b/backends/p4fmt/options.h index 3fd994fed3..3c97b2c787 100644 --- a/backends/p4fmt/options.h +++ b/backends/p4fmt/options.h @@ -4,7 +4,7 @@ #include "frontends/common/options.h" #include "frontends/common/parser_options.h" -namespace P4Fmt { +namespace P4::P4Fmt { class P4fmtOptions : public CompilerOptions { public: @@ -24,6 +24,6 @@ class P4fmtOptions : public CompilerOptions { using P4FmtContext = P4CContextWithOptions; -} // namespace P4Fmt +} // namespace P4::P4Fmt #endif /* BACKENDS_P4FMT_OPTIONS_H_ */ diff --git a/backends/p4fmt/p4fmt.cpp b/backends/p4fmt/p4fmt.cpp index 1fba9d078f..6296d37d80 100644 --- a/backends/p4fmt/p4fmt.cpp +++ b/backends/p4fmt/p4fmt.cpp @@ -8,6 +8,8 @@ #include "lib/error.h" #include "options.h" +namespace P4::P4Fmt { + std::stringstream getFormattedOutput(std::filesystem::path inputFile) { AutoCompileContext autoP4FmtContext(new P4Fmt::P4FmtContext); auto &options = P4Fmt::P4FmtContext::get().options(); @@ -17,8 +19,8 @@ std::stringstream getFormattedOutput(std::filesystem::path inputFile) { std::stringstream formattedOutput; const IR::P4Program *program = P4::parseP4File(options); - if (program == nullptr && ::errorCount() != 0) { - ::error("Failed to parse P4 file."); + if (program == nullptr && ::P4::errorCount() != 0) { + ::P4::error("Failed to parse P4 file."); return formattedOutput; } @@ -26,10 +28,12 @@ std::stringstream getFormattedOutput(std::filesystem::path inputFile) { // Print the program before running front end passes. program->apply(top4); - if (::errorCount() > 0) { - ::error("Failed to format p4 program."); + if (::P4::errorCount() > 0) { + ::P4::error("Failed to format p4 program."); return formattedOutput; } return formattedOutput; } + +} // namespace P4::P4Fmt diff --git a/backends/p4fmt/p4fmt.h b/backends/p4fmt/p4fmt.h index 04e63c07ea..b5d0d2a611 100644 --- a/backends/p4fmt/p4fmt.h +++ b/backends/p4fmt/p4fmt.h @@ -4,7 +4,11 @@ #include #include +namespace P4::P4Fmt { + /// Formats a P4 program from the input file, returns formatted output std::stringstream getFormattedOutput(std::filesystem::path inputFile); +} // namespace P4::P4Fmt + #endif /* BACKENDS_P4FMT_P4FMT_H_ */ diff --git a/backends/p4fmt/refcheck.cpp b/backends/p4fmt/refcheck.cpp index ef6afec810..2aabcc335a 100644 --- a/backends/p4fmt/refcheck.cpp +++ b/backends/p4fmt/refcheck.cpp @@ -10,7 +10,9 @@ #include "options.h" #include "p4fmt.h" -namespace P4Fmt { +using namespace P4; + +namespace P4::P4Fmt { namespace { class ReferenceCheckerOptions : protected P4fmtOptions { @@ -30,7 +32,8 @@ class ReferenceCheckerOptions : protected P4fmtOptions { [this](const char *arg) { inputFile = arg; if (!std::filesystem::exists(inputFile.value())) { - ::error("The input P4 program '%s' does not exist.", inputFile.value().c_str()); + ::P4::error("The input P4 program '%s' does not exist.", + inputFile.value().c_str()); return false; } return true; @@ -58,17 +61,17 @@ class ReferenceCheckerOptions : protected P4fmtOptions { if (unprocessedOptions != nullptr && !unprocessedOptions->empty()) { for (const auto &option : *unprocessedOptions) { - ::error("Unprocessed input: %s", option); + ::P4::error("Unprocessed input: %s", option); } return EXIT_FAILURE; } if (!inputFile.has_value()) { - ::error("No input file specified."); + ::P4::error("No input file specified."); return EXIT_FAILURE; } if (!referenceFile.has_value()) { - ::error( + ::P4::error( "Reference file has not been specified. Use " "--reference-file."); return EXIT_FAILURE; @@ -100,7 +103,7 @@ int compareAgainstReference(const std::stringstream &formattedOutput, P4Tools::printInfo("Running diff command: \"%s\"", command.str()); FILE *pipe = popen(command.str().c_str(), "r"); if (pipe == nullptr) { - ::error("Unable to create pipe to diff command."); + ::P4::error("Unable to create pipe to diff command."); return EXIT_FAILURE; } // Read and print the output of the diff command. @@ -110,7 +113,7 @@ int compareAgainstReference(const std::stringstream &formattedOutput, result << buffer; } if (pclose(pipe) != 0) { - ::error("Diff command failed.\n%1%", result.str()); + ::P4::error("Diff command failed.\n%1%", result.str()); return EXIT_FAILURE; } return EXIT_SUCCESS; @@ -125,7 +128,7 @@ std::optional getFilePath(const ReferenceCheckerOptions & // If a reference file is explicitly provided, just overwrite this file. referencePath = referenceFileOpt.value(); } else { - ::error("Reference file has not been specified."); + ::P4::error("Reference file has not been specified."); return std::nullopt; } return referencePath.replace_extension(suffix); @@ -139,7 +142,7 @@ int run(const ReferenceCheckerOptions &options) { std::stringstream formattedOutput = getFormattedOutput(options.getInputFile()); if (formattedOutput.str().empty()) { - ::error("Formatting Failed"); + ::P4::error("Formatting Failed"); return EXIT_FAILURE; } @@ -159,10 +162,10 @@ int run(const ReferenceCheckerOptions &options) { auto referenceFile = std::filesystem::absolute(referenceFileOpt.value()); return compareAgainstReference(formattedOutput, referenceFile); } - ::error("Reference file has not been specified."); + ::P4::error("Reference file has not been specified."); return EXIT_FAILURE; } -} // namespace P4Fmt +} // namespace P4::P4Fmt class RefCheckContext : public BaseCompileContext {}; @@ -170,7 +173,7 @@ int main(int argc, char *argv[]) { AutoCompileContext autoP4RefCheckContext(new RefCheckContext); P4Fmt::ReferenceCheckerOptions options; - if (options.processOptions(argc, argv) == EXIT_FAILURE || ::errorCount() != 0) { + if (options.processOptions(argc, argv) == EXIT_FAILURE || ::P4::errorCount() != 0) { return EXIT_FAILURE; } @@ -178,5 +181,5 @@ int main(int argc, char *argv[]) { if (result == EXIT_FAILURE) { return EXIT_FAILURE; } - return ::errorCount() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + return ::P4::errorCount() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/backends/p4test/midend.cpp b/backends/p4test/midend.cpp index 3281fd5d6b..3cd139a1b1 100644 --- a/backends/p4test/midend.cpp +++ b/backends/p4test/midend.cpp @@ -62,7 +62,7 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/unrollLoops.h" -namespace P4Test { +namespace P4::P4Test { class SkipControls : public P4::ActionSynthesisPolicy { const std::set *skip; @@ -179,4 +179,4 @@ MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) { addDebugHooks(hooks, true); } -} // namespace P4Test +} // namespace P4::P4Test diff --git a/backends/p4test/midend.h b/backends/p4test/midend.h index 4c7e3c7376..3b10075090 100644 --- a/backends/p4test/midend.h +++ b/backends/p4test/midend.h @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/p4/evaluator/evaluator.h" #include "ir/ir.h" -namespace P4Test { +namespace P4::P4Test { class MidEnd : public PassManager { std::vector hooks; @@ -40,6 +40,6 @@ class MidEnd : public PassManager { } }; -} // namespace P4Test +} // namespace P4::P4Test #endif /* BACKENDS_P4TEST_MIDEND_H_ */ diff --git a/backends/p4test/p4test.cpp b/backends/p4test/p4test.cpp index d0ec0c38c1..82d85a13a1 100644 --- a/backends/p4test/p4test.cpp +++ b/backends/p4test/p4test.cpp @@ -35,6 +35,8 @@ limitations under the License. #include "lib/nullstream.h" #include "midend.h" +using namespace P4; + class P4TestOptions : public CompilerOptions { public: bool parseOnly = false; @@ -76,7 +78,7 @@ class P4TestOptions : public CompilerOptions { registerOption( "--turn-off-logn", nullptr, [](const char *) { - ::Log::Detail::enableLoggingGlobally = false; + ::P4::Log::Detail::enableLoggingGlobally = false; return true; }, "Turn off LOGN() statements in the compiler.\n" @@ -113,7 +115,7 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { if (options.loadIRFromJson == false) options.setInputFile(); } - if (::errorCount() > 0) return 1; + if (::P4::errorCount() > 0) return 1; const IR::P4Program *program = nullptr; auto hook = options.getDebugHook(); if (options.loadIRFromJson) { @@ -132,7 +134,7 @@ int main(int argc, char *const argv[]) { program = P4::parseP4File(options); info.emitInfo("PARSER"); - if (program != nullptr && ::errorCount() == 0) { + if (program != nullptr && ::P4::errorCount() == 0) { P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); info.emitInfo("PASS P4COptionPragmaParser"); @@ -154,7 +156,7 @@ int main(int argc, char *const argv[]) { } log_dump(program, "Initial program"); - if (program != nullptr && ::errorCount() == 0) { + if (program != nullptr && ::P4::errorCount() == 0) { P4::serializeP4RuntimeIfRequired(program, options); if (!options.parseOnly && !options.validateOnly) { @@ -201,12 +203,12 @@ int main(int argc, char *const argv[]) { t2 << ss2.str() << std::flush; auto rv = system("json_diff t1.json t2.json"); if (rv != 0) - ::warning(ErrorType::WARN_FAILED, "json_diff failed with code %1%", rv); + ::P4::warning(ErrorType::WARN_FAILED, "json_diff failed with code %1%", rv); } } } } if (Log::verbose()) std::cerr << "Done." << std::endl; - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/p4tools/common/compiler/compiler_result.cpp b/backends/p4tools/common/compiler/compiler_result.cpp index 52e6d33f1f..caf4cc86f1 100644 --- a/backends/p4tools/common/compiler/compiler_result.cpp +++ b/backends/p4tools/common/compiler/compiler_result.cpp @@ -1,9 +1,9 @@ #include "backends/p4tools/common/compiler/compiler_result.h" -namespace P4Tools { +namespace P4::P4Tools { const IR::P4Program &CompilerResult::getProgram() const { return program; } CompilerResult::CompilerResult(const IR::P4Program &program) : program(program) {} -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/compiler_result.h b/backends/p4tools/common/compiler/compiler_result.h index c9b3c6ee3c..ec1f6b1835 100644 --- a/backends/p4tools/common/compiler/compiler_result.h +++ b/backends/p4tools/common/compiler/compiler_result.h @@ -7,7 +7,7 @@ #include "ir/ir.h" #include "lib/castable.h" -namespace P4Tools { +namespace P4::P4Tools { /// An extensible result object which is returned by the CompilerTarget. /// In its simplest form, this holds the transformed P4 program after the front- and midend passes. @@ -30,6 +30,6 @@ class CompilerResult : public ICastable { /// This is a convenience definition for the return value. using CompilerResultOrError = std::optional>; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_COMPILER_RESULT_H_ */ diff --git a/backends/p4tools/common/compiler/compiler_target.cpp b/backends/p4tools/common/compiler/compiler_target.cpp index a4ba0a3814..bfdc368e65 100644 --- a/backends/p4tools/common/compiler/compiler_target.cpp +++ b/backends/p4tools/common/compiler/compiler_target.cpp @@ -14,7 +14,7 @@ #include "lib/compile_context.h" #include "lib/error.h" -namespace P4Tools { +namespace P4::P4Tools { ICompileContext *CompilerTarget::makeContext(std::string_view toolName) { return get(toolName).makeContextImpl(); @@ -73,12 +73,12 @@ ICompileContext *CompilerTarget::makeContextImpl() const { std::vector *CompilerTarget::initCompilerImpl(int argc, char **argv) const { auto *result = CompileContext::get().options().process(argc, argv); - return ::errorCount() > 0 ? nullptr : result; + return ::P4::errorCount() > 0 ? nullptr : result; } const IR::P4Program *CompilerTarget::runParser(const ParserOptions &options) { const auto *program = P4::parseP4File(options); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return nullptr; } return program; @@ -92,7 +92,7 @@ const IR::P4Program *CompilerTarget::runFrontend(const CompilerOptions &options, auto frontEnd = mkFrontEnd(); frontEnd.addDebugHook(options.getDebugHook()); program = frontEnd.run(options, program); - if ((program == nullptr) || ::errorCount() > 0) { + if ((program == nullptr) || ::P4::errorCount() > 0) { return nullptr; } return program; @@ -122,4 +122,4 @@ const CompilerTarget &CompilerTarget::get(std::string_view toolName) { return Target::get(toolName); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/compiler_target.h b/backends/p4tools/common/compiler/compiler_target.h index 790f177f48..4c09c4f3c6 100644 --- a/backends/p4tools/common/compiler/compiler_target.h +++ b/backends/p4tools/common/compiler/compiler_target.h @@ -14,7 +14,7 @@ #include "ir/ir.h" #include "lib/compile_context.h" -namespace P4Tools { +namespace P4::P4Tools { /// Encapsulates the details of invoking the P4 compiler for a target device and architecture. class CompilerTarget : public Target { @@ -92,6 +92,6 @@ class CompilerTarget : public Target { static const CompilerTarget &get(std::string_view toolName); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_COMPILER_TARGET_H_ */ diff --git a/backends/p4tools/common/compiler/configuration.h b/backends/p4tools/common/compiler/configuration.h index 673f3b4560..cce9ac7ed4 100644 --- a/backends/p4tools/common/compiler/configuration.h +++ b/backends/p4tools/common/compiler/configuration.h @@ -5,7 +5,7 @@ #include "ir/configuration.h" -namespace P4Tools { +namespace P4::P4Tools { /// A P4CConfiguration implementation that increases the maximum width for a bit field or /// integer. @@ -24,6 +24,6 @@ class CompilerConfiguration : public DefaultP4CConfiguration { CompilerConfiguration() = default; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONFIGURATION_H_ */ diff --git a/backends/p4tools/common/compiler/context.h b/backends/p4tools/common/compiler/context.h index 4b99cedfd9..13e69f3fc2 100644 --- a/backends/p4tools/common/compiler/context.h +++ b/backends/p4tools/common/compiler/context.h @@ -4,7 +4,7 @@ #include "backends/p4tools/common/compiler/configuration.h" #include "frontends/common/options.h" -namespace P4Tools { +namespace P4::P4Tools { /// A compilation context for P4Tools that provides a custom compiler configuration. template @@ -31,6 +31,6 @@ class CompileContext : public virtual P4CContext { OptionsType optionsInstance; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONTEXT_H_ */ diff --git a/backends/p4tools/common/compiler/convert_hs_index.cpp b/backends/p4tools/common/compiler/convert_hs_index.cpp index 94fa184f88..b093b4c29e 100644 --- a/backends/p4tools/common/compiler/convert_hs_index.cpp +++ b/backends/p4tools/common/compiler/convert_hs_index.cpp @@ -6,7 +6,7 @@ #include "ir/irutils.h" #include "lib/cstring.h" -namespace P4Tools { +namespace P4::P4Tools { const IR::Node *HSIndexToMember::postorder(IR::ArrayIndex *curArrayIndex) { if (const auto *arrayConst = curArrayIndex->right->to()) { @@ -22,4 +22,4 @@ const IR::ArrayIndex *HSIndexToMember::produceStackIndex(const IR::Type *type, IR::Constant::get(IR::Type_Bits::get(32), arrayIndex)); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/convert_hs_index.h b/backends/p4tools/common/compiler/convert_hs_index.h index 33a81afdae..a88520877e 100644 --- a/backends/p4tools/common/compiler/convert_hs_index.h +++ b/backends/p4tools/common/compiler/convert_hs_index.h @@ -7,7 +7,7 @@ #include "ir/node.h" #include "ir/visitor.h" -namespace P4Tools { +namespace P4::P4Tools { /// The main class for finding non-concrete header stack indices. class HSIndexToMember : public Transform { @@ -21,6 +21,6 @@ class HSIndexToMember : public Transform { size_t arrayIndex); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_HS_INDEX_H_ */ diff --git a/backends/p4tools/common/compiler/convert_struct_expr.cpp b/backends/p4tools/common/compiler/convert_struct_expr.cpp index d58ba40bd7..9a286a69be 100644 --- a/backends/p4tools/common/compiler/convert_struct_expr.cpp +++ b/backends/p4tools/common/compiler/convert_struct_expr.cpp @@ -2,7 +2,7 @@ #include "ir/irutils.h" -namespace P4Tools { +namespace P4::P4Tools { const IR::Node *ConvertStructExpr::postorder(IR::StructExpression *structExpr) { const auto *structType = structExpr->type; @@ -26,4 +26,4 @@ ConvertStructExpr::ConvertStructExpr(const P4::TypeMap *typeMap) : typeMap(typeM setName("ConvertStructExpr"); visitDagOnce = false; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/convert_struct_expr.h b/backends/p4tools/common/compiler/convert_struct_expr.h index 58203abcdd..1138792933 100644 --- a/backends/p4tools/common/compiler/convert_struct_expr.h +++ b/backends/p4tools/common/compiler/convert_struct_expr.h @@ -6,7 +6,7 @@ #include "ir/node.h" #include "ir/visitor.h" -namespace P4Tools { +namespace P4::P4Tools { /// This pass does two things. First, it converts any type member of struct expression that is a /// Type_Name into a Tupe_StructLike. Second, if the type is a Type_Header, it converts the @@ -21,6 +21,6 @@ class ConvertStructExpr : public Transform { const IR::Node *postorder(IR::StructExpression *expr) override; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_STRUCT_EXPR_H_ */ diff --git a/backends/p4tools/common/compiler/convert_varbits.cpp b/backends/p4tools/common/compiler/convert_varbits.cpp index f20eaca73e..0a73dd2d71 100644 --- a/backends/p4tools/common/compiler/convert_varbits.cpp +++ b/backends/p4tools/common/compiler/convert_varbits.cpp @@ -2,7 +2,7 @@ #include "lib/log.h" -namespace P4Tools { +namespace P4::P4Tools { const IR::Node *ConvertVarbits::postorder(IR::Type_Varbits *varbit) { // At this point, we do not know the future size of the varbit. We assume 0 for now. @@ -20,4 +20,4 @@ ConvertVarbits::ConvertVarbits() { setName("ConvertVarbits"); visitDagOnce = false; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/convert_varbits.h b/backends/p4tools/common/compiler/convert_varbits.h index 42fe678246..8623dfa395 100644 --- a/backends/p4tools/common/compiler/convert_varbits.h +++ b/backends/p4tools/common/compiler/convert_varbits.h @@ -8,7 +8,7 @@ #include "ir/visitor.h" #include "lib/null.h" -namespace P4Tools { +namespace P4::P4Tools { /// Converts all existing Type_Varbit types in the program into a custom Extracted_Varbit type. /// Extracted_Varbit also contains information about the width that was assigned to the type by @@ -22,6 +22,6 @@ class ConvertVarbits : public Transform { const IR::Node *postorder(IR::Expression *expr) override; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_CONVERT_VARBITS_H_ */ diff --git a/backends/p4tools/common/compiler/midend.cpp b/backends/p4tools/common/compiler/midend.cpp index 1b0fb7ca0f..5b42a3a6f3 100644 --- a/backends/p4tools/common/compiler/midend.cpp +++ b/backends/p4tools/common/compiler/midend.cpp @@ -38,7 +38,7 @@ #include "midend/simplifySelectCases.h" #include "midend/simplifySelectList.h" -namespace P4Tools { +namespace P4::P4Tools { MidEnd::MidEnd(const CompilerOptions &options) { setName("MidEnd"); @@ -169,4 +169,4 @@ void MidEnd::addDefaultPasses() { }); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/midend.h b/backends/p4tools/common/compiler/midend.h index 213f5304d1..95b3683a2d 100644 --- a/backends/p4tools/common/compiler/midend.h +++ b/backends/p4tools/common/compiler/midend.h @@ -10,7 +10,7 @@ #include "midend/convertEnums.h" #include "midend/convertErrors.h" -namespace P4Tools { +namespace P4::P4Tools { /// Implements a generic mid end for all targets. If needed, targets can customize this to /// implement things like targets-specific conversion of P4 enums to bit. @@ -67,6 +67,6 @@ class MidEnd : public PassManager { void addDefaultPasses(); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_COMPILER_MIDEND_H_ */ diff --git a/backends/p4tools/common/compiler/reachability.cpp b/backends/p4tools/common/compiler/reachability.cpp index 2a5f3affef..f7bfd58130 100644 --- a/backends/p4tools/common/compiler/reachability.cpp +++ b/backends/p4tools/common/compiler/reachability.cpp @@ -15,7 +15,7 @@ #include "lib/exceptions.h" #include "lib/log.h" -namespace P4Tools { +namespace P4::P4Tools { using namespace P4::literals; @@ -610,4 +610,4 @@ const IR::Expression *ReachabilityEngine::stringToNode(std::string /*name*/) { P4C_UNIMPLEMENTED("Converting a string into an IR::Expression"); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/compiler/reachability.h b/backends/p4tools/common/compiler/reachability.h index 9758fa2020..bb29c6039b 100644 --- a/backends/p4tools/common/compiler/reachability.h +++ b/backends/p4tools/common/compiler/reachability.h @@ -17,7 +17,7 @@ #include "lib/cstring.h" #include "lib/null.h" -namespace P4Tools { +namespace P4::P4Tools { using DCGVertexType = const IR::Node *; using DCGVertexTypeSet = std::unordered_set; @@ -200,6 +200,6 @@ class ReachabilityEngine { void addEdge(DCGVertexType vertex, IR::ID vertexName = IR::ID()); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* COMMON_COMPILER_REACHABILITY_H_ */ diff --git a/backends/p4tools/common/control_plane/symbolic_variables.cpp b/backends/p4tools/common/control_plane/symbolic_variables.cpp index 0e8e2fe59a..1dae015117 100644 --- a/backends/p4tools/common/control_plane/symbolic_variables.cpp +++ b/backends/p4tools/common/control_plane/symbolic_variables.cpp @@ -3,7 +3,7 @@ #include "backends/p4tools/common/lib/variables.h" #include "ir/irutils.h" -namespace P4Tools { +namespace P4::P4Tools { namespace ControlPlaneState { @@ -62,4 +62,4 @@ std::pair getTableRa } // namespace Bmv2ControlPlaneState -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/control_plane/symbolic_variables.h b/backends/p4tools/common/control_plane/symbolic_variables.h index 3275cbab7e..9a367defb5 100644 --- a/backends/p4tools/common/control_plane/symbolic_variables.h +++ b/backends/p4tools/common/control_plane/symbolic_variables.h @@ -4,7 +4,7 @@ #include "ir/ir.h" #include "ir/irutils.h" -namespace P4Tools { +namespace P4::P4Tools { /// Defines accessors and utility functions for state that is managed by the control plane. /// This class can be extended by targets to customize initialization behavior and add @@ -62,6 +62,6 @@ std::pair getTableRa } // namespace Bmv2ControlPlaneState -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_CONTROL_PLANE_SYMBOLIC_VARIABLES_H_ */ diff --git a/backends/p4tools/common/core/abstract_execution_state.cpp b/backends/p4tools/common/core/abstract_execution_state.cpp index b33e4f1e66..fac023cb44 100644 --- a/backends/p4tools/common/core/abstract_execution_state.cpp +++ b/backends/p4tools/common/core/abstract_execution_state.cpp @@ -5,7 +5,7 @@ #include "backends/p4tools/common/lib/variables.h" #include "ir/irutils.h" -namespace P4Tools { +namespace P4::P4Tools { /* ========================================================================================= * Constructors @@ -395,4 +395,4 @@ const IR::P4Table *AbstractExecutionState::findTable(const IR::Member *member) c return nullptr; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/core/abstract_execution_state.h b/backends/p4tools/common/core/abstract_execution_state.h index d489915fd1..dd9008c1ec 100644 --- a/backends/p4tools/common/core/abstract_execution_state.h +++ b/backends/p4tools/common/core/abstract_execution_state.h @@ -6,7 +6,7 @@ #include "backends/p4tools/common/lib/symbolic_env.h" #include "ir/ir.h" -namespace P4Tools { +namespace P4::P4Tools { /// Represents state of execution after having reached a program point. class AbstractExecutionState { @@ -150,6 +150,6 @@ class AbstractExecutionState { [[nodiscard]] const IR::P4Action *getP4Action(const IR::MethodCallExpression *actionExpr) const; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_CORE_ABSTRACT_EXECUTION_STATE_H_ */ diff --git a/backends/p4tools/common/core/target.cpp b/backends/p4tools/common/core/target.cpp index e69ddf3601..7b5bd977ca 100644 --- a/backends/p4tools/common/core/target.cpp +++ b/backends/p4tools/common/core/target.cpp @@ -11,7 +11,7 @@ #include "backends/p4tools/common/lib/variables.h" #include "ir/irutils.h" -namespace P4Tools { +namespace P4::P4Tools { Target::Spec::Spec(std::string deviceName, std::string archName) : deviceName(std::move(deviceName)), archName(std::move(archName)) { @@ -93,4 +93,4 @@ Target::Target(std::string_view toolName, const std::string &deviceName, } } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/core/target.h b/backends/p4tools/common/core/target.h index 6bf058cc26..0dd7e505e1 100644 --- a/backends/p4tools/common/core/target.h +++ b/backends/p4tools/common/core/target.h @@ -8,7 +8,7 @@ #include "ir/ir.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { /// Encapsulates the details of a target device and architecture for a single tool. Implementations /// are singletons and must provide a default constructor. Instances are automatically registered @@ -108,6 +108,6 @@ class Target { static std::map> defaultDeviceByArch; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_CORE_TARGET_H_ */ diff --git a/backends/p4tools/common/core/z3_solver.cpp b/backends/p4tools/common/core/z3_solver.cpp index 13bac34812..6e5bb4484a 100644 --- a/backends/p4tools/common/core/z3_solver.cpp +++ b/backends/p4tools/common/core/z3_solver.cpp @@ -26,7 +26,7 @@ #include "lib/log.h" #include "lib/timer.h" -namespace P4Tools { +namespace P4::P4Tools { /// Converts a Z3 expression to a string. const char *toString(const z3::expr &e) { return Z3_ast_to_string(e.ctx(), e); } @@ -617,4 +617,4 @@ z3::expr Z3Translator::translate(const IR::Expression *expression) { return result; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/core/z3_solver.h b/backends/p4tools/common/core/z3_solver.h index 5f73a2493d..90a8d86352 100644 --- a/backends/p4tools/common/core/z3_solver.h +++ b/backends/p4tools/common/core/z3_solver.h @@ -17,7 +17,7 @@ #include "lib/rtti.h" #include "lib/safe_vector.h" -namespace P4Tools { +namespace P4::P4Tools { /// A stack of maps, which map Z3-internal expression IDs of declared Z3 variables to their /// corresponding P4 state variable. The maps are pushed and pop according to the solver push() and @@ -244,6 +244,6 @@ class Z3Translator : public virtual Inspector { std::reference_wrapper solver; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_CORE_Z3_SOLVER_H_ */ diff --git a/backends/p4tools/common/lib/arch_spec.cpp b/backends/p4tools/common/lib/arch_spec.cpp index 8c65899ef1..9f4920bf38 100644 --- a/backends/p4tools/common/lib/arch_spec.cpp +++ b/backends/p4tools/common/lib/arch_spec.cpp @@ -4,7 +4,7 @@ #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { ArchSpec::ArchSpec(cstring packageName, const std::vector &archVectorInput) : packageName(packageName) { @@ -50,4 +50,4 @@ const ArchSpec::ArchMember *ArchSpec::getArchMember(size_t blockIndex) const { size_t ArchSpec::getArchVectorSize() const { return archVector.size(); } cstring ArchSpec::getPackageName() const { return packageName; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/arch_spec.h b/backends/p4tools/common/lib/arch_spec.h index d76a6e9189..640a89c340 100644 --- a/backends/p4tools/common/lib/arch_spec.h +++ b/backends/p4tools/common/lib/arch_spec.h @@ -7,7 +7,7 @@ #include "lib/cstring.h" -namespace P4Tools { +namespace P4::P4Tools { /// Specifies a canonical representation of the target pipeline as documented in P4 code. class ArchSpec { @@ -56,6 +56,6 @@ class ArchSpec { [[nodiscard]] cstring getPackageName() const; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_ARCH_SPEC_H_ */ diff --git a/backends/p4tools/common/lib/constants.h b/backends/p4tools/common/lib/constants.h index 3319b25b97..599c44d025 100644 --- a/backends/p4tools/common/lib/constants.h +++ b/backends/p4tools/common/lib/constants.h @@ -1,7 +1,7 @@ #ifndef BACKENDS_P4TOOLS_COMMON_LIB_CONSTANTS_H_ #define BACKENDS_P4TOOLS_COMMON_LIB_CONSTANTS_H_ -namespace P4Tools { +namespace P4::P4Tools { class P4Constants { public: @@ -29,6 +29,6 @@ class P4Constants { static constexpr const char *MATCH_KIND_LPM = "lpm"; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_CONSTANTS_H_ */ diff --git a/backends/p4tools/common/lib/format_int.cpp b/backends/p4tools/common/lib/format_int.cpp index c13bb9426a..089c572e7e 100644 --- a/backends/p4tools/common/lib/format_int.cpp +++ b/backends/p4tools/common/lib/format_int.cpp @@ -15,7 +15,7 @@ #include "lib/cstring.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { std::string formatBin(const big_int &value, int width, const FormatOptions &formatOptions) { std::stringstream out; @@ -292,7 +292,7 @@ std::optional convertToIpv4String(const std::vector &byteA constexpr uint8_t ipv4ByteSize = 4U; if (byteArray.size() != ipv4ByteSize) { - ::error("Invalid IPv4 address byte array of size %1%", byteArray.size()); + ::P4::error("Invalid IPv4 address byte array of size %1%", byteArray.size()); return std::nullopt; } @@ -311,7 +311,7 @@ std::optional convertToIpv6String(const std::vector &byteA constexpr uint8_t chunkSize = 8U; constexpr uint8_t ipv6ByteSize = 16U; if (byteArray.size() != ipv6ByteSize) { - ::error("Invalid IPv6 address byte array of size %1%", byteArray.size()); + ::P4::error("Invalid IPv6 address byte array of size %1%", byteArray.size()); return std::nullopt; } @@ -330,7 +330,7 @@ std::optional convertToIpv6String(const std::vector &byteA std::optional convertToMacString(const std::vector &byteArray) { constexpr uint8_t macByteSize = 6U; if (byteArray.size() != macByteSize) { - ::error("Invalid MAC address byte array of size %1%", byteArray.size()); + ::P4::error("Invalid MAC address byte array of size %1%", byteArray.size()); return std::nullopt; } @@ -343,4 +343,4 @@ std::optional convertToMacString(const std::vector &byteAr } return ss.str(); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/format_int.h b/backends/p4tools/common/lib/format_int.h index c19dacb709..5760e5302e 100644 --- a/backends/p4tools/common/lib/format_int.h +++ b/backends/p4tools/common/lib/format_int.h @@ -8,7 +8,7 @@ #include "ir/ir.h" #include "lib/big_int_util.h" -namespace P4Tools { +namespace P4::P4Tools { /// Defines common formatting options. struct FormatOptions { @@ -101,6 +101,6 @@ std::optional convertToIpv6String(const std::vector &byteA /// @returns std::nullopt if the conversion fails. std::optional convertToMacString(const std::vector &byteArray); -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_FORMAT_INT_H_ */ diff --git a/backends/p4tools/common/lib/formulae.h b/backends/p4tools/common/lib/formulae.h index 1483d86dc6..5ee5824732 100644 --- a/backends/p4tools/common/lib/formulae.h +++ b/backends/p4tools/common/lib/formulae.h @@ -8,7 +8,7 @@ #include "ir/node.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { /// Provides common functionality for implementing a thin wrapper around a 'const Node*' to enforce /// invariants on which forms of IR nodes can inhabit implementations of this type. Implementations @@ -32,6 +32,6 @@ class AbstractRepCheckedNode : public ICastable { DECLARE_TYPEINFO(AbstractRepCheckedNode); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_FORMULAE_H_ */ diff --git a/backends/p4tools/common/lib/gen_eq.cpp b/backends/p4tools/common/lib/gen_eq.cpp index 7b357c89f8..591931c42b 100644 --- a/backends/p4tools/common/lib/gen_eq.cpp +++ b/backends/p4tools/common/lib/gen_eq.cpp @@ -6,7 +6,7 @@ #include "ir/vector.h" #include "lib/exceptions.h" -namespace P4Tools::GenEq { +namespace P4::P4Tools::GenEq { /// Recursively resolve lists of size 1 by returning the expression contained within. const IR::Expression *resolveSingletonList(const IR::Expression *expr) { @@ -88,4 +88,4 @@ const IR::Expression *equate(const IR::Expression *left, const IR::Expression *r return mkEq(left, right); } -} // namespace P4Tools::GenEq +} // namespace P4::P4Tools::GenEq diff --git a/backends/p4tools/common/lib/gen_eq.h b/backends/p4tools/common/lib/gen_eq.h index 2476ad3e11..8a3d0c0377 100644 --- a/backends/p4tools/common/lib/gen_eq.h +++ b/backends/p4tools/common/lib/gen_eq.h @@ -3,7 +3,7 @@ #include "ir/ir.h" -namespace P4Tools::GenEq { +namespace P4::P4Tools::GenEq { /// Generates a semantic equality on two input expressions, recursing into lists and structs. /// This supports fuzzy matching on singleton lists: singleton lists are considered the same as @@ -11,6 +11,6 @@ namespace P4Tools::GenEq { /// attempting to generate the equality. The expression types need to be semantically compatible. const IR::Expression *equate(const IR::Expression *left, const IR::Expression *right); -} // namespace P4Tools::GenEq +} // namespace P4::P4Tools::GenEq #endif /* BACKENDS_P4TOOLS_COMMON_LIB_GEN_EQ_H_ */ diff --git a/backends/p4tools/common/lib/ir_compare.h b/backends/p4tools/common/lib/ir_compare.h index 96b99bcd9c..f79a24a606 100644 --- a/backends/p4tools/common/lib/ir_compare.h +++ b/backends/p4tools/common/lib/ir_compare.h @@ -3,7 +3,7 @@ #include "ir/ir.h" -namespace IR { +namespace P4::IR { /// Equals for StateVariable pointers. We only compare the label. struct StateVariableEqual { @@ -25,5 +25,6 @@ struct StateVariableLess { } }; -} // namespace IR +} // namespace P4::IR + #endif /* BACKENDS_P4TOOLS_COMMON_LIB_IR_COMPARE_H_ */ diff --git a/backends/p4tools/common/lib/logging.cpp b/backends/p4tools/common/lib/logging.cpp index 3908a8c911..7fa4394935 100644 --- a/backends/p4tools/common/lib/logging.cpp +++ b/backends/p4tools/common/lib/logging.cpp @@ -7,11 +7,11 @@ #include "lib/log.h" #include "lib/timer.h" -namespace P4Tools { +namespace P4::P4Tools { -void enableInformationLogging() { ::Log::addDebugSpec("tools_info:4"); } +void enableInformationLogging() { ::P4::Log::addDebugSpec("tools_info:4"); } -void enablePerformanceLogging() { ::Log::addDebugSpec("tools_performance:4"); } +void enablePerformanceLogging() { ::P4::Log::addDebugSpec("tools_performance:4"); } void printPerformanceReport(const std::optional &basePath) { // Do not emit a report if performance logging is not enabled. @@ -46,7 +46,7 @@ void printPerformanceReport(const std::optional &basePath perfFilePath.replace_extension(".csv"); auto perfFile = std::ofstream(perfFilePath, std::ios::out | std::ios::app); if (!perfFile.is_open()) { - ::error("Failed to open the performance report file %1%", perfFilePath.c_str()); + ::P4::error("Failed to open the performance report file %1%", perfFilePath.c_str()); return; } @@ -58,4 +58,4 @@ void printPerformanceReport(const std::optional &basePath perfFile.close(); } } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/logging.h b/backends/p4tools/common/lib/logging.h index 778a868cb5..5e6dde01d4 100644 --- a/backends/p4tools/common/lib/logging.h +++ b/backends/p4tools/common/lib/logging.h @@ -10,7 +10,7 @@ #include "lib/log.h" -namespace P4Tools { +namespace P4::P4Tools { /// Helper function for @printFeature inline std::string logHelper(boost::format &f) { return f.str(); } @@ -61,6 +61,6 @@ void enablePerformanceLogging(); /// If a file is provided, it will be written to the file. void printPerformanceReport(const std::optional &basePath = std::nullopt); -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_LOGGING_H_ */ diff --git a/backends/p4tools/common/lib/model.cpp b/backends/p4tools/common/lib/model.cpp index f5cacf24d3..25fa33e972 100644 --- a/backends/p4tools/common/lib/model.cpp +++ b/backends/p4tools/common/lib/model.cpp @@ -12,7 +12,7 @@ #include "lib/exceptions.h" #include "lib/log.h" -namespace P4Tools { +namespace P4::P4Tools { Model::SubstVisitor::SubstVisitor(const Model &model, bool doComplete) : self(model), doComplete(doComplete) {} @@ -111,4 +111,4 @@ void Model::mergeMap(const SymbolicMapping &sourceMap) { } } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/model.h b/backends/p4tools/common/lib/model.h index 6fd8cb2da0..4059aba828 100644 --- a/backends/p4tools/common/lib/model.h +++ b/backends/p4tools/common/lib/model.h @@ -9,7 +9,7 @@ #include "ir/solver.h" #include "ir/visitor.h" -namespace P4Tools { +namespace P4::P4Tools { /// Symbolic maps map a state variable to a IR::Expression. using SymbolicMapType = absl::btree_map; @@ -92,6 +92,6 @@ class Model { [[nodiscard]] const SymbolicMapping &getSymbolicMap() const; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_MODEL_H_ */ diff --git a/backends/p4tools/common/lib/namespace_context.cpp b/backends/p4tools/common/lib/namespace_context.cpp index 0de3b4ee1f..566ea06d1a 100644 --- a/backends/p4tools/common/lib/namespace_context.cpp +++ b/backends/p4tools/common/lib/namespace_context.cpp @@ -7,7 +7,7 @@ #include "lib/enumerator.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { const NamespaceContext *NamespaceContext::Empty = new NamespaceContext(nullptr, nullptr); @@ -112,4 +112,4 @@ cstring NamespaceContext::genName(cstring name, char sep) const { return cstring::make_unique(getUsedNames(), name, sep); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/namespace_context.h b/backends/p4tools/common/lib/namespace_context.h index 0b39073a9f..f6f9139b5c 100644 --- a/backends/p4tools/common/lib/namespace_context.h +++ b/backends/p4tools/common/lib/namespace_context.h @@ -8,7 +8,7 @@ #include "ir/ir.h" #include "lib/cstring.h" -namespace P4Tools { +namespace P4::P4Tools { /// Represents a stack of namespaces. class NamespaceContext { @@ -50,6 +50,6 @@ class NamespaceContext { cstring genName(cstring name, char sep) const; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_NAMESPACE_CONTEXT_H_ */ diff --git a/backends/p4tools/common/lib/symbolic_env.cpp b/backends/p4tools/common/lib/symbolic_env.cpp index 26bf02f063..b60bea00e2 100644 --- a/backends/p4tools/common/lib/symbolic_env.cpp +++ b/backends/p4tools/common/lib/symbolic_env.cpp @@ -9,7 +9,7 @@ #include "ir/visitor.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { const IR::Expression *SymbolicEnv::get(const IR::StateVariable &var) const { auto it = map.find(var); @@ -151,4 +151,4 @@ bool SymbolicEnv::isSymbolicValue(const IR::Node *node) { return false; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/symbolic_env.h b/backends/p4tools/common/lib/symbolic_env.h index 8b74dc3cb5..59a6249245 100644 --- a/backends/p4tools/common/lib/symbolic_env.h +++ b/backends/p4tools/common/lib/symbolic_env.h @@ -5,7 +5,7 @@ #include "ir/ir.h" #include "ir/node.h" -namespace P4Tools { +namespace P4::P4Tools { /// A symbolic environment maps variables to their symbolic value. A symbolic value is just an /// expression on the program's initial state. @@ -38,6 +38,6 @@ class SymbolicEnv { static bool isSymbolicValue(const IR::Node *); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_SYMBOLIC_ENV_H_ */ diff --git a/backends/p4tools/common/lib/table_utils.cpp b/backends/p4tools/common/lib/table_utils.cpp index ccfaaf1353..ff3a3f9ea9 100644 --- a/backends/p4tools/common/lib/table_utils.cpp +++ b/backends/p4tools/common/lib/table_utils.cpp @@ -2,7 +2,7 @@ #include "ir/irutils.h" -namespace P4Tools::TableUtils { +namespace P4::P4Tools::TableUtils { using namespace P4::literals; @@ -122,4 +122,4 @@ const IR::Expression *computeEntryMatch(const IR::P4Table &table, const IR::Entr return entryMatchCondition; } -} // namespace P4Tools::TableUtils +} // namespace P4::P4Tools::TableUtils diff --git a/backends/p4tools/common/lib/table_utils.h b/backends/p4tools/common/lib/table_utils.h index 1e21941cdc..f8486cbee0 100644 --- a/backends/p4tools/common/lib/table_utils.h +++ b/backends/p4tools/common/lib/table_utils.h @@ -4,7 +4,7 @@ #include "ir/ir.h" #include "lib/cstring.h" -namespace P4Tools::TableUtils { +namespace P4::P4Tools::TableUtils { /// KeyProperties define properties of table keys that are useful for execution. struct KeyProperties { @@ -77,6 +77,6 @@ const IR::PathExpression *getDefaultActionName(const IR::P4Table &table); const IR::Expression *computeEntryMatch(const IR::P4Table &table, const IR::Entry &entry, const IR::Key &key); -} // namespace P4Tools::TableUtils +} // namespace P4::P4Tools::TableUtils #endif /* BACKENDS_P4TOOLS_COMMON_LIB_TABLE_UTILS_H_ */ diff --git a/backends/p4tools/common/lib/taint.cpp b/backends/p4tools/common/lib/taint.cpp index 10410c4a4f..25a0724b3d 100644 --- a/backends/p4tools/common/lib/taint.cpp +++ b/backends/p4tools/common/lib/taint.cpp @@ -19,7 +19,7 @@ #include "lib/log.h" #include "lib/null.h" -namespace P4Tools { +namespace P4::P4Tools { const IR::StringLiteral Taint::TAINTED_STRING_LITERAL = IR::StringLiteral("Taint"_cs); @@ -268,4 +268,4 @@ const IR::Expression *Taint::propagateTaint(const IR::Expression *expr) { return expr->apply(TaintPropagator()); } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/taint.h b/backends/p4tools/common/lib/taint.h index f059650f9c..f42e8543f6 100644 --- a/backends/p4tools/common/lib/taint.h +++ b/backends/p4tools/common/lib/taint.h @@ -4,7 +4,7 @@ #include "backends/p4tools/common/lib/model.h" #include "ir/ir.h" -namespace P4Tools { +namespace P4::P4Tools { class Taint { public: @@ -26,6 +26,6 @@ class Taint { const IR::Expression *programPacket); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_TAINT_H_ */ diff --git a/backends/p4tools/common/lib/trace_event.cpp b/backends/p4tools/common/lib/trace_event.cpp index d36baba023..b5d33e0ac5 100644 --- a/backends/p4tools/common/lib/trace_event.cpp +++ b/backends/p4tools/common/lib/trace_event.cpp @@ -1,6 +1,6 @@ #include "backends/p4tools/common/lib/trace_event.h" -namespace P4Tools { +namespace P4::P4Tools { std::ostream &operator<<(std::ostream &os, const TraceEvent &event) { event.print(os); @@ -17,4 +17,4 @@ const TraceEvent *TraceEvent::evaluate(const Model & /*model*/, bool /*doComplet return this; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/trace_event.h b/backends/p4tools/common/lib/trace_event.h index 3ce8cb5bb7..a0d63b9df0 100644 --- a/backends/p4tools/common/lib/trace_event.h +++ b/backends/p4tools/common/lib/trace_event.h @@ -8,7 +8,7 @@ #include "ir/visitor.h" #include "lib/castable.h" -namespace P4Tools { +namespace P4::P4Tools { /// An event in a trace of the execution of a P4 program. class TraceEvent : public ICastable { @@ -38,6 +38,6 @@ class TraceEvent : public ICastable { DECLARE_TYPEINFO(TraceEvent); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_TRACE_EVENT_H_ */ diff --git a/backends/p4tools/common/lib/trace_event_types.cpp b/backends/p4tools/common/lib/trace_event_types.cpp index 54206cdff5..2288e3f2dd 100644 --- a/backends/p4tools/common/lib/trace_event_types.cpp +++ b/backends/p4tools/common/lib/trace_event_types.cpp @@ -14,7 +14,7 @@ #include "lib/null.h" #include "lib/source_file.h" -namespace P4Tools::TraceEvents { +namespace P4::P4Tools::TraceEvents { /* ============================================================================================= * Generic @@ -366,4 +366,4 @@ void ParserState::print(std::ostream &os) const { os << "[State] " << state->con const IR::ParserState *ParserState::getParserState() const { return state; } -} // namespace P4Tools::TraceEvents +} // namespace P4::P4Tools::TraceEvents diff --git a/backends/p4tools/common/lib/trace_event_types.h b/backends/p4tools/common/lib/trace_event_types.h index 1ab86dd4bc..d60fa58911 100644 --- a/backends/p4tools/common/lib/trace_event_types.h +++ b/backends/p4tools/common/lib/trace_event_types.h @@ -13,7 +13,7 @@ #include "lib/cstring.h" /// This file defines explicit types of trace events extended from the generic trace class. -namespace P4Tools::TraceEvents { +namespace P4::P4Tools::TraceEvents { /* ============================================================================================= * Generic @@ -354,6 +354,6 @@ class ParserState : public TraceEvent { DECLARE_TYPEINFO(ParserState, TraceEvent); }; -} // namespace P4Tools::TraceEvents +} // namespace P4::P4Tools::TraceEvents #endif /* BACKENDS_P4TOOLS_COMMON_LIB_TRACE_EVENT_TYPES_H_ */ diff --git a/backends/p4tools/common/lib/util.cpp b/backends/p4tools/common/lib/util.cpp index 3155e917ee..963e579d75 100644 --- a/backends/p4tools/common/lib/util.cpp +++ b/backends/p4tools/common/lib/util.cpp @@ -19,7 +19,7 @@ #include "lib/exceptions.h" #include "lib/null.h" -namespace P4Tools { +namespace P4::P4Tools { /* ========================================================================================= * Seeds, timestamps, randomness. @@ -196,4 +196,4 @@ const IR::Type_Declaration *resolveProgramType(const IR::IGeneralNamespace *ns, return decl; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/lib/util.h b/backends/p4tools/common/lib/util.h index bc8343b109..a43cab9acd 100644 --- a/backends/p4tools/common/lib/util.h +++ b/backends/p4tools/common/lib/util.h @@ -13,7 +13,7 @@ #include "ir/ir.h" -namespace P4Tools { +namespace P4::P4Tools { /// General utility functions that are not present in the compiler framework. class Utils { @@ -124,6 +124,6 @@ const IR::IDeclaration *findProgramDecl(const IR::IGeneralNamespace *ns, const IR::Type_Declaration *resolveProgramType(const IR::IGeneralNamespace *ns, const IR::Type_Name *type); -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_UTIL_H_ */ diff --git a/backends/p4tools/common/lib/variables.cpp b/backends/p4tools/common/lib/variables.cpp index 8f0b02eda8..e955c39579 100644 --- a/backends/p4tools/common/lib/variables.cpp +++ b/backends/p4tools/common/lib/variables.cpp @@ -6,7 +6,7 @@ #include "ir/id.h" -namespace P4Tools::ToolsVariables { +namespace P4::P4Tools::ToolsVariables { /// The prefix used for state variables. static const IR::PathExpression VAR_PREFIX = IR::PathExpression("p4tools*var"); @@ -62,4 +62,4 @@ IR::StateVariable convertReference(const IR::Expression *ref) { return path; } -} // namespace P4Tools::ToolsVariables +} // namespace P4::P4Tools::ToolsVariables diff --git a/backends/p4tools/common/lib/variables.h b/backends/p4tools/common/lib/variables.h index f7c90c3588..7d7a7917a5 100644 --- a/backends/p4tools/common/lib/variables.h +++ b/backends/p4tools/common/lib/variables.h @@ -7,7 +7,7 @@ /// Variables internal to P4Tools. These variables do not exist in the P4 /// program itself, but are generated and added to the environment by the P4Tools tooling. These /// variables are also used for SMT solvers as symbolic variables. -namespace P4Tools { +namespace P4::P4Tools { using namespace P4::literals; @@ -52,6 +52,6 @@ IR::StateVariable convertReference(const IR::Expression *ref); } // namespace ToolsVariables -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_LIB_VARIABLES_H_ */ diff --git a/backends/p4tools/common/options.cpp b/backends/p4tools/common/options.cpp index a104b1a2a8..90e0d9af84 100644 --- a/backends/p4tools/common/options.cpp +++ b/backends/p4tools/common/options.cpp @@ -15,7 +15,7 @@ #include "lib/error.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { std::tuple AbstractP4cToolOptions::convertArgs( const std::vector &args) { @@ -37,7 +37,7 @@ std::optional AbstractP4cToolOptions::process( char **argv = nullptr; std::tie(argc, argv) = convertArgs(args); - // Establish a dummy compilation context so that we can use ::error to report errors while + // Establish a dummy compilation context so that we can use ::P4::error to report errors while // processing command-line options. class DummyCompileContext : public BaseCompileContext { } dummyContext; @@ -45,7 +45,7 @@ std::optional AbstractP4cToolOptions::process( // Delegate to the hook. auto *remainingArgs = process(argc, argv); - if ((remainingArgs == nullptr) || ::errorCount() > 0) { + if ((remainingArgs == nullptr) || ::P4::errorCount() > 0) { return std::nullopt; } @@ -57,7 +57,7 @@ std::optional AbstractP4cToolOptions::process( std::tie(argc, argv) = convertArgs(compilerArgs); auto *unprocessedCompilerArgs = P4Tools::CompilerTarget::initCompiler(_toolName, argc, argv); - if ((unprocessedCompilerArgs == nullptr) || ::errorCount() > 0) { + if ((unprocessedCompilerArgs == nullptr) || ::P4::errorCount() > 0) { return std::nullopt; } BUG_CHECK(unprocessedCompilerArgs->empty(), "Compiler did not process all of its arguments: %s", @@ -66,13 +66,13 @@ std::optional AbstractP4cToolOptions::process( // Remaining arguments should be source files. Ensure we have exactly one and send it to the // compiler. if (remainingArgs->size() > 1) { - ::error("Only one input file can be specified. Duplicate args:\n%1%", - cstring::join(remainingArgs->begin(), remainingArgs->end(), "\n ")); + ::P4::error("Only one input file can be specified. Duplicate args:\n%1%", + cstring::join(remainingArgs->begin(), remainingArgs->end(), "\n ")); usage(); return std::nullopt; } if (remainingArgs->empty()) { - ::error("No input files specified"); + ::P4::error("No input files specified"); usage(); return std::nullopt; } @@ -149,7 +149,7 @@ AbstractP4cToolOptions::AbstractP4cToolOptions(std::string_view toolName, std::s {"--target", "target", "Specifies the device targeted by the program.", std::optional>{[](const char *arg) { if (!P4Tools::Target::setDevice(arg)) { - ::error("Unsupported target device: %s", arg); + ::P4::error("Unsupported target device: %s", arg); return false; } return true; @@ -157,7 +157,7 @@ AbstractP4cToolOptions::AbstractP4cToolOptions(std::string_view toolName, std::s {"--arch", "arch", "Specifies the architecture targeted by the program.", std::optional>{[](const char *arg) { if (!P4Tools::Target::setArch(arg)) { - ::error("Unsupported architecture: %s", arg); + ::P4::error("Unsupported architecture: %s", arg); return false; } return true; @@ -214,4 +214,4 @@ bool AbstractP4cToolOptions::validateOptions() const { return true; } const std::string &AbstractP4cToolOptions::getToolName() const { return _toolName; } -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/common/options.h b/backends/p4tools/common/options.h index 1f6e9b2d94..96a7fe33bc 100644 --- a/backends/p4tools/common/options.h +++ b/backends/p4tools/common/options.h @@ -10,7 +10,7 @@ #include "lib/cstring.h" #include "lib/options.h" -namespace P4Tools { +namespace P4::P4Tools { /// Encapsulates and processes command-line options for a compiler-based tool. Implementations /// should use the singleton pattern and define a static get() for obtaining the singleton @@ -56,6 +56,6 @@ class AbstractP4cToolOptions : protected Util::Options { explicit AbstractP4cToolOptions(std::string_view toolName, std::string_view message); }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_OPTIONS_H_ */ diff --git a/backends/p4tools/common/p4ctool.h b/backends/p4tools/common/p4ctool.h index 4f9496db1a..79b921ba79 100644 --- a/backends/p4tools/common/p4ctool.h +++ b/backends/p4tools/common/p4ctool.h @@ -11,7 +11,7 @@ #include "backends/p4tools/common/options.h" #include "frontends/common/options.h" -namespace P4Tools { +namespace P4::P4Tools { /// Abstract class for all compiler-based tools. Implementations should instantiate this template /// on a subclass of AbstractP4cToolOptions. @@ -65,6 +65,6 @@ class AbstractP4cTool { } }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_COMMON_P4CTOOL_H_ */ diff --git a/backends/p4tools/modules/smith/common/declarations.cpp b/backends/p4tools/modules/smith/common/declarations.cpp index 2b9a1be956..6f04e1339e 100644 --- a/backends/p4tools/modules/smith/common/declarations.cpp +++ b/backends/p4tools/modules/smith/common/declarations.cpp @@ -19,7 +19,7 @@ #include "lib/exceptions.h" #include "lib/source_file.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { IR::StatOrDecl *DeclarationGenerator::generateRandomStatementOrDeclaration(bool is_in_func) { std::vector percent = {PCT.STATEMENTORDECLARATION_VAR, @@ -746,4 +746,4 @@ IR::ParameterList *DeclarationGenerator::genParameterList() { return new IR::ParameterList(params); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/common/declarations.h b/backends/p4tools/modules/smith/common/declarations.h index 06000eb1da..e794ce454f 100644 --- a/backends/p4tools/modules/smith/common/declarations.h +++ b/backends/p4tools/modules/smith/common/declarations.h @@ -8,7 +8,7 @@ #include "ir/ir.h" #include "lib/cstring.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class DeclarationGenerator : public Generator { public: @@ -81,6 +81,6 @@ class DeclarationGenerator : public Generator { virtual IR::ParameterList *genParameterList(); }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_DECLARATIONS_H_ */ diff --git a/backends/p4tools/modules/smith/common/expressions.cpp b/backends/p4tools/modules/smith/common/expressions.cpp index 2805dfe57e..302612677c 100644 --- a/backends/p4tools/modules/smith/common/expressions.cpp +++ b/backends/p4tools/modules/smith/common/expressions.cpp @@ -17,7 +17,7 @@ #include "ir/vector.h" #include "lib/exceptions.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { const IR::Type_Boolean *ExpressionGenerator::genBoolType() { return IR::Type_Boolean::get(); } @@ -1243,4 +1243,4 @@ IR::Expression *ExpressionGenerator::pickLvalOrSlice(const IR::Type *tp) { return expr; } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/common/expressions.h b/backends/p4tools/modules/smith/common/expressions.h index c6104b1fca..6e532f56ba 100644 --- a/backends/p4tools/modules/smith/common/expressions.h +++ b/backends/p4tools/modules/smith/common/expressions.h @@ -12,7 +12,7 @@ #include "ir/vector.h" #include "lib/cstring.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { using TyperefProbs = struct TyperefProbs { int64_t p4_bit; @@ -114,6 +114,6 @@ class ExpressionGenerator : public Generator { virtual bool checkInputArg(const IR::Parameter *param); }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_EXPRESSIONS_H_ */ diff --git a/backends/p4tools/modules/smith/common/generator.h b/backends/p4tools/modules/smith/common/generator.h index 37abd6ff11..9407db38e3 100644 --- a/backends/p4tools/modules/smith/common/generator.h +++ b/backends/p4tools/modules/smith/common/generator.h @@ -3,7 +3,7 @@ #include -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class SmithTarget; @@ -15,6 +15,6 @@ class Generator { const SmithTarget &target() { return _target; } }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_GENERATOR_H_ */ diff --git a/backends/p4tools/modules/smith/common/parser.cpp b/backends/p4tools/modules/smith/common/parser.cpp index 4e140b6985..10c4c3af76 100644 --- a/backends/p4tools/modules/smith/common/parser.cpp +++ b/backends/p4tools/modules/smith/common/parser.cpp @@ -21,7 +21,7 @@ #include "lib/cstring.h" #include "lib/exceptions.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { IR::MethodCallStatement *ParserGenerator::genHdrExtract(IR::Member *pkt_call, IR::Expression *mem) { auto *args = new IR::Vector(); @@ -268,4 +268,4 @@ void ParserGenerator::buildParserTree() { state_list.push_back(ParserGenerator::genHdrStates()); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/common/parser.h b/backends/p4tools/modules/smith/common/parser.h index 59da5007ce..c7e415a939 100644 --- a/backends/p4tools/modules/smith/common/parser.h +++ b/backends/p4tools/modules/smith/common/parser.h @@ -7,7 +7,7 @@ #include "ir/vector.h" #include "lib/cstring.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class ParserGenerator : public Generator { private: @@ -30,6 +30,6 @@ class ParserGenerator : public Generator { [[nodiscard]] IR::IndexedVector getStates() const { return state_list; } }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_PARSER_H_ */ diff --git a/backends/p4tools/modules/smith/common/scope.cpp b/backends/p4tools/modules/smith/common/scope.cpp index b5c38cd8b8..a31631f324 100644 --- a/backends/p4tools/modules/smith/common/scope.cpp +++ b/backends/p4tools/modules/smith/common/scope.cpp @@ -17,7 +17,7 @@ #include "lib/cstring.h" #include "lib/exceptions.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { std::vector *> P4Scope::scope; std::set P4Scope::usedNames; @@ -339,4 +339,4 @@ const IR::Type_Declaration *P4Scope::getTypeByName(cstring name) { } return nullptr; } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/common/scope.h b/backends/p4tools/modules/smith/common/scope.h index d0e6c5e7a8..be88ca49fa 100644 --- a/backends/p4tools/modules/smith/common/scope.h +++ b/backends/p4tools/modules/smith/common/scope.h @@ -12,7 +12,7 @@ #include "ir/vector.h" #include "lib/cstring.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { struct Requirements { bool require_scalar{false}; @@ -119,6 +119,6 @@ class P4Scope { static std::vector getFilteredDecls(std::set filter); static std::set *getCallableTables(); }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_SCOPE_H_ */ diff --git a/backends/p4tools/modules/smith/common/statements.cpp b/backends/p4tools/modules/smith/common/statements.cpp index 07739de2ac..47e33585da 100644 --- a/backends/p4tools/modules/smith/common/statements.cpp +++ b/backends/p4tools/modules/smith/common/statements.cpp @@ -20,7 +20,7 @@ #include "lib/exceptions.h" #include "lib/log.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { IR::Statement *StatementGenerator::genStatement(bool is_in_func) { // functions can!have exit statements so set their probability to zero @@ -456,4 +456,4 @@ IR::ForInStatement *StatementGenerator::genForInLoopStatement(bool is_in_func) { return forInStmt; } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/common/statements.h b/backends/p4tools/modules/smith/common/statements.h index 43e55a1bda..a14c9081ec 100644 --- a/backends/p4tools/modules/smith/common/statements.h +++ b/backends/p4tools/modules/smith/common/statements.h @@ -5,7 +5,7 @@ #include "ir/indexed_vector.h" #include "ir/ir.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class StatementGenerator : public Generator { public: @@ -43,6 +43,6 @@ class StatementGenerator : public Generator { virtual IR::ForInStatement *genForInLoopStatement(bool is_in_func); }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_STATEMENTS_H_ */ diff --git a/backends/p4tools/modules/smith/common/table.cpp b/backends/p4tools/modules/smith/common/table.cpp index c8aa637087..49a4d296b0 100644 --- a/backends/p4tools/modules/smith/common/table.cpp +++ b/backends/p4tools/modules/smith/common/table.cpp @@ -17,7 +17,7 @@ #include "lib/cstring.h" #include "lib/exceptions.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { IR::P4Table *TableGenerator::genTableDeclaration() { IR::TableProperties *tbProperties = genTablePropertyList(); @@ -156,4 +156,4 @@ IR::Property *TableGenerator::genActionListProperty() { return new IR::Property(name, acts, false); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/common/table.h b/backends/p4tools/modules/smith/common/table.h index 1edcde3332..a4ab5fa006 100644 --- a/backends/p4tools/modules/smith/common/table.h +++ b/backends/p4tools/modules/smith/common/table.h @@ -6,7 +6,7 @@ #include "ir/ir.h" #include "lib/cstring.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class TableGenerator : public Generator { public: @@ -32,6 +32,6 @@ class TableGenerator : public Generator { IR::Property *genActionListProperty(); }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_COMMON_TABLE_H_ */ diff --git a/backends/p4tools/modules/smith/core/target.cpp b/backends/p4tools/modules/smith/core/target.cpp index 9aeee340c7..b14aa8693c 100644 --- a/backends/p4tools/modules/smith/core/target.cpp +++ b/backends/p4tools/modules/smith/core/target.cpp @@ -5,11 +5,11 @@ #include "backends/p4tools/common/compiler/compiler_target.h" #include "backends/p4tools/common/core/target.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { SmithTarget::SmithTarget(const std::string &deviceName, const std::string &archName) : P4Tools::CompilerTarget("smith", deviceName, archName) {} const SmithTarget &SmithTarget::get() { return P4Tools::Target::get("smith"); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/core/target.h b/backends/p4tools/modules/smith/core/target.h index 4131f59dea..065edd44b8 100644 --- a/backends/p4tools/modules/smith/core/target.h +++ b/backends/p4tools/modules/smith/core/target.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/smith/common/table.h" #include "ir/ir.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class SmithTarget : public CompilerTarget { public: @@ -37,6 +37,6 @@ class SmithTarget : public CompilerTarget { private: }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_CORE_TARGET_H_ */ diff --git a/backends/p4tools/modules/smith/main.cpp b/backends/p4tools/modules/smith/main.cpp index ca1f798313..26c44b5705 100644 --- a/backends/p4tools/modules/smith/main.cpp +++ b/backends/p4tools/modules/smith/main.cpp @@ -9,6 +9,8 @@ #include "lib/exceptions.h" #include "lib/timer.h" +using namespace P4; + int main(int argc, char **argv) { setup_signals(); diff --git a/backends/p4tools/modules/smith/options.cpp b/backends/p4tools/modules/smith/options.cpp index 0a6978981b..2f2ea3da46 100644 --- a/backends/p4tools/modules/smith/options.cpp +++ b/backends/p4tools/modules/smith/options.cpp @@ -10,7 +10,7 @@ #include "lib/error.h" #include "lib/exceptions.h" -namespace P4Tools { +namespace P4::P4Tools { SmithOptions &SmithOptions::get() { static SmithOptions INSTANCE; @@ -27,7 +27,7 @@ void SmithOptions::processArgs(const std::vector &args) { char **argv = nullptr; std::tie(argc, argv) = convertArgs(args); - // Establish a dummy compilation context so that we can use ::error to report errors while + // Establish a dummy compilation context so that we can use ::P4::error to report errors while // processing command-line options. class DummyCompileContext : public BaseCompileContext { } dummyContext; @@ -35,11 +35,11 @@ void SmithOptions::processArgs(const std::vector &args) { // Delegate to the hook. auto *remainingArgs = P4Tools::AbstractP4cToolOptions::process(argc, argv); - if ((remainingArgs == nullptr) || ::errorCount() > 0) { + if ((remainingArgs == nullptr) || ::P4::errorCount() > 0) { return; } } SmithOptions::SmithOptions() : AbstractP4cToolOptions(P4Smith::TOOL_NAME, "P4Smith options.") {} -} // namespace P4Tools +} // namespace P4::P4Tools diff --git a/backends/p4tools/modules/smith/options.h b/backends/p4tools/modules/smith/options.h index c0bb56e10b..a56bf5954f 100644 --- a/backends/p4tools/modules/smith/options.h +++ b/backends/p4tools/modules/smith/options.h @@ -4,7 +4,7 @@ #include "backends/p4tools/common/options.h" -namespace P4Tools { +namespace P4::P4Tools { class SmithOptions : public AbstractP4cToolOptions { public: @@ -20,6 +20,6 @@ class SmithOptions : public AbstractP4cToolOptions { // using P4toZ3Context = P4CContextWithOptions; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_OPTIONS_H_ */ diff --git a/backends/p4tools/modules/smith/register.h.in b/backends/p4tools/modules/smith/register.h.in index 8ed1d5400f..a83a5d8204 100644 --- a/backends/p4tools/modules/smith/register.h.in +++ b/backends/p4tools/modules/smith/register.h.in @@ -3,11 +3,11 @@ @include_statements_var@ -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { inline void registerSmithTargets() { @smith_targets_var@} -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_REGISTER_H_ */ diff --git a/backends/p4tools/modules/smith/smith.cpp b/backends/p4tools/modules/smith/smith.cpp index 8c7658259f..a108903745 100644 --- a/backends/p4tools/modules/smith/smith.cpp +++ b/backends/p4tools/modules/smith/smith.cpp @@ -20,7 +20,7 @@ #include "lib/error.h" #include "lib/nullstream.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { void Smith::registerTarget() { registerSmithTargets(); } @@ -60,7 +60,7 @@ int Smith::mainImpl(const CompilerResult & /*result*/) { } auto *ostream = openFile(outputFile, false); if (ostream == nullptr) { - ::error("must have [file]"); + ::P4::error("must have [file]"); exit(EXIT_FAILURE); } if (smithOptions.seed.has_value()) { @@ -90,4 +90,4 @@ int Smith::mainImpl(const CompilerResult & /*result*/) { return EXIT_SUCCESS; } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/smith.h b/backends/p4tools/modules/smith/smith.h index 1753049cfd..04cbb88c37 100644 --- a/backends/p4tools/modules/smith/smith.h +++ b/backends/p4tools/modules/smith/smith.h @@ -7,7 +7,7 @@ #include "backends/p4tools/common/p4ctool.h" #include "backends/p4tools/modules/smith/options.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { class Smith : public AbstractP4cTool { protected: @@ -20,6 +20,6 @@ class Smith : public AbstractP4cTool { int main(const std::vector &args); }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_SMITH_H_ */ diff --git a/backends/p4tools/modules/smith/targets/bmv2/psa.cpp b/backends/p4tools/modules/smith/targets/bmv2/psa.cpp index 69adcbbc26..2a88add11e 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/psa.cpp +++ b/backends/p4tools/modules/smith/targets/bmv2/psa.cpp @@ -19,7 +19,7 @@ #include "ir/node.h" #include "ir/vector.h" -namespace P4Tools::P4Smith::BMv2 { +namespace P4::P4Tools::P4Smith::BMv2 { using namespace P4::literals; @@ -439,4 +439,4 @@ const IR::P4Program *Bmv2PsaSmithTarget::generateP4Program() const { return new IR::P4Program(*objects); } -} // namespace P4Tools::P4Smith::BMv2 +} // namespace P4::P4Tools::P4Smith::BMv2 diff --git a/backends/p4tools/modules/smith/targets/bmv2/psa.h b/backends/p4tools/modules/smith/targets/bmv2/psa.h index a35d950abf..1d8b3d45a2 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/psa.h +++ b/backends/p4tools/modules/smith/targets/bmv2/psa.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/smith/targets/bmv2/target.h" #include "ir/ir.h" -namespace P4Tools::P4Smith::BMv2 { +namespace P4::P4Tools::P4Smith::BMv2 { class Bmv2PsaSmithTarget : public AbstractBMv2SmithTarget { private: @@ -56,6 +56,6 @@ class Bmv2PsaSmithTarget : public AbstractBMv2SmithTarget { Bmv2PsaSmithTarget(); }; -} // namespace P4Tools::P4Smith::BMv2 +} // namespace P4::P4Tools::P4Smith::BMv2 #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_BMV2_PSA_H_ */ diff --git a/backends/p4tools/modules/smith/targets/bmv2/register.h b/backends/p4tools/modules/smith/targets/bmv2/register.h index a39a1e3a82..fb427f4973 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/register.h +++ b/backends/p4tools/modules/smith/targets/bmv2/register.h @@ -4,13 +4,13 @@ #include "backends/p4tools/modules/smith/targets/bmv2/psa.h" #include "backends/p4tools/modules/smith/targets/bmv2/v1model.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { inline void bmv2RegisterSmithTarget() { BMv2::Bmv2V1modelSmithTarget::make(); BMv2::Bmv2PsaSmithTarget::make(); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_BMV2_REGISTER_H_ */ diff --git a/backends/p4tools/modules/smith/targets/bmv2/target.cpp b/backends/p4tools/modules/smith/targets/bmv2/target.cpp index fb5e299651..10ec63152a 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/target.cpp +++ b/backends/p4tools/modules/smith/targets/bmv2/target.cpp @@ -5,7 +5,7 @@ #include "backends/p4tools/modules/smith/core/target.h" -namespace P4Tools::P4Smith::BMv2 { +namespace P4::P4Tools::P4Smith::BMv2 { /* ============================================================================================= * AbstractBMv2SmithTarget implementation @@ -15,4 +15,4 @@ AbstractBMv2SmithTarget::AbstractBMv2SmithTarget(const std::string &deviceName, const std::string &archName) : SmithTarget(deviceName, archName) {} -} // namespace P4Tools::P4Smith::BMv2 +} // namespace P4::P4Tools::P4Smith::BMv2 diff --git a/backends/p4tools/modules/smith/targets/bmv2/target.h b/backends/p4tools/modules/smith/targets/bmv2/target.h index d99673ab1a..54dfe858e5 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/target.h +++ b/backends/p4tools/modules/smith/targets/bmv2/target.h @@ -5,12 +5,12 @@ #include "backends/p4tools/modules/smith/core/target.h" -namespace P4Tools::P4Smith::BMv2 { +namespace P4::P4Tools::P4Smith::BMv2 { class AbstractBMv2SmithTarget : public SmithTarget { protected: explicit AbstractBMv2SmithTarget(const std::string &deviceName, const std::string &archName); }; -} // namespace P4Tools::P4Smith::BMv2 +} // namespace P4::P4Tools::P4Smith::BMv2 #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_BMV2_TARGET_H_ */ diff --git a/backends/p4tools/modules/smith/targets/bmv2/v1model.cpp b/backends/p4tools/modules/smith/targets/bmv2/v1model.cpp index 5ecfbfa2b1..16b8ee4ab9 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/v1model.cpp +++ b/backends/p4tools/modules/smith/targets/bmv2/v1model.cpp @@ -19,7 +19,7 @@ #include "ir/node.h" #include "ir/vector.h" -namespace P4Tools::P4Smith::BMv2 { +namespace P4::P4Tools::P4Smith::BMv2 { using namespace P4::literals; @@ -382,4 +382,4 @@ const IR::P4Program *Bmv2V1modelSmithTarget::generateP4Program() const { return new IR::P4Program(*objects); } -} // namespace P4Tools::P4Smith::BMv2 +} // namespace P4::P4Tools::P4Smith::BMv2 diff --git a/backends/p4tools/modules/smith/targets/bmv2/v1model.h b/backends/p4tools/modules/smith/targets/bmv2/v1model.h index 4db53fd4c2..4eb34bae82 100644 --- a/backends/p4tools/modules/smith/targets/bmv2/v1model.h +++ b/backends/p4tools/modules/smith/targets/bmv2/v1model.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/smith/targets/bmv2/target.h" #include "ir/ir.h" -namespace P4Tools::P4Smith::BMv2 { +namespace P4::P4Tools::P4Smith::BMv2 { class Bmv2V1modelSmithTarget : public AbstractBMv2SmithTarget { private: @@ -56,6 +56,6 @@ class Bmv2V1modelSmithTarget : public AbstractBMv2SmithTarget { Bmv2V1modelSmithTarget(); }; -} // namespace P4Tools::P4Smith::BMv2 +} // namespace P4::P4Tools::P4Smith::BMv2 #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_BMV2_V1MODEL_H_ */ diff --git a/backends/p4tools/modules/smith/targets/generic/register.h b/backends/p4tools/modules/smith/targets/generic/register.h index 71f562c9ee..1292ecc3d8 100644 --- a/backends/p4tools/modules/smith/targets/generic/register.h +++ b/backends/p4tools/modules/smith/targets/generic/register.h @@ -3,10 +3,10 @@ #include "backends/p4tools/modules/smith/targets/generic/target.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { inline void genericRegisterSmithTarget() { Generic::GenericCoreSmithTarget::make(); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_GENERIC_REGISTER_H_ */ diff --git a/backends/p4tools/modules/smith/targets/generic/target.cpp b/backends/p4tools/modules/smith/targets/generic/target.cpp index cab4aff488..6f89f09392 100644 --- a/backends/p4tools/modules/smith/targets/generic/target.cpp +++ b/backends/p4tools/modules/smith/targets/generic/target.cpp @@ -19,7 +19,7 @@ #include "ir/node.h" #include "ir/vector.h" -namespace P4Tools::P4Smith::Generic { +namespace P4::P4Tools::P4Smith::Generic { using namespace P4::literals; @@ -230,4 +230,4 @@ const IR::P4Program *GenericCoreSmithTarget::generateP4Program() const { return new IR::P4Program(*objects); } -} // namespace P4Tools::P4Smith::Generic +} // namespace P4::P4Tools::P4Smith::Generic diff --git a/backends/p4tools/modules/smith/targets/generic/target.h b/backends/p4tools/modules/smith/targets/generic/target.h index 1447dc7f88..10da3a2fcf 100644 --- a/backends/p4tools/modules/smith/targets/generic/target.h +++ b/backends/p4tools/modules/smith/targets/generic/target.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/smith/core/target.h" #include "ir/ir.h" -namespace P4Tools::P4Smith::Generic { +namespace P4::P4Tools::P4Smith::Generic { class AbstractGenericSmithTarget : public SmithTarget { protected: @@ -66,6 +66,6 @@ class GenericCoreSmithTarget : public AbstractGenericSmithTarget { GenericCoreSmithTarget(); }; -} // namespace P4Tools::P4Smith::Generic +} // namespace P4::P4Tools::P4Smith::Generic #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_GENERIC_TARGET_H_ */ diff --git a/backends/p4tools/modules/smith/targets/generic/test/smith_for_in_loop_test.cpp b/backends/p4tools/modules/smith/targets/generic/test/smith_for_in_loop_test.cpp index cf97f831ae..97a394623b 100644 --- a/backends/p4tools/modules/smith/targets/generic/test/smith_for_in_loop_test.cpp +++ b/backends/p4tools/modules/smith/targets/generic/test/smith_for_in_loop_test.cpp @@ -11,7 +11,7 @@ #include "gtest/gtest.h" #include "ir/ir.h" -namespace Test { +namespace P4::Test { class P4SmithForInLoopTest : public ::testing::Test { protected: @@ -70,4 +70,4 @@ TEST_F(P4SmithForInLoopTest, CheckForLoopBody) { EXPECT_FALSE(forInStmt->body->is()); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/smith/targets/generic/test/smith_for_loop_test.cpp b/backends/p4tools/modules/smith/targets/generic/test/smith_for_loop_test.cpp index 642128f905..66e0001697 100644 --- a/backends/p4tools/modules/smith/targets/generic/test/smith_for_loop_test.cpp +++ b/backends/p4tools/modules/smith/targets/generic/test/smith_for_loop_test.cpp @@ -11,7 +11,7 @@ #include "gtest/gtest.h" #include "ir/ir.h" -namespace Test { +namespace P4::Test { class P4SmithForLoopTest : public ::testing::Test { protected: @@ -79,4 +79,4 @@ TEST_F(P4SmithForLoopTest, CheckForLoopBody) { EXPECT_FALSE(forStmt->body->is()); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/smith/targets/nic/register.h b/backends/p4tools/modules/smith/targets/nic/register.h index 36c256a884..ffcc34195d 100644 --- a/backends/p4tools/modules/smith/targets/nic/register.h +++ b/backends/p4tools/modules/smith/targets/nic/register.h @@ -3,10 +3,10 @@ #include "backends/p4tools/modules/smith/targets/nic/target.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { inline void nicRegisterSmithTarget() { Nic::DpdkPnaSmithTarget::make(); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_NIC_REGISTER_H_ */ diff --git a/backends/p4tools/modules/smith/targets/nic/target.cpp b/backends/p4tools/modules/smith/targets/nic/target.cpp index 9da0b28d6a..fe05565893 100644 --- a/backends/p4tools/modules/smith/targets/nic/target.cpp +++ b/backends/p4tools/modules/smith/targets/nic/target.cpp @@ -18,7 +18,7 @@ #include "ir/node.h" #include "ir/vector.h" -namespace P4Tools::P4Smith::Nic { +namespace P4::P4Tools::P4Smith::Nic { using namespace P4::literals; @@ -315,4 +315,4 @@ const IR::P4Program *DpdkPnaSmithTarget::generateP4Program() const { return new IR::P4Program(*objects); } -} // namespace P4Tools::P4Smith::Nic +} // namespace P4::P4Tools::P4Smith::Nic diff --git a/backends/p4tools/modules/smith/targets/nic/target.h b/backends/p4tools/modules/smith/targets/nic/target.h index 28542b8da2..a3a19bf9a5 100644 --- a/backends/p4tools/modules/smith/targets/nic/target.h +++ b/backends/p4tools/modules/smith/targets/nic/target.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/smith/core/target.h" #include "ir/ir.h" -namespace P4Tools::P4Smith::Nic { +namespace P4::P4Tools::P4Smith::Nic { class AbstractNicSmithTarget : public SmithTarget { protected: @@ -60,6 +60,6 @@ class DpdkPnaSmithTarget : public AbstractNicSmithTarget { DpdkPnaSmithTarget(); }; -} // namespace P4Tools::P4Smith::Nic +} // namespace P4::P4Tools::P4Smith::Nic #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_NIC_TARGET_H_ */ diff --git a/backends/p4tools/modules/smith/targets/tofino/register.h b/backends/p4tools/modules/smith/targets/tofino/register.h index 0c1ee00092..ca9bbebabc 100644 --- a/backends/p4tools/modules/smith/targets/tofino/register.h +++ b/backends/p4tools/modules/smith/targets/tofino/register.h @@ -3,10 +3,10 @@ #include "backends/p4tools/modules/smith/targets/tofino/target.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { inline void tofinoRegisterSmithTarget() { Tofino::TofinoTnaSmithTarget::make(); } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_TOFINO_REGISTER_H_ */ diff --git a/backends/p4tools/modules/smith/targets/tofino/target.cpp b/backends/p4tools/modules/smith/targets/tofino/target.cpp index 074311d8c1..3866721cc1 100644 --- a/backends/p4tools/modules/smith/targets/tofino/target.cpp +++ b/backends/p4tools/modules/smith/targets/tofino/target.cpp @@ -20,7 +20,7 @@ #include "ir/vector.h" #include "lib/cstring.h" -namespace P4Tools::P4Smith::Tofino { +namespace P4::P4Tools::P4Smith::Tofino { using namespace P4::literals; @@ -616,4 +616,4 @@ const IR::P4Program *TofinoTnaSmithTarget::generateP4Program() const { return new IR::P4Program(*objects); } -} // namespace P4Tools::P4Smith::Tofino +} // namespace P4::P4Tools::P4Smith::Tofino diff --git a/backends/p4tools/modules/smith/targets/tofino/target.h b/backends/p4tools/modules/smith/targets/tofino/target.h index c7c488f109..9c993b4fb1 100644 --- a/backends/p4tools/modules/smith/targets/tofino/target.h +++ b/backends/p4tools/modules/smith/targets/tofino/target.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/smith/core/target.h" #include "ir/ir.h" -namespace P4Tools::P4Smith::Tofino { +namespace P4::P4Tools::P4Smith::Tofino { class AbstractTofinoSmithTarget : public SmithTarget { protected: @@ -62,6 +62,6 @@ class TofinoTnaSmithTarget : public AbstractTofinoSmithTarget { TofinoTnaSmithTarget(); }; -} // namespace P4Tools::P4Smith::Tofino +} // namespace P4::P4Tools::P4Smith::Tofino #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TARGETS_TOFINO_TARGET_H_ */ diff --git a/backends/p4tools/modules/smith/toolname.h b/backends/p4tools/modules/smith/toolname.h index 88b7a126bf..bb13e43258 100644 --- a/backends/p4tools/modules/smith/toolname.h +++ b/backends/p4tools/modules/smith/toolname.h @@ -3,10 +3,10 @@ #include -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { static inline constexpr std::string_view TOOL_NAME = "smith"; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_TOOLNAME_H_ */ diff --git a/backends/p4tools/modules/smith/util/util.cpp b/backends/p4tools/modules/smith/util/util.cpp index 445c6554a2..d667e9ea09 100644 --- a/backends/p4tools/modules/smith/util/util.cpp +++ b/backends/p4tools/modules/smith/util/util.cpp @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/smith/common/scope.h" #include "backends/p4tools/modules/smith/util/wordlist.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { std::string getRandomString(size_t len) { // Add "for" and "in" to the list of P4 keywords, even though the wordlist doesn't contain them. @@ -59,4 +59,4 @@ std::string getRandomString(size_t len) { return ret; } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/util/util.h b/backends/p4tools/modules/smith/util/util.h index ae8e7ce358..002205a708 100644 --- a/backends/p4tools/modules/smith/util/util.h +++ b/backends/p4tools/modules/smith/util/util.h @@ -5,7 +5,7 @@ #include "lib/cstring.h" -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { static constexpr int INTEGER_WIDTH(32); @@ -20,6 +20,6 @@ static const cstring ETH_HDR("eth_hdr"); /// @param len : Ignored when choosing from the wordlist. std::string getRandomString(size_t len); -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_UTIL_UTIL_H_ */ diff --git a/backends/p4tools/modules/smith/util/wordlist.cpp b/backends/p4tools/modules/smith/util/wordlist.cpp index 43728f4233..0e24b37792 100644 --- a/backends/p4tools/modules/smith/util/wordlist.cpp +++ b/backends/p4tools/modules/smith/util/wordlist.cpp @@ -3,7 +3,7 @@ #include #include -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { std::size_t Wordlist::counter = 0; @@ -700,4 +700,4 @@ const char *P4Tools::P4Smith::Wordlist::getFromWordlist() { return ""; } -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith diff --git a/backends/p4tools/modules/smith/util/wordlist.h b/backends/p4tools/modules/smith/util/wordlist.h index 637cdb35cb..3213454535 100644 --- a/backends/p4tools/modules/smith/util/wordlist.h +++ b/backends/p4tools/modules/smith/util/wordlist.h @@ -5,7 +5,7 @@ #define WORDLIST_LENGTH 10000 -namespace P4Tools::P4Smith { +namespace P4::P4Tools::P4Smith { /// This class is a wrapper around an underlying array of words, which is currently being /// used to aid random name generation. @@ -27,6 +27,6 @@ class Wordlist { static const std::array WORDS; }; -} // namespace P4Tools::P4Smith +} // namespace P4::P4Tools::P4Smith #endif /* BACKENDS_P4TOOLS_MODULES_SMITH_UTIL_WORDLIST_H_ */ diff --git a/backends/p4tools/modules/testgen/core/compiler_result.cpp b/backends/p4tools/modules/testgen/core/compiler_result.cpp index 7059e0fde5..bde762ceb2 100644 --- a/backends/p4tools/modules/testgen/core/compiler_result.cpp +++ b/backends/p4tools/modules/testgen/core/compiler_result.cpp @@ -5,7 +5,7 @@ #include "backends/p4tools/common/compiler/reachability.h" #include "midend/coverage.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { TestgenCompilerResult::TestgenCompilerResult(CompilerResult compilerResult, P4::Coverage::CoverageSet coverableNodes, @@ -23,4 +23,4 @@ const P4::Coverage::CoverageSet &TestgenCompilerResult::getCoverableNodes() cons return coverableNodes; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/compiler_result.h b/backends/p4tools/modules/testgen/core/compiler_result.h index 6e0a66e470..35278090c7 100644 --- a/backends/p4tools/modules/testgen/core/compiler_result.h +++ b/backends/p4tools/modules/testgen/core/compiler_result.h @@ -5,7 +5,7 @@ #include "backends/p4tools/common/compiler/reachability.h" #include "midend/coverage.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Extends the CompilerResult with the associated P4RuntimeApi class TestgenCompilerResult : public CompilerResult { @@ -32,6 +32,6 @@ class TestgenCompilerResult : public CompilerResult { DECLARE_TYPEINFO(TestgenCompilerResult, CompilerResult); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_COMPILER_RESULT_H_ */ diff --git a/backends/p4tools/modules/testgen/core/extern_info.h b/backends/p4tools/modules/testgen/core/extern_info.h index d8d1beac63..f76c06a877 100644 --- a/backends/p4tools/modules/testgen/core/extern_info.h +++ b/backends/p4tools/modules/testgen/core/extern_info.h @@ -7,7 +7,7 @@ #include "ir/ir.h" #include "ir/vector.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// This class defines parameters useful for the invocation of P4 extern and P4Testgen-internal /// functions. @@ -35,6 +35,6 @@ class ExternInfo { ExternInfo &operator=(ExternInfo &&) = delete; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_EXTERN_INFO_H_ */ diff --git a/backends/p4tools/modules/testgen/core/program_info.cpp b/backends/p4tools/modules/testgen/core/program_info.cpp index a36eede4fd..dc54052236 100644 --- a/backends/p4tools/modules/testgen/core/program_info.cpp +++ b/backends/p4tools/modules/testgen/core/program_info.cpp @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" #include "backends/p4tools/modules/testgen/lib/continuation.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { ProgramInfo::ProgramInfo(const TestgenCompilerResult &compilerResult) : compilerResult(compilerResult), concolicMethodImpls({}) { @@ -98,4 +98,4 @@ void ProgramInfo::produceCopyInOutCall(const IR::Parameter *param, size_t paramI } } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/program_info.h b/backends/p4tools/modules/testgen/core/program_info.h index c832af67c9..3dab814e97 100644 --- a/backends/p4tools/modules/testgen/core/program_info.h +++ b/backends/p4tools/modules/testgen/core/program_info.h @@ -15,7 +15,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" #include "backends/p4tools/modules/testgen/lib/continuation.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Stores target-specific information about a P4 program. class ProgramInfo : public ICastable { @@ -118,6 +118,6 @@ class ProgramInfo : public ICastable { DECLARE_TYPEINFO(ProgramInfo); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_PROGRAM_INFO_H_ */ diff --git a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp index b8e8dbb75e..c50784ffc7 100644 --- a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.cpp @@ -24,7 +24,7 @@ #include "backends/p4tools/modules/testgen/lib/continuation.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { AbstractStepper::AbstractStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -388,4 +388,4 @@ void AbstractStepper::declareBaseType(ExecutionState &nextState, const IR::State nextState.set(paramPath, programInfo.createTargetUninitialized(baseType, false)); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h index 6cfbfe6a0b..563f912e9d 100644 --- a/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h @@ -16,7 +16,7 @@ #include "backends/p4tools/modules/testgen/lib/continuation.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// A framework for implementing small-step operational semantics. Each instance is good for one /// small-step evaluation. @@ -177,6 +177,6 @@ class AbstractStepper : public Inspector { const IR::Type_Base *baseType) const; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_ABSTRACT_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp index 9ffb551e06..b68fd748dd 100644 --- a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.cpp @@ -40,7 +40,7 @@ #include "backends/p4tools/modules/testgen/lib/packet_vars.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { CmdStepper::CmdStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -548,4 +548,4 @@ bool CmdStepper::preorder(const IR::SwitchStatement *switchStatement) { return false; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h index c708519aff..14c13f45e4 100644 --- a/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/continuation.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Implements small-step operational semantics for commands. class CmdStepper : public AbstractStepper { @@ -57,6 +57,6 @@ class CmdStepper : public AbstractStepper { const ExecutionState &state) const = 0; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_CMD_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/core/small_step/expr_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/expr_stepper.cpp index da915338ff..4c4e71d79b 100644 --- a/backends/p4tools/modules/testgen/core/small_step/expr_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/expr_stepper.cpp @@ -31,7 +31,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { ExprStepper::ExprStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -520,4 +520,4 @@ void ExprStepper::stepNoMatch(std::string traceLog, const IR::Expression *condit } } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/small_step/expr_stepper.h b/backends/p4tools/modules/testgen/core/small_step/expr_stepper.h index aef124c854..6023d9948f 100644 --- a/backends/p4tools/modules/testgen/core/small_step/expr_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/expr_stepper.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/core/small_step/abstract_stepper.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Implements small-step operational semantics for expressions. class ExprStepper : public AbstractStepper { @@ -296,6 +296,6 @@ class ExprStepper : public AbstractStepper { bool preorder(const IR::P4Table *table) override; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_EXPR_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp index 949e2f0611..2b8b9ae408 100644 --- a/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/extern_stepper.cpp @@ -30,7 +30,7 @@ #include "backends/p4tools/modules/testgen/lib/packet_vars.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { std::vector> ExprStepper::setFields( ExecutionState &nextState, const std::vector &flatFields, @@ -925,4 +925,4 @@ void ExprStepper::evalExternMethodCall(const ExternInfo &externInfo) { return evalInternalExternMethodCall(externInfo); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/small_step/small_step.cpp b/backends/p4tools/modules/testgen/core/small_step/small_step.cpp index f45381e81b..d3d094a129 100644 --- a/backends/p4tools/modules/testgen/core/small_step/small_step.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/small_step.cpp @@ -28,7 +28,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { SmallStepEvaluator::Branch::Branch(ExecutionState &nextState) : constraint(IR::BoolLiteral::get(true)), nextState(nextState) {} @@ -218,7 +218,7 @@ class CommandVisitor { if (solverResult == std::nullopt || !solverResult.value()) { std::stringstream condStream; guard.cond->dbprint(condStream); - ::warning( + ::P4::warning( "Guard %1% was not satisfiable." " Incrementing number of guard violations.", condStream.str().c_str()); @@ -244,4 +244,4 @@ SmallStepEvaluator::Result SmallStepEvaluator::step(ExecutionState &state) { return new std::vector({Branch(state)}); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/small_step/small_step.h b/backends/p4tools/modules/testgen/core/small_step/small_step.h index d01268200d..bf9df0c0c4 100644 --- a/backends/p4tools/modules/testgen/core/small_step/small_step.h +++ b/backends/p4tools/modules/testgen/core/small_step/small_step.h @@ -15,7 +15,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// The main class that implements small-step operational semantics. Delegates to implementations /// of AbstractStepper. @@ -79,6 +79,6 @@ class SmallStepEvaluator { SmallStepEvaluator(AbstractSolver &solver, const ProgramInfo &programInfo); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_SMALL_STEP_H_ */ diff --git a/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp b/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp index eab57bc4ea..88ef436bc9 100644 --- a/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/core/small_step/table_stepper.cpp @@ -36,7 +36,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { const ExecutionState *TableStepper::getExecutionState() { return &stepper->state; } @@ -580,4 +580,4 @@ TableStepper::TableStepper(ExprStepper *stepper, const IR::P4Table *table) } } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/small_step/table_stepper.h b/backends/p4tools/modules/testgen/core/small_step/table_stepper.h index 19d05e256c..24f38f9868 100644 --- a/backends/p4tools/modules/testgen/core/small_step/table_stepper.h +++ b/backends/p4tools/modules/testgen/core/small_step/table_stepper.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Implements small-step operational semantics for tables. class TableStepper { @@ -151,6 +151,6 @@ class TableStepper { virtual ~TableStepper() = default; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SMALL_STEP_TABLE_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp index 7a23fe6ffd..81cdd84ee1 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.cpp @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { DepthFirstSearch::DepthFirstSearch(AbstractSolver &solver, const ProgramInfo &programInfo) : SymbolicExecutor(solver, programInfo) {} @@ -67,7 +67,7 @@ void DepthFirstSearch::runImpl(const Callback &callBack, ExecutionStateReference throw; } // Otherwise we try to roll back as we typically do. - ::warning("Path encountered unimplemented feature. Message: %1%\n", e.what()); + ::P4::warning("Path encountered unimplemented feature. Message: %1%\n", e.what()); } // Roll back to a previous branch and continue execution from there, but if there are no @@ -84,4 +84,4 @@ void DepthFirstSearch::runImpl(const Callback &callBack, ExecutionStateReference } } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h index f4140119ac..2b6db2ce2f 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/depth_first.h @@ -8,7 +8,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// A simple depth-first traversal strategy. /// If this selection strategy hits a branch point, it will choose a path at random and continue @@ -45,6 +45,6 @@ class DepthFirstSearch : public SymbolicExecutor { [[nodiscard]] std::optional pickSuccessor(StepResult successors); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_DEPTH_FIRST_H_ */ diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.cpp index 4f6334db3b..5945d9df84 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.cpp @@ -16,7 +16,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { GreedyNodeSelection::GreedyNodeSelection(AbstractSolver &solver, const ProgramInfo &programInfo) : SymbolicExecutor(solver, programInfo) {} @@ -109,7 +109,7 @@ void GreedyNodeSelection::runImpl(const Callback &callBack, throw; } // Otherwise we try to roll back as we typically do. - ::warning("Path encountered unimplemented feature. Message: %1%\n", e.what()); + ::P4::warning("Path encountered unimplemented feature. Message: %1%\n", e.what()); } // Roll back to a previous branch and continue execution from there, but if there are no @@ -135,4 +135,4 @@ void GreedyNodeSelection::runImpl(const Callback &callBack, } } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.h b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.h index 8c4f1c45f6..48de815c95 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/greedy_node_cov.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Greedy path selection strategy, which, at branch points, picks the first execution state which /// has covered or potentially will cover program nodes which have not been visited yet. @@ -77,6 +77,6 @@ class GreedyNodeSelection : public SymbolicExecutor { [[nodiscard]] std::optional pickSuccessor(StepResult successors); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_GREEDY_NODE_COV_H_ */ diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/path_selection.h b/backends/p4tools/modules/testgen/core/symbolic_executor/path_selection.h index c5300c2235..74788a3673 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/path_selection.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/path_selection.h @@ -3,7 +3,7 @@ #include -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { enum class PathSelectionPolicy { DepthFirst, @@ -16,6 +16,6 @@ inline bool requiresLookahead(PathSelectionPolicy &pathSelectionPolicy) { return LOOKAHEAD_STRATEGYIES.find(pathSelectionPolicy) != LOOKAHEAD_STRATEGYIES.end(); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_PATH_SELECTION_H_ */ diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp index 3b7bfd49e2..3fbb356a81 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.cpp @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { RandomBacktrack::RandomBacktrack(AbstractSolver &solver, const ProgramInfo &programInfo) : SymbolicExecutor(solver, programInfo) {} @@ -62,7 +62,7 @@ void RandomBacktrack::runImpl(const Callback &callBack, ExecutionStateReference throw; } // Otherwise we try to roll back as we typically do. - ::warning("Path encountered unimplemented feature. Message: %1%\n", e.what()); + ::P4::warning("Path encountered unimplemented feature. Message: %1%\n", e.what()); } // Roll back to a previous branch and continue execution from there, but if there are no @@ -78,4 +78,4 @@ void RandomBacktrack::runImpl(const Callback &callBack, ExecutionStateReference } } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h index 838f2ff653..5d05adc188 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/random_backtrack.h @@ -8,7 +8,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// A simple random traversal strategy. /// If this selection strategy hits a branch point, it will choose a path at random and continue @@ -45,6 +45,6 @@ class RandomBacktrack : public SymbolicExecutor { [[nodiscard]] std::optional pickSuccessor(StepResult successors); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_RANDOM_BACKTRACK_H_ */ diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.cpp index 58af2fe346..5e4eea35e9 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.cpp @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { void SelectedBranches::runImpl(const Callback &callBack, ExecutionStateReference executionState) { try { @@ -34,7 +34,7 @@ void SelectedBranches::runImpl(const Callback &callBack, ExecutionStateReference } if (selectedBranches.empty()) { // Not enough steps in the input selected branches string, cannot continue. - ::warning("The selected path is incomplete, not emitting a testcase."); + ::P4::warning("The selected path is incomplete, not emitting a testcase."); break; } // If there are multiple, pop one branch decision from the input list and pick @@ -51,7 +51,7 @@ void SelectedBranches::runImpl(const Callback &callBack, ExecutionStateReference // We've reached the end of the program. Call back and end execution. handleTerminalState(callBack, executionState); if (!selectedBranches.empty()) { - ::warning( + ::P4::warning( "Execution reached a final state before executing whole " "selected path!"); } @@ -101,9 +101,9 @@ ExecutionState *SelectedBranches::chooseBranch(const std::vector &branch } } // If not found, the input selected branch list is invalid. - ::error("The selected branches string doesn't match any branch."); + ::P4::error("The selected branches string doesn't match any branch."); return nullptr; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h b/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h index 8c691c98e3..d1130fc135 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/selected_branches.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Explores one path described by a list of branches. class SelectedBranches : public SymbolicExecutor { @@ -36,6 +36,6 @@ class SelectedBranches : public SymbolicExecutor { std::list selectedBranches; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_SELECTED_BRANCHES_H_ */ diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp index 0f81d1fff4..0c718a0a2b 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.cpp @@ -20,7 +20,7 @@ #include "backends/p4tools/modules/testgen/lib/final_state.h" #include "backends/p4tools/modules/testgen/lib/logging.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { SymbolicExecutor::StepResult SymbolicExecutor::step(ExecutionState &state) { StepResult successors = nullptr; @@ -47,12 +47,12 @@ bool SymbolicExecutor::handleTerminalState(const Callback &callback, // a warning and continue on a different path. auto solverResult = solver.checkSat(terminalState.getPathConstraint()); if (!solverResult) { - ::warning("Solver timed out"); + ::P4::warning("Solver timed out"); return false; } if (!*solverResult) { - ::warning("Path constraints unsatisfiable"); + ::P4::warning("Path constraints unsatisfiable"); return false; } @@ -74,7 +74,7 @@ bool SymbolicExecutor::evaluateBranch(const SymbolicExecutor::Branch &branch, // Check the consistency of the path constraints asserted so far. auto solverResult = solver.checkSat(branch.nextState.get().getPathConstraint()); if (solverResult == std::nullopt) { - ::warning("Solver timed out"); + ::P4::warning("Solver timed out"); } return solverResult.value_or(false); } @@ -126,4 +126,4 @@ void SymbolicExecutor::printCurrentTraceAndBranches(std::ostream &out, out << strBranches << ")"; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h index d3186b8189..3da7935f0c 100644 --- a/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h +++ b/backends/p4tools/modules/testgen/core/symbolic_executor/symbolic_executor.h @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/lib/final_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Base abstract class for symbolic execution. It requires the implementation of /// the run method, and carries the base Branch struct, to be reused in inherited @@ -93,6 +93,6 @@ class SymbolicExecutor { SmallStepEvaluator evaluator; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_SYMBOLIC_EXECUTOR_SYMBOLIC_EXECUTOR_H_ */ diff --git a/backends/p4tools/modules/testgen/core/target.cpp b/backends/p4tools/modules/testgen/core/target.cpp index 72af998ec2..439d62a0ab 100644 --- a/backends/p4tools/modules/testgen/core/target.cpp +++ b/backends/p4tools/modules/testgen/core/target.cpp @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/toolname.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { TestgenTarget::TestgenTarget(const std::string &deviceName, const std::string &archName) : CompilerTarget(TOOL_NAME, deviceName, archName) {} @@ -88,4 +88,4 @@ CompilerResultOrError TestgenTarget::runCompilerImpl(const CompilerOptions &opti *new TestgenCompilerResult(CompilerResult(*program), coverage.getCoverableNodes(), dcg)}; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/core/target.h b/backends/p4tools/modules/testgen/core/target.h index 38342a2b28..a7fa162aa6 100644 --- a/backends/p4tools/modules/testgen/core/target.h +++ b/backends/p4tools/modules/testgen/core/target.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/lib/test_backend.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { class TestgenTarget : public CompilerTarget { public: @@ -67,6 +67,6 @@ class TestgenTarget : public CompilerTarget { const IR::P4Program *program) const override; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_CORE_TARGET_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.cpp b/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.cpp index 4e15bc1877..66c9d3dbcc 100644 --- a/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.cpp +++ b/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.cpp @@ -15,7 +15,7 @@ #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { bool CoverableNodesScanner::preorder(const IR::ParserState *parserState) { // Already have seen this executionState. We might be in a loop. @@ -155,4 +155,4 @@ void CoverableNodesScanner::updateNodeCoverage(const IR::Node *node, CoverableNodesScanner::CoverableNodesScanner(const ExecutionState &state) : state(state), coverageOptions(TestgenOptions::get().coverageOptions) {} -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.h b/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.h index 1a2005615c..5d9d3253bd 100644 --- a/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.h +++ b/backends/p4tools/modules/testgen/lib/collect_coverable_nodes.h @@ -9,7 +9,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// A cache of already computed nodes to avoid superfluous computation. using NodeCache = std::map; @@ -53,6 +53,6 @@ class CoverableNodesScanner : public Inspector { const P4::Coverage::CoverageSet &getCoverableNodes(); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /*BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_COLLECT_COVERABLE_NODES_H_*/ diff --git a/backends/p4tools/modules/testgen/lib/concolic.cpp b/backends/p4tools/modules/testgen/lib/concolic.cpp index 5cbbd94934..3a5bd82a51 100644 --- a/backends/p4tools/modules/testgen/lib/concolic.cpp +++ b/backends/p4tools/modules/testgen/lib/concolic.cpp @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { bool ConcolicMethodImpls::matches(const std::vector ¶mNames, const IR::Vector *args) { @@ -131,4 +131,4 @@ const ConcolicMethodImpls::ImplList *Concolic::getCoreConcolicMethodImpls() { return &CORE_CONCOLIC_METHOD_IMPLS; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/concolic.h b/backends/p4tools/modules/testgen/lib/concolic.h index f7040cab2b..9bc894f014 100644 --- a/backends/p4tools/modules/testgen/lib/concolic.h +++ b/backends/p4tools/modules/testgen/lib/concolic.h @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// TODO: This is a very ugly data structure. Essentially, you can store both state variables /// and entire expression as keys. State variables can actually compared, expressions are always @@ -88,6 +88,6 @@ class Concolic { static const ConcolicMethodImpls::ImplList *getCoreConcolicMethodImpls(); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_CONCOLIC_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/continuation.cpp b/backends/p4tools/modules/testgen/lib/continuation.cpp index 91b19d3dc0..45180563fc 100644 --- a/backends/p4tools/modules/testgen/lib/continuation.cpp +++ b/backends/p4tools/modules/testgen/lib/continuation.cpp @@ -9,7 +9,7 @@ #include "ir/visitor.h" #include "lib/exceptions.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { Continuation::Return::Return(const IR::Node *expr) : expr(expr) {} @@ -169,4 +169,4 @@ const Continuation::Parameter *Continuation::genParameter(const IR::Type *type, return new Parameter(new IR::PathExpression(type, new IR::Path(varName))); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/continuation.h b/backends/p4tools/modules/testgen/lib/continuation.h index 9c8ec0843c..18832ae245 100644 --- a/backends/p4tools/modules/testgen/lib/continuation.h +++ b/backends/p4tools/modules/testgen/lib/continuation.h @@ -18,11 +18,11 @@ #include "ir/node.h" #include "lib/cstring.h" -namespace Test { +namespace P4::Test { class SmallStepTest; -} // namespace Test +} // namespace P4::Test -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// A continuation is a function that optionally takes an argument and executes a sequence of /// commands. @@ -204,6 +204,6 @@ class Continuation { body(std::move(body)) {} }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_CONTINUATION_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/exceptions.h b/backends/p4tools/modules/testgen/lib/exceptions.h index 4443a3a9fe..8e6d7001df 100644 --- a/backends/p4tools/modules/testgen/lib/exceptions.h +++ b/backends/p4tools/modules/testgen/lib/exceptions.h @@ -4,7 +4,7 @@ #include "absl/strings/str_cat.h" #include "lib/exceptions.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// This class indicates a feature that is not implemented in P4Testgen. /// Paths with this unimplemented feature should be skipped @@ -33,6 +33,6 @@ class TestgenUnimplemented final : public Util::P4CExceptionBase { throw TestgenUnimplemented(__LINE__, __FILE__, __VA_ARGS__); \ } while (0) -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXCEPTIONS_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/execution_state.cpp b/backends/p4tools/modules/testgen/lib/execution_state.cpp index c0dfd7dfa9..c6d743b195 100644 --- a/backends/p4tools/modules/testgen/lib/execution_state.cpp +++ b/backends/p4tools/modules/testgen/lib/execution_state.cpp @@ -34,7 +34,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /* ============================================================================================= * Constructors @@ -548,4 +548,4 @@ const IR::SymbolicVariable *ExecutionState::createPacketVariable(const IR::Type return variable; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/execution_state.h b/backends/p4tools/modules/testgen/lib/execution_state.h index 92e33b2118..172ef5e7f8 100644 --- a/backends/p4tools/modules/testgen/lib/execution_state.h +++ b/backends/p4tools/modules/testgen/lib/execution_state.h @@ -28,7 +28,7 @@ #include "backends/p4tools/modules/testgen/lib/continuation.h" #include "backends/p4tools/modules/testgen/lib/test_object.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Represents state of execution after having reached a program point. class ExecutionState : public AbstractExecutionState { @@ -408,6 +408,6 @@ class ExecutionState : public AbstractExecutionState { using ExecutionStateReference = std::reference_wrapper; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_EXECUTION_STATE_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/final_state.cpp b/backends/p4tools/modules/testgen/lib/final_state.cpp index c21069db95..633e7817a5 100644 --- a/backends/p4tools/modules/testgen/lib/final_state.cpp +++ b/backends/p4tools/modules/testgen/lib/final_state.cpp @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/lib/packet_vars.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { FinalState::FinalState(AbstractSolver &solver, const ExecutionState &finalState) : solver(solver), @@ -90,12 +90,12 @@ std::optional> FinalState::computeConco } auto solverResult = solver.get().checkSat(asserts); if (!solverResult) { - ::warning("Timed out trying to solve this concolic execution path."); + ::P4::warning("Timed out trying to solve this concolic execution path."); return std::nullopt; } if (!*solverResult) { - ::warning("Concolic constraints for this path are unsatisfiable."); + ::P4::warning("Concolic constraints for this path are unsatisfiable."); return std::nullopt; } auto &model = processModel(state, *new Model(solver.get().getSymbolicMapping()), false); @@ -116,4 +116,4 @@ const std::vector> *FinalState::getTrac } const P4::Coverage::CoverageSet &FinalState::getVisited() const { return state.get().getVisited(); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/final_state.h b/backends/p4tools/modules/testgen/lib/final_state.h index 76924977e9..88f989337e 100644 --- a/backends/p4tools/modules/testgen/lib/final_state.h +++ b/backends/p4tools/modules/testgen/lib/final_state.h @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Represents the final state after execution. class FinalState { @@ -75,6 +75,6 @@ class FinalState { [[nodiscard]] const P4::Coverage::CoverageSet &getVisited() const; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_FINAL_STATE_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/logging.cpp b/backends/p4tools/modules/testgen/lib/logging.cpp index ba1ab354fa..69db5dcb78 100644 --- a/backends/p4tools/modules/testgen/lib/logging.cpp +++ b/backends/p4tools/modules/testgen/lib/logging.cpp @@ -3,12 +3,12 @@ #include "lib/log.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { -void enableTraceLogging() { ::Log::addDebugSpec("test_traces:4"); } +void enableTraceLogging() { ::P4::Log::addDebugSpec("test_traces:4"); } -void enableStepLogging() { ::Log::addDebugSpec("small_step:4"); } +void enableStepLogging() { ::P4::Log::addDebugSpec("small_step:4"); } -void enableCoverageLogging() { ::Log::addDebugSpec("coverage:4"); } +void enableCoverageLogging() { ::P4::Log::addDebugSpec("coverage:4"); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/logging.h b/backends/p4tools/modules/testgen/lib/logging.h index fd6b6cba50..61fcb354e2 100644 --- a/backends/p4tools/modules/testgen/lib/logging.h +++ b/backends/p4tools/modules/testgen/lib/logging.h @@ -7,7 +7,7 @@ #include "backends/p4tools/common/lib/logging.h" // IWYU pragma: export #include "backends/p4tools/common/lib/util.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Helper functions that prints strings associated with verbose test information, for example /// traces, or the test values themselves. @@ -25,6 +25,6 @@ void enableStepLogging(); /// Enable printing of the statement coverage statistics the interpreter collects. void enableCoverageLogging(); -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_LOGGING_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/packet_vars.cpp b/backends/p4tools/modules/testgen/lib/packet_vars.cpp index 162a8d7007..a4acc37402 100644 --- a/backends/p4tools/modules/testgen/lib/packet_vars.cpp +++ b/backends/p4tools/modules/testgen/lib/packet_vars.cpp @@ -2,7 +2,7 @@ #include "ir/id.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { using namespace P4::literals; @@ -22,4 +22,4 @@ const IR::Member PacketVars::EMIT_BUFFER_LABEL = const IR::SymbolicVariable PacketVars::PAYLOAD_SYMBOL = IR::SymbolicVariable(&PacketVars::PACKET_SIZE_VAR_TYPE, "*payload"_cs); -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/packet_vars.h b/backends/p4tools/modules/testgen/lib/packet_vars.h index 2e773e37e7..68046e29d4 100644 --- a/backends/p4tools/modules/testgen/lib/packet_vars.h +++ b/backends/p4tools/modules/testgen/lib/packet_vars.h @@ -3,7 +3,7 @@ #include "ir/ir.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Contains utility functions and variables related to the creation and manipulation of input /// packets. @@ -33,6 +33,6 @@ class PacketVars { static const IR::SymbolicVariable PAYLOAD_SYMBOL; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_PACKET_VARS_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/test_backend.cpp b/backends/p4tools/modules/testgen/lib/test_backend.cpp index 9433697263..3ad3e7953b 100644 --- a/backends/p4tools/modules/testgen/lib/test_backend.cpp +++ b/backends/p4tools/modules/testgen/lib/test_backend.cpp @@ -25,7 +25,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { TestBackEnd::TestBackEnd(const ProgramInfo &programInfo, const TestBackendConfiguration &testBackendConfiguration, @@ -282,4 +282,4 @@ bool TestBackEnd::needsToTerminate(int64_t testCount) const { // possible. return maxTests != 0 && testCount >= maxTests; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/test_backend.h b/backends/p4tools/modules/testgen/lib/test_backend.h index 3a26b02ae4..9a01f13196 100644 --- a/backends/p4tools/modules/testgen/lib/test_backend.h +++ b/backends/p4tools/modules/testgen/lib/test_backend.h @@ -18,7 +18,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { class TestBackEnd { private: @@ -133,6 +133,6 @@ class TestBackEnd { [[nodiscard]] const AbstractTestList &getTests() const { return tests; } }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_BACKEND_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/test_backend_configuration.h b/backends/p4tools/modules/testgen/lib/test_backend_configuration.h index 79dd06a8f1..3120ee22e5 100644 --- a/backends/p4tools/modules/testgen/lib/test_backend_configuration.h +++ b/backends/p4tools/modules/testgen/lib/test_backend_configuration.h @@ -6,7 +6,7 @@ #include "lib/cstring.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// A file path which may not be set. using OptionalFilePath = std::optional; @@ -28,6 +28,6 @@ struct TestBackendConfiguration { std::optional seed; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_BACKEND_CONFIGURATION_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/test_framework.cpp b/backends/p4tools/modules/testgen/lib/test_framework.cpp index ba9c2d3058..5bfe832247 100644 --- a/backends/p4tools/modules/testgen/lib/test_framework.cpp +++ b/backends/p4tools/modules/testgen/lib/test_framework.cpp @@ -2,7 +2,7 @@ #include "backends/p4tools/modules/testgen/lib/exceptions.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { TestFramework::TestFramework(const TestBackendConfiguration &testBackendConfiguration) : testBackendConfiguration(testBackendConfiguration) {} @@ -22,4 +22,4 @@ AbstractTestReferenceOrError TestFramework::produceTest(const TestSpec * /*spec* TESTGEN_UNIMPLEMENTED("produceTest() not implemented for this test framework."); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/test_framework.h b/backends/p4tools/modules/testgen/lib/test_framework.h index 229edeee7c..0ab85bf8dd 100644 --- a/backends/p4tools/modules/testgen/lib/test_framework.h +++ b/backends/p4tools/modules/testgen/lib/test_framework.h @@ -21,7 +21,7 @@ #include "backends/p4tools/modules/testgen/lib/test_object.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { using namespace P4::literals; @@ -188,6 +188,6 @@ class TestFramework { [[nodiscard]] bool isInFileMode() const; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_FRAMEWORK_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/test_object.h b/backends/p4tools/modules/testgen/lib/test_object.h index 6752634b46..d2f888f853 100644 --- a/backends/p4tools/modules/testgen/lib/test_object.h +++ b/backends/p4tools/modules/testgen/lib/test_object.h @@ -6,7 +6,7 @@ #include "lib/castable.h" #include "lib/cstring.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /* ========================================================================================= * Abstract Test Object Class @@ -34,6 +34,6 @@ class TestObject : public ICastable { /// A map of test objects. using TestObjectMap = ordered_map; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_OBJECT_H_ */ diff --git a/backends/p4tools/modules/testgen/lib/test_spec.cpp b/backends/p4tools/modules/testgen/lib/test_spec.cpp index 2bff6db08f..087cde08ec 100644 --- a/backends/p4tools/modules/testgen/lib/test_spec.cpp +++ b/backends/p4tools/modules/testgen/lib/test_spec.cpp @@ -14,7 +14,7 @@ #include "lib/exceptions.h" #include "lib/ordered_map.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { using namespace P4::literals; @@ -308,4 +308,4 @@ TestObjectMap TestSpec::getTestObjectCategory(cstring category) const { return {}; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/lib/test_spec.h b/backends/p4tools/modules/testgen/lib/test_spec.h index 207fbb7678..dbe4443979 100644 --- a/backends/p4tools/modules/testgen/lib/test_spec.h +++ b/backends/p4tools/modules/testgen/lib/test_spec.h @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/lib/test_object.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// This file defines a series of test objects which, in sum, produce an abstract test /// specification. @@ -355,6 +355,6 @@ class TestSpec { static constexpr int TTL = 0; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_LIB_TEST_SPEC_H_ */ diff --git a/backends/p4tools/modules/testgen/main.cpp b/backends/p4tools/modules/testgen/main.cpp index cd5ca9f868..8e1745811a 100644 --- a/backends/p4tools/modules/testgen/main.cpp +++ b/backends/p4tools/modules/testgen/main.cpp @@ -9,6 +9,8 @@ #include "backends/p4tools/modules/testgen/testgen.h" #include "backends/p4tools/modules/testgen/toolname.h" +using namespace P4; + std::string updateErrorMsg(std::string errorMsg) { for (const std::string_view toReplace : {"Compiler", "compiler"}) { if (const auto pos = errorMsg.find(toReplace); pos != std::string::npos) { diff --git a/backends/p4tools/modules/testgen/options.cpp b/backends/p4tools/modules/testgen/options.cpp index be2d9e91f9..34f720d0eb 100644 --- a/backends/p4tools/modules/testgen/options.cpp +++ b/backends/p4tools/modules/testgen/options.cpp @@ -15,7 +15,7 @@ #include "backends/p4tools/modules/testgen/lib/logging.h" #include "backends/p4tools/modules/testgen/toolname.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { using namespace P4::literals; @@ -51,7 +51,8 @@ TestgenOptions::TestgenOptions() throw std::invalid_argument("Invalid input."); } } catch (std::invalid_argument &) { - ::error("Invalid input value %1% for --max-tests. Expected positive integer.", arg); + ::P4::error("Invalid input value %1% for --max-tests. Expected positive integer.", + arg); return false; } return true; @@ -64,7 +65,7 @@ TestgenOptions::TestgenOptions() [this](const char *arg) { stopMetric = cstring(arg).toUpper(); if (SUPPORTED_STOP_METRICS.count(stopMetric) == 0) { - ::error( + ::P4::error( "Stop metric %1% not supported. Supported stop metrics are " "%2%.", stopMetric, Utils::containerToString(SUPPORTED_STOP_METRICS)); @@ -84,20 +85,20 @@ TestgenOptions::TestgenOptions() auto minPacketLenStr = rangeStr.substr(0, packetLenStr); minPktSize = std::stoi(minPacketLenStr); if (minPktSize < 0) { - ::error( + ::P4::error( "Invalid minimum packet size %1%. Minimum packet size must be at least 0.", minPktSize); } auto maxPacketLenStr = rangeStr.substr(packetLenStr + 1); maxPktSize = std::stoi(maxPacketLenStr); if (maxPktSize < minPktSize) { - ::error( + ::P4::error( "Invalid packet size range %1%:%2%. The maximum packet size must be at " "least the size of the minimum packet size.", minPktSize, maxPktSize); } } catch (std::invalid_argument &) { - ::error( + ::P4::error( "Invalid packet size range %1%. Expected format is [min]:[max], where [min] " "and [max] are integers.", arg); @@ -123,7 +124,7 @@ TestgenOptions::TestgenOptions() auto loPortStr = rangeStr.substr(0, portStr); auto loPortRange = std::stoi(loPortStr); if (loPortRange < 0) { - ::error( + ::P4::error( "Invalid low port value %1%. low port value must be at " "least " "0.", @@ -132,7 +133,7 @@ TestgenOptions::TestgenOptions() auto hiPortStr = rangeStr.substr(portStr + 1); auto hiPortRange = std::stoi(hiPortStr); if (hiPortRange < loPortRange) { - ::error( + ::P4::error( "Invalid permitted port range %1%:%2%. The high port value must " "be " "at " @@ -141,7 +142,7 @@ TestgenOptions::TestgenOptions() } permittedPortRanges.emplace_back(loPortRange, hiPortRange); } catch (std::invalid_argument &) { - ::error( + ::P4::error( "Invalid permitted port range %1%. Expected format is [lo]:[hi], where " "[lo] " "and [hi] are integers.", @@ -197,7 +198,7 @@ TestgenOptions::TestgenOptions() selectedBranches = arg; // These options are mutually exclusive. if (trackBranches) { - ::error( + ::P4::error( "--input-branches and --track-branches are mutually exclusive. Choose " "one or the other."); return false; @@ -212,7 +213,7 @@ TestgenOptions::TestgenOptions() trackBranches = true; // These options are mutually exclusive. if (!selectedBranches.empty()) { - ::error( + ::P4::error( "--input-branches and --track-branches are mutually exclusive. Choose " "one or the other."); return false; @@ -227,7 +228,7 @@ TestgenOptions::TestgenOptions() [this](const char *) { outputPacketOnly = true; if (!selectedBranches.empty()) { - ::error( + ::P4::error( "--input-branches cannot guarantee --output-packet-only." " Aborting."); return false; @@ -241,7 +242,7 @@ TestgenOptions::TestgenOptions() [this](const char *) { droppedPacketOnly = true; if (!selectedBranches.empty()) { - ::error( + ::P4::error( "--input-branches cannot guarantee --dropped-packet-only." " Aborting."); return false; @@ -272,7 +273,7 @@ TestgenOptions::TestgenOptions() [](const std::pair &mapTuple) { return mapTuple.first; }); - ::error( + ::P4::error( "Path selection policy %1% not supported. Supported path selection policies are " "%2%.", selectionString, Utils::containerToString(printSet)); @@ -304,7 +305,7 @@ TestgenOptions::TestgenOptions() return true; } } - ::error( + ::P4::error( "Coverage tracking for label %1% not supported. Supported coverage tracking " "options are " "%2%.", @@ -334,7 +335,7 @@ TestgenOptions::TestgenOptions() throw std::invalid_argument("Invalid input."); } } catch (std::invalid_argument &) { - ::error( + ::P4::error( "Invalid input value %1% for --assert-min-coverage. " "Expected float in range [0, 1].", arg); @@ -426,7 +427,7 @@ TestgenOptions::TestgenOptions() bool TestgenOptions::validateOptions() const { if (minCoverage > 0 && !hasCoverageTracking) { - ::error( + ::P4::error( ErrorType::ERR_INVALID, "It is not allowed to have --assert-min-coverage set to non-zero without a coverage " "tracking enabled with --track-coverage option. Without coverage tracking, the " @@ -436,4 +437,4 @@ bool TestgenOptions::validateOptions() const { return true; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/options.h b/backends/p4tools/modules/testgen/options.h index 9d8ae04fc5..f074b6c2e4 100644 --- a/backends/p4tools/modules/testgen/options.h +++ b/backends/p4tools/modules/testgen/options.h @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/core/symbolic_executor/path_selection.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Encapsulates and processes command-line options for P4Testgen. class TestgenOptions : public AbstractP4cToolOptions { @@ -111,6 +111,6 @@ class TestgenOptions : public AbstractP4cToolOptions { TestgenOptions(); }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_OPTIONS_H_ */ diff --git a/backends/p4tools/modules/testgen/register.h.in b/backends/p4tools/modules/testgen/register.h.in index 27cef142a5..51fbf9d086 100644 --- a/backends/p4tools/modules/testgen/register.h.in +++ b/backends/p4tools/modules/testgen/register.h.in @@ -3,11 +3,11 @@ @include_statements_var@ -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { inline void registerTestgenTargets() { @testgen_targets_var@} -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_REGISTER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp index 02d6e13269..72a1c647f0 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.cpp @@ -30,7 +30,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/constants.h" #include "backends/p4tools/modules/testgen/targets/bmv2/program_info.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { Bmv2V1ModelCmdStepper::Bmv2V1ModelCmdStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -129,7 +129,7 @@ std::map Bmv2V1ModelCmdStepper::getExcept // Would also need to augment ProgramInfo to detect whether the ingress MAU refers // to parser_err. - ::warning("Ingress parser exception handler not fully implemented"); + ::P4::warning("Ingress parser exception handler not fully implemented"); result.emplace(Continuation::Exception::Reject, Continuation::Body({})); result.emplace( Continuation::Exception::PacketTooShort, @@ -152,4 +152,4 @@ std::map Bmv2V1ModelCmdStepper::getExcept return result; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h index dfdf4638ea..03e29e4371 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/cmd_stepper.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/targets/bmv2/program_info.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class Bmv2V1ModelCmdStepper : public CmdStepper { protected: @@ -36,6 +36,6 @@ class Bmv2V1ModelCmdStepper : public CmdStepper { const ProgramInfo &programInfo); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_CMD_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.cpp b/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.cpp index 350baf6451..ceb21e8b02 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.cpp @@ -21,7 +21,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.h" #include "backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { BMv2V1ModelCompilerResult::BMv2V1ModelCompilerResult(TestgenCompilerResult compilerResult, P4::P4RuntimeAPI p4runtimeApi, @@ -42,4 +42,4 @@ const DirectExternMap &BMv2V1ModelCompilerResult::getDirectExternMap() const { return directExternMap; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.h b/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.h index e4a44af9a8..87995cf62e 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/compiler_result.h @@ -10,7 +10,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.h" #include "backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// Extends the CompilerResult with information specific to the V1Model running on BMv2. class BMv2V1ModelCompilerResult : public TestgenCompilerResult { @@ -44,6 +44,6 @@ class BMv2V1ModelCompilerResult : public TestgenCompilerResult { DECLARE_TYPEINFO(BMv2V1ModelCompilerResult, TestgenCompilerResult); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_COMPILER_RESULT_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/concolic.cpp b/backends/p4tools/modules/testgen/targets/bmv2/concolic.cpp index 2c37bf3e09..36533635cd 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/concolic.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/concolic.cpp @@ -26,7 +26,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/lib/packet_vars.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { using namespace P4::literals; @@ -294,4 +294,4 @@ std::ostream &operator<<(std::ostream &os, Bmv2HashAlgorithm algo) { return os << "INVALID [" << int(algo) << "]"; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/concolic.h b/backends/p4tools/modules/testgen/targets/bmv2/concolic.h index 1bb49c2f2d..686fbf931b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/concolic.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/concolic.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { enum class Bmv2HashAlgorithm { crc32, @@ -52,6 +52,6 @@ class Bmv2Concolic : public Concolic { static const ConcolicMethodImpls::ImplList *getBmv2ConcolicMethodImpls(); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_CONCOLIC_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/constants.cpp b/backends/p4tools/modules/testgen/targets/bmv2/constants.cpp index e21a718bd5..22ff9fc89c 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/constants.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/constants.cpp @@ -1,3 +1,3 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/constants.h" -namespace P4Tools::P4Testgen::Bmv2 {} // namespace P4Tools::P4Testgen::Bmv2 +namespace P4::P4Tools::P4Testgen::Bmv2 {} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/constants.h b/backends/p4tools/modules/testgen/targets/bmv2/constants.h index 747c40b483..6f256ba908 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/constants.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/constants.h @@ -3,7 +3,7 @@ #include -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { enum bmv2_gress_t { BMV2_INGRESS, BMV2_EGRESS }; @@ -43,6 +43,6 @@ class BMv2Constants { static constexpr int DROP_PORT = 511; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_CONSTANTS_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp b/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp index 30bc69d19b..83d953d71b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.cpp @@ -40,7 +40,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/table_stepper.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { std::string Bmv2V1ModelExprStepper::getClassName() { return "Bmv2V1ModelExprStepper"; } @@ -777,7 +777,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls const IR::StateVariable &meterResult = ToolsVariables::convertReference(externInfo.externArguments.at(1)->expression); if (testBackend != "PTF") { - ::warning( + ::P4::warning( "meter.execute_meter not implemented for %1%. Choosing default value (GREEN).", testBackend); auto &nextState = stepper.state.clone(); @@ -886,7 +886,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls // configuring the extern. We just set the default value (green). auto testBackend = TestgenOptions::get().testBackend; if (testBackend != "PTF" || tableEntry == nullptr) { - ::warning( + ::P4::warning( "direct_meter.read configuration not possible for %1%. Choosing default value " "(GREEN).", testBackend); @@ -966,7 +966,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls {"*method.digest"_cs, {"receiver"_cs, "data"_cs}, [](const ExternInfo & /*externInfo*/, Bmv2V1ModelExprStepper &stepper) { - ::warning("digest not fully implemented."); + ::P4::warning("digest not fully implemented."); auto &nextState = stepper.state.clone(); nextState.popBody(); stepper.result->emplace_back(nextState); @@ -1016,7 +1016,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls if (stepper.state.hasProperty("recirculate_count"_cs)) { if (stepper.state.getProperty("recirculate_count"_cs) > 0) { auto &nextState = stepper.state.clone(); - ::warning("Only single recirculation supported for now. Dropping packet."); + ::P4::warning("Only single recirculation supported for now. Dropping packet."); auto *dropStmt = new IR::MethodCallStatement( Utils::generateInternalMethodCall("drop_and_exit", {})); nextState.replaceTopBody(dropStmt); @@ -1031,7 +1031,8 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls } // If any of the input arguments is tainted, the entire extern is unreliable. if (argsAreTainted) { - ::warning("clone args are tainted and not predictable. Skipping clone execution."); + ::P4::warning( + "clone args are tainted and not predictable. Skipping clone execution."); auto &nextState = stepper.state.clone(); nextState.popBody(); stepper.result->emplace_back(nextState); @@ -1103,7 +1104,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls if (stepper.state.hasProperty("recirculate_count"_cs)) { recirculateCount = stepper.state.getProperty("recirculate_count"_cs); if (recirculateCount > 0) { - ::warning("Only single resubmit supported for now. Dropping packet."); + ::P4::warning("Only single resubmit supported for now. Dropping packet."); auto *dropStmt = new IR::MethodCallStatement( Utils::generateInternalMethodCall("drop_and_exit", {})); nextState.replaceTopBody(dropStmt); @@ -1164,7 +1165,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls if (stepper.state.hasProperty("recirculate_count"_cs)) { recirculateCount = stepper.state.getProperty("recirculate_count"_cs); if (recirculateCount > 0) { - ::warning("Only single recirculation supported for now. Dropping packet."); + ::P4::warning("Only single recirculation supported for now. Dropping packet."); auto *dropStmt = new IR::MethodCallStatement( Utils::generateInternalMethodCall("drop_and_exit", {})); nextState.replaceTopBody(dropStmt); @@ -1207,7 +1208,7 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls if (stepper.state.hasProperty("recirculate_count"_cs)) { if (stepper.state.getProperty("recirculate_count"_cs) > 0) { auto &nextState = stepper.state.clone(); - ::warning("Only single recirculation supported for now. Dropping packet."); + ::P4::warning("Only single recirculation supported for now. Dropping packet."); auto *dropStmt = new IR::MethodCallStatement( Utils::generateInternalMethodCall("drop_and_exit", {})); nextState.replaceTopBody(dropStmt); @@ -1222,7 +1223,8 @@ const Bmv2V1ModelExprStepper::ExternMethodImpls } // If any of the input arguments is tainted, the entire extern is unreliable. if (argsAreTainted) { - ::warning("clone args are tainted and not predictable. Skipping clone execution."); + ::P4::warning( + "clone args are tainted and not predictable. Skipping clone execution."); auto &nextState = stepper.state.clone(); nextState.popBody(); stepper.result->emplace_back(nextState); @@ -1644,4 +1646,4 @@ bool Bmv2V1ModelExprStepper::preorder(const IR::P4Table *table) { return tableStepper.eval(); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.h b/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.h index 1fa662ff44..cd2997c839 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/testgen/core/small_step/small_step.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class Bmv2V1ModelExprStepper : public ExprStepper { protected: @@ -51,6 +51,6 @@ class Bmv2V1ModelExprStepper : public ExprStepper { bool preorder(const IR::P4Table * /*table*/) override; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_EXPR_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.cpp b/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.cpp index ac2f3bd724..a15eaf947e 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.cpp @@ -6,7 +6,7 @@ #include "ir/ir.h" #include "lib/error.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { bool MapDirectExterns::preorder(const IR::Declaration_Instance *declInstance) { declaredExterns[declInstance->name] = declInstance; @@ -17,7 +17,7 @@ std::optional MapDirectExterns::getExternFromT const IR::Property *tableImplementation) { const auto *selectorExpr = tableImplementation->value->to(); if (selectorExpr == nullptr) { - ::error("Extern property is not an expression %1%", tableImplementation->value); + ::P4::error("Extern property is not an expression %1%", tableImplementation->value); return std::nullopt; } // If the extern expression is a constructor call it is not relevant. @@ -27,19 +27,19 @@ std::optional MapDirectExterns::getExternFromT // Try to find the extern in the declared instances. const auto *implPath = selectorExpr->expression->to(); if (implPath == nullptr) { - ::error("Invalid extern path %1%", selectorExpr->expression); + ::P4::error("Invalid extern path %1%", selectorExpr->expression); return std::nullopt; } // If the extern is not in the list of declared instances, move on. auto it = declaredExterns.find(implPath->path->name.name); if (it == declaredExterns.end()) { - ::error("Cannot find direct extern declaration %1%", implPath); + ::P4::error("Cannot find direct extern declaration %1%", implPath); return std::nullopt; } // BMv2 does not support direct externs attached to multiple tables. auto mappedTable = directExternMap.find(it->second->controlPlaneName()); if (mappedTable != directExternMap.end()) { - ::error( + ::P4::error( "Direct extern %1% was already mapped to table %2%. It can not be " "attached to two tables.", it->second, mappedTable->second); @@ -64,4 +64,4 @@ bool MapDirectExterns::preorder(const IR::P4Table *table) { const DirectExternMap &MapDirectExterns::getDirectExternMap() { return directExternMap; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.h b/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.h index 10262466e9..d0f5b2d90c 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/map_direct_externs.h @@ -9,7 +9,7 @@ #include "ir/visitor.h" #include "lib/cstring.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// A mapping of the control plane name of extern declarations which are associated with a table. /// Such an extern is referred to as direct extern. There can only be one extern associated with a @@ -45,6 +45,6 @@ class MapDirectExterns : public Inspector { const DirectExternMap &getDirectExternMap(); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /*BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_MAP_DIRECT_EXTERNS_H_*/ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp b/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp index 8348b8926a..5be84fa3c9 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.cpp @@ -16,7 +16,7 @@ #include "lib/error.h" #include "lib/exceptions.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { static const std::vector NAMES{ "Priority", "Text", "True", "False", "LineStatementClose", @@ -314,7 +314,7 @@ std::vector combineTokensToNames(const std::vector &inputVector) { if (input.is(Token::Kind::Text)) { auto strtmp = std::string(input.lexeme()); if (strtmp == "." && prevToken.is(Token::Kind::Number)) { - ::error( + ::P4::error( "Syntax error, unexpected INTEGER. P4 does not support floating point values. " "Exiting"); } @@ -562,7 +562,7 @@ const IR::Node *AssertsParser::postorder(IR::P4Table *tableContext) { restrictions.end()); continue; } - ::warning( + ::P4::warning( "Restriction %1% is not feasible. Not generating entries for table %2% and instead " "using default action.", restrStr, tableContext); @@ -695,4 +695,4 @@ Token Lexer::next() noexcept { return atom(Token::Kind::Mul); } } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.h b/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.h index 8e37dcfed6..ddd022d6f9 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4_asserts_parser.h @@ -13,7 +13,7 @@ #include "ir/visitor.h" #include "lib/cstring.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// Maps control plane identifiers to their corresponding IR type. /// Once we have resolved the tokens in the annotation, we can then lookup the corresponding type. @@ -119,6 +119,6 @@ class Lexer { char prev() noexcept; char get() noexcept; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_P4_ASSERTS_PARSER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.cpp b/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.cpp index e65c9fa682..f822dfaa80 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.cpp @@ -13,7 +13,7 @@ #include "lib/exceptions.h" #include "lib/null.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { RefersToParser::RefersToParser() { setName("RefersToParser"); } @@ -180,4 +180,4 @@ bool RefersToParser::preorder(const IR::P4Table *tableContext) { ConstraintsVector RefersToParser::getRestrictionsVector() const { return restrictionsVector; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.h b/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.h index f7e0a4bc74..e2d1c5161b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4_refers_to_parser.h @@ -5,7 +5,7 @@ #include "ir/ir.h" #include "ir/visitor.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class RefersToParser : public Inspector { private: @@ -45,6 +45,6 @@ class RefersToParser : public Inspector { [[nodiscard]] ConstraintsVector getRestrictionsVector() const; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_P4_REFERS_TO_PARSER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.cpp b/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.cpp index ecc46dea79..3909d02508 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.cpp @@ -1,5 +1,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.h" +namespace P4 { + std::vector P4Tools::P4Testgen::Bmv2::PropagateP4RuntimeTranslation::lookupP4RuntimeAnnotations( const P4::TypeMap &typeMap, const IR::Type *type) { @@ -8,7 +10,7 @@ P4Tools::P4Testgen::Bmv2::PropagateP4RuntimeTranslation::lookupP4RuntimeAnnotati if (typeName != nullptr) { type = typeMap.getType(typeName); if (type == nullptr) { - ::error("Type %1% not found in the type map.", typeName); + ::P4::error("Type %1% not found in the type map.", typeName); return p4RuntimeAnnotations; } type = type->getP4Type(); @@ -67,3 +69,5 @@ P4Tools::P4Testgen::Bmv2::PropagateP4RuntimeTranslation::PropagateP4RuntimeTrans : _typeMap(typeMap) { setName("PropagateP4RuntimeTranslation"); } + +} // namespace P4 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.h b/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.h index d1b09c4767..703686ce54 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/p4runtime_translation.h @@ -6,7 +6,7 @@ #include "ir/ir.h" #include "ir/visitor.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { using namespace P4::literals; @@ -28,6 +28,6 @@ class PropagateP4RuntimeTranslation : public Transform { explicit PropagateP4RuntimeTranslation(const P4::TypeMap &typeMap); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_P4RUNTIME_TRANSLATION_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp b/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp index 0e1e0a8780..01b44c1f80 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/program_info.cpp @@ -28,7 +28,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/concolic.h" #include "backends/p4tools/modules/testgen/targets/bmv2/constants.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { const IR::Type_Bits Bmv2V1ModelProgramInfo::PARSER_ERR_BITS = IR::Type_Bits(32, false); @@ -272,4 +272,4 @@ const ArchSpec Bmv2V1ModelProgramInfo::ARCH_SPEC = ArchSpec( // control Deparser(packet_out b, in H hdr); {"Deparser"_cs, {nullptr, "*hdr"_cs}}}); -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/program_info.h b/backends/p4tools/modules/testgen/targets/bmv2/program_info.h index 2af04731c8..a5218efcfb 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/program_info.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/program_info.h @@ -10,7 +10,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/targets/bmv2/compiler_result.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class Bmv2V1ModelProgramInfo : public ProgramInfo { private: @@ -84,6 +84,6 @@ class Bmv2V1ModelProgramInfo : public ProgramInfo { DECLARE_TYPEINFO(Bmv2V1ModelProgramInfo, ProgramInfo); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_PROGRAM_INFO_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/register.h b/backends/p4tools/modules/testgen/targets/bmv2/register.h index 9da926b279..5fcf591394 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/register.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/register.h @@ -7,11 +7,11 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/target.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Register the BMv2 testgen target with the testgen framework. inline void bmv2RegisterTestgenTarget() { Bmv2::Bmv2V1ModelTestgenTarget::make(); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_REGISTER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp b/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp index f8f9fa6d64..88c3c9a08e 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.cpp @@ -32,7 +32,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { using namespace P4::literals; @@ -365,7 +365,7 @@ void Bmv2V1ModelTableStepper::checkTargetProperties( properties.tableIsTainted = properties.tableIsTainted || keyIsTainted; // If the key expression is tainted, do not bother resolving the remaining keys. if (properties.tableIsTainted) { - ::warning("Key %1% of table %2% is tainted.", keyElement->expression, table); + ::P4::warning("Key %1% of table %2% is tainted.", keyElement->expression, table); return; } } @@ -398,7 +398,7 @@ void Bmv2V1ModelTableStepper::evalTargetTable( return; } if (!properties.defaultIsImmutable) { - ::warning( + ::P4::warning( "Table %1%: Overriding default actions not supported for test back end %2%. " "Choosing default action", properties.tableName, testBackend); @@ -424,7 +424,7 @@ void Bmv2V1ModelTableStepper::evalTargetTable( evalTableActionSelector(tableActionList); } else { // We can only generate profile entries for PTF and Protobuf tests. - ::warning( + ::P4::warning( "Action selector control plane entries are not implemented. Using default " "action."); } @@ -437,7 +437,7 @@ void Bmv2V1ModelTableStepper::evalTargetTable( evalTableActionProfile(tableActionList); } else { // We can only generate profile entries for PTF and Protobuf tests. - ::warning( + ::P4::warning( "Action profile control plane entries are not implemented. Using default " "action."); } @@ -465,4 +465,4 @@ Bmv2V1ModelTableStepper::Bmv2V1ModelTableStepper(Bmv2V1ModelExprStepper *stepper const IR::P4Table *table) : TableStepper(stepper, table) {} -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.h b/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.h index 7ff9533213..c1edf13939 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/table_stepper.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/expr_stepper.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class Bmv2V1ModelTableStepper : public TableStepper { private: @@ -70,6 +70,6 @@ class Bmv2V1ModelTableStepper : public TableStepper { explicit Bmv2V1ModelTableStepper(Bmv2V1ModelExprStepper *stepper, const IR::P4Table *table); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TABLE_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/target.cpp b/backends/p4tools/modules/testgen/targets/bmv2/target.cpp index a0e52194ea..6f4c738806 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/target.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/target.cpp @@ -25,7 +25,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/program_info.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /* ============================================================================================= * Bmv2V1ModelTestgenTarget implementation @@ -50,7 +50,7 @@ CompilerResultOrError Bmv2V1ModelTestgenTarget::runCompilerImpl( /// After the front end, get the P4Runtime API for the V1model architecture. auto p4runtimeApi = P4::P4RuntimeSerializer::get()->generateP4Runtime(program, "v1model"_cs); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return std::nullopt; } @@ -66,20 +66,20 @@ CompilerResultOrError Bmv2V1ModelTestgenTarget::runCompilerImpl( P4ProgramDCGCreator dcgCreator(dcg); program->apply(dcgCreator); } - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return std::nullopt; } /// Collect coverage information about the program. auto coverage = P4::Coverage::CollectNodes(TestgenOptions::get().coverageOptions); program->apply(coverage); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return std::nullopt; } // Parses any @refers_to annotations and converts them into a vector of restrictions. auto refersToParser = RefersToParser(); program->apply(refersToParser); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return std::nullopt; } ConstraintsVector p4ConstraintsRestrictions = refersToParser.getRestrictionsVector(); @@ -88,14 +88,14 @@ CompilerResultOrError Bmv2V1ModelTestgenTarget::runCompilerImpl( // expressions, and stores them in p4ConstraintsRestrictions to move targetConstraints // further. program->apply(AssertsParser(p4ConstraintsRestrictions)); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return std::nullopt; } // Try to map all instances of direct externs to the table they are attached to. // Save the map in @var directExternMap. auto directExternMapper = MapDirectExterns(); program->apply(directExternMapper); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return std::nullopt; } @@ -169,4 +169,4 @@ Bmv2V1ModelExprStepper *Bmv2V1ModelTestgenTarget::getExprStepperImpl( return new Bmv2V1ModelExprStepper(state, solver, programInfo); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/target.h b/backends/p4tools/modules/testgen/targets/bmv2/target.h index f984196b19..3f18d080c9 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/target.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/target.h @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/program_info.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class Bmv2V1ModelTestgenTarget : public TestgenTarget { public: @@ -44,6 +44,6 @@ class Bmv2V1ModelTestgenTarget : public TestgenTarget { const IR::P4Program *program) const override; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TARGET_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/binary.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/binary.cpp index 6ce62587ed..ab3893372f 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/binary.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/binary.cpp @@ -7,7 +7,7 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" #include "backends/p4tools/modules/testgen/test/small-step/util.h" -namespace Test { +namespace P4::Test { using SmallStepUtil::createSmallStepExprTest; using SmallStepUtil::extractExpr; @@ -80,4 +80,4 @@ TEST_F(SmallStepTest, Binary04) { } // anonymous namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/p4_asserts_parser_test.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/p4_asserts_parser_test.cpp index e550ba147e..fba5e706c8 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/p4_asserts_parser_test.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/p4_asserts_parser_test.cpp @@ -30,7 +30,7 @@ extern const char *sourcePath; extern const char *buildPath; -namespace Test { +namespace P4::Test { using namespace P4::literals; class P4AssertsParserTest : public P4ToolsTest {}; @@ -146,4 +146,4 @@ TEST_F(P4AssertsParserTest, RestrictionMiddleblockReferToInAction) { ASSERT_TRUE(parsingResult[1]->equiv(*operation)); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/reachability.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/reachability.cpp index 6bd92296b9..d324f2b306 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/reachability.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/reachability.cpp @@ -23,7 +23,7 @@ #include "lib/exceptions.h" #include "test/gtest/env.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -458,4 +458,4 @@ TEST_F(P4CReachability, testReachabilityEngineNegTable2) { ASSERT_TRUE(!checkResultingSTF(ids, "tmp")); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/unary.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/unary.cpp index 5c8645bd76..b2ce75b4a9 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/unary.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/unary.cpp @@ -8,7 +8,7 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" #include "backends/p4tools/modules/testgen/test/small-step/util.h" -namespace Test { +namespace P4::Test { using SmallStepUtil::createSmallStepExprTest; using SmallStepUtil::extractExpr; @@ -61,4 +61,4 @@ TEST_F(SmallStepTest, Unary03) { } // anonymous namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/value.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/value.cpp index 07d91386f2..9c044f1afc 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/value.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/small-step/value.cpp @@ -8,7 +8,7 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" #include "backends/p4tools/modules/testgen/test/small-step/util.h" -namespace Test { +namespace P4::Test { using SmallStepUtil::createSmallStepExprTest; using SmallStepUtil::extractExpr; @@ -42,4 +42,4 @@ TEST_F(SmallStepTest, Value02) { } // anonymous namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.cpp index 915edf4f6a..2aeed17a47 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.cpp @@ -13,7 +13,7 @@ #include "ir/irutils.h" #include "lib/exceptions.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -239,4 +239,4 @@ TEST_F(PTFTest, Ptf04) { } } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.h b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.h index b46f315755..657e02a8a8 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/ptf.h @@ -4,7 +4,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.h" #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { using TestBackendConfiguration = P4Tools::P4Testgen::TestBackendConfiguration; using Packet = P4Tools::P4Testgen::Packet; @@ -28,6 +28,6 @@ class PTFTest : public P4ToolsTest { TableConfig gettest1TableConfig2(); }; -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_TEST_BACKEND_PTF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.cpp index 5ead04c78a..6272186205 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.cpp @@ -13,7 +13,7 @@ #include "ir/irutils.h" #include "lib/exceptions.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -239,4 +239,4 @@ TEST_F(STFTest, Stf04) { } } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.h b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.h index ae1eb35c9a..5bfca70337 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/test_backend/stf.h @@ -4,7 +4,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.h" #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { using TestBackendConfiguration = P4Tools::P4Testgen::TestBackendConfiguration; using Packet = P4Tools::P4Testgen::Packet; @@ -28,6 +28,6 @@ class STFTest : public P4ToolsTest { TableConfig gettest1TableConfig2(); }; -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_TEST_BACKEND_STF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/api_test.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/api_test.cpp index e8cc38ff6b..4e8c9d4060 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/api_test.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/api_test.cpp @@ -8,7 +8,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -92,4 +92,4 @@ V1Switch(parse(), verifyChecksum(), ingress(), egress(), computeChecksum(), depa const auto *protobufTest = testList[0]->checkedTo(); EXPECT_THAT(protobufTest->getFormattedTest(), ::testing::HasSubstr(R"(input_packet)")); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp index aab2a1bdeb..f8289253b1 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/benchmark.cpp @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -47,4 +47,4 @@ TEST(P4TestgenBenchmark, SuccessfullyGenerate1000Tests) { // Print the report. P4Tools::printPerformanceReport(); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/control_plane_filter_test.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/control_plane_filter_test.cpp index 114ae02d47..a997e83d6c 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/control_plane_filter_test.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/control_plane_filter_test.cpp @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -280,4 +280,4 @@ TEST(P4TestgenControlPlaneFilterTest, FiltersMultipleControlPlaneEntities) { } // namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/output_option_test.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/output_option_test.cpp index 1a1c0ba609..a8f6b47c6d 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/output_option_test.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/testgen_api/output_option_test.cpp @@ -7,7 +7,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -102,4 +102,4 @@ V1Switch(parse(), verifyChecksum(), ingress(), egress(), computeChecksum(), depa } } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/transformations/saturation_arithm.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/transformations/saturation_arithm.cpp index 20a0725f1a..5cafb778e7 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/transformations/saturation_arithm.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/transformations/saturation_arithm.cpp @@ -20,7 +20,7 @@ #include "backends/p4tools/modules/testgen/core/target.h" #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -247,4 +247,4 @@ TEST_F(Z3SolverSubSat05, SubSat05) { test(expression, variableValue); } } // namespace ArithmTest -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/asrt_model.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/asrt_model.cpp index 60d4027359..e7a41d58f8 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/asrt_model.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/asrt_model.cpp @@ -23,7 +23,7 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" #include "backends/p4tools/modules/testgen/test/z3-solver/accessor.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -206,4 +206,4 @@ TEST_F(Z3SolverTest, Assertion2Model) { } // anonymous namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/expressions.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/expressions.cpp index b94f8dff11..8b85bdd8b8 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/expressions.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test/z3-solver/expressions.cpp @@ -15,7 +15,7 @@ #include "backends/p4tools/modules/testgen/core/target.h" #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -310,4 +310,4 @@ TEST_F(Z3SolverCastBit2Bool, Cast) { test(expression, variableValue); } } // namespace Z3Test -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp index 1b87cba2d2..250709d551 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.cpp @@ -30,7 +30,7 @@ #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { const big_int Bmv2TestBackend::ZERO_PKT_VAL = 0x2000000; const big_int Bmv2TestBackend::ZERO_PKT_MAX = 0xffffffff; @@ -43,7 +43,7 @@ Bmv2TestBackend::Bmv2TestBackend(const Bmv2V1ModelProgramInfo &programInfo, : TestBackEnd(programInfo, testBackendConfiguration, symbex) { cstring testBackendString = TestgenOptions::get().testBackend; if (testBackendString.isNullOrEmpty()) { - ::error( + ::P4::error( "No test back end provided. Please provide a test back end using the --test-backend " "parameter. Supported back ends are %1%.", Utils::containerToString(SUPPORTED_BACKENDS)); @@ -165,4 +165,4 @@ const TestSpec *Bmv2TestBackend::createTestSpec(const ExecutionState *executionS return testSpec; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h index ff2d7b615d..37aaec4ad4 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend.h @@ -17,7 +17,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/program_info.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { class Bmv2TestBackend : public TestBackEnd { private: @@ -45,6 +45,6 @@ class Bmv2TestBackend : public TestBackEnd { const TestInfo &testInfo) override; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.cpp index 0208ffad5b..531ff9da48 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.cpp @@ -17,7 +17,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { Bmv2TestFramework::Bmv2TestFramework(const TestBackendConfiguration &testBackendConfiguration) : TestFramework(testBackendConfiguration) {} @@ -202,4 +202,4 @@ inja::json Bmv2TestFramework::getExpectedPacket(const TestSpec *testSpec) const return verifyData; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h index 86e73ca624..898836ec8b 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/lib/test_object.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// Bmv2TestFramework provides common utility functions for BMv2-style test frameworks. class Bmv2TestFramework : public TestFramework { @@ -44,6 +44,6 @@ class Bmv2TestFramework : public TestFramework { /// Converts the output packet, port, and mask into Inja format. virtual inja::json getExpectedPacket(const TestSpec *testSpec) const; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_COMMON_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.cpp index d0f8e764e4..4cca9c32e9 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.cpp @@ -22,7 +22,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { Metadata::Metadata(const TestBackendConfiguration &testBackendConfiguration) : Bmv2TestFramework(testBackendConfiguration) {} @@ -141,4 +141,4 @@ void Metadata::writeTestToFile(const TestSpec *testSpec, cstring selectedBranche emitTestcase(testSpec, selectedBranches, testId, testCase, currentCoverage); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.h index 8ec44f0ec5..8832313e5a 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/metadata.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// Extracts information from the @testSpec to emit a Metadata test case. class Metadata : public Bmv2TestFramework { @@ -50,6 +50,6 @@ class Metadata : public Bmv2TestFramework { static std::string getTestCaseTemplate(); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_METADATA_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.cpp index 2597cf846b..107c71015d 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.cpp @@ -26,7 +26,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { Protobuf::Protobuf(const TestBackendConfiguration &testBackendConfiguration, P4::P4RuntimeAPI p4RuntimeApi) @@ -369,4 +369,4 @@ AbstractTestReferenceOrError Protobuf::produceTest(const TestSpec *testSpec, return new ProtobufTest(inja::render(getTestCaseTemplate(), dataJson)); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.h index acdf5149a9..2d09f2cb4d 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf.h @@ -16,7 +16,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { using P4::ControlPlaneAPI::p4rt_id_t; @@ -90,6 +90,6 @@ class Protobuf : public Bmv2TestFramework { const std::vector &args) const; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.cpp index 5793de6f5c..a5eb7ac71f 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.cpp @@ -18,7 +18,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { ProtobufIr::ProtobufIr(const TestBackendConfiguration &testBackendConfiguration, P4::P4RuntimeAPI p4RuntimeApi) @@ -462,4 +462,4 @@ AbstractTestReferenceOrError ProtobufIr::produceTest(const TestSpec *testSpec, return new ProtobufIrTest(inja::render(getTestCaseTemplate(), dataJson)); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h index b3207c577d..2d6212d564 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/protobuf_ir.h @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { struct ProtobufIrTest : public AbstractTest { private: @@ -98,6 +98,6 @@ class ProtobufIr : public Bmv2TestFramework { inja::json &rulesJson); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PROTOBUF_IR_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.cpp index 05e5f1e825..b030150a3c 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.cpp @@ -16,7 +16,7 @@ #include "lib/log.h" #include "nlohmann/json.hpp" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { PTF::PTF(const TestBackendConfiguration &testBackendConfiguration) : Bmv2TestFramework(testBackendConfiguration) {} @@ -311,4 +311,4 @@ void PTF::writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, si emitTestcase(testSpec, selectedBranches, testId, testCase, currentCoverage); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.h index 00e9e10b87..7f63cf8a4f 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/ptf.h @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// Extracts information from the @testSpec to emit a PTF test case. class PTF : public Bmv2TestFramework { @@ -59,6 +59,6 @@ class PTF : public Bmv2TestFramework { static std::vector> getIgnoreMasks(const IR::Constant *mask); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_PTF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.cpp index 480ea22258..377b2e946e 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.cpp @@ -24,7 +24,7 @@ #include "backends/p4tools/modules/testgen/lib/exceptions.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { STF::STF(const TestBackendConfiguration &testBackendConfiguration) : Bmv2TestFramework(testBackendConfiguration) {} @@ -249,4 +249,4 @@ void STF::writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, si emitTestcase(testSpec, selectedBranches, testId, testCase, currentCoverage); } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.h b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.h index 5a704b8306..67febb2f93 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_backend/stf.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/test_backend/common.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /// Extracts information from the @testSpec to emit a STF test case. class STF : public Bmv2TestFramework { @@ -44,6 +44,6 @@ class STF : public Bmv2TestFramework { const std::vector &args) const override; }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_BACKEND_STF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_spec.cpp b/backends/p4tools/modules/testgen/targets/bmv2/test_spec.cpp index 4acdc5703e..fac3440061 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_spec.cpp +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_spec.cpp @@ -5,7 +5,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { using namespace P4::literals; @@ -330,4 +330,4 @@ void MetadataCollection::addMetaDataField(cstring name, const IR::Literal *metad cstring Range::getObjectName() const { return "Range"_cs; } -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 diff --git a/backends/p4tools/modules/testgen/targets/bmv2/test_spec.h b/backends/p4tools/modules/testgen/targets/bmv2/test_spec.h index f228e417c0..c30a8974ff 100644 --- a/backends/p4tools/modules/testgen/targets/bmv2/test_spec.h +++ b/backends/p4tools/modules/testgen/targets/bmv2/test_spec.h @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/bmv2/constants.h" -namespace P4Tools::P4Testgen::Bmv2 { +namespace P4::P4Tools::P4Testgen::Bmv2 { /* ========================================================================================= * IndexExpression @@ -376,6 +376,6 @@ class Range : public TableMatch { DECLARE_TYPEINFO(Range, TableMatch); }; -} // namespace P4Tools::P4Testgen::Bmv2 +} // namespace P4::P4Tools::P4Testgen::Bmv2 #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_BMV2_TEST_SPEC_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp index e2e82bf682..69068dbc05 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.cpp @@ -29,7 +29,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/lib/test_object.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { STF::STF(const TestBackendConfiguration &testBackendConfiguration) : TestFramework(testBackendConfiguration) {} @@ -260,4 +260,4 @@ void STF::writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, si emitTestcase(testSpec, selectedBranches, testId, testCase, currentCoverage); } -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h index 93a1c5409f..5e7c2cce31 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h @@ -12,7 +12,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { /// Extracts information from the @testSpec to emit a STF test case. class STF : public TestFramework { @@ -55,6 +55,6 @@ class STF : public TestFramework { const std::vector &args); }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_EBPF_BACKEND_STF_STF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp index 1698ea2f02..5bc0fd192c 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.cpp @@ -24,7 +24,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/targets/ebpf/program_info.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { EBPFCmdStepper::EBPFCmdStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -80,4 +80,4 @@ std::map EBPFCmdStepper::getExceptionHand return result; } -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h index e687aa3e5a..3938a49b33 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/cmd_stepper.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/targets/ebpf/program_info.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFCmdStepper : public CmdStepper { protected: @@ -36,6 +36,6 @@ class EBPFCmdStepper : public CmdStepper { const ProgramInfo &programInfo); }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_CMD_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/concolic.cpp b/backends/p4tools/modules/testgen/targets/ebpf/concolic.cpp index 7161e9dac6..33c22db3a6 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/concolic.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/concolic.cpp @@ -2,7 +2,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { const ConcolicMethodImpls::ImplList EBPFConcolic::EBPF_CONCOLIC_METHOD_IMPLS{}; @@ -10,4 +10,4 @@ const ConcolicMethodImpls::ImplList *EBPFConcolic::getEBPFConcolicMethodImpls() return &EBPF_CONCOLIC_METHOD_IMPLS; } -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/concolic.h b/backends/p4tools/modules/testgen/targets/ebpf/concolic.h index 0a0dc822cc..482a0b3a62 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/concolic.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/concolic.h @@ -3,7 +3,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFConcolic : public Concolic { private: @@ -15,6 +15,6 @@ class EBPFConcolic : public Concolic { static const ConcolicMethodImpls::ImplList *getEBPFConcolicMethodImpls(); }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_CONCOLIC_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/constants.cpp b/backends/p4tools/modules/testgen/targets/ebpf/constants.cpp index 3a8fbb342f..38231a7054 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/constants.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/constants.cpp @@ -1,8 +1,8 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/constants.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { const IR::PathExpression EBPFConstants::ACCEPT_VAR = IR::PathExpression(IR::Type_Boolean::get(), new IR::Path("*accept")); -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/constants.h b/backends/p4tools/modules/testgen/targets/ebpf/constants.h index 05dc347f11..098374eb5b 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/constants.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/constants.h @@ -3,7 +3,7 @@ #include "ir/ir.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFConstants { public: @@ -13,6 +13,6 @@ class EBPFConstants { static constexpr int PORT_BIT_WIDTH = 9; }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_CONSTANTS_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.cpp b/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.cpp index 356733614c..585c2ecd2c 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.cpp @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/targets/ebpf/table_stepper.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { EBPFExprStepper::EBPFExprStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -41,7 +41,7 @@ const EBPFExprStepper::ExternMethodImpls EBPFExprStepper::EBPF_ {"CounterArray.add"_cs, {"index"_cs, "value"_cs}, [](const ExternInfo & /*externInfo*/, EBPFExprStepper &stepper) { - ::warning("CounterArray.add not fully implemented."); + ::P4::warning("CounterArray.add not fully implemented."); auto &nextState = stepper.state.clone(); nextState.popBody(); stepper.result->emplace_back(nextState); @@ -60,7 +60,7 @@ const EBPFExprStepper::ExternMethodImpls EBPFExprStepper::EBPF_ {"CounterArray.increment"_cs, {"index"_cs}, [](const ExternInfo & /*externInfo*/, EBPFExprStepper &stepper) { - ::warning("CounterArray.increment not fully implemented."); + ::P4::warning("CounterArray.increment not fully implemented."); auto &nextState = stepper.state.clone(); nextState.popBody(); stepper.result->emplace_back(nextState); @@ -195,4 +195,4 @@ bool EBPFExprStepper::preorder(const IR::P4Table *table) { return tableStepper.eval(); } -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.h b/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.h index a35b7db31e..236836df58 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.h @@ -10,7 +10,7 @@ #include "backends/p4tools/modules/testgen/core/small_step/expr_stepper.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFExprStepper : public ExprStepper { private: @@ -30,6 +30,6 @@ class EBPFExprStepper : public ExprStepper { /// @returns a method call statement that calls packet_out.emit on the provided input label. static const IR::MethodCallStatement *produceEmitCall(const IR::Member *fieldLabel); }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_EXPR_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp b/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp index b42aec4427..f567be2c23 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/program_info.cpp @@ -24,7 +24,7 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/concolic.h" #include "backends/p4tools/modules/testgen/targets/ebpf/constants.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { using namespace P4::literals; @@ -129,4 +129,4 @@ const ArchSpec EBPFProgramInfo::ARCH_SPEC = // control filter(inout H headers, out bool accept); {"filter"_cs, {"*hdr"_cs, "*accept"_cs}}}); -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/program_info.h b/backends/p4tools/modules/testgen/targets/ebpf/program_info.h index 70d1edb723..8cd4d239ff 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/program_info.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/program_info.h @@ -10,7 +10,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" #include "backends/p4tools/modules/testgen/lib/continuation.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFProgramInfo : public ProgramInfo { private: @@ -51,6 +51,6 @@ class EBPFProgramInfo : public ProgramInfo { DECLARE_TYPEINFO(EBPFProgramInfo, ProgramInfo); }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_PROGRAM_INFO_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/register.h b/backends/p4tools/modules/testgen/targets/ebpf/register.h index a9aa07aefa..75e396b078 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/register.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/register.h @@ -7,11 +7,11 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/target.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Register the ebpf testgen target with the testgen framework. inline void ebpfRegisterTestgenTarget() { EBPF::EBPFTestgenTarget::make(); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* TESTGEN_TARGETS_EBPF_REGISTER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp b/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp index db07052915..e8bc440de9 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.cpp @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { void EBPFTableStepper::checkTargetProperties( const std::vector & /*tableActionList*/) { @@ -24,7 +24,7 @@ void EBPFTableStepper::checkTargetProperties( properties.tableIsTainted = properties.tableIsTainted || keyIsTainted; // If the key expression is tainted, do not bother resolving the remaining keys. if (properties.tableIsTainted) { - ::warning("Key %1% of table %2% is tainted.", keyElement->expression, table); + ::P4::warning("Key %1% of table %2% is tainted.", keyElement->expression, table); return; } } @@ -70,4 +70,4 @@ void EBPFTableStepper::evalTargetTable( EBPFTableStepper::EBPFTableStepper(EBPFExprStepper *stepper, const IR::P4Table *table) : TableStepper(stepper, table) {} -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.h b/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.h index f9635e118a..7f8dd042ee 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/table_stepper.h @@ -10,7 +10,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/ebpf/expr_stepper.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFTableStepper : public TableStepper { private: @@ -38,6 +38,6 @@ class EBPFTableStepper : public TableStepper { explicit EBPFTableStepper(EBPFExprStepper *stepper, const IR::P4Table *table); }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_TABLE_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/target.cpp b/backends/p4tools/modules/testgen/targets/ebpf/target.cpp index ab03e01d65..143eeb682b 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/target.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/target.cpp @@ -22,7 +22,7 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/program_info.h" #include "backends/p4tools/modules/testgen/targets/ebpf/test_backend.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { /* ============================================================================================= * EBPFTestgenTarget implementation @@ -60,8 +60,8 @@ const EBPFProgramInfo *EBPFTestgenTarget::produceProgramInfoImpl( // packets. There might be a bug in the framework auto &testgenOptions = TestgenOptions::get(); if (testgenOptions.maxPktSize > 12000) { - ::warning("Max packet size %1% larger than 12000 bits. Bounding size to 12000 bits.", - testgenOptions.maxPktSize); + ::P4::warning("Max packet size %1% larger than 12000 bits. Bounding size to 12000 bits.", + testgenOptions.maxPktSize); testgenOptions.maxPktSize = 12000; } @@ -93,4 +93,4 @@ MidEnd EBPFTestgenTarget::mkMidEnd(const CompilerOptions &options) const { return midEnd; } -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/target.h b/backends/p4tools/modules/testgen/targets/ebpf/target.h index 679cb2e686..36df058165 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/target.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/target.h @@ -18,7 +18,7 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/program_info.h" #include "backends/p4tools/modules/testgen/targets/ebpf/test_backend.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFTestgenTarget : public TestgenTarget { public: @@ -46,6 +46,6 @@ class EBPFTestgenTarget : public TestgenTarget { [[nodiscard]] MidEnd mkMidEnd(const CompilerOptions &options) const override; }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* TESTGEN_TARGETS_EBPF_TARGET_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp index 6ae78c55f4..a8b1e5256d 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.cpp @@ -25,7 +25,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/targets/ebpf/backend/stf/stf.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { const big_int EBPFTestBackend::ZERO_PKT_VAL = 0x2000000; const big_int EBPFTestBackend::ZERO_PKT_MAX = 0xffffffff; @@ -37,7 +37,7 @@ EBPFTestBackend::EBPFTestBackend(const ProgramInfo &programInfo, : TestBackEnd(programInfo, testBackendConfiguration, symbex) { cstring testBackendString = TestgenOptions::get().testBackend; if (testBackendString.isNullOrEmpty()) { - ::error( + ::P4::error( "No test back end provided. Please provide a test back end using the --test-backend " "parameter. Supported back ends are %1%.", Utils::containerToString(SUPPORTED_BACKENDS)); @@ -104,4 +104,4 @@ const TestSpec *EBPFTestBackend::createTestSpec(const ExecutionState *executionS return testSpec; } -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF diff --git a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h index b495884979..1a73f53632 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/test_backend.h @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/test_backend.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::EBPF { +namespace P4::P4Tools::P4Testgen::EBPF { class EBPFTestBackend : public TestBackEnd { private: @@ -47,6 +47,6 @@ class EBPFTestBackend : public TestBackEnd { const TestInfo &testInfo) override; }; -} // namespace P4Tools::P4Testgen::EBPF +} // namespace P4::P4Tools::P4Testgen::EBPF #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_EBPF_TEST_BACKEND_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/ebpf/test_spec.cpp b/backends/p4tools/modules/testgen/targets/ebpf/test_spec.cpp index 728de1785b..164bb19b17 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/test_spec.cpp +++ b/backends/p4tools/modules/testgen/targets/ebpf/test_spec.cpp @@ -1,3 +1,3 @@ #include "backends/p4tools/modules/testgen/targets/ebpf/test_spec.h" -namespace P4Tools::P4Testgen::EBPF {} +namespace P4::P4Tools::P4Testgen::EBPF {} diff --git a/backends/p4tools/modules/testgen/targets/ebpf/test_spec.h b/backends/p4tools/modules/testgen/targets/ebpf/test_spec.h index 1728cd8bec..1263e5b923 100644 --- a/backends/p4tools/modules/testgen/targets/ebpf/test_spec.h +++ b/backends/p4tools/modules/testgen/targets/ebpf/test_spec.h @@ -1,6 +1,6 @@ #ifndef TESTGEN_TARGETS_EBPF_TEST_SPEC_H_ #define TESTGEN_TARGETS_EBPF_TEST_SPEC_H_ -namespace P4Tools::P4Testgen::EBPF {} +namespace P4::P4Tools::P4Testgen::EBPF {} #endif /* TESTGEN_TARGETS_EBPF_TEST_SPEC_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.cpp b/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.cpp index 250c7c5669..77bb454160 100644 --- a/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.cpp @@ -21,7 +21,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/targets/pna/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { Metadata::Metadata(const TestBackendConfiguration &testBackendConfiguration) : TestFramework(testBackendConfiguration) {} @@ -189,4 +189,4 @@ void Metadata::writeTestToFile(const TestSpec *testSpec, cstring selectedBranche emitTestcase(testSpec, selectedBranches, testId, testCase, currentCoverage); } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.h b/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.h index f0149acd9d..496fd222da 100644 --- a/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.h +++ b/backends/p4tools/modules/testgen/targets/pna/backend/metadata/metadata.h @@ -17,7 +17,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { /// Extracts information from the @testSpec to emit a Metadata test case. class Metadata : public TestFramework { @@ -69,6 +69,6 @@ class Metadata : public TestFramework { static std::vector> getIgnoreMasks(const IR::Constant *mask); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_METADATA_METADATA_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.cpp b/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.cpp index 8b1cb98b46..e910e64663 100644 --- a/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.cpp @@ -23,7 +23,7 @@ #include "backends/p4tools/modules/testgen/options.h" #include "backends/p4tools/modules/testgen/targets/pna/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { PTF::PTF(const TestBackendConfiguration &testBackendConfiguration) : TestFramework(testBackendConfiguration) {} @@ -416,4 +416,4 @@ void PTF::writeTestToFile(const TestSpec *testSpec, cstring selectedBranches, si emitTestcase(testSpec, selectedBranches, testId, testCase, currentCoverage); } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.h b/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.h index 46e4eab6d2..04340591de 100644 --- a/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.h +++ b/backends/p4tools/modules/testgen/targets/pna/backend/ptf/ptf.h @@ -19,7 +19,7 @@ #include "backends/p4tools/modules/testgen/lib/test_object.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { /// Extracts information from the @testSpec to emit a PTF test case. class PTF : public TestFramework { @@ -76,6 +76,6 @@ class PTF : public TestFramework { const std::vector &args); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_BACKEND_PTF_PTF_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/concolic.cpp b/backends/p4tools/modules/testgen/targets/pna/concolic.cpp index 74d62d7e37..b34a1d7f99 100644 --- a/backends/p4tools/modules/testgen/targets/pna/concolic.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/concolic.cpp @@ -2,7 +2,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { const ConcolicMethodImpls::ImplList PnaDpdkConcolic::PNA_DPDK_CONCOLIC_METHOD_IMPLS{}; @@ -10,4 +10,4 @@ const ConcolicMethodImpls::ImplList *PnaDpdkConcolic::getPnaDpdkConcolicMethodIm return &PNA_DPDK_CONCOLIC_METHOD_IMPLS; } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/concolic.h b/backends/p4tools/modules/testgen/targets/pna/concolic.h index 6445150f15..a6cc571388 100644 --- a/backends/p4tools/modules/testgen/targets/pna/concolic.h +++ b/backends/p4tools/modules/testgen/targets/pna/concolic.h @@ -3,7 +3,7 @@ #include "backends/p4tools/modules/testgen/lib/concolic.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaDpdkConcolic : public Concolic { private: @@ -15,6 +15,6 @@ class PnaDpdkConcolic : public Concolic { static const ConcolicMethodImpls::ImplList *getPnaDpdkConcolicMethodImpls(); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_CONCOLIC_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/constants.cpp b/backends/p4tools/modules/testgen/targets/pna/constants.cpp index 76cde9f0a2..4e47d061c6 100644 --- a/backends/p4tools/modules/testgen/targets/pna/constants.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/constants.cpp @@ -3,7 +3,7 @@ #include "ir/id.h" #include "lib/cstring.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { using namespace P4::literals; @@ -18,4 +18,4 @@ const IR::Member PnaConstants::PARSER_ERROR = const IR::SymbolicVariable PnaSymbolicVars::DIRECTION = IR::SymbolicVariable(IR::Type_Bits::get(32), "direction"_cs); -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/constants.h b/backends/p4tools/modules/testgen/targets/pna/constants.h index aa0adc4c7d..e4bc8fc6e7 100644 --- a/backends/p4tools/modules/testgen/targets/pna/constants.h +++ b/backends/p4tools/modules/testgen/targets/pna/constants.h @@ -3,7 +3,7 @@ #include "ir/ir.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { enum PacketDirection { NET_TO_HOST, HOST_TO_NET }; @@ -33,6 +33,6 @@ class PnaSymbolicVars { static const IR::SymbolicVariable DIRECTION; }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_CONSTANTS_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.cpp b/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.cpp index 22b3c27edf..e3ce156f83 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.cpp @@ -23,7 +23,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { std::string PnaDpdkCmdStepper::getClassName() { return "PnaDpdkCmdStepper"; } @@ -90,4 +90,4 @@ std::map PnaDpdkCmdStepper::getExceptionH return result; } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.h b/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.h index 949336aa2e..b8ece397c7 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.h +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/cmd_stepper.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaDpdkCmdStepper : public SharedPnaCmdStepper { protected: @@ -36,6 +36,6 @@ class PnaDpdkCmdStepper : public SharedPnaCmdStepper { const ProgramInfo &programInfo); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_DPDK_CMD_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.cpp b/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.cpp index 2f3ab4378a..f983ea0f5f 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.cpp @@ -7,7 +7,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { std::string PnaDpdkExprStepper::getClassName() { return "PnaDpdkExprStepper"; } @@ -39,4 +39,4 @@ bool PnaDpdkExprStepper::preorder(const IR::P4Table *table) { return PnaDpdkTableStepper(this, table).eval(); } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.h b/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.h index 8da170649b..5cb17c3fcf 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.h +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.h @@ -10,7 +10,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaDpdkExprStepper : public SharedPnaExprStepper { protected: @@ -28,6 +28,6 @@ class PnaDpdkExprStepper : public SharedPnaExprStepper { bool preorder(const IR::P4Table * /*table*/) override; }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_DPDK_EXPR_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.cpp b/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.cpp index b5c486b34f..2403f51011 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.cpp @@ -18,7 +18,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/concolic.h" #include "backends/p4tools/modules/testgen/targets/pna/constants.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { using namespace P4::literals; @@ -143,4 +143,4 @@ const ArchSpec PnaDpdkProgramInfo::ARCH_SPEC = ArchSpec( {"MainDeparserT"_cs, {nullptr, "*main_hdr"_cs, "*main_user_meta"_cs, "*ostd"_cs}}, }); -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h b/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h index 5be5cd66ac..fa7cc7d4c7 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/lib/continuation.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_program_info.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaDpdkProgramInfo : public SharedPnaProgramInfo { private: @@ -33,6 +33,6 @@ class PnaDpdkProgramInfo : public SharedPnaProgramInfo { DECLARE_TYPEINFO(PnaDpdkProgramInfo, SharedPnaProgramInfo); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_DPDK_PROGRAM_INFO_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.cpp b/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.cpp index ec8a71bf90..14cace822b 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.cpp @@ -4,9 +4,9 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { PnaDpdkTableStepper::PnaDpdkTableStepper(PnaDpdkExprStepper *stepper, const IR::P4Table *table) : SharedPnaTableStepper(stepper, table) {} -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.h b/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.h index c5ffec330a..e93bbddeb7 100644 --- a/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.h +++ b/backends/p4tools/modules/testgen/targets/pna/dpdk/table_stepper.h @@ -8,13 +8,13 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/expr_stepper.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaDpdkTableStepper : public SharedPnaTableStepper { public: explicit PnaDpdkTableStepper(PnaDpdkExprStepper *stepper, const IR::P4Table *table); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_DPDK_TABLE_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/register.h b/backends/p4tools/modules/testgen/targets/pna/register.h index 0baa499e2b..f212a89b7e 100644 --- a/backends/p4tools/modules/testgen/targets/pna/register.h +++ b/backends/p4tools/modules/testgen/targets/pna/register.h @@ -7,11 +7,11 @@ #include "backends/p4tools/modules/testgen/targets/pna/target.h" #include "backends/p4tools/modules/testgen/testgen.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// Register the PNA testgen target with the testgen framework. inline void pnaRegisterTestgenTarget() { Pna::PnaDpdkTestgenTarget::make(); } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_REGISTER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.cpp b/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.cpp index 21c97f462e..b0e799da2f 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.cpp @@ -6,10 +6,10 @@ #include "backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { SharedPnaCmdStepper::SharedPnaCmdStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) : CmdStepper(state, solver, programInfo) {} -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.h b/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.h index 3d52a2eefa..850d6d54ae 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.h +++ b/backends/p4tools/modules/testgen/targets/pna/shared_cmd_stepper.h @@ -7,7 +7,7 @@ #include "backends/p4tools/modules/testgen/core/small_step/cmd_stepper.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class SharedPnaCmdStepper : public CmdStepper { public: @@ -15,6 +15,6 @@ class SharedPnaCmdStepper : public CmdStepper { const ProgramInfo &programInfo); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_SHARED_CMD_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.cpp b/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.cpp index 2758ba3c07..5e23e2055d 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.cpp @@ -21,7 +21,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/constants.h" #include "backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { SharedPnaExprStepper::SharedPnaExprStepper(ExecutionState &state, AbstractSolver &solver, const ProgramInfo &programInfo) @@ -181,4 +181,4 @@ bool SharedPnaExprStepper::preorder(const IR::P4Table *table) { return tableStepper.eval(); } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h b/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h index 164c50f122..4bf06cf376 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h +++ b/backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h @@ -8,7 +8,7 @@ #include "backends/p4tools/modules/testgen/core/small_step/expr_stepper.h" #include "backends/p4tools/modules/testgen/lib/execution_state.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class SharedPnaExprStepper : public ExprStepper { private: @@ -23,6 +23,6 @@ class SharedPnaExprStepper : public ExprStepper { bool preorder(const IR::P4Table * /*table*/) override; }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_SHARED_EXPR_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_program_info.cpp b/backends/p4tools/modules/testgen/targets/pna/shared_program_info.cpp index e3c1797383..8a79d87e97 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_program_info.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/shared_program_info.cpp @@ -16,7 +16,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/concolic.h" #include "backends/p4tools/modules/testgen/targets/pna/constants.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { const IR::Type_Bits SharedPnaProgramInfo::PARSER_ERR_BITS = IR::Type_Bits(32, false); @@ -69,4 +69,4 @@ const IR::PathExpression *SharedPnaProgramInfo::getBlockParam(cstring blockLabel return new IR::PathExpression(paramType, new IR::Path(archRef)); } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_program_info.h b/backends/p4tools/modules/testgen/targets/pna/shared_program_info.h index 6c60bdc95f..9c9f0d4463 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_program_info.h +++ b/backends/p4tools/modules/testgen/targets/pna/shared_program_info.h @@ -9,7 +9,7 @@ #include "backends/p4tools/modules/testgen/core/program_info.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class SharedPnaProgramInfo : public ProgramInfo { private: @@ -43,6 +43,6 @@ class SharedPnaProgramInfo : public ProgramInfo { DECLARE_TYPEINFO(SharedPnaProgramInfo, ProgramInfo); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_SHARED_PROGRAM_INFO_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.cpp b/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.cpp index 94834321be..958e046669 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.cpp @@ -30,7 +30,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h" #include "backends/p4tools/modules/testgen/targets/pna/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { using namespace P4::literals; @@ -346,7 +346,7 @@ void SharedPnaTableStepper::checkTargetProperties( properties.tableIsTainted = properties.tableIsTainted || keyIsTainted; // If the key expression is tainted, do not bother resolving the remaining keys. if (properties.tableIsTainted) { - ::warning("Key %1% of table %2% is tainted.", keyElement->expression, table); + ::P4::warning("Key %1% of table %2% is tainted.", keyElement->expression, table); return; } } @@ -377,7 +377,7 @@ void SharedPnaTableStepper::evalTargetTable( return; } if (!properties.defaultIsImmutable) { - ::warning( + ::P4::warning( "Table %1%: Overriding default actions not supported for test back end %2%. " "Choosing default action", properties.tableName, testBackend); @@ -403,7 +403,7 @@ void SharedPnaTableStepper::evalTargetTable( evalTableActionSelector(tableActionList); } else { // We can only generate profile entries for PTF and Protobuf tests. - ::warning( + ::P4::warning( "Action selector control plane entries are not implemented. Using default " "action."); } @@ -416,7 +416,7 @@ void SharedPnaTableStepper::evalTargetTable( evalTableActionProfile(tableActionList); } else { // We can only generate profile entries for PTF and Protobuf tests. - ::warning( + ::P4::warning( "Action profile control plane entries are not implemented. Using default " "action."); } @@ -444,4 +444,4 @@ SharedPnaTableStepper::SharedPnaTableStepper(SharedPnaExprStepper *stepper, const IR::P4Table *table) : TableStepper(stepper, table) {} -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h b/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h index 2e74aeba8e..e03f7ad22b 100644 --- a/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h +++ b/backends/p4tools/modules/testgen/targets/pna/shared_table_stepper.h @@ -11,7 +11,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/shared_expr_stepper.h" #include "backends/p4tools/modules/testgen/targets/pna/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class SharedPnaTableStepper : public TableStepper { protected: @@ -69,6 +69,6 @@ class SharedPnaTableStepper : public TableStepper { explicit SharedPnaTableStepper(SharedPnaExprStepper *stepper, const IR::P4Table *table); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_SHARED_TABLE_STEPPER_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/target.cpp b/backends/p4tools/modules/testgen/targets/pna/target.cpp index 60add89f95..3d9a1f3ca8 100644 --- a/backends/p4tools/modules/testgen/targets/pna/target.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/target.cpp @@ -20,7 +20,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h" #include "backends/p4tools/modules/testgen/targets/pna/test_backend.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { /* ============================================================================================= * PnaDpdkTestgenTarget implementation @@ -85,4 +85,4 @@ MidEnd PnaDpdkTestgenTarget::mkMidEnd(const CompilerOptions &options) const { return midEnd; } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/target.h b/backends/p4tools/modules/testgen/targets/pna/target.h index 2674b9b0ca..558f9a0cf4 100644 --- a/backends/p4tools/modules/testgen/targets/pna/target.h +++ b/backends/p4tools/modules/testgen/targets/pna/target.h @@ -18,7 +18,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h" #include "backends/p4tools/modules/testgen/targets/pna/test_backend.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaDpdkTestgenTarget : public TestgenTarget { public: @@ -46,6 +46,6 @@ class PnaDpdkTestgenTarget : public TestgenTarget { [[nodiscard]] MidEnd mkMidEnd(const CompilerOptions &options) const override; }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_TARGET_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/test_backend.cpp b/backends/p4tools/modules/testgen/targets/pna/test_backend.cpp index b138efdc57..dc5d1b37d4 100644 --- a/backends/p4tools/modules/testgen/targets/pna/test_backend.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/test_backend.cpp @@ -28,7 +28,7 @@ #include "backends/p4tools/modules/testgen/targets/pna/dpdk/program_info.h" #include "backends/p4tools/modules/testgen/targets/pna/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { const std::set PnaTestBackend::SUPPORTED_BACKENDS = {"METADATA", "PTF"}; @@ -38,7 +38,7 @@ PnaTestBackend::PnaTestBackend(const ProgramInfo &programInfo, : TestBackEnd(programInfo, testBackendConfiguration, symbex) { cstring testBackendString = TestgenOptions::get().testBackend; if (testBackendString.isNullOrEmpty()) { - ::error( + ::P4::error( "No test back end provided. Please provide a test back end using the --test-backend " "parameter. Supported back ends are %1%.", Utils::containerToString(SUPPORTED_BACKENDS)); @@ -129,4 +129,4 @@ const TestSpec *PnaTestBackend::createTestSpec(const ExecutionState *executionSt return testSpec; } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/test_backend.h b/backends/p4tools/modules/testgen/targets/pna/test_backend.h index f50810b421..0b4d479220 100644 --- a/backends/p4tools/modules/testgen/targets/pna/test_backend.h +++ b/backends/p4tools/modules/testgen/targets/pna/test_backend.h @@ -20,7 +20,7 @@ #include "backends/p4tools/modules/testgen/lib/test_backend.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { class PnaTestBackend : public TestBackEnd { private: @@ -41,6 +41,6 @@ class PnaTestBackend : public TestBackEnd { const TestInfo &testInfo) override; }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_TEST_BACKEND_H_ */ diff --git a/backends/p4tools/modules/testgen/targets/pna/test_spec.cpp b/backends/p4tools/modules/testgen/targets/pna/test_spec.cpp index e241ee98c4..4601d608d9 100644 --- a/backends/p4tools/modules/testgen/targets/pna/test_spec.cpp +++ b/backends/p4tools/modules/testgen/targets/pna/test_spec.cpp @@ -5,7 +5,7 @@ #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { using namespace P4::literals; @@ -217,4 +217,4 @@ void MetadataCollection::addMetaDataField(cstring name, const IR::Literal *metad cstring Range::getObjectName() const { return "Range"_cs; } -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna diff --git a/backends/p4tools/modules/testgen/targets/pna/test_spec.h b/backends/p4tools/modules/testgen/targets/pna/test_spec.h index 9be0f8efd2..540d5ddb20 100644 --- a/backends/p4tools/modules/testgen/targets/pna/test_spec.h +++ b/backends/p4tools/modules/testgen/targets/pna/test_spec.h @@ -14,7 +14,7 @@ #include "backends/p4tools/modules/testgen/lib/test_object.h" #include "backends/p4tools/modules/testgen/lib/test_spec.h" -namespace P4Tools::P4Testgen::Pna { +namespace P4::P4Tools::P4Testgen::Pna { /* ========================================================================================= * PnaDpdkRegister @@ -232,6 +232,6 @@ class Range : public TableMatch { DECLARE_TYPEINFO(Range, TableMatch); }; -} // namespace P4Tools::P4Testgen::Pna +} // namespace P4::P4Tools::P4Testgen::Pna #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TARGETS_PNA_TEST_SPEC_H_ */ diff --git a/backends/p4tools/modules/testgen/test/gtest_utils.cpp b/backends/p4tools/modules/testgen/test/gtest_utils.cpp index c1a7551026..2d4063e0e8 100644 --- a/backends/p4tools/modules/testgen/test/gtest_utils.cpp +++ b/backends/p4tools/modules/testgen/test/gtest_utils.cpp @@ -13,7 +13,7 @@ #include "backends/p4tools/modules/testgen/register.h" #include "backends/p4tools/modules/testgen/toolname.h" -namespace Test { +namespace P4::Test { P4ToolsTestCase::P4ToolsTestCase(const P4Tools::CompilerResult &compilerResults) : compilerResults(compilerResults) {} @@ -75,4 +75,4 @@ const IR::SymbolicVariable *SymbolicConverter::preorder(IR::Member *member) { return P4Tools::ToolsVariables::getSymbolicVariable(member->type, member->toString()); } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/test/gtest_utils.h b/backends/p4tools/modules/testgen/test/gtest_utils.h index 6a94f40a54..7310e26159 100644 --- a/backends/p4tools/modules/testgen/test/gtest_utils.h +++ b/backends/p4tools/modules/testgen/test/gtest_utils.h @@ -11,7 +11,7 @@ #include "frontends/common/options.h" #include "ir/ir.h" -namespace Test { +namespace P4::Test { /// Encapsulates functionality for running the front- and mid-ends of the compiler in a test. class P4ToolsTestCase { @@ -57,6 +57,6 @@ class SymbolicConverter : public Transform { const IR::SymbolicVariable *preorder(IR::Member *member) override; }; -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_GTEST_UTILS_H_ */ diff --git a/backends/p4tools/modules/testgen/test/lib/format_int.cpp b/backends/p4tools/modules/testgen/test/lib/format_int.cpp index c2a504044c..7ebbcf8552 100644 --- a/backends/p4tools/modules/testgen/test/lib/format_int.cpp +++ b/backends/p4tools/modules/testgen/test/lib/format_int.cpp @@ -10,7 +10,7 @@ #include "ir/ir.h" #include "ir/irutils.h" -namespace Test { +namespace P4::Test { namespace { @@ -415,4 +415,4 @@ TEST_F(FormatTest, TestMACConversion) { } // anonymous namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/test/lib/format_int.h b/backends/p4tools/modules/testgen/test/lib/format_int.h index d946e55d96..11bd469f3c 100644 --- a/backends/p4tools/modules/testgen/test/lib/format_int.h +++ b/backends/p4tools/modules/testgen/test/lib/format_int.h @@ -3,11 +3,11 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { /// Helper methods to build configurations for Format Tests. class FormatTest : public P4ToolsTest {}; -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_LIB_FORMAT_INT_H_ */ diff --git a/backends/p4tools/modules/testgen/test/lib/p4info_api.cpp b/backends/p4tools/modules/testgen/test/lib/p4info_api.cpp index 6aec3b7a01..ff8597e3fe 100644 --- a/backends/p4tools/modules/testgen/test/lib/p4info_api.cpp +++ b/backends/p4tools/modules/testgen/test/lib/p4info_api.cpp @@ -2,7 +2,7 @@ #include "backends/p4tools/common/control_plane/p4info_map.h" -namespace Test { +namespace P4::Test { namespace { @@ -22,4 +22,4 @@ TEST_F(P4RuntimeApiTest, SzudzikPairingisCorrect) { } // namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/test/lib/p4info_api.h b/backends/p4tools/modules/testgen/test/lib/p4info_api.h index 45362c3113..2dc25cbe4b 100644 --- a/backends/p4tools/modules/testgen/test/lib/p4info_api.h +++ b/backends/p4tools/modules/testgen/test/lib/p4info_api.h @@ -3,11 +3,11 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { /// Helper methods to build configurations for P4RuntimeApi Tests. class P4RuntimeApiTest : public P4ToolsTest {}; -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_LIB_P4INFO_API_H_ */ diff --git a/backends/p4tools/modules/testgen/test/lib/taint.cpp b/backends/p4tools/modules/testgen/test/lib/taint.cpp index 8b03421a25..a4d2bf6ea7 100644 --- a/backends/p4tools/modules/testgen/test/lib/taint.cpp +++ b/backends/p4tools/modules/testgen/test/lib/taint.cpp @@ -15,7 +15,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/test/small-step/util.h" -namespace Test { +namespace P4::Test { namespace { @@ -310,4 +310,4 @@ TEST_F(TaintTest, Taint10) { } // anonymous namespace -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/test/lib/taint.h b/backends/p4tools/modules/testgen/test/lib/taint.h index dd2f3a030f..461456be2e 100644 --- a/backends/p4tools/modules/testgen/test/lib/taint.h +++ b/backends/p4tools/modules/testgen/test/lib/taint.h @@ -3,11 +3,11 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { /// Helper methods to build configurations for Taint Tests. class TaintTest : public P4ToolsTest {}; -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_LIB_TAINT_H_ */ diff --git a/backends/p4tools/modules/testgen/test/small-step/util.cpp b/backends/p4tools/modules/testgen/test/small-step/util.cpp index 3670eb819f..a0ce7d5e1c 100644 --- a/backends/p4tools/modules/testgen/test/small-step/util.cpp +++ b/backends/p4tools/modules/testgen/test/small-step/util.cpp @@ -7,7 +7,7 @@ #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { namespace SmallStepUtil { @@ -64,4 +64,4 @@ V1Switch(parse(), verifyChecksum(), mau(), mau(), computeChecksum(), deparse()) } // namespace SmallStepUtil -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/test/small-step/util.h b/backends/p4tools/modules/testgen/test/small-step/util.h index 673c14cf5e..72f01137f8 100644 --- a/backends/p4tools/modules/testgen/test/small-step/util.h +++ b/backends/p4tools/modules/testgen/test/small-step/util.h @@ -27,7 +27,7 @@ #include "backends/p4tools/modules/testgen/lib/execution_state.h" #include "backends/p4tools/modules/testgen/test/gtest_utils.h" -namespace Test { +namespace P4::Test { using Body = P4Tools::P4Testgen::Continuation::Body; using Continuation = P4Tools::P4Testgen::Continuation; @@ -167,6 +167,6 @@ void stepAndExamineOp( } // namespace SmallStepUtil -} // namespace Test +} // namespace P4::Test #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_SMALL_STEP_UTIL_H_ */ diff --git a/backends/p4tools/modules/testgen/test/z3-solver/accessor.h b/backends/p4tools/modules/testgen/test/z3-solver/accessor.h index 98e142ade7..748f67f365 100644 --- a/backends/p4tools/modules/testgen/test/z3-solver/accessor.h +++ b/backends/p4tools/modules/testgen/test/z3-solver/accessor.h @@ -5,7 +5,7 @@ #include "backends/p4tools/common/core/z3_solver.h" -namespace P4Tools { +namespace P4::P4Tools { // The main class for access to a private members class Z3SolverAccessor { @@ -38,6 +38,6 @@ class Z3SolverAccessor { Z3Solver &solver; }; -} // namespace P4Tools +} // namespace P4::P4Tools #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TEST_Z3_SOLVER_ACCESSOR_H_ */ diff --git a/backends/p4tools/modules/testgen/test/z3-solver/constraints.cpp b/backends/p4tools/modules/testgen/test/z3-solver/constraints.cpp index 8496172cdd..5fa84167da 100644 --- a/backends/p4tools/modules/testgen/test/z3-solver/constraints.cpp +++ b/backends/p4tools/modules/testgen/test/z3-solver/constraints.cpp @@ -9,7 +9,7 @@ #include "ir/irutils.h" #include "lib/cstring.h" -namespace Test { +namespace P4::Test { using namespace P4::literals; using ConstraintVector = const std::vector; @@ -188,4 +188,4 @@ TEST_F(Z3SolverSatisfiabilityChecks, Bools) { } } -} // namespace Test +} // namespace P4::Test diff --git a/backends/p4tools/modules/testgen/testgen.cpp b/backends/p4tools/modules/testgen/testgen.cpp index 87578e9172..f32411eb03 100644 --- a/backends/p4tools/modules/testgen/testgen.cpp +++ b/backends/p4tools/modules/testgen/testgen.cpp @@ -28,7 +28,7 @@ #include "backends/p4tools/modules/testgen/register.h" #include "backends/p4tools/modules/testgen/toolname.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { namespace { @@ -53,22 +53,22 @@ SymbolicExecutor *pickExecutionEngine(const TestgenOptions &testgenOptions, int postProcess(const TestgenOptions &testgenOptions, const TestBackEnd &testBackend) { // Do not print this warning if assertion mode is enabled. if (testBackend.getTestCount() == 0 && !testgenOptions.assertionModeEnabled) { - ::warning( + ::P4::warning( "Unable to generate tests with given inputs. Double-check provided options and " "parameters.\n"); } if (testBackend.getCoverage() < testgenOptions.minCoverage) { - ::error("The tests did not achieve requested coverage of %1%, the coverage is %2%.", - testgenOptions.minCoverage, testBackend.getCoverage()); + ::P4::error("The tests did not achieve requested coverage of %1%, the coverage is %2%.", + testgenOptions.minCoverage, testBackend.getCoverage()); } - return ::errorCount() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + return ::P4::errorCount() == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } std::optional generateAndCollectAbstractTests( const TestgenOptions &testgenOptions, const ProgramInfo &programInfo) { if (!testgenOptions.testBaseName.has_value()) { - ::error( + ::P4::error( "Test collection requires a test name. No name was provided as part of the " "P4Testgen options."); return std::nullopt; @@ -107,7 +107,7 @@ int generateAndWriteAbstractTests(const TestgenOptions &testgenOptions, } else if (!P4CContext::get().options().file.empty()) { testPath = P4CContext::get().options().file.stem(); } else { - ::error("Neither a file nor test base name was set. Can not infer a test name."); + ::P4::error("Neither a file nor test base name was set. Can not infer a test name."); } // Create the directory, if the directory string is valid and if it does not exist. @@ -116,7 +116,7 @@ int generateAndWriteAbstractTests(const TestgenOptions &testgenOptions, try { std::filesystem::create_directories(testDir); } catch (const std::exception &err) { - ::error("Unable to create directory %1%: %2%", testDir.c_str(), err.what()); + ::P4::error("Unable to create directory %1%: %2%", testDir.c_str(), err.what()); return EXIT_FAILURE; } testPath = testDir / testPath; @@ -156,7 +156,7 @@ std::optional generateTestsImpl(std::optional generateTestsImpl(std::optional(); const auto *programInfo = TestgenTarget::produceProgramInfo(*testgenCompilerResult); - if (programInfo == nullptr || ::errorCount() > 0) { - ::error("P4Testgen encountered errors during preprocessing."); + if (programInfo == nullptr || ::P4::errorCount() > 0) { + ::P4::error("P4Testgen encountered errors during preprocessing."); return std::nullopt; } @@ -199,8 +199,8 @@ int Testgen::mainImpl(const CompilerResult &compilerResult) { const auto *testgenCompilerResult = compilerResult.checkedTo(); const auto *programInfo = TestgenTarget::produceProgramInfo(*testgenCompilerResult); - if (programInfo == nullptr || ::errorCount() > 0) { - ::error("P4Testgen encountered errors during preprocessing."); + if (programInfo == nullptr || ::P4::errorCount() > 0) { + ::P4::error("P4Testgen encountered errors during preprocessing."); return EXIT_FAILURE; } return generateAndWriteAbstractTests(TestgenOptions::get(), *programInfo); @@ -263,4 +263,4 @@ int Testgen::writeTests(const CompilerOptions &compilerOptions, return EXIT_FAILURE; } -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen diff --git a/backends/p4tools/modules/testgen/testgen.h b/backends/p4tools/modules/testgen/testgen.h index 3b6501cd84..7da665d502 100644 --- a/backends/p4tools/modules/testgen/testgen.h +++ b/backends/p4tools/modules/testgen/testgen.h @@ -6,7 +6,7 @@ #include "backends/p4tools/modules/testgen/lib/test_framework.h" #include "backends/p4tools/modules/testgen/options.h" -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { /// This is main implementation of the P4Testgen tool. class Testgen : public AbstractP4cTool { @@ -48,6 +48,6 @@ class Testgen : public AbstractP4cTool { virtual ~Testgen() = default; }; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TESTGEN_H_ */ diff --git a/backends/p4tools/modules/testgen/toolname.h b/backends/p4tools/modules/testgen/toolname.h index ba0f0afb89..e73f67eb22 100644 --- a/backends/p4tools/modules/testgen/toolname.h +++ b/backends/p4tools/modules/testgen/toolname.h @@ -3,10 +3,10 @@ #include -namespace P4Tools::P4Testgen { +namespace P4::P4Tools::P4Testgen { static inline constexpr std::string_view TOOL_NAME = "testgen"; -} // namespace P4Tools::P4Testgen +} // namespace P4::P4Tools::P4Testgen #endif /* BACKENDS_P4TOOLS_MODULES_TESTGEN_TOOLNAME_H_ */ diff --git a/backends/tc/backend.cpp b/backends/tc/backend.cpp index 4550d8cb1a..9d3d8d0c24 100644 --- a/backends/tc/backend.cpp +++ b/backends/tc/backend.cpp @@ -21,7 +21,7 @@ and limitations under the License. #include "backends/ebpf/ebpfOptions.h" #include "backends/ebpf/target.h" -namespace TC { +namespace P4::TC { using namespace P4::literals; @@ -43,7 +43,7 @@ const cstring pnaOutputMeta = "pna_main_output_metadata_t"_cs; bool Backend::process() { CHECK_NULL(toplevel); if (toplevel->getMain() == nullptr) { - ::error("main is missing in the package"); + ::P4::error("main is missing in the package"); return false; // no main } auto refMapEBPF = refMap; @@ -57,7 +57,7 @@ bool Backend::process() { new P4::TypeChecking(refMap, typeMap, true), tcIR, genIJ}); backEnd.addDebugHook(hook, true); toplevel->getProgram()->apply(backEnd); - if (::errorCount() > 0) return false; + if (::P4::errorCount() > 0) return false; if (!ebpfCodeGen(refMapEBPF, typeMapEBPF)) return false; return true; } @@ -73,10 +73,10 @@ bool Backend::ebpfCodeGen(P4::ReferenceMap *refMapEBPF, P4::TypeMap *typeMapEBPF if (!main) return false; if (main->type->name != "PNA_NIC") { - ::warning(ErrorType::WARN_INVALID, - "%1%: the main package should be called PNA_NIC" - "; are you using the wrong architecture?", - main->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main package should be called PNA_NIC" + "; are you using the wrong architecture?", + main->type->name); return false; } @@ -128,7 +128,7 @@ void Backend::serialize() const { ebpf_program->emit(&c); ebpf_program->emitParser(&p); ebpf_program->emitHeader(&h); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return; } std::filesystem::path outputFile = options.outputFolder / (progName + ".template"); @@ -151,15 +151,15 @@ void Backend::serialize() const { auto pstream = openFile(parserFile, false); auto hstream = openFile(headerFile, false); if (cstream == nullptr) { - ::error("Unable to open File %1%", postParserFile); + ::P4::error("Unable to open File %1%", postParserFile); return; } if (pstream == nullptr) { - ::error("Unable to open File %1%", parserFile); + ::P4::error("Unable to open File %1%", parserFile); return; } if (hstream == nullptr) { - ::error("Unable to open File %1%", headerFile); + ::P4::error("Unable to open File %1%", headerFile); return; } *cstream << c.toString(); @@ -180,7 +180,7 @@ bool Backend::serializeIntrospectionJson(std::ostream &out) const { void ConvertToBackendIR::setPipelineName() { if (options.file.empty()) { - ::error("filename is not given in command line option"); + ::P4::error("filename is not given in command line option"); return; } @@ -231,14 +231,15 @@ void ConvertToBackendIR::postorder(const IR::P4Action *action) { IR::TCActionParam *tcActionParam = new IR::TCActionParam(); tcActionParam->setParamName(param->name.originalName); if (!paramType->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1% parameter with type other than bit is not supported", param); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1% parameter with type other than bit is not supported", param); return; } else { auto paramTypeName = paramType->to()->baseName(); if (paramTypeName != "bit") { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1% parameter with type other than bit is not supported", param); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1% parameter with type other than bit is not supported", + param); return; } tcActionParam->setDataType(TC::BIT_TYPE); @@ -254,12 +255,12 @@ void ConvertToBackendIR::postorder(const IR::P4Action *action) { if (val != TC::BIT_TYPE) { tcActionParam->setDataType(val); } else { - ::error(ErrorType::ERR_INVALID, - "tc_type annotation cannot have '%1%' as value", expr); + ::P4::error(ErrorType::ERR_INVALID, + "tc_type annotation cannot have '%1%' as value", expr); } } else { - ::error(ErrorType::ERR_INVALID, - "tc_type annotation cannot have '%1%' as value", expr); + ::P4::error(ErrorType::ERR_INVALID, + "tc_type annotation cannot have '%1%' as value", expr); } } auto direction = param->direction; @@ -295,8 +296,8 @@ void ConvertToBackendIR::updateConstEntries(const IR::P4Table *t, IR::TCTable *t for (auto e : entriesList->entries) { auto keyset = e->getKeys(); if (keyset->components.size() != keys->keyElements.size()) { - ::error(ErrorType::ERR_INVALID, - "No of keys in const_entries should be same as no of keys in the table."); + ::P4::error(ErrorType::ERR_INVALID, + "No of keys in const_entries should be same as no of keys in the table."); return; } ordered_map keyList; @@ -398,10 +399,11 @@ void ConvertToBackendIR::updateDefaultMissAction(const IR::P4Table *t, IR::TCTab auto i = 0; if (isTCMayOverrideMiss) { if (paramList->parameters.empty()) - ::warning(ErrorType::WARN_INVALID, - "%1% annotation cannot be used with default_action without " - "parameters", - overrideAnno); + ::P4::warning( + ErrorType::WARN_INVALID, + "%1% annotation cannot be used with default_action without " + "parameters", + overrideAnno); else tabledef->setTcMayOverrideMiss(); } @@ -422,10 +424,10 @@ void ConvertToBackendIR::updateDefaultMissAction(const IR::P4Table *t, IR::TCTab } } else { if (isTCMayOverrideMiss) - ::warning(ErrorType::WARN_INVALID, - "%1% annotation cannot be used with default_action with " - "directional parameters", - overrideAnno); + ::P4::warning(ErrorType::WARN_INVALID, + "%1% annotation cannot be used with default_action with " + "directional parameters", + overrideAnno); } } } @@ -466,68 +468,69 @@ void ConvertToBackendIR::updateDefaultHitAction(const IR::P4Table *t, IR::TCTabl } } if (isTableOnly && isDefaultHit && isDefaultHitConst) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' has an action reference '%2%' which is " - "annotated with '@tableonly', '@default_hit' and '@default_hit_const'", - t->name.originalName, action->getName().originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' has an action reference '%2%' which is " + "annotated with '@tableonly', '@default_hit' and '@default_hit_const'", + t->name.originalName, action->getName().originalName); break; } else if (isTableOnly && isDefaultHit) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' has an action reference '%2%' which is " - "annotated with '@tableonly' and '@default_hit'", - t->name.originalName, action->getName().originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' has an action reference '%2%' which is " + "annotated with '@tableonly' and '@default_hit'", + t->name.originalName, action->getName().originalName); break; } else if (isTableOnly && isDefaultHitConst) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' has an action reference '%2%' which is " - "annotated with '@tableonly' and '@default_hit_const'", - t->name.originalName, action->getName().originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' has an action reference '%2%' which is " + "annotated with '@tableonly' and '@default_hit_const'", + t->name.originalName, action->getName().originalName); break; } else if (isDefaultHit && isDefaultHitConst) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' has an action reference '%2%' which is " - "annotated with '@default_hit' and '@default_hit_const'", - t->name.originalName, action->getName().originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' has an action reference '%2%' which is " + "annotated with '@default_hit' and '@default_hit_const'", + t->name.originalName, action->getName().originalName); break; } else if (isTcMayOverrideHit) { auto adecl = refMap->getDeclaration(action->getPath(), true); auto p4Action = adecl->getNode()->checkedTo(); if (!isDefaultHit && !isDefaultHitConst) { - ::warning(ErrorType::WARN_INVALID, - "Table '%1%' has an action reference '%2%' which is " - "annotated with '@tc_may_override' without '@default_hit' or " - "'@default_hit_const'", - t->name.originalName, action->getName().originalName); + ::P4::warning(ErrorType::WARN_INVALID, + "Table '%1%' has an action reference '%2%' which is " + "annotated with '@tc_may_override' without '@default_hit' or " + "'@default_hit_const'", + t->name.originalName, action->getName().originalName); isTcMayOverrideHit = false; break; } else if (p4Action->getParameters()->parameters.empty()) { - ::warning(ErrorType::WARN_INVALID, - " '@tc_may_override' cannot be used for %1% action " - " without parameters", - action->getName().originalName); + ::P4::warning(ErrorType::WARN_INVALID, + " '@tc_may_override' cannot be used for %1% action " + " without parameters", + action->getName().originalName); isTcMayOverrideHit = false; break; } isTcMayOverrideHitAction = true; } } - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return; } if ((defaultHit > 0) && (defaultHitConst > 0)) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' cannot have both '@default_hit' action " - "and '@default_hit_const' action", - t->name.originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' cannot have both '@default_hit' action " + "and '@default_hit_const' action", + t->name.originalName); return; } else if (defaultHit > 1) { - ::error(ErrorType::ERR_INVALID, "Table '%1%' can have only one '@default_hit' action", - t->name.originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' can have only one '@default_hit' action", + t->name.originalName); return; } else if (defaultHitConst > 1) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' can have only one '@default_hit_const' action", - t->name.originalName); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' can have only one '@default_hit_const' action", + t->name.originalName); return; } if (defaultActionName != nullptr && @@ -567,10 +570,10 @@ void ConvertToBackendIR::updatePnaDirectCounter(const IR::P4Table *t, IR::TCTabl auto externInstance = P4::ExternInstance::resolve(expr, refMap, typeMap); if (!externInstance) { - ::error(ErrorType::ERR_INVALID, - "Expected %1% property value for table %2% to resolve to an " - "extern instance: %3%", - propertyName, t->name.originalName, property); + ::P4::error(ErrorType::ERR_INVALID, + "Expected %1% property value for table %2% to resolve to an " + "extern instance: %3%", + propertyName, t->name.originalName, property); return; } for (auto ext : externsInfo) { @@ -626,8 +629,8 @@ unsigned ConvertToBackendIR::GetAccessNumericValue(std::string_view access) { mask = 1; break; default: - ::error(ErrorType::ERR_INVALID, - "tc_acl annotation cannot have '%1%' in access permisson", s); + ::P4::error(ErrorType::ERR_INVALID, + "tc_acl annotation cannot have '%1%' in access permisson", s); } value |= mask; } @@ -661,7 +664,7 @@ cstring ConvertToBackendIR::HandleTableAccessPermission(const IR::P4Table *t) { if (IsTableAddOnMiss) { auto access = data_path.find('C'); if (!access) { - ::warning( + ::P4::warning( ErrorType::WARN_INVALID, "Add on miss table '%1%' should have 'create' access permissons for data path.", t->name.originalName); @@ -707,8 +710,8 @@ void ConvertToBackendIR::postorder(const IR::P4Table *t) { if (sizeProperty->fitsUint64()) { tEntriesCount = sizeProperty->asUint64(); } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "table with size %1% cannot be supported", t->getSizeProperty()); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "table with size %1% cannot be supported", t->getSizeProperty()); return; } } @@ -736,10 +739,10 @@ void ConvertToBackendIR::postorder(const IR::P4Table *t) { if (auto val = expr->to()) { tableDefinition->setNumMask(val->asUint64()); } else { - ::error(ErrorType::ERR_INVALID, - "nummask annotation cannot have '%1%' as value. Only integer " - "constants are allowed", - expr); + ::P4::error(ErrorType::ERR_INVALID, + "nummask annotation cannot have '%1%' as value. Only integer " + "constants are allowed", + expr); } } } @@ -1150,8 +1153,8 @@ unsigned int ConvertToBackendIR::findMappedKernelMeta(const IR::Member *mem) { case TC::INPUT_TIMESTAMP: return TC::SKBTSTAMP; case TC::INPUT_PARSER_ERROR: - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1% is not supported in this target", mem); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1% is not supported in this target", mem); return TC::UNSUPPORTED; case TC::INPUT_CLASS_OF_SERVICE: return TC::SKBPRIO; @@ -1257,9 +1260,9 @@ void ConvertToBackendIR::updateMatchType(const IR::P4Table *t, IR::TCTable *tabl matchTypeInfo->name.name == "optional") { tableMatchType = TC::TERNARY_TYPE; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "match type %1% is not supported in this target", - key->keyElements[0]->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "match type %1% is not supported in this target", + key->keyElements[0]->matchType); return; } } else { @@ -1291,8 +1294,8 @@ void ConvertToBackendIR::updateMatchType(const IR::P4Table *t, IR::TCTable *tabl keyMatchType = TC::TERNARY_TYPE; ternaryKey++; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "match type %1% is not supported in this target", k->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "match type %1% is not supported in this target", k->matchType); return; } keyCount++; @@ -1323,4 +1326,4 @@ bool ConvertToBackendIR::checkParameterDirection(const IR::TCAction *tcAction) { return dirParam; } -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/backend.h b/backends/tc/backend.h index 9b70730621..20a714ea6c 100644 --- a/backends/tc/backend.h +++ b/backends/tc/backend.h @@ -35,7 +35,7 @@ and limitations under the License. #include "tcAnnotations.h" #include "tc_defines.h" -namespace TC { +namespace P4::TC { extern cstring PnaMainParserInputMetaFields[TC::MAX_PNA_PARSER_META]; extern cstring PnaMainInputMetaFields[TC::MAX_PNA_INPUT_META]; @@ -173,6 +173,6 @@ class Backend : public PassManager { bool emitCFile(); }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_BACKEND_H_ */ diff --git a/backends/tc/ebpfCodeGen.cpp b/backends/tc/ebpfCodeGen.cpp index dfa13401eb..2fdcd83bac 100644 --- a/backends/tc/ebpfCodeGen.cpp +++ b/backends/tc/ebpfCodeGen.cpp @@ -16,7 +16,7 @@ and limitations under the License. #include "ebpfCodeGen.h" -namespace TC { +namespace P4::TC { // =====================PNAEbpfGenerator============================= void PNAEbpfGenerator::emitPNAIncludes(EBPF::CodeBuilder *builder) const { @@ -628,7 +628,8 @@ void PnaStateTranslationVisitor::compileExtractField(const IR::Expression *expr, std::string sInt = annoVal->text.substr(2).c_str(); unsigned int width = std::stoi(sInt); if (widthToExtract != width) { - ::error("Width of the field doesnt match the annotation width. '%1%'", field); + ::P4::error("Width of the field doesnt match the annotation width. '%1%'", + field); } noEndiannessConversion = true; break; @@ -697,10 +698,11 @@ void PnaStateTranslationVisitor::compileExtractField(const IR::Expression *expr, // To correctly insert that padding, the length of field must be known, but tools like // nikss-ctl (and the nikss library) don't consume P4info.txt to have such knowledge. // There is also a bug in (de)parser causing such fields to be deparsed incorrectly. - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: fields wider than 64 bits must have a size multiple of 8 bits (1 byte) " - "due to ambiguous padding in the LSB byte when the condition is not met", - field); + ::P4::error( + ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: fields wider than 64 bits must have a size multiple of 8 bits (1 byte) " + "due to ambiguous padding in the LSB byte when the condition is not met", + field); } // wide values; read all bytes one by one. @@ -815,12 +817,12 @@ void EBPFTablePNA::emitKeyType(EBPF::CodeBuilder *builder) { auto matchType = mtdecl->getNode()->checkedTo(); if (!isMatchTypeSupported(matchType)) { - ::error(ErrorType::ERR_UNSUPPORTED, "Match of type %1% not supported", - c->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Match of type %1% not supported", + c->matchType); } - auto ebpfType = ::get(keyTypes, c); - cstring fieldName = ::get(keyFieldNames, c); + auto ebpfType = ::P4::get(keyTypes, c); + cstring fieldName = ::P4::get(keyFieldNames, c); if (ebpfType->is() && ebpfType->as().alignment() > structAlignment) { @@ -1152,7 +1154,7 @@ bool IngressDeparserPNA::build() { auto pl = controlBlock->container->type->applyParams; if (pl->size() != 4) { - ::error(ErrorType::ERR_EXPECTED, "Expected deparser to have exactly 4 parameters"); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected deparser to have exactly 4 parameters"); return false; } @@ -1338,8 +1340,8 @@ bool ConvertToEBPFParserPNA::preorder(const IR::ParserBlock *prsr) { unsigned numOfParams = 4; if (pl->size() != numOfParams) { - ::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly %1% parameters", - numOfParams); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly %1% parameters", + numOfParams); return false; } @@ -1385,8 +1387,8 @@ bool ConvertToEBPFControlPNA::preorder(const IR::ControlBlock *ctrl) { auto pl = ctrl->container->type->applyParams; unsigned numOfParams = 4; if (pl->size() != numOfParams) { - ::error(ErrorType::ERR_EXPECTED, "Expected control to have exactly %1% parameters", - numOfParams); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected control to have exactly %1% parameters", + numOfParams); return false; } auto it = pl->parameters.begin(); @@ -1487,7 +1489,8 @@ bool ConvertToEBPFControlPNA::preorder(const IR::ExternBlock *instance) { auto ctr = new EBPFCounterPNA(program, di, name, control->codeGen); control->counters.emplace(name, ctr); } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", instance); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", + instance); } return false; @@ -1547,8 +1550,8 @@ bool ControlBodyTranslatorPNA::preorder(const IR::Member *m) { builder->append("compiler_meta__->parser_error"); return false; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: this metadata field is not supported", m); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: this metadata field is not supported", m); } } } @@ -1583,24 +1586,24 @@ const IR::P4Action *ControlBodyTranslatorPNA::GetAddOnMissHitAction(cstring acti if (action->name.originalName == actionName) { auto annotations = a->getAnnotations(); if (annotations && annotations->getSingle("defaultonly"_cs)) { - ::error(ErrorType::ERR_UNEXPECTED, - "add_entry hit action %1% cannot be annotated with defaultonly.", - actionName); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "add_entry hit action %1% cannot be annotated with defaultonly.", + actionName); } return action; } } - ::error(ErrorType::ERR_UNEXPECTED, - "add_entry extern can only be applied for one of the hit action of table " - "%1%. %2% is not hit action of table.", - table->instanceName, actionName); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "add_entry extern can only be applied for one of the hit action of table " + "%1%. %2% is not hit action of table.", + table->instanceName, actionName); return nullptr; } void ControlBodyTranslatorPNA::ValidateAddOnMissMissAction(const IR::P4Action *act) { if (!act) { - ::error(ErrorType::ERR_UNEXPECTED, "%1% add_entry extern can only be used in an action", - act); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1% add_entry extern can only be used in an action", + act); } const IR::P4Table *t = table->table->container; const IR::Expression *defaultAction = t->getDefaultAction(); @@ -1608,13 +1611,13 @@ void ControlBodyTranslatorPNA::ValidateAddOnMissMissAction(const IR::P4Action *a auto defaultActionName = table->getActionNameExpression(defaultAction); CHECK_NULL(defaultActionName); if (defaultActionName->path->name.originalName != act->name.originalName) { - ::error(ErrorType::ERR_UNEXPECTED, - "add_entry extern can only be applied in default action of the table."); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "add_entry extern can only be applied in default action of the table."); } if (!IsTableAddOnMiss(t)) { - ::warning(ErrorType::WARN_MISSING, - "add_entry extern can only be used in an action" - " of a table with property add_on_miss equals to true."); + ::P4::warning(ErrorType::WARN_MISSING, + "add_entry extern can only be used in an action" + " of a table with property add_on_miss equals to true."); } ((ConvertToBackendIR *)tcIR)->updateAddOnMissTable(t); } @@ -1698,10 +1701,10 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio auto paramList = action->getParameters(); auto components = param->to()->components; if (paramList->parameters.size() != components.size()) { - ::error(ErrorType::ERR_UNEXPECTED, - "Action params in add_entry should be same as no of action " - "parameters. %1%", - action); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Action params in add_entry should be same as no of action " + "parameters. %1%", + action); } if (paramList->parameters.size() != 0) { builder->emitIndent(); @@ -1714,10 +1717,10 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio for (size_t index = 0; index < components.size(); index++) { auto param = paramList->getParameter(index); if (param->direction != IR::Direction::None) { - ::error(ErrorType::ERR_UNEXPECTED, - "Parameters of action called from add_entry should be " - "directionless. %1%", - actionName); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Parameters of action called from add_entry should be " + "directionless. %1%", + actionName); } builder->emitIndent(); builder->appendFormat("update_act_bpf_val->u.%s.%s = ", actionExtName, @@ -1738,9 +1741,9 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio } } else { - ::error(ErrorType::ERR_UNEXPECTED, - "action parameters of add_entry extern should be a structure only. %1%", - param); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "action parameters of add_entry extern should be a structure only. %1%", + param); } } builder->newline(); @@ -1832,8 +1835,8 @@ void ControlBodyTranslatorPNA::processApply(const P4::ApplyMethod *method) { builder->newline(); // Emit Keys for (auto c : table->keyGenerator->keyElements) { - auto ebpfType = ::get(table->keyTypes, c); - cstring fieldName = ::get(table->keyFieldNames, c); + auto ebpfType = ::P4::get(table->keyTypes, c); + cstring fieldName = ::P4::get(table->keyFieldNames, c); if (fieldName == nullptr || ebpfType == nullptr) continue; bool memcpy = false; EBPF::EBPFScalarType *scalar = nullptr; @@ -1967,7 +1970,8 @@ void ControlBodyTranslatorPNA::processMethod(const P4::ExternMethod *method) { if (method->method->type->name == "write") { reg->emitRegisterWrite(builder, method, this); } else if (method->method->type->name == "read") { - ::warning(ErrorType::WARN_UNUSED, "This Register(%1%) read value is not used!", name); + ::P4::warning(ErrorType::WARN_UNUSED, "This Register(%1%) read value is not used!", + name); reg->emitRegisterRead(builder, method, this, nullptr); } return; @@ -1981,7 +1985,8 @@ void ControlBodyTranslatorPNA::processMethod(const P4::ExternMethod *method) { hash->processMethod(builder, method->method->name.name, method->expr, this); return; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unexpected method call", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unexpected method call", + method->expr); } } @@ -2076,8 +2081,9 @@ void ActionTranslationVisitorPNA::processMethod(const P4::ExternMethod *method) if (pna_ctr != nullptr) pna_ctr->emitDirectMethodInvocation(builder, method, this->tcIR); else - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Table %2% does not own DirectCounter named %3%", - method->expr, table->table->container, instanceName); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: Table %2% does not own DirectCounter named %3%", method->expr, + table->table->container, instanceName); } else { ControlBodyTranslatorPNA::processMethod(method); } @@ -2101,8 +2107,8 @@ void EBPFTablePNA::validateKeys() const { auto matchType = mtdecl->getNode()->checkedTo(); if (matchType->name.name == P4::P4CoreLibrary::instance().lpmMatch.name) { if (it != *lastKey) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% field key must be at the end of whole key", - it->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1% field key must be at the end of whole key", it->matchType); } } } @@ -2125,8 +2131,8 @@ void DeparserHdrEmitTranslatorPNA::processMethod(const P4::ExternMethod *method) auto exprType = deparser->program->typeMap->getType(expr); auto headerToEmit = exprType->to(); if (headerToEmit == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", - expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Cannot emit a non-header type %1%", expr); } cstring msgStr; @@ -2161,8 +2167,8 @@ void DeparserHdrEmitTranslatorPNA::processMethod(const P4::ExternMethod *method) auto etype = EBPF::EBPFTypeFactory::instance->create(ftype); auto et = etype->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", f); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", f); return; } bool noEndiannessConversion = false; @@ -2196,8 +2202,8 @@ void DeparserHdrEmitTranslatorPNA::emitField(EBPF::CodeBuilder *builder, cstring auto et = type->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", hdrExpr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", hdrExpr); return; } unsigned widthToEmit = et->widthInBits(); @@ -2464,4 +2470,4 @@ void CRC32ChecksumAlgorithmPNA::emitGlobals(EBPF::CodeBuilder *builder) { builder->appendLine(code); } -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/ebpfCodeGen.h b/backends/tc/ebpfCodeGen.h index 31a23bb8fe..f244604d94 100644 --- a/backends/tc/ebpfCodeGen.h +++ b/backends/tc/ebpfCodeGen.h @@ -21,7 +21,7 @@ and limitations under the License. #include "backend.h" #include "tcExterns.h" -namespace TC { +namespace P4::TC { using namespace P4::literals; @@ -80,8 +80,8 @@ class PNAErrorCodesGen : public Inspector { // type ParserError_t is u8, which can have values from 0 to 255 if (id > 255) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: Reached maximum number of possible errors", - decl); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "%1%: Reached maximum number of possible errors", decl); } } builder->newline(); @@ -281,7 +281,7 @@ class EBPFControlPNA : public EBPF::EBPFControlPSA { : EBPF::EBPFControlPSA(program, control, parserHeaders) {} EBPFRegisterPNA *getRegister(cstring name) const { - auto result = ::get(pna_registers, name); + auto result = ::P4::get(pna_registers, name); BUG_CHECK(result != nullptr, "No register named %1%", name); return result; } @@ -464,6 +464,6 @@ class EBPFHashAlgorithmTypeFactoryPNA : public EBPF::EBPFHashAlgorithmTypeFactor EBPF::EBPFHashAlgorithmPSA *create(int type, const EBPF::EBPFProgram *program, cstring name); }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_EBPFCODEGEN_H_ */ diff --git a/backends/tc/introspection.cpp b/backends/tc/introspection.cpp index 99ce2fec14..b1952c417d 100644 --- a/backends/tc/introspection.cpp +++ b/backends/tc/introspection.cpp @@ -18,7 +18,7 @@ and limitations under the License. /// This file defines functions for the pass to generate the introspection file -namespace TC { +namespace P4::TC { void IntrospectionGenerator::postorder(const IR::P4Table *t) { p4tables.emplace(t->name.originalName, t); @@ -75,12 +75,12 @@ void IntrospectionGenerator::collectKeyInfo(const IR::Key *key, struct TableAttr auto val = std::move(*tcVal); keyField->type = val; } else { - ::error(ErrorType::ERR_INVALID, - "tc_type annotation cannot have '%1%' as value", expr); + ::P4::error(ErrorType::ERR_INVALID, + "tc_type annotation cannot have '%1%' as value", expr); } } else { - ::error(ErrorType::ERR_INVALID, "tc_type annotation cannot have '%1%' as value", - expr); + ::P4::error(ErrorType::ERR_INVALID, + "tc_type annotation cannot have '%1%' as value", expr); } } if (anno->name == IR::Annotation::nameAnnotation) { @@ -121,7 +121,7 @@ void IntrospectionGenerator::collectActionInfo(const IR::ActionList *actionlist, actionInfo->annotations.push_back(actionAnno); } if (isTableOnly && isDefaultOnly) { - ::error( + ::P4::error( "Table '%1%' has an action reference '%2%' which is " "annotated with both '@tableonly' and '@defaultonly'", p4table->getName().originalName, action->getName().originalName); @@ -344,7 +344,7 @@ const Util::JsonObject *IntrospectionGenerator::genIntrospectionJson() { bool IntrospectionGenerator::serializeIntrospectionJson(std::ostream &destination) { auto *json = genIntrospectionJson(); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return false; } json->serialize(destination); @@ -360,4 +360,4 @@ std::optional IntrospectionGenerator::checkValidTcType(const IR::String return std::nullopt; } -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/introspection.h b/backends/tc/introspection.h index ab40c256ee..d5aba9fbb1 100644 --- a/backends/tc/introspection.h +++ b/backends/tc/introspection.h @@ -28,7 +28,7 @@ and limitations under the License. /// This file declares the different structures to be used in the introspection json file and the /// pass to generate the file An introspection json file generated by the tc backend is used for /// control plane programming by P4TC in Linux kernel -namespace TC { +namespace P4::TC { using namespace P4::literals; @@ -173,6 +173,6 @@ class IntrospectionGenerator : public Inspector { cstring externalName(const IR::IDeclaration *declaration); }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_INTROSPECTION_H_ */ diff --git a/backends/tc/midend.cpp b/backends/tc/midend.cpp index a8b0ef567c..2a5aa3d5c4 100644 --- a/backends/tc/midend.cpp +++ b/backends/tc/midend.cpp @@ -16,7 +16,7 @@ and limitations under the License. #include "midend.h" -namespace TC { +namespace P4::TC { const IR::ToplevelBlock *MidEnd::run(TCOptions &options, const IR::P4Program *program, std::ostream *outStream) { @@ -71,9 +71,9 @@ const IR::ToplevelBlock *MidEnd::run(TCOptions &options, const IR::P4Program *pr midEnd.setName("MidEnd"); midEnd.addDebugHooks(hooks); program = program->apply(midEnd); - if (::errorCount() > 0) return nullptr; + if (::P4::errorCount() > 0) return nullptr; return evaluator->getToplevelBlock(); } -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/midend.h b/backends/tc/midend.h index bcfad71b2f..bd940b920d 100644 --- a/backends/tc/midend.h +++ b/backends/tc/midend.h @@ -57,7 +57,7 @@ and limitations under the License. #include "midend/validateProperties.h" #include "options.h" -namespace TC { +namespace P4::TC { class MidEnd { public: @@ -70,6 +70,6 @@ class MidEnd { const IR::ToplevelBlock *run(TCOptions &options, const IR::P4Program *program, std::ostream *outStream = nullptr); }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_MIDEND_H_ */ diff --git a/backends/tc/options.h b/backends/tc/options.h index 76c8ee47a6..d489c555e4 100644 --- a/backends/tc/options.h +++ b/backends/tc/options.h @@ -20,7 +20,7 @@ and limitations under the License. #include "backends/ebpf/ebpfOptions.h" #include "frontends/common/options.h" -namespace TC { +namespace P4::TC { class TCOptions : public CompilerOptions { public: @@ -81,6 +81,6 @@ class TCOptions : public CompilerOptions { using TCContext = P4CContextWithOptions; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_OPTIONS_H_ */ diff --git a/backends/tc/pnaProgramStructure.cpp b/backends/tc/pnaProgramStructure.cpp index 058b6d4f39..7a3098909d 100644 --- a/backends/tc/pnaProgramStructure.cpp +++ b/backends/tc/pnaProgramStructure.cpp @@ -16,7 +16,7 @@ and limitations under the License. #include "pnaProgramStructure.h" -namespace TC { +namespace P4::TC { using namespace P4::literals; @@ -79,9 +79,9 @@ void InspectPnaProgram::addTypesAndInstances(const IR::Type_StructLike *type, bo if (ft->is()) { // The headers struct can not contain nested structures. if (isHeader && ft->is()) { - ::error(ErrorType::ERR_INVALID, - "Type %1% should only contain headers, header stacks, or header unions", - type); + ::P4::error(ErrorType::ERR_INVALID, + "Type %1% should only contain headers, header stacks, or header unions", + type); return; } auto st = ft->to(); @@ -102,8 +102,8 @@ void InspectPnaProgram::addTypesAndInstances(const IR::Type_StructLike *type, bo if (auto h_type = uft->to()) { addHeaderInstance(h_type, uf->controlPlaneName()); } else { - ::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, - uft); + ::P4::error(ErrorType::ERR_INVALID, "Type %1% cannot contain type %2%", ft, + uft); return; } } @@ -278,4 +278,4 @@ bool ParsePnaArchitecture::preorder(const IR::PackageBlock *block) { return false; } -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/pnaProgramStructure.h b/backends/tc/pnaProgramStructure.h index eba4da8fbc..9185eb74bc 100644 --- a/backends/tc/pnaProgramStructure.h +++ b/backends/tc/pnaProgramStructure.h @@ -23,7 +23,7 @@ and limitations under the License. #include "ir/ir.h" #include "lib/cstring.h" -namespace TC { +namespace P4::TC { enum block_t { PARSER, @@ -111,9 +111,9 @@ class ParsePnaArchitecture : public Inspector { } void modelError(const char *format, const IR::INode *node) { - ::error(ErrorType::ERR_MODEL, - (cstring(format) + "\nAre you using an up-to-date 'pna.p4'?").c_str(), - node->getNode()); + ::P4::error(ErrorType::ERR_MODEL, + (cstring(format) + "\nAre you using an up-to-date 'pna.p4'?").c_str(), + node->getNode()); } bool preorder(const IR::ToplevelBlock *block) override; @@ -153,6 +153,6 @@ class InspectPnaProgram : public Inspector { bool preorder(const IR::Parameter *parameter) override; }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_PNAPROGRAMSTRUCTURE_H_ */ diff --git a/backends/tc/tc.cpp b/backends/tc/tc.cpp index 0315635ec6..ece7ec7a3f 100644 --- a/backends/tc/tc.cpp +++ b/backends/tc/tc.cpp @@ -29,6 +29,8 @@ and limitations under the License. #include "options.h" #include "version.h" +using namespace P4; + int main(int argc, char *const argv[]) { setup_gc_logging(); AutoCompileContext autoTCContext(new TC::TCContext); @@ -39,17 +41,17 @@ int main(int argc, char *const argv[]) { if (options.process(argc, argv) != nullptr) { options.setInputFile(); } - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return 1; } auto hook = options.getDebugHook(); auto chkprogram = P4::parseP4File(options); - if (chkprogram == nullptr || ::errorCount() > 0) { + if (chkprogram == nullptr || ::P4::errorCount() > 0) { return 1; } const IR::P4Program *program = chkprogram; - if (program == nullptr || ::errorCount() > 0) { + if (program == nullptr || ::P4::errorCount() > 0) { return 1; } try { @@ -62,7 +64,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (program == nullptr || ::errorCount() > 0) { + if (program == nullptr || ::P4::errorCount() > 0) { return 1; } @@ -73,11 +75,11 @@ int main(int argc, char *const argv[]) { midEnd.addDebugHook(hook); try { toplevel = midEnd.run(options, program); - if (::errorCount() > 1 || toplevel == nullptr) { + if (::P4::errorCount() > 1 || toplevel == nullptr) { return 1; } if (toplevel->getMain() == nullptr) { - ::error("Cannot process input file. Program does not contain a 'main' module"); + ::P4::error("Cannot process input file. Program does not contain a 'main' module"); return 1; } if (!options.dumpJsonFile.empty()) @@ -86,7 +88,7 @@ int main(int argc, char *const argv[]) { std::cerr << bug.what() << std::endl; return 1; } - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { return 1; } TC::Backend backend(toplevel, &midEnd.refMap, &midEnd.typeMap, options); @@ -102,9 +104,9 @@ int main(int argc, char *const argv[]) { } } backend.serialize(); - if (::errorCount() > 0) { + if (::P4::errorCount() > 0) { std::remove(introspecFile.c_str()); return 1; } - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/tc/tcAnnotations.cpp b/backends/tc/tcAnnotations.cpp index 4cc6b4fb00..e518679207 100644 --- a/backends/tc/tcAnnotations.cpp +++ b/backends/tc/tcAnnotations.cpp @@ -16,7 +16,7 @@ and limitations under the License. #include "tcAnnotations.h" -namespace TC { +namespace P4::TC { using namespace P4::literals; @@ -36,4 +36,4 @@ const cstring ParseTCAnnotations::tc_init_val = "tc_init_val"_cs; const cstring ParseTCAnnotations::tc_numel = "tc_numel"_cs; const cstring ParseTCAnnotations::tc_acl = "tc_acl"_cs; -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/tcAnnotations.h b/backends/tc/tcAnnotations.h index c4a475d0f6..a1830920f7 100644 --- a/backends/tc/tcAnnotations.h +++ b/backends/tc/tcAnnotations.h @@ -20,7 +20,7 @@ and limitations under the License. #include "frontends/p4/parseAnnotations.h" #include "ir/ir.h" -namespace TC { +namespace P4::TC { class ParseTCAnnotations : public P4::ParseAnnotations { public: @@ -52,6 +52,6 @@ class ParseTCAnnotations : public P4::ParseAnnotations { PARSE_EMPTY(tc_numel)}) {} }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_TCANNOTATIONS_H_ */ diff --git a/backends/tc/tcExterns.cpp b/backends/tc/tcExterns.cpp index 906e2ff3e1..568d7fa2cb 100644 --- a/backends/tc/tcExterns.cpp +++ b/backends/tc/tcExterns.cpp @@ -16,7 +16,7 @@ and limitations under the License. #include "tcExterns.h" -namespace TC { +namespace P4::TC { void EBPFRegisterPNA::emitInitializer(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, ControlBodyTranslatorPNA *translator) { @@ -89,7 +89,7 @@ void EBPFCounterPNA::emitDirectMethodInvocation(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, const ConvertToBackendIR *tcIR) { if (method->method->name.name != "count") { - ::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); return; } BUG_CHECK(isDirect, "Bad Counter invocation"); @@ -130,7 +130,7 @@ void EBPFCounterPNA::emitMethodInvocation(EBPF::CodeBuilder *builder, const P4::ExternMethod *method, ControlBodyTranslatorPNA *translator) { if (method->method->name.name != "count") { - ::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unexpected method %1%", method->expr); return; } BUG_CHECK(!isDirect, "DirectCounter used outside of table"); @@ -184,10 +184,10 @@ void EBPFChecksumPNA::init(const EBPF::EBPFProgram *program, cstring name, int t if (engine == nullptr) { if (declaration->arguments->empty()) - ::error(ErrorType::ERR_UNSUPPORTED, "InternetChecksum not yet implemented"); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "InternetChecksum not yet implemented"); else - ::error(ErrorType::ERR_UNSUPPORTED, "Hash algorithm not yet implemented: %1%", - declaration->arguments->at(0)); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Hash algorithm not yet implemented: %1%", + declaration->arguments->at(0)); } } @@ -208,7 +208,7 @@ void EBPFInternetChecksumPNA::processMethod(EBPF::CodeBuilder *builder, cstring } else if (method == "get") { engine->emitGet(builder); } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call %1%", expr); } } @@ -254,7 +254,7 @@ void InternetChecksumAlgorithmPNA::emitGetInternalState(EBPF::CodeBuilder *build void InternetChecksumAlgorithmPNA::emitSetInternalState(EBPF::CodeBuilder *builder, const IR::MethodCallExpression *expr) { if (expr->arguments->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", expr); return; } builder->emitIndent(); @@ -283,7 +283,7 @@ void InternetChecksumAlgorithmPNA::updateChecksum(EBPF::CodeBuilder *builder, for (auto field : arguments) { auto fieldType = field->type->to(); if (fieldType == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported field type: %1%", field->type); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unsupported field type: %1%", field->type); return; } const int width = fieldType->width_bits(); @@ -302,15 +302,17 @@ void InternetChecksumAlgorithmPNA::updateChecksum(EBPF::CodeBuilder *builder, } if (width > 64) { if (remainingBits != 16) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: field wider than 64 bits must be aligned to 16 bits in input data", - field); + ::P4::error( + ErrorType::ERR_UNSUPPORTED, + "%1%: field wider than 64 bits must be aligned to 16 bits in input data", + field); continue; } if (width % 16 != 0) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: field wider than 64 bits must have size in bits multiply of 16 bits", - field); + ::P4::error( + ErrorType::ERR_UNSUPPORTED, + "%1%: field wider than 64 bits must have size in bits multiply of 16 bits", + field); continue; } @@ -478,4 +480,4 @@ void EBPFDigestPNA::emitPushElement(EBPF::CodeBuilder *builder, cstring elem) co builder->append("bpf_p4tc_extern_digest_pack(skb, &ext_params, sizeof(ext_params));"); } -} // namespace TC +} // namespace P4::TC diff --git a/backends/tc/tcExterns.h b/backends/tc/tcExterns.h index 95490ee6b0..d9e76c5742 100644 --- a/backends/tc/tcExterns.h +++ b/backends/tc/tcExterns.h @@ -17,7 +17,7 @@ and limitations under the License. #include "backend.h" #include "ebpfCodeGen.h" -namespace TC { +namespace P4::TC { using namespace P4::literals; @@ -65,14 +65,14 @@ class EBPFRegisterPNA : public EBPF::EBPFTableBase { CHECK_NULL(di); this->instanceName = di->toString(); if (!di->type->is()) { - ::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); + ::P4::error(ErrorType::ERR_MODEL, "Missing specialization: %1%", di); return; } auto ts = di->type->to(); if (ts->arguments->size() != PARAM_INDEX_2) { - ::error(ErrorType::ERR_MODEL, "Expected a type specialized with two arguments: %1%", - ts); + ::P4::error(ErrorType::ERR_MODEL, "Expected a type specialized with two arguments: %1%", + ts); return; } @@ -101,8 +101,8 @@ class EBPFTablePNADirectCounterPropertyVisitor : public EBPF::EBPFTablePsaProper auto di = decl->to(); CHECK_NULL(di); if (EBPF::EBPFObject::getSpecializedTypeName(di) != "DirectCounter") { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: not a DirectCounter, see declaration of %2%", - pe, decl); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "%1%: not a DirectCounter, see declaration of %2%", pe, decl); return false; } auto counterName = EBPF::EBPFObject::externalName(di); @@ -152,7 +152,7 @@ class EBPFChecksumPNA : public EBPF::EBPFChecksumPSA { : EBPF::EBPFChecksumPSA(program, block, name) { auto di = block->to(); if (di->arguments->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", block); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Expected exactly 1 argument %1%", block); return; } int type = di->arguments->at(0)->expression->checkedTo()->asInt(); @@ -196,6 +196,6 @@ class EBPFDigestPNA : public EBPF::EBPFDigestPSA { void emitPushElement(EBPF::CodeBuilder *builder, cstring elem) const; }; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_TCEXTERNS_H_ */ diff --git a/backends/tc/tc_defines.h b/backends/tc/tc_defines.h index 3d6bfaa608..93bf482ab5 100644 --- a/backends/tc/tc_defines.h +++ b/backends/tc/tc_defines.h @@ -17,7 +17,7 @@ and limitations under the License. #ifndef BACKENDS_TC_TC_DEFINES_H_ #define BACKENDS_TC_TC_DEFINES_H_ -namespace TC { +namespace P4::TC { inline constexpr auto DEFAULT_TABLE_ENTRIES = 1024; inline constexpr auto DEFAULT_KEY_MASK = 8; @@ -91,6 +91,6 @@ inline constexpr auto NONE = 0; inline constexpr auto IN = 1; inline constexpr auto OUT = 2; inline constexpr auto INOUT = 3; -} // namespace TC +} // namespace P4::TC #endif /* BACKENDS_TC_TC_DEFINES_H_ */ diff --git a/backends/ubpf/codeGen.h b/backends/ubpf/codeGen.h index d7bff17bc2..8275808b0e 100644 --- a/backends/ubpf/codeGen.h +++ b/backends/ubpf/codeGen.h @@ -5,7 +5,7 @@ #include "lib/sourceCodeBuilder.h" #include "target.h" -namespace UBPF { +namespace P4::UBPF { class UbpfCodeBuilder : public EBPF::CodeBuilder { public: @@ -14,6 +14,6 @@ class UbpfCodeBuilder : public EBPF::CodeBuilder { : EBPF::CodeBuilder(target), target(target) {} }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_CODEGEN_H_ */ diff --git a/backends/ubpf/midend.cpp b/backends/ubpf/midend.cpp index 5515f8933c..d28974025d 100644 --- a/backends/ubpf/midend.cpp +++ b/backends/ubpf/midend.cpp @@ -49,7 +49,7 @@ limitations under the License. #include "midend/tableHit.h" #include "midend/validateProperties.h" -namespace UBPF { +namespace P4::UBPF { class EnumOn32Bits : public P4::ChooseEnumRepresentation { bool convert(const IR::Type_Enum *type) const override { @@ -126,8 +126,8 @@ const IR::ToplevelBlock *MidEnd::run(EbpfOptions &options, const IR::P4Program * midEnd.setName("MidEnd"); midEnd.addDebugHooks(hooks); program = program->apply(midEnd); - if (::errorCount() > 0) return nullptr; + if (::P4::errorCount() > 0) return nullptr; return evaluator->getToplevelBlock(); } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/midend.h b/backends/ubpf/midend.h index f6bc1ecf21..777e3151c3 100644 --- a/backends/ubpf/midend.h +++ b/backends/ubpf/midend.h @@ -21,7 +21,7 @@ limitations under the License. #include "backends/ebpf/midend.h" #include "ir/ir.h" -namespace UBPF { +namespace P4::UBPF { class MidEnd : public EBPF::MidEnd { public: @@ -30,6 +30,6 @@ class MidEnd : public EBPF::MidEnd { std::ostream *outStream = nullptr); }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_MIDEND_H_ */ diff --git a/backends/ubpf/p4c-ubpf.cpp b/backends/ubpf/p4c-ubpf.cpp index b92cfea7d6..6ab9fdb929 100644 --- a/backends/ubpf/p4c-ubpf.cpp +++ b/backends/ubpf/p4c-ubpf.cpp @@ -37,29 +37,31 @@ limitations under the License. #include "ubpfBackend.h" #include "ubpfModel.h" +using namespace P4; + void compile(EbpfOptions &options) { auto hook = options.getDebugHook(); bool isv1 = options.langVersion == CompilerOptions::FrontendVersion::P4_14; if (isv1) { - ::error(ErrorType::ERR_UNSUPPORTED, "- this compiler only handles P4-16"); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "- this compiler only handles P4-16"); return; } auto program = P4::parseP4File(options); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; P4::FrontEnd frontend; program = UBPF::UBPFModel::instance.run(program); frontend.addDebugHook(hook); program = frontend.run(options, program); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; P4::serializeP4RuntimeIfRequired(program, options); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; UBPF::MidEnd midend; midend.addDebugHook(hook); auto toplevel = midend.run(options, program); - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; UBPF::run_ubpf_backend(options, toplevel, &midend.refMap, &midend.typeMap); } @@ -76,7 +78,7 @@ int main(int argc, char *const argv[]) { options.setInputFile(); } - if (::errorCount() > 0) exit(1); + if (::P4::errorCount() > 0) exit(1); try { compile(options); @@ -87,5 +89,5 @@ int main(int argc, char *const argv[]) { if (Log::verbose()) std::cout << "Done." << std::endl; - return ::errorCount() > 0; + return ::P4::errorCount() > 0; } diff --git a/backends/ubpf/target.cpp b/backends/ubpf/target.cpp index 0158efde30..87601a550d 100644 --- a/backends/ubpf/target.cpp +++ b/backends/ubpf/target.cpp @@ -16,7 +16,7 @@ limitations under the License. #include "target.h" -namespace UBPF { +namespace P4::UBPF { void UbpfTarget::emitIncludes(Util::SourceCodeBuilder *builder) const { builder->append( @@ -181,4 +181,4 @@ void UbpfTarget::emitChecksumHelpers(EBPF::CodeBuilder *builder) const { "}"); } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/target.h b/backends/ubpf/target.h index 596a23eac4..0ac8b8e173 100644 --- a/backends/ubpf/target.h +++ b/backends/ubpf/target.h @@ -21,7 +21,7 @@ limitations under the License. #include "backends/ebpf/target.h" #include "ubpfHelpers.h" -namespace UBPF { +namespace P4::UBPF { using namespace P4::literals; @@ -64,6 +64,6 @@ class UbpfTarget : public EBPF::Target { cstring packetDescriptorType() const override { return "void"_cs; } }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_TARGET_H_ */ diff --git a/backends/ubpf/ubpfBackend.cpp b/backends/ubpf/ubpfBackend.cpp index f0f4f483f2..52f862f99a 100644 --- a/backends/ubpf/ubpfBackend.cpp +++ b/backends/ubpf/ubpfBackend.cpp @@ -24,7 +24,7 @@ limitations under the License. #include "ubpfProgram.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { void run_ubpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *toplevel, P4::ReferenceMap *refMap, P4::TypeMap *typeMap) { @@ -32,8 +32,9 @@ void run_ubpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *tople auto main = toplevel->getMain(); if (main == nullptr) { - ::warning(ErrorType::WARN_MISSING, - "Could not locate top-level block; is there a %1% module?", IR::P4Program::main); + ::P4::warning(ErrorType::WARN_MISSING, + "Could not locate top-level block; is there a %1% module?", + IR::P4Program::main); return; } @@ -41,8 +42,8 @@ void run_ubpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *tople if (options.target.isNullOrEmpty() || options.target == "ubpf") { target = new UbpfTarget(); } else { - ::error(ErrorType::ERR_INVALID, "Unknown target %s; legal choice is 'ubpf'", - options.target); + ::P4::error(ErrorType::ERR_INVALID, "Unknown target %s; legal choice is 'ubpf'", + options.target); return; } @@ -74,4 +75,4 @@ void run_ubpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *tople hstream->flush(); } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfBackend.h b/backends/ubpf/ubpfBackend.h index 676e26c4a3..2e3ddaa8e3 100644 --- a/backends/ubpf/ubpfBackend.h +++ b/backends/ubpf/ubpfBackend.h @@ -21,12 +21,12 @@ limitations under the License. #include "frontends/p4/evaluator/evaluator.h" #include "ir/ir.h" -namespace UBPF { +namespace P4::UBPF { void run_ubpf_backend(const EbpfOptions &options, const IR::ToplevelBlock *toplevel, P4::ReferenceMap *refMap, P4::TypeMap *typeMap); std::string extract_file_name(const std::string &fullPath); -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFBACKEND_H_ */ diff --git a/backends/ubpf/ubpfControl.cpp b/backends/ubpf/ubpfControl.cpp index 8698b39a8d..79f9922cea 100644 --- a/backends/ubpf/ubpfControl.cpp +++ b/backends/ubpf/ubpfControl.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "frontends/p4/typeMap.h" #include "lib/error.h" -namespace UBPF { +namespace P4::UBPF { UBPFControlBodyTranslator::UBPFControlBodyTranslator(const UBPFControl *control) : EBPF::CodeGenInspector(control->program->refMap, control->program->typeMap), @@ -59,8 +59,8 @@ void UBPFControlBodyTranslator::processFunction(const P4::ExternFunction *functi builder->appendFormat(" = ubpf_hash(&%s, sizeof(%s))", hashKeyInstanceName, hashKeyInstanceName); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Not supported hash algorithm type", - algorithmType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Not supported hash algorithm type", + algorithmType); } return; @@ -70,7 +70,7 @@ void UBPFControlBodyTranslator::processFunction(const P4::ExternFunction *functi visit(function->expr->arguments->at(0)->expression); builder->append(")"); } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: One argument expected", function->expr); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: One argument expected", function->expr); } return; } @@ -106,8 +106,8 @@ cstring UBPFControlBodyTranslator::createHashKeyInstance(const P4::ExternFunctio auto atype = UBPFTypeFactory::instance->create(dataArgument->type); if (!atype->is()) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unsupported argument type", - dataArgument->type); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: Unsupported argument type", + dataArgument->type); } auto ubpfList = atype->to(); ubpfList->name = this->refMap->newName("tuple"); @@ -148,8 +148,8 @@ void UBPFControlBodyTranslator::processMethod(const P4::ExternMethod *method) { if (declType->name.name == p4lib.packetOut.name) { if (method->method->name.name == p4lib.packetOut.emit.name) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Emit extern not supported in control block", - method->expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: Emit extern not supported in control block", method->expr); return; } } else if (declType->name.name == UBPFModel::instance.registerModel.name) { @@ -163,7 +163,7 @@ void UBPFControlBodyTranslator::processMethod(const P4::ExternMethod *method) { pRegister->emitMethodInvocation(builder, method); return; } - ::error(ErrorType::ERR_UNEXPECTED, "%1%: Unexpected method call", method->expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: Unexpected method call", method->expr); } void UBPFControlBodyTranslator::processApply(const P4::ApplyMethod *method) { @@ -258,7 +258,7 @@ bool UBPFControlBodyTranslator::preorder(const IR::PathExpression *expression) { auto param = decl->getNode()->to(); if (param != nullptr) { if (toDereference.count(param) > 0) builder->append("*"); - auto subst = ::get(substitution, param); + auto subst = ::P4::get(substitution, param); if (subst != nullptr) { builder->append(subst->name); return false; @@ -318,7 +318,7 @@ bool UBPFControlBodyTranslator::preorder(const IR::MethodCallExpression *express return false; } - ::error(ErrorType::ERR_UNEXPECTED, "Unsupported method invocation %1%", expression); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unsupported method invocation %1%", expression); return false; } @@ -581,8 +581,8 @@ void UBPFControl::scanConstants() { } else if (!b->is()) { continue; } else { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", - b->toString()); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected block %s nested within control", + b->toString()); } } } @@ -638,8 +638,8 @@ bool UBPFControl::build() { auto pl = controlBlock->container->type->applyParams; size_t numberOfArgs = UBPFModel::instance.numberOfControlBlockArguments(); if (pl->size() != numberOfArgs) { - ::error(ErrorType::ERR_EXPECTED, "Expected control block to have exactly %d parameter", - numberOfArgs); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected control block to have exactly %d parameter", + numberOfArgs); return false; } @@ -650,7 +650,7 @@ bool UBPFControl::build() { codeGen->substitute(headers, parserHeaders); scanConstants(); - return ::errorCount() == 0; + return ::P4::errorCount() == 0; } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfControl.h b/backends/ubpf/ubpfControl.h index 8bd4a42712..5ec64ac37f 100644 --- a/backends/ubpf/ubpfControl.h +++ b/backends/ubpf/ubpfControl.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/ebpfControl.h" #include "ubpfRegister.h" -namespace UBPF { +namespace P4::UBPF { class UBPFControl; @@ -81,13 +81,13 @@ class UBPFControl : public EBPF::EBPFControl { bool build(); UBPFTable *getTable(cstring name) const { - auto result = ::get(tables, name); + auto result = ::P4::get(tables, name); BUG_CHECK(result != nullptr, "No table named %1%", name); return result; } UBPFRegister *getRegister(cstring name) const { - auto result = ::get(registers, name); + auto result = ::P4::get(registers, name); BUG_CHECK(result != nullptr, "No register named %1%", name); return result; } @@ -96,6 +96,6 @@ class UBPFControl : public EBPF::EBPFControl { void scanConstants(); }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFCONTROL_H_ */ diff --git a/backends/ubpf/ubpfDeparser.cpp b/backends/ubpf/ubpfDeparser.cpp index 057d028d10..9a92681a2d 100644 --- a/backends/ubpf/ubpfDeparser.cpp +++ b/backends/ubpf/ubpfDeparser.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { class OutHeaderSize final : public EBPF::CodeGenInspector { P4::ReferenceMap *refMap; @@ -29,7 +29,7 @@ class OutHeaderSize final : public EBPF::CodeGenInspector { std::map substitution; bool illegal(const IR::Statement *statement) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in deparser", statement); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: not supported in deparser", statement); return false; } @@ -48,7 +48,7 @@ class OutHeaderSize final : public EBPF::CodeGenInspector { auto decl = refMap->getDeclaration(expression->path, true); auto param = decl->getNode()->to(); if (param != nullptr) { - auto subst = ::get(substitution, param); + auto subst = ::P4::get(substitution, param); if (subst != nullptr) { builder->append(subst->name); return false; @@ -81,7 +81,8 @@ class OutHeaderSize final : public EBPF::CodeGenInspector { auto type = typeMap->getType(h); auto ht = type->to(); if (ht == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", h); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", + h); return false; } unsigned width = ht->width_bits(); @@ -112,8 +113,8 @@ void UBPFDeparserTranslationVisitor::compileEmitField(const IR::Expression *expr unsigned alignment, EBPF::EBPFType *type) { auto et = type->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", expr); return; } @@ -221,7 +222,8 @@ void UBPFDeparserTranslationVisitor::compileEmit(const IR::Vector auto type = typeMap->getType(expr); auto ht = type->to(); if (ht == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", expr); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot emit a non-header type %1%", + expr); return; } @@ -251,8 +253,8 @@ void UBPFDeparserTranslationVisitor::compileEmit(const IR::Vector auto etype = UBPFTypeFactory::instance->create(ftype); auto et = etype->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", f); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", f); return; } compileEmitField(expr, f->name, alignment, etype); @@ -278,15 +280,15 @@ bool UBPFDeparserTranslationVisitor::preorder(const IR::MethodCallExpression *ex } } - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in deparser %1%", expression); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in deparser %1%", expression); return false; } bool UBPFDeparser::build() { auto pl = controlBlock->container->type->applyParams; if (pl->size() != 2) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected deparser to have exactly 2 parameters", - controlBlock->getNode()); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected deparser to have exactly 2 parameters", + controlBlock->getNode()); return false; } @@ -298,7 +300,7 @@ bool UBPFDeparser::build() { codeGen = new UBPFDeparserTranslationVisitor(this); codeGen->substitute(headers, parserHeaders); - return ::errorCount() == 0; + return ::P4::errorCount() == 0; } void UBPFDeparser::emit(EBPF::CodeBuilder *builder) { @@ -348,4 +350,4 @@ void UBPFDeparser::emit(EBPF::CodeBuilder *builder) { codeGen->setBuilder(builder); controlBlock->container->body->apply(*codeGen); } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfDeparser.h b/backends/ubpf/ubpfDeparser.h index 939809e56a..babcd31e65 100644 --- a/backends/ubpf/ubpfDeparser.h +++ b/backends/ubpf/ubpfDeparser.h @@ -22,7 +22,7 @@ limitations under the License. #include "ubpfHelpers.h" #include "ubpfProgram.h" -namespace UBPF { +namespace P4::UBPF { class UBPFDeparser; @@ -38,12 +38,14 @@ class UBPFDeparserTranslationVisitor : public EBPF::CodeGenInspector { virtual void compileEmit(const IR::Vector *args); bool notSupported(const IR::Expression *expression) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser", + expression); return false; } bool notSupported(const IR::StatOrDecl *statOrDecl) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser", statOrDecl); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: not supported in Deparser", + statOrDecl); return false; } @@ -76,6 +78,6 @@ class UBPFDeparser : public EBPF::EBPFObject { bool build(); void emit(EBPF::CodeBuilder *builder); }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFDEPARSER_H_ */ diff --git a/backends/ubpf/ubpfHelpers.h b/backends/ubpf/ubpfHelpers.h index ddddb17053..213ff6a33e 100644 --- a/backends/ubpf/ubpfHelpers.h +++ b/backends/ubpf/ubpfHelpers.h @@ -17,12 +17,12 @@ limitations under the License. #ifndef BACKENDS_UBPF_UBPFHELPERS_H_ #define BACKENDS_UBPF_UBPFHELPERS_H_ -namespace UBPF { +namespace P4::UBPF { #ifndef UNUSED #define UNUSED __attribute__((__unused__)) #endif -} // namespace UBPF +} // namespace P4::UBPF #endif // BACKENDS_UBPF_UBPFHELPERS_H_ diff --git a/backends/ubpf/ubpfModel.cpp b/backends/ubpf/ubpfModel.cpp index 3986cd89fe..ee0a19f53c 100644 --- a/backends/ubpf/ubpfModel.cpp +++ b/backends/ubpf/ubpfModel.cpp @@ -16,9 +16,9 @@ limitations under the License. #include "ubpfModel.h" -namespace UBPF { +namespace P4::UBPF { cstring UBPFModel::reservedPrefix = "ubpf_"_cs; UBPFModel UBPFModel::instance; -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfModel.h b/backends/ubpf/ubpfModel.h index dc65931ee8..c6dfa9caf9 100644 --- a/backends/ubpf/ubpfModel.h +++ b/backends/ubpf/ubpfModel.h @@ -23,20 +23,20 @@ limitations under the License. #include "ir/pass_manager.h" #include "lib/cstring.h" -namespace UBPF { +namespace P4::UBPF { using namespace P4::literals; -struct Pipeline_Model : public ::Model::Elem { +struct Pipeline_Model : public ::P4::Model::Elem { Pipeline_Model() : Elem("Pipeline"_cs), parser("prs"_cs), control("p"_cs), deparser("dprs"_cs) {} - ::Model::Elem parser; - ::Model::Elem control; - ::Model::Elem deparser; + ::P4::Model::Elem parser; + ::P4::Model::Elem control; + ::P4::Model::Elem deparser; }; -struct Register_Model : public ::Model::Extern_Model { +struct Register_Model : public ::P4::Model::Extern_Model { Register_Model() : Extern_Model("Register"_cs), sizeParam("size"_cs), @@ -46,25 +46,25 @@ struct Register_Model : public ::Model::Extern_Model { index("index"_cs), value("value"_cs) {} - ::Model::Elem sizeParam; - ::Model::Elem read; - ::Model::Elem write; - ::Model::Elem initial_value; - ::Model::Elem index; - ::Model::Elem value; + ::P4::Model::Elem sizeParam; + ::P4::Model::Elem read; + ::P4::Model::Elem write; + ::P4::Model::Elem initial_value; + ::P4::Model::Elem index; + ::P4::Model::Elem value; }; -struct Algorithm_Model : public ::Model::Enum_Model { - Algorithm_Model() : ::Model::Enum_Model("HashAlgorithm"_cs), lookup3("lookup3"_cs) {} +struct Algorithm_Model : public ::P4::Model::Enum_Model { + Algorithm_Model() : ::P4::Model::Enum_Model("HashAlgorithm"_cs), lookup3("lookup3"_cs) {} - ::Model::Elem lookup3; + ::P4::Model::Elem lookup3; }; -struct Hash_Model : public ::Model::Elem { - Hash_Model() : ::Model::Elem("hash"_cs) {} +struct Hash_Model : public ::P4::Model::Elem { + Hash_Model() : ::P4::Model::Elem("hash"_cs) {} }; -class UBPFModel : public ::Model::Model { +class UBPFModel : public ::P4::Model::Model { protected: UBPFModel() : CPacketName("pkt"_cs), @@ -84,16 +84,16 @@ class UBPFModel : public ::Model::Model { static UBPFModel instance; static cstring reservedPrefix; - ::Model::Elem CPacketName; - ::Model::Param_Model packet; + ::P4::Model::Elem CPacketName; + ::P4::Model::Param_Model packet; Pipeline_Model pipeline; Register_Model registerModel; - ::Model::Elem drop; - ::Model::Elem pass; - ::Model::Elem ubpf_time_get_ns; - ::Model::Elem truncate; - ::Model::Extern_Model csum_replace2; - ::Model::Extern_Model csum_replace4; + ::P4::Model::Elem drop; + ::P4::Model::Elem pass; + ::P4::Model::Elem ubpf_time_get_ns; + ::P4::Model::Elem truncate; + ::P4::Model::Extern_Model csum_replace2; + ::P4::Model::Extern_Model csum_replace4; Algorithm_Model hashAlgorithm; Hash_Model hash; unsigned version = 20200515; @@ -128,6 +128,6 @@ class UBPFModel : public ::Model::Model { } }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFMODEL_H_ */ diff --git a/backends/ubpf/ubpfParser.cpp b/backends/ubpf/ubpfParser.cpp index 1a4654af52..6f5fe0cc20 100644 --- a/backends/ubpf/ubpfParser.cpp +++ b/backends/ubpf/ubpfParser.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "ubpfModel.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { namespace { class UBPFStateTranslationVisitor : public EBPF::CodeGenInspector { @@ -287,8 +287,8 @@ void UBPFStateTranslationVisitor::compileExtract(const IR::Expression *destinati auto ht = type->to(); if (ht == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot extract to a non-struct type %1%", - destination); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Cannot extract to a non-struct type %1%", + destination); return; } @@ -301,8 +301,8 @@ void UBPFStateTranslationVisitor::compileExtract(const IR::Expression *destinati auto etype = UBPFTypeFactory::instance->create(ftype); auto et = etype->to(); if (et == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Only headers with fixed widths supported %1%", f); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Only headers with fixed widths supported %1%", f); return; } compileExtractField(destination, f->name, hdrOffsetBits, etype); @@ -387,8 +387,8 @@ bool UBPFStateTranslationVisitor::preorder(const IR::MethodCallExpression *expre if (decl == state->parser->packet) { if (extMethod->method->name.name == p4lib.packetIn.extract.name) { if (expression->arguments->size() != 1) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Variable-sized header fields not yet supported %1%", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Variable-sized header fields not yet supported %1%", expression); return false; } compileExtract(expression->arguments->at(0)->expression); @@ -397,7 +397,7 @@ bool UBPFStateTranslationVisitor::preorder(const IR::MethodCallExpression *expre if (extMethod->method->name.name == p4lib.packetIn.advance.name) { if (expression->arguments->size() != 1) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected 1 argument", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected 1 argument", expression); return false; } compileAdvance(expression->arguments->at(0)->expression); @@ -409,7 +409,7 @@ bool UBPFStateTranslationVisitor::preorder(const IR::MethodCallExpression *expre } } - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in parser %1%", expression); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in parser %1%", expression); return false; } @@ -428,7 +428,7 @@ bool UBPFStateTranslationVisitor::preorder(const IR::AssignmentStatement *stat) return false; } } - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in parser %1%", stat->right); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected method call in parser %1%", stat->right); } else { builder->emitIndent(); visit(stat->left); @@ -463,8 +463,8 @@ bool UBPFParser::build() { auto pl = parserBlock->container->type->applyParams; size_t numberOfArgs = UBPFModel::instance.numberOfParserArguments(); if (pl->size() != numberOfArgs) { - ::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly %d parameters", - numberOfArgs); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected parser to have exactly %d parameters", + numberOfArgs); return false; } @@ -489,4 +489,4 @@ bool UBPFParser::build() { return true; } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfParser.h b/backends/ubpf/ubpfParser.h index e664e13400..d6c95db275 100644 --- a/backends/ubpf/ubpfParser.h +++ b/backends/ubpf/ubpfParser.h @@ -21,7 +21,7 @@ limitations under the License. #include "ir/ir.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { class UBPFParserState : public EBPF::EBPFParserState { public: @@ -44,6 +44,6 @@ class UBPFParser : public EBPF::EBPFParser { bool build(); }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFPARSER_H_ */ diff --git a/backends/ubpf/ubpfProgram.cpp b/backends/ubpf/ubpfProgram.cpp index 7091a6f2a0..214d6fbd4f 100644 --- a/backends/ubpf/ubpfProgram.cpp +++ b/backends/ubpf/ubpfProgram.cpp @@ -22,20 +22,20 @@ limitations under the License. #include "ubpfParser.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { bool UBPFProgram::build() { bool success = true; auto pack = toplevel->getMain(); if (pack->type->name != "ubpf") - ::warning(ErrorType::WARN_INVALID, - "%1%: the main ubpf package should be called ubpf" - "; are you using the wrong architecture?", - pack->type->name); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%: the main ubpf package should be called ubpf" + "; are you using the wrong architecture?", + pack->type->name); if (pack->getConstructorParameters()->size() != 3) { - ::error(ErrorType::ERR_MODEL, "Expected toplevel package %1% to have 3 parameters", - pack->type); + ::P4::error(ErrorType::ERR_MODEL, "Expected toplevel package %1% to have 3 parameters", + pack->type); return false; } @@ -298,4 +298,4 @@ void UBPFProgram::emitPipeline(EBPF::CodeBuilder *builder) { builder->blockEnd(true); } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfProgram.h b/backends/ubpf/ubpfProgram.h index 1706254139..d0d7d5cab6 100644 --- a/backends/ubpf/ubpfProgram.h +++ b/backends/ubpf/ubpfProgram.h @@ -26,7 +26,7 @@ limitations under the License. #include "target.h" #include "ubpfModel.h" -namespace UBPF { +namespace P4::UBPF { class UBPFControl; class UBPFParser; @@ -84,6 +84,6 @@ class UBPFProgram : public EBPF::EBPFProgram { } }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFPROGRAM_H_ */ diff --git a/backends/ubpf/ubpfRegister.cpp b/backends/ubpf/ubpfRegister.cpp index 92db34f8a6..4eb7702bbc 100644 --- a/backends/ubpf/ubpfRegister.cpp +++ b/backends/ubpf/ubpfRegister.cpp @@ -16,7 +16,7 @@ limitations under the License. #include "ubpfRegister.h" -namespace UBPF { +namespace P4::UBPF { static cstring last_key_name; @@ -144,4 +144,4 @@ void UBPFRegister::emitKeyInstance(EBPF::CodeBuilder *builder, last_key_name = keyName; } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfRegister.h b/backends/ubpf/ubpfRegister.h index 8defc09f70..fccef46e1d 100644 --- a/backends/ubpf/ubpfRegister.h +++ b/backends/ubpf/ubpfRegister.h @@ -20,7 +20,7 @@ limitations under the License. #include "ubpfTable.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { class UBPFRegister final : public UBPFTableBase { public: @@ -35,6 +35,6 @@ class UBPFRegister final : public UBPFTableBase { cstring emitValueInstanceIfNeeded(EBPF::CodeBuilder *builder, const IR::Argument *arg_value); }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFREGISTER_H_ */ diff --git a/backends/ubpf/ubpfTable.cpp b/backends/ubpf/ubpfTable.cpp index 10c7454b66..e35c237cbd 100644 --- a/backends/ubpf/ubpfTable.cpp +++ b/backends/ubpf/ubpfTable.cpp @@ -24,7 +24,7 @@ limitations under the License. #include "ubpfParser.h" #include "ubpfType.h" -namespace UBPF { +namespace P4::UBPF { namespace { @@ -204,7 +204,8 @@ void UBPFTable::setTableKind() { auto matchType = mtdecl->getNode()->to(); if (matchType->name.name == P4::P4CoreLibrary::instance().lpmMatch.name) { if (tableKind == EBPF::TableLPMTrie) { - ::error(ErrorType::ERR_UNSUPPORTED, "only one LPM field allowed", it->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "only one LPM field allowed", + it->matchType); return; } tableKind = EBPF::TableLPMTrie; @@ -223,14 +224,14 @@ void UBPFTable::setTableSize(const IR::TableBlock *table) { auto pConstant = sz->to(); if (pConstant->asInt() <= 0) { - ::error(ErrorType::ERR_INVALID, "negative size", pConstant); + ::P4::error(ErrorType::ERR_INVALID, "negative size", pConstant); return; } this->size = pConstant->asInt(); if (this->size > UINT16_MAX) { - ::error(ErrorType::ERR_UNSUPPORTED, "size too large. Using default value (%2%).", pConstant, - UINT16_MAX); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "size too large. Using default value (%2%).", + pConstant, UINT16_MAX); return; } } @@ -251,7 +252,7 @@ void UBPFTable::emitKeyType(EBPF::CodeBuilder *builder) { auto ebpfType = UBPFTypeFactory::instance->create(type); cstring fieldName = c->expression->toString().replace('.', '_'); if (!ebpfType->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: illegal type %2% for key field", c, type); + ::P4::error(ErrorType::ERR_INVALID, "%1%: illegal type %2% for key field", c, type); return; } unsigned width = ebpfType->to()->widthInBits(); @@ -269,9 +270,9 @@ void UBPFTable::emitKeyType(EBPF::CodeBuilder *builder) { builder->appendFormat("uint32_t prefix_len%d;", key_idx); builder->newline(); } - auto ebpfType = ::get(keyTypes, c); + auto ebpfType = ::P4::get(keyTypes, c); builder->emitIndent(); - cstring fieldName = ::get(keyFieldNames, c); + cstring fieldName = ::P4::get(keyFieldNames, c); ebpfType->declare(builder, fieldName, false); builder->append("; /* "); c->expression->apply(commentGen); @@ -282,8 +283,8 @@ void UBPFTable::emitKeyType(EBPF::CodeBuilder *builder) { auto matchType = mtdecl->getNode()->to(); if (matchType->name.name != P4::P4CoreLibrary::instance().exactMatch.name && matchType->name.name != P4::P4CoreLibrary::instance().lpmMatch.name) - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Match of type %1% not supported", - c->matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Match of type %1% not supported", + c->matchType); key_idx++; } } @@ -376,8 +377,8 @@ void UBPFTable::emitTypes(EBPF::CodeBuilder *builder) { void UBPFTable::emitKey(EBPF::CodeBuilder *builder, cstring keyName) { if (keyGenerator == nullptr) return; for (auto c : keyGenerator->keyElements) { - auto ebpfType = ::get(keyTypes, c); - cstring fieldName = ::get(keyFieldNames, c); + auto ebpfType = ::P4::get(keyTypes, c); + cstring fieldName = ::P4::get(keyFieldNames, c); CHECK_NULL(fieldName); bool memcpy = false; EBPF::EBPFScalarType *scalar = nullptr; @@ -448,10 +449,10 @@ void UBPFTable::emitInitializer(EBPF::CodeBuilder *builder) { // Default action must be set from a control plane and 'const' qualifier // does not permit to modify default action by a control plane. if (defact->isConstant) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: uBPF target does not allow 'const default_action'. " - "Use `default_action` instead.", - defact); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: uBPF target does not allow 'const default_action'. " + "Use `default_action` instead.", + defact); } auto ac = mi->to(); BUG_CHECK(ac != nullptr, "%1%: expected an action call", mce); @@ -495,11 +496,11 @@ void UBPFTable::emitInitializer(EBPF::CodeBuilder *builder) { // Check if there are const entries. auto entries = t->getEntries(); if (entries != nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Immutable table entries cannot be configured by the uBPF target " - "and should not be used.", - entries); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Immutable table entries cannot be configured by the uBPF target " + "and should not be used.", + entries); } } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfTable.h b/backends/ubpf/ubpfTable.h index 93d049a511..5f81ab1aa8 100644 --- a/backends/ubpf/ubpfTable.h +++ b/backends/ubpf/ubpfTable.h @@ -21,7 +21,7 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "ubpfProgram.h" -namespace UBPF { +namespace P4::UBPF { class UBPFTableBase : public EBPF::EBPFObject { public: @@ -79,6 +79,6 @@ class UBPFTable final : public UBPFTableBase { void emitInitializer(EBPF::CodeBuilder *builder); }; -} // namespace UBPF +} // namespace P4::UBPF #endif // BACKENDS_UBPF_UBPFTABLE_H_ diff --git a/backends/ubpf/ubpfType.cpp b/backends/ubpf/ubpfType.cpp index cae6034877..ad34902b20 100644 --- a/backends/ubpf/ubpfType.cpp +++ b/backends/ubpf/ubpfType.cpp @@ -18,7 +18,7 @@ limitations under the License. #include "ubpfHelpers.h" -namespace UBPF { +namespace P4::UBPF { using namespace P4::literals; @@ -52,7 +52,7 @@ EBPF::EBPFType *UBPFTypeFactory::create(const IR::Type *type) { } else if (auto tpl = type->to()) { result = new UBPFListType(tpl); } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% not supported", type); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Type %1% not supported", type); } return result; } @@ -197,8 +197,8 @@ UBPFListType::UBPFListType(const IR::Type_List *lst) : EBPFType(lst) { auto ltype = UBPFTypeFactory::instance->create(el); auto wt = ltype->to(); if (wt == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "UBPF: Unsupported type in Type_List: %s", - el->getP4Type()); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "UBPF: Unsupported type in Type_List: %s", el->getP4Type()); } else { width += wt->widthInBits(); implWidth += wt->implementationWidthInBits(); @@ -227,8 +227,8 @@ UBPFListType::UBPFListType(const IR::Type_List *lst) : EBPFType(lst) { elements.push_back(pad); paddingIndex++; } else { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Not supported bitwidth in %1%", - this->type->getNode()); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "Not supported bitwidth in %1%", + this->type->getNode()); } } idx++; @@ -278,4 +278,4 @@ void UBPFListType::emit(EBPF::CodeBuilder *builder) { } } -} // namespace UBPF +} // namespace P4::UBPF diff --git a/backends/ubpf/ubpfType.h b/backends/ubpf/ubpfType.h index aada218a8e..efc7d5a5d5 100644 --- a/backends/ubpf/ubpfType.h +++ b/backends/ubpf/ubpfType.h @@ -20,7 +20,7 @@ limitations under the License. #include "backends/ebpf/ebpfType.h" #include "lib/sourceCodeBuilder.h" -namespace UBPF { +namespace P4::UBPF { class UBPFTypeFactory : public EBPF::EBPFTypeFactory { public: @@ -141,6 +141,6 @@ class UBPFListType : public EBPF::EBPFType, public EBPF::IHasWidth { DECLARE_TYPEINFO(UBPFListType, EBPF::EBPFType, EBPF::IHasWidth); }; -} // namespace UBPF +} // namespace P4::UBPF #endif /* BACKENDS_UBPF_UBPFTYPE_H_ */ diff --git a/bazel/example/main.cc b/bazel/example/main.cc index e8f8fa66ae..c799a94464 100644 --- a/bazel/example/main.cc +++ b/bazel/example/main.cc @@ -26,6 +26,6 @@ int main() { std::cout << p4info.DebugString(); // Demonstrate that IR extension is present. - IR::MyCustomStatement statement("Hello, P4 extension world!"_cs); + P4::IR::MyCustomStatement statement("Hello, P4 extension world!"_cs); std::cout << statement << std::endl; } diff --git a/control-plane/bfruntime.cpp b/control-plane/bfruntime.cpp index b919fc2683..796feefa3b 100644 --- a/control-plane/bfruntime.cpp +++ b/control-plane/bfruntime.cpp @@ -43,9 +43,9 @@ TypeSpecParser TypeSpecParser::make(const p4configv1::P4Info &p4info, auto e = fSpec.serializable_enum().name(); auto typeEnum = enums.find(e); if (typeEnum == enums.end()) { - ::error(ErrorType::ERR_NOT_FOUND, - "Enum type '%1%' not found in typeInfo for '%2%' '%3%'", e, instanceType, - instanceName); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "Enum type '%1%' not found in typeInfo for '%2%' '%3%'", e, + instanceType, instanceName); return; } type = makeTypeBytes(typeEnum->second.underlying_type().bitwidth()); @@ -63,19 +63,19 @@ TypeSpecParser TypeSpecParser::make(const p4configv1::P4Info &p4info, auto typeName = fSpec.new_type().name(); auto newType = newtypes.find(typeName); if (newType == newtypes.end()) { - ::error(ErrorType::ERR_NOT_FOUND, - "New type '%1%' not found in typeInfo for '%2%' '%3%'", typeName, - instanceType, instanceName); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "New type '%1%' not found in typeInfo for '%2%' '%3%'", typeName, + instanceType, instanceName); return; } type = makeTypeBytes(newType->second.translated_type().sdn_bitwidth()); } if (!type) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Error when generating BF-RT info for '%1%' '%2%': " - "packed type is too complex", - instanceType, instanceName); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Error when generating BF-RT info for '%1%' '%2%': " + "packed type is too complex", + instanceType, instanceName); return; } @@ -139,11 +139,11 @@ TypeSpecParser TypeSpecParser::make(const p4configv1::P4Info &p4info, fields.push_back({prefix + member.name() + suffix, id++, type}); } } else { - ::error(ErrorType::ERR_UNSUPPORTED, - "Error when generating BF-RT info for '%1%' '%2%': " - "only structs, headers, tuples, bitstrings and " - "serializable enums are currently supported types", - instanceType, instanceName); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Error when generating BF-RT info for '%1%' '%2%': " + "only structs, headers, tuples, bitstrings and " + "serializable enums are currently supported types", + instanceType, instanceName); } return TypeSpecParser(std::move(fields)); @@ -508,7 +508,8 @@ void BFRuntimeGenerator::addActionProfCommon( tableJson->emplace("key"_cs, keyJson); if (actionProf.tableIds.empty()) { - ::warning("Action profile '%1%' is not used by any table, skipping it", actionProf.name); + ::P4::warning("Action profile '%1%' is not used by any table, skipping it", + actionProf.name); return; } auto oneTableId = actionProf.tableIds.at(0); @@ -545,7 +546,7 @@ Util::JsonArray *BFRuntimeGenerator::makeActionSpecs(const p4configv1::Table &ta for (const auto &action_ref : table.action_refs()) { auto *action = Standard::findAction(p4info, action_ref.id()); if (action == nullptr) { - ::error(ErrorType::ERR_INVALID, "Invalid action id '%1%'", action_ref.id()); + ::P4::error(ErrorType::ERR_INVALID, "Invalid action id '%1%'", action_ref.id()); continue; } auto *spec = new Util::JsonObject(); @@ -563,8 +564,8 @@ Util::JsonArray *BFRuntimeGenerator::makeActionSpecs(const p4configv1::Table &ta spec->emplace("action_scope", "DefaultOnly"); break; default: - ::error(ErrorType::ERR_INVALID, "Invalid action ref scope '%1%' in P4Info", - int(action_ref.scope())); + ::P4::error(ErrorType::ERR_INVALID, "Invalid action ref scope '%1%' in P4Info", + int(action_ref.scope())); break; } auto *annotations = @@ -628,7 +629,7 @@ void BFRuntimeGenerator::addDirectResources(const p4configv1::Table &table, addMeterDataFields(dataJson, *meter); attributesJson->append("MeterByteCountAdjust"); } else { - ::error(ErrorType::ERR_UNKNOWN, "Unknown direct resource id '%1%'", directResId); + ::P4::error(ErrorType::ERR_UNKNOWN, "Unknown direct resource id '%1%'", directResId); continue; } } @@ -688,8 +689,8 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const { break; } if (matchType == std::nullopt) { - ::error(ErrorType::ERR_UNSUPPORTED, "Unsupported match type for BF-RT: %1%", - int(mf.match_type())); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Unsupported match type for BF-RT: %1%", + int(mf.match_type())); continue; } needsPriority |= addMatchTypePriority(matchType); @@ -724,11 +725,11 @@ void BFRuntimeGenerator::addMatchTables(Util::JsonArray *tablesJson) const { // Control plane requires there's no duplicate key in one table. if (dupKey.count(keyName) != 0) { - ::error(ErrorType::ERR_DUPLICATE, - "Key \"%s\" is duplicate in Table \"%s\". It doesn't meet BFRT's " - "requirements.\n" - "Please using @name annotation for the duplicate key names", - keyName, pre.name()); + ::P4::error(ErrorType::ERR_DUPLICATE, + "Key \"%s\" is duplicate in Table \"%s\". It doesn't meet BFRT's " + "requirements.\n" + "Please using @name annotation for the duplicate key names", + keyName, pre.name()); return; } else { dupKey.insert(keyName); diff --git a/control-plane/bfruntime.h b/control-plane/bfruntime.h index 892f29f5b8..a208505663 100644 --- a/control-plane/bfruntime.h +++ b/control-plane/bfruntime.h @@ -226,7 +226,7 @@ static std::vector collectTableIds(const p4configv1::P4Info &p4info, const for (auto it = first; it != last; it++) { auto *table = Standard::findTable(p4info, *it); if (table == nullptr) { - ::error(ErrorType::ERR_INVALID, "Invalid table id '%1%'", *it); + ::P4::error(ErrorType::ERR_INVALID, "Invalid table id '%1%'", *it); continue; } tableIds.push_back(*it); diff --git a/control-plane/bytestrings.cpp b/control-plane/bytestrings.cpp index 3cb4273e91..d18f2b9d77 100644 --- a/control-plane/bytestrings.cpp +++ b/control-plane/bytestrings.cpp @@ -29,7 +29,7 @@ namespace ControlPlaneAPI { std::optional stringReprConstant(big_int value, int width) { // TODO(antonin): support negative values if (value < 0) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Negative values not supported yet", value); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Negative values not supported yet", value); return std::nullopt; } BUG_CHECK(width > 0, "Unexpected width 0"); diff --git a/control-plane/bytestrings.h b/control-plane/bytestrings.h index 2938b37b82..2ebe6b2cbf 100644 --- a/control-plane/bytestrings.h +++ b/control-plane/bytestrings.h @@ -22,12 +22,12 @@ limitations under the License. #include "lib/big_int_util.h" -namespace IR { +namespace P4::IR { class Constant; class BoolLiteral; -} // namespace IR +} // namespace P4::IR namespace P4 { diff --git a/control-plane/p4RuntimeArchHandler.cpp b/control-plane/p4RuntimeArchHandler.cpp index 7b7104da19..ea1703da13 100644 --- a/control-plane/p4RuntimeArchHandler.cpp +++ b/control-plane/p4RuntimeArchHandler.cpp @@ -45,9 +45,9 @@ std::optional getExternInstanceFromProperty(const IR::P4Table *t auto property = table->properties->getProperty(propertyName); if (property == nullptr) return std::nullopt; if (!property->value->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected %1% property value for table %2% to be an expression: %3%", propertyName, - table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected %1% property value for table %2% to be an expression: %3%", + propertyName, table->controlPlaneName(), property); return std::nullopt; } @@ -55,19 +55,19 @@ std::optional getExternInstanceFromProperty(const IR::P4Table *t if (isConstructedInPlace) *isConstructedInPlace = expr->is(); if (expr->is() && property->getAnnotation(IR::Annotation::nameAnnotation) == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Table '%1%' has an anonymous table property '%2%' with no name annotation, " - "which is not supported by P4Runtime", - table->controlPlaneName(), propertyName); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Table '%1%' has an anonymous table property '%2%' with no name annotation, " + "which is not supported by P4Runtime", + table->controlPlaneName(), propertyName); return std::nullopt; } auto name = property->controlPlaneName(); auto externInstance = ExternInstance::resolve(expr, refMap, typeMap, name); if (!externInstance) { - ::error(ErrorType::ERR_INVALID, - "Expected %1% property value for table %2% to resolve to an " - "extern instance: %3%", - propertyName, table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_INVALID, + "Expected %1% property value for table %2% to resolve to an " + "extern instance: %3%", + propertyName, table->controlPlaneName(), property); return std::nullopt; } @@ -78,9 +78,9 @@ bool isExternPropertyConstructedInPlace(const IR::P4Table *table, const cstring auto property = table->properties->getProperty(propertyName); if (property == nullptr) return false; if (!property->value->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected %1% property value for table %2% to be an expression: %3%", propertyName, - table->controlPlaneName(), property); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected %1% property value for table %2% to be an expression: %3%", + propertyName, table->controlPlaneName(), property); return false; } @@ -100,15 +100,15 @@ int64_t getTableSize(const IR::P4Table *table) { } if (!sizeProperty->value->is()) { - ::error(ErrorType::ERR_EXPECTED, "Expected an expression for table size property: %1%", - sizeProperty); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected an expression for table size property: %1%", + sizeProperty); return defaultTableSize; } auto expression = sizeProperty->value->to()->expression; if (!expression->is()) { - ::error(ErrorType::ERR_EXPECTED, "Expected a constant for table size property: %1%", - sizeProperty); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a constant for table size property: %1%", + sizeProperty); return defaultTableSize; } @@ -132,10 +132,10 @@ void serializeStructuredExpression(const IR::Expression *expr, p4configv1::Expre if (expr->is()) { auto *constant = expr->to(); if (!constant->fitsInt64()) { - ::error(ErrorType::ERR_OVERLIMIT, - "%1%: integer literal in structured annotation must fit in int64, " - "consider using a string literal for larger values", - expr); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "%1%: integer literal in structured annotation must fit in int64, " + "consider using a string literal for larger values", + expr); return; } sExpr->set_int64_value(constant->asInt64()); diff --git a/control-plane/p4RuntimeArchHandler.h b/control-plane/p4RuntimeArchHandler.h index 8c000d7c80..d3dba57265 100644 --- a/control-plane/p4RuntimeArchHandler.h +++ b/control-plane/p4RuntimeArchHandler.h @@ -401,9 +401,9 @@ struct Counterlike { // P4Info. auto unit = instance->getParameterValue("type"_cs); if (!unit->is()) { - ::error(ErrorType::ERR_INVALID, - "%1% '%2%' has a unit type which is not an enum constant: %3%", - CounterlikeTraits::name(), declaration, unit); + ::P4::error(ErrorType::ERR_INVALID, + "%1% '%2%' has a unit type which is not an enum constant: %3%", + CounterlikeTraits::name(), declaration, unit); return std::nullopt; } @@ -415,8 +415,8 @@ struct Counterlike { auto sem = size->template to(); val = sem->value->template to()->value; } else { - ::error(ErrorType::ERR_INVALID, "%1% '%2%' has a non-constant size: %3%", - CounterlikeTraits::name(), declaration, size); + ::P4::error(ErrorType::ERR_INVALID, "%1% '%2%' has a non-constant size: %3%", + CounterlikeTraits::name(), declaration, size); return std::nullopt; } @@ -455,22 +455,22 @@ struct Counterlike { BUG_CHECK(instance.name != std::nullopt, "Caller should've ensured we have a name"); if (instance.type->name != CounterlikeTraits::directTypeName()) { - ::error(ErrorType::ERR_EXPECTED, "Expected a direct %1%: %2%", - CounterlikeTraits::name(), instance.expression); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a direct %1%: %2%", + CounterlikeTraits::name(), instance.expression); return std::nullopt; } auto unitArgument = instance.substitution.lookupByName("type"_cs)->expression; if (unitArgument == nullptr) { - ::error(ErrorType::ERR_EXPECTED, - "Direct %1% instance %2% should take a constructor argument", - CounterlikeTraits::name(), instance.expression); + ::P4::error(ErrorType::ERR_EXPECTED, + "Direct %1% instance %2% should take a constructor argument", + CounterlikeTraits::name(), instance.expression); return std::nullopt; } if (!unitArgument->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "Direct %1% instance %2% has an unexpected constructor argument", - CounterlikeTraits::name(), instance.expression); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Direct %1% instance %2% has an unexpected constructor argument", + CounterlikeTraits::name(), instance.expression); return std::nullopt; } diff --git a/control-plane/p4RuntimeArchStandard.cpp b/control-plane/p4RuntimeArchStandard.cpp index 6714616853..9bab516124 100644 --- a/control-plane/p4RuntimeArchStandard.cpp +++ b/control-plane/p4RuntimeArchStandard.cpp @@ -105,10 +105,10 @@ class P4RuntimeArchHandlerV1Model final : public P4RuntimeArchHandlerCommonsecond; @@ -130,17 +130,17 @@ class P4RuntimeArchHandlerV1Model final : public P4RuntimeArchHandlerCommonvalue->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "Unexpected value %1% for supports_timeout on table %2%", timeout, table); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unexpected value %1% for supports_timeout on table %2%", timeout, table); return false; } auto expr = timeout->value->to()->expression; if (!expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "Unexpected non-boolean value %1% for supports_timeout " - "property on table %2%", - timeout, table); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unexpected non-boolean value %1% for supports_timeout " + "property on table %2%", + timeout, table); return false; } diff --git a/control-plane/p4RuntimeArchStandard.h b/control-plane/p4RuntimeArchStandard.h index 64f646f728..ed57dbdfec 100644 --- a/control-plane/p4RuntimeArchStandard.h +++ b/control-plane/p4RuntimeArchStandard.h @@ -450,14 +450,14 @@ struct Register { auto size = instance->getParameterValue("size"_cs)->to(); if (!size->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Register '%1%' has a non-constant size: %2%", - declaration, size); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Register '%1%' has a non-constant size: %2%", + declaration, size); return std::nullopt; } if (!size->to()->fitsInt()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Register '%1%' has a size that doesn't fit in an integer: %2%", declaration, - size); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Register '%1%' has a size that doesn't fit in an integer: %2%", + declaration, size); return std::nullopt; } @@ -551,9 +551,9 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { if (instance) { if (instance->type->name != ActionProfileTraits::typeName() && instance->type->name != ActionSelectorTraits::typeName()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected an action profile or action selector: %1%", - instance->expression); + ::P4::error(ErrorType::ERR_EXPECTED, + "Expected an action profile or action selector: %1%", + instance->expression); } else if (isConstructedInPlace) { symbols->add(SymbolType::P4RT_ACTION_PROFILE(), *instance->name); } @@ -564,8 +564,8 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { table, CounterTraits::directPropertyName(), refMap, typeMap, &isConstructedInPlace); if (instance) { if (instance->type->name != CounterTraits::directTypeName()) { - ::error(ErrorType::ERR_EXPECTED, "Expected a direct counter: %1%", - instance->expression); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a direct counter: %1%", + instance->expression); } else if (isConstructedInPlace) { symbols->add(SymbolType::P4RT_DIRECT_COUNTER(), *instance->name); } @@ -576,8 +576,8 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { refMap, typeMap, &isConstructedInPlace); if (instance) { if (instance->type->name != MeterTraits::directTypeName()) { - ::error(ErrorType::ERR_EXPECTED, "Expected a direct meter: %1%", - instance->expression); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a direct meter: %1%", + instance->expression); } else if (isConstructedInPlace) { symbols->add(SymbolType::P4RT_DIRECT_METER(), *instance->name); } @@ -739,8 +739,8 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { auto size = instance->substitution.lookupByName(ActionProfileTraits::sizeParamName()) ->expression; if (!size->template is()) { - ::error(ErrorType::ERR_INVALID, "Action profile '%1%' has non-constant size '%2%'", - *instance->name, size); + ::P4::error(ErrorType::ERR_INVALID, "Action profile '%1%' has non-constant size '%2%'", + *instance->name, size); return std::nullopt; } return getActionProfile(*instance->name, instance->type, @@ -753,8 +753,8 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { auto decl = instance->node->to(); auto size = instance->getParameterValue(ActionProfileTraits::sizeParamName()); if (!size->template is()) { - ::error(ErrorType::ERR_INVALID, "Action profile '%1%' has non-constant size '%2%'", - decl->controlPlaneName(), size); + ::P4::error(ErrorType::ERR_INVALID, "Action profile '%1%' has non-constant size '%2%'", + decl->controlPlaneName(), size); return std::nullopt; } return getActionProfile(decl->controlPlaneName(), instance->type, @@ -784,10 +784,10 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { CHECK_NULL(maxGroupSizeConstant); profile->set_max_group_size(maxGroupSizeConstant->asInt()); } else { - ::warning(ErrorType::WARN_IGNORE, - "Ignoring annotation @max_group_size on action profile '%1%', " - "which does not have a selector", - actionProfile.annotations); + ::P4::warning(ErrorType::WARN_IGNORE, + "Ignoring annotation @max_group_size on action profile '%1%', " + "which does not have a selector", + actionProfile.annotations); } } @@ -806,16 +806,16 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { } else if (selectorSizeSemantics->value.toUpper() == "SUM_OF_MEMBERS") { profile->mutable_sum_of_members(); } else { - ::error(ErrorType::ERR_INVALID, - "Expected selector_size_semantics value \"sum_of_weights\" or " - "\"sum_of_members\", but got '%1%'", - selectorSizeSemantics); + ::P4::error(ErrorType::ERR_INVALID, + "Expected selector_size_semantics value \"sum_of_weights\" or " + "\"sum_of_members\", but got '%1%'", + selectorSizeSemantics); } } else { - ::warning(ErrorType::WARN_IGNORE, - "Ignoring annotation @selector_size_semantics on action " - "profile '%1%', which does not have a selector ", - actionProfile.annotations); + ::P4::warning(ErrorType::WARN_IGNORE, + "Ignoring annotation @selector_size_semantics on action " + "profile '%1%', which does not have a selector ", + actionProfile.annotations); } } @@ -831,15 +831,15 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { profile->mutable_sum_of_members()->set_max_member_weight( maxMemberWeightConstant->asInt()); } else if (actionProfile.type != ActionProfileType::INDIRECT_WITH_SELECTOR) { - ::warning(ErrorType::WARN_IGNORE, - "Ignoring annotation @max_member_weight on action profile " - "'%1%', which does not have a selector", - actionProfile.annotations); + ::P4::warning(ErrorType::WARN_IGNORE, + "Ignoring annotation @max_member_weight on action profile " + "'%1%', which does not have a selector", + actionProfile.annotations); } else { - ::warning(ErrorType::WARN_IGNORE, - "Ignoring annotation @max_member_weight on action profile '%1%', " - "which does not use 'sum_of_members' as its SelectorSizeSemantics", - actionProfile.annotations); + ::P4::warning(ErrorType::WARN_IGNORE, + "Ignoring annotation @max_member_weight on action profile '%1%', " + "which does not use 'sum_of_members' as its SelectorSizeSemantics", + actionProfile.annotations); } } @@ -965,9 +965,10 @@ class P4RuntimeArchHandlerCommon : public P4RuntimeArchHandlerIface { const IR::Property *impl = getTableImplementationProperty(table); if (impl == nullptr) return std::nullopt; if (!impl->value->is()) { - ::error(ErrorType::ERR_EXPECTED, - "Expected implementation property value for table %1% to be an expression: %2%", - table->controlPlaneName(), impl); + ::P4::error( + ErrorType::ERR_EXPECTED, + "Expected implementation property value for table %1% to be an expression: %2%", + table->controlPlaneName(), impl); return std::nullopt; } auto expr = impl->value->to()->expression; @@ -1071,21 +1072,21 @@ class P4RuntimeArchHandlerPSAPNA : public P4RuntimeArchHandlerCommon { return false; } } else if (expr->is()) { - ::error(ErrorType::ERR_UNEXPECTED, - "Unresolved value %1% for psa_idle_timeout " - "property on table %2%. Must be a constant and one of " - "{ NOTIFY_CONTROL, NO_TIMEOUT }", - timeout, table); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unresolved value %1% for psa_idle_timeout " + "property on table %2%. Must be a constant and one of " + "{ NOTIFY_CONTROL, NO_TIMEOUT }", + timeout, table); return false; } } } - ::error(ErrorType::ERR_UNEXPECTED, - "Unexpected value %1% for psa_idle_timeout " - "property on table %2%. Supported values are " - "{ NOTIFY_CONTROL, NO_TIMEOUT }", - timeout, table); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unexpected value %1% for psa_idle_timeout " + "property on table %2%. Supported values are " + "{ NOTIFY_CONTROL, NO_TIMEOUT }", + timeout, table); return false; } }; diff --git a/control-plane/p4RuntimeSerializer.cpp b/control-plane/p4RuntimeSerializer.cpp index 332c62c5bf..0e5694afdb 100644 --- a/control-plane/p4RuntimeSerializer.cpp +++ b/control-plane/p4RuntimeSerializer.cpp @@ -84,12 +84,12 @@ static std::optional explicitNameAnnotation(const IR::IAnnotated *item) auto *anno = item->getAnnotation(IR::Annotation::nameAnnotation); if (!anno) return std::nullopt; if (anno->expr.size() != 1) { - ::error(ErrorType::ERR_INVALID, "A %1% annotation must have one argument", anno); + ::P4::error(ErrorType::ERR_INVALID, "A %1% annotation must have one argument", anno); return std::nullopt; } auto *str = anno->expr[0]->to(); if (!str) { - ::error(ErrorType::ERR_INVALID, "An %1% annotation's argument must be a string", anno); + ::P4::error(ErrorType::ERR_INVALID, "An %1% annotation's argument must be a string", anno); return std::nullopt; } return str->value; @@ -118,13 +118,13 @@ static bool writeJsonTo(const Message &message, std::ostream *destination, std::string output; if (!MessageToJsonString(message, &output, options).ok()) { - ::error(ErrorType::ERR_IO, "Failed to serialize protobuf message to JSON"); + ::P4::error(ErrorType::ERR_IO, "Failed to serialize protobuf message to JSON"); return false; } *destination << output; if (!destination->good()) { - ::error(ErrorType::ERR_IO, "Failed to write JSON protobuf message to the output"); + ::P4::error(ErrorType::ERR_IO, "Failed to write JSON protobuf message to the output"); return false; } @@ -147,13 +147,13 @@ static bool writeTextTo(const Message &message, std::ostream *destination) { *destination << "# proto-file: " << message.GetDescriptor()->file()->name() << "\n"; *destination << "# proto-message: " << message.GetTypeName() << "\n\n"; if (!textPrinter.PrintToString(message, &output)) { - ::error(ErrorType::ERR_IO, "Failed to serialize protobuf message to text"); + ::P4::error(ErrorType::ERR_IO, "Failed to serialize protobuf message to text"); return false; } *destination << output; if (!destination->good()) { - ::error(ErrorType::ERR_IO, "Failed to write text protobuf message to the output"); + ::P4::error(ErrorType::ERR_IO, "Failed to write text protobuf message to the output"); return false; } @@ -211,9 +211,10 @@ class FieldIdAllocator { auto id = getIdAnnotation(*it); if (!id) continue; if (*id == 0) { - ::error(ErrorType::ERR_INVALID, "%1%: 0 is not a valid @id value", *it); + ::P4::error(ErrorType::ERR_INVALID, "%1%: 0 is not a valid @id value", *it); } else if (assignedIds.count(*id) > 0) { - ::error(ErrorType::ERR_DUPLICATE, "%1%: @id %2% is used multiple times", *it, *id); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: @id %2% is used multiple times", *it, + *id); } idMapping[*it] = *id; assignedIds.insert(*id); @@ -257,7 +258,7 @@ static std::optional getDefaultAction(const IR::P4Table *table, R table->properties->getProperty(IR::TableProperties::defaultActionPropertyName); if (defaultActionProperty == nullptr) return std::nullopt; if (!defaultActionProperty->value->is()) { - ::error(ErrorType::ERR_EXPECTED, "Expected an action: %1%", defaultActionProperty); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected an action: %1%", defaultActionProperty); return std::nullopt; } @@ -273,9 +274,9 @@ static std::optional getDefaultAction(const IR::P4Table *table, R BUG_CHECK(instance->is(), "Expected an action: %1%", expr); actionName = instance->to()->action->controlPlaneName(); } else { - ::error(ErrorType::ERR_UNEXPECTED, - "Unexpected expression in default action for table %1%: %2%", - table->controlPlaneName(), expr); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Unexpected expression in default action for table %1%: %2%", + table->controlPlaneName(), expr); return std::nullopt; } @@ -451,9 +452,9 @@ class P4RuntimeAnalyzer { auto pName = names.insert(pre.name()); auto pId = ids->insert(pre.id()); if (!pName.second) { - ::error(ErrorType::ERR_DUPLICATE, - "Name '%1%' is used for multiple %2% objects in the P4Info message", - pre.name(), typeName); + ::P4::error(ErrorType::ERR_DUPLICATE, + "Name '%1%' is used for multiple %2% objects in the P4Info message", + pre.name(), typeName); dupCnt++; return; } @@ -571,10 +572,10 @@ class P4RuntimeAnalyzer { if (!paramType->is() && !paramType->is() && !paramType->is() && !paramType->is() && !paramType->is()) { - ::error(ErrorType::ERR_TYPE_ERROR, - "Action parameter %1% has a type which is not " - "bit<>, int<>, bool, type or serializable enum", - actionParam); + ::P4::error(ErrorType::ERR_TYPE_ERROR, + "Action parameter %1% has a type which is not " + "bit<>, int<>, bool, type or serializable enum", + actionParam); continue; } if (!paramType->is()) { @@ -688,10 +689,10 @@ class P4RuntimeAnalyzer { auto isTableOnly = (action.annotations->getAnnotation("tableonly"_cs) != nullptr); auto isDefaultOnly = (action.annotations->getAnnotation("defaultonly"_cs) != nullptr); if (isTableOnly && isDefaultOnly) { - ::error(ErrorType::ERR_INVALID, - "Table '%1%' has an action reference ('%2%') which is annotated " - "with both '@tableonly' and '@defaultonly'", - name, action.name); + ::P4::error(ErrorType::ERR_INVALID, + "Table '%1%' has an action reference ('%2%') which is annotated " + "with both '@tableonly' and '@defaultonly'", + name, action.name); } if (isTableOnly) action_ref->set_scope(p4configv1::ActionRef::TABLE_ONLY); @@ -776,12 +777,13 @@ class P4RuntimeAnalyzer { unsigned int size = 0; auto sizeConstant = inst->size->to(); if (sizeConstant == nullptr || !sizeConstant->fitsInt()) { - ::error(ErrorType::ERR_INVALID, "@size should be an integer for declaration %1%", inst); + ::P4::error(ErrorType::ERR_INVALID, "@size should be an integer for declaration %1%", + inst); return; } if (sizeConstant->value < 0) { - ::error(ErrorType::ERR_INVALID, - "@size should be a positive integer for declaration %1%", inst); + ::P4::error(ErrorType::ERR_INVALID, + "@size should be a positive integer for declaration %1%", inst); return; } size = static_cast(sizeConstant->value); @@ -806,9 +808,9 @@ class P4RuntimeAnalyzer { auto matchTypeName = getMatchTypeName(matchPathExpr, refMap); auto matchType = getMatchType(matchTypeName); if (matchType == std::nullopt) { - ::error(ErrorType::ERR_UNSUPPORTED, - "unsupported match type %1% for Value Set '@match' annotation", - matchAnnotation); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "unsupported match type %1% for Value Set '@match' annotation", + matchAnnotation); return; } if (matchType != MatchField::MatchTypes::UNSPECIFIED) @@ -835,12 +837,12 @@ class P4RuntimeAnalyzer { for (auto f : fields) { auto fType = f->type; if (!fType->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Unsupported type argument for Value Set; " - "this version of P4Runtime requires that when the type parameter " - "of a Value Set is a struct, all the fields of the struct " - "must be of type bit, but %1% is not", - f); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Unsupported type argument for Value Set; " + "this version of P4Runtime requires that when the type parameter " + "of a Value Set is a struct, all the fields of the struct " + "must be of type bit, but %1% is not", + f); continue; } auto *match = vs->add_match(); @@ -858,12 +860,12 @@ class P4RuntimeAnalyzer { auto serEnum = et->to(); auto fType = serEnum->type; if (!fType->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Unsupported type argument for Value Set; " - "this version of P4Runtime requires that when the type parameter " - "of a Value Set is a serializable enum, " - "it must be of type bit, but %1% is not", - serEnum); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Unsupported type argument for Value Set; " + "this version of P4Runtime requires that when the type parameter " + "of a Value Set is a serializable enum, " + "it must be of type bit, but %1% is not", + serEnum); } auto fields = serEnum->members; p4rt_id_t index = 1; @@ -876,16 +878,16 @@ class P4RuntimeAnalyzer { } } else if (et->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: Unsupported type argument for Value Set; " - "this version of P4Runtime requires the type parameter of a Value Set " - "to be a bit, a struct of bit fields, or a serializable enum", - inst); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: Unsupported type argument for Value Set; " + "this version of P4Runtime requires the type parameter of a Value Set " + "to be a bit, a struct of bit fields, or a serializable enum", + inst); } else { - ::error(ErrorType::ERR_INVALID, - "%1%: invalid type parameter for Value Set; " - "it must be one of bit, struct, tuple or serializable enum", - inst); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid type parameter for Value Set; " + "it must be one of bit, struct, tuple or serializable enum", + inst); } } @@ -898,9 +900,9 @@ class P4RuntimeAnalyzer { void addPkgInfo(const IR::ToplevelBlock *evaluatedProgram, cstring arch) const { auto *main = evaluatedProgram->getMain(); if (main == nullptr) { - ::warning(ErrorType::WARN_MISSING, - "Program does not contain a main module, " - "so P4Info's 'pkg_info' field will not be set"); + ::P4::warning(ErrorType::WARN_MISSING, + "Program does not contain a main module, " + "so P4Info's 'pkg_info' field will not be set"); return; } auto *decl = main->node->to(); @@ -919,8 +921,9 @@ class P4RuntimeAnalyzer { auto setStringField = [kv, pkginfo, &keysVisited](cstring fName) { auto *v = kv->expression->to(); if (v == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Value for '%1%' key in @pkginfo annotation is not a string", kv); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Value for '%1%' key in @pkginfo annotation is not a string", + kv); return; } // kv annotations are represented with an IndexedVector in @@ -939,16 +942,16 @@ class P4RuntimeAnalyzer { name == "contact" || name == "url") { setStringField(name); } else if (name == "arch") { - ::warning(ErrorType::WARN_INVALID, - "The '%1%' field in PkgInfo should be set by the compiler, " - "not by the user", - kv); + ::P4::warning(ErrorType::WARN_INVALID, + "The '%1%' field in PkgInfo should be set by the compiler, " + "not by the user", + kv); // override the value set previously with the user-provided // value. setStringField(name); } else { - ::warning(ErrorType::WARN_UNKNOWN, - "Unknown key name '%1%' in @pkginfo annotation", name); + ::P4::warning(ErrorType::WARN_UNKNOWN, + "Unknown key name '%1%' in @pkginfo annotation", name); } } } @@ -962,10 +965,11 @@ class P4RuntimeAnalyzer { auto setInt32Field = [kv, &platform_properties](cstring fName) { auto *v = kv->expression->to(); if (v == nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Value for '%1%' key in @platform_property annotation is not an " - "integer", - kv); + ::P4::error( + ErrorType::ERR_UNSUPPORTED, + "Value for '%1%' key in @platform_property annotation is not an " + "integer", + kv); return; } // use Protobuf reflection library to minimize code duplication. @@ -979,8 +983,8 @@ class P4RuntimeAnalyzer { name == "multicast_group_table_max_replicas_per_entry") { setInt32Field(name); } else { - ::warning(ErrorType::WARN_UNKNOWN, - "Unknown key name '%1%' in @platform_property annotation", name); + ::P4::warning(ErrorType::WARN_UNKNOWN, + "Unknown key name '%1%' in @platform_property annotation", name); } } } @@ -1067,7 +1071,7 @@ class P4RuntimeEntriesConverter { if (auto c = e->priority->to()) { protoEntry->set_priority(c->asInt()); } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: entry should have priority", e); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: entry should have priority", e); return; } } else { @@ -1084,10 +1088,11 @@ class P4RuntimeEntriesConverter { auto priorityAnnotation = e->getAnnotation("priority"_cs); if (priorityAnnotation != nullptr) { - ::warning(ErrorType::WARN_DEPRECATED, - "The @priority annotation on %1% is not part of the P4 specification, " - "nor of the P4Runtime specification, and will be ignored", - e); + ::P4::warning( + ErrorType::WARN_DEPRECATED, + "The @priority annotation on %1% is not part of the P4 specification, " + "nor of the P4Runtime specification, and will be ignored", + e); } } } @@ -1110,7 +1115,7 @@ class P4RuntimeEntriesConverter { void addAction(p4v1::TableEntry *protoEntry, const IR::Expression *actionRef, ReferenceMap *refMap, TypeMap *typeMap) const { if (!actionRef->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: invalid action in entries list", actionRef); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid action in entries list", actionRef); return; } auto actionCall = actionRef->to(); @@ -1141,8 +1146,8 @@ class P4RuntimeEntriesConverter { auto value = stringRepr(sei->value->to(), width); protoParam->set_value(*value); } else { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported argument expression", - arg->expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported argument expression", + arg->expression); continue; } } @@ -1170,8 +1175,8 @@ class P4RuntimeEntriesConverter { addOptional(protoEntry, fieldId++, k, keyWidth, typeMap); } else { if (!k->is()) - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: match type not supported by P4Runtime serializer", matchType); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: match type not supported by P4Runtime serializer", matchType); continue; } } @@ -1197,12 +1202,12 @@ class P4RuntimeEntriesConverter { BUG_CHECK(w == keyWidth, "SerEnum bitwidth mismatch"); return stringRepr(type, w); } - ::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); return std::nullopt; } else if (k->is()) { return convertSimpleKeyExpression(k->to()->expr, keyWidth, typeMap); } else { - ::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); return std::nullopt; } } @@ -1223,12 +1228,12 @@ class P4RuntimeEntriesConverter { if (auto sei = ei->to()) { return simpleKeyExpressionValue(sei->value, typeMap); } - ::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid Member key expression", k); return std::nullopt; } else if (k->is()) { return simpleKeyExpressionValue(k->to()->expr, typeMap); } else { - ::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid key expression", k); return std::nullopt; } } @@ -1260,14 +1265,14 @@ class P4RuntimeEntriesConverter { auto mask = km->right->to()->value; auto len = trailing_zeros(mask); if (len + count_ones(mask) != keyWidth) { // any remaining 0s in the prefix? - ::error(ErrorType::ERR_INVALID, "%1% invalid mask for LPM key", k); + ::P4::error(ErrorType::ERR_INVALID, "%1% invalid mask for LPM key", k); return; } if ((*value & mask) != *value) { - ::warning(ErrorType::WARN_MISMATCH, - "P4Runtime requires that LPM matches have masked-off bits set to 0, " - "updating value %1% to conform to the P4Runtime specification", - km->left); + ::P4::warning(ErrorType::WARN_MISMATCH, + "P4Runtime requires that LPM matches have masked-off bits set to 0, " + "updating value %1% to conform to the P4Runtime specification", + km->left); *value &= mask; } if (mask == 0) // don't care @@ -1298,10 +1303,11 @@ class P4RuntimeEntriesConverter { auto mask = simpleKeyExpressionValue(km->right, typeMap); if (value == std::nullopt || mask == std::nullopt) return; if ((*value & *mask) != *value) { - ::warning(ErrorType::WARN_MISMATCH, - "P4Runtime requires that Ternary matches have masked-off bits set to 0, " - "updating value %1% to conform to the P4Runtime specification", - km->left); + ::P4::warning( + ErrorType::WARN_MISMATCH, + "P4Runtime requires that Ternary matches have masked-off bits set to 0, " + "updating value %1% to conform to the P4Runtime specification", + km->left); *value &= *mask; } if (*mask == 0) // don't care @@ -1339,7 +1345,8 @@ class P4RuntimeEntriesConverter { // For e.g. 16 bit key has a max value of 65535, Range of (1..65536) // will be converted to (1..0) and will fail below check. if (*start > *end) - ::error(ErrorType::ERR_INVALID, "%s Invalid range for table entry", kr->srcInfo); + ::P4::error(ErrorType::ERR_INVALID, "%s Invalid range for table entry", + kr->srcInfo); if (*start == 0 && *end == maxValue) // don't care return; startStr = stringReprConstant(*start, keyWidth); @@ -1425,7 +1432,7 @@ class P4RuntimeEntriesConverter { // P4Info generation). auto dupCnt = analyzer.checkForDuplicates(); if (dupCnt > 0) { - ::error(ErrorType::ERR_DUPLICATE, "Found %1% duplicate name(s) in the P4Info", dupCnt); + ::P4::error(ErrorType::ERR_DUPLICATE, "Found %1% duplicate name(s) in the P4Info", dupCnt); } analyzer.addPkgInfo(evaluatedProgram, arch); @@ -1454,8 +1461,8 @@ P4RuntimeAPI P4RuntimeSerializer::generateP4Runtime(const IR::P4Program *program auto archHandlerBuilderIt = archHandlerBuilders.find(arch); if (archHandlerBuilderIt == archHandlerBuilders.end()) { - ::error(ErrorType::ERR_UNSUPPORTED, "Arch '%1%' not supported by P4Runtime serializer", - arch); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Arch '%1%' not supported by P4Runtime serializer", + arch); return P4RuntimeAPI{new p4configv1::P4Info(), new p4v1::WriteRequest()}; } @@ -1473,9 +1480,9 @@ P4RuntimeAPI P4RuntimeSerializer::generateP4Runtime(const IR::P4Program *program auto *evaluatedProgram = evaluator->getToplevelBlock(); if (!p4RuntimeProgram || !evaluatedProgram) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: unsupported P4 program (cannot apply necessary program transformations)", - "Cannot generate P4Info message"); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: unsupported P4 program (cannot apply necessary program transformations)", + "Cannot generate P4Info message"); return P4RuntimeAPI{new p4configv1::P4Info(), new p4v1::WriteRequest()}; } @@ -1502,7 +1509,8 @@ void P4RuntimeAPI::serializeP4InfoTo(std::ostream *destination, P4RuntimeFormat success = writers::writeTextTo(*p4Info, destination); break; } - if (!success) ::error(ErrorType::ERR_IO, "Failed to serialize the P4Runtime API to the output"); + if (!success) + ::P4::error(ErrorType::ERR_IO, "Failed to serialize the P4Runtime API to the output"); } void P4RuntimeAPI::serializeEntriesTo(std::ostream *destination, P4RuntimeFormat format) const { @@ -1523,8 +1531,8 @@ void P4RuntimeAPI::serializeEntriesTo(std::ostream *destination, P4RuntimeFormat break; } if (!success) - ::error(ErrorType::ERR_IO, - "Failed to serialize the P4Runtime static table entries to the output"); + ::P4::error(ErrorType::ERR_IO, + "Failed to serialize the P4Runtime static table entries to the output"); } static bool parseFileNames(cstring fileNameVector, std::vector &files, @@ -1548,13 +1556,13 @@ static bool parseFileNames(cstring fileNameVector, std::vector &files, } else if (name.endsWith(".txtpb")) { formats.push_back(P4::P4RuntimeFormat::TEXT_PROTOBUF); } else if (name.endsWith(".txt")) { - ::warning(ErrorType::WARN_DEPRECATED, - ".txt format is being deprecated; use .txtpb instead"); + ::P4::warning(ErrorType::WARN_DEPRECATED, + ".txt format is being deprecated; use .txtpb instead"); formats.push_back(P4::P4RuntimeFormat::TEXT); } else { - ::error(ErrorType::ERR_UNKNOWN, - "%1%: unknown file kind; known suffixes are .bin, .txt, .json, and .txtpb", - name); + ::P4::error(ErrorType::ERR_UNKNOWN, + "%1%: unknown file kind; known suffixes are .bin, .txt, .json, and .txtpb", + name); return false; } } @@ -1597,7 +1605,7 @@ void P4RuntimeSerializer::serializeP4RuntimeIfRequired(const P4RuntimeAPI &p4Run P4::P4RuntimeFormat format = formats.at(i); std::ostream *out = openFile(file.string(), false); if (!out) { - ::error(ErrorType::ERR_IO, "Couldn't open P4Runtime API file: %1%", file); + ::P4::error(ErrorType::ERR_IO, "Couldn't open P4Runtime API file: %1%", file); continue; } p4Runtime.serializeP4InfoTo(out, format); @@ -1619,8 +1627,8 @@ void P4RuntimeSerializer::serializeP4RuntimeIfRequired(const P4RuntimeAPI &p4Run P4::P4RuntimeFormat format = formats.at(i); std::ostream *out = openFile(file.string(), false); if (!out) { - ::error(ErrorType::ERR_IO, "Couldn't open P4Runtime static entries file: %1%", - options.p4RuntimeEntriesFile); + ::P4::error(ErrorType::ERR_IO, "Couldn't open P4Runtime static entries file: %1%", + options.p4RuntimeEntriesFile); continue; } p4Runtime.serializeEntriesTo(out, format); diff --git a/control-plane/p4RuntimeSerializer.h b/control-plane/p4RuntimeSerializer.h index a50fc42d28..a43cfe3221 100644 --- a/control-plane/p4RuntimeSerializer.h +++ b/control-plane/p4RuntimeSerializer.h @@ -40,11 +40,13 @@ class WriteRequest; } // namespace v1 } // namespace p4 -namespace IR { +namespace P4::IR { class P4Program; -} // namespace IR +} // namespace P4::IR +namespace P4 { class CompilerOptions; +} // namespace P4 namespace P4 { diff --git a/control-plane/p4RuntimeSymbolTable.cpp b/control-plane/p4RuntimeSymbolTable.cpp index 3249c80c26..2365043974 100644 --- a/control-plane/p4RuntimeSymbolTable.cpp +++ b/control-plane/p4RuntimeSymbolTable.cpp @@ -39,7 +39,7 @@ std::optional getIdAnnotation(const IR::IAnnotated *node) { const auto *idConstant = idAnnotation->expr[0]->to(); CHECK_NULL(idConstant); if (!idConstant->fitsUint()) { - ::error(ErrorType::ERR_INVALID, "%1%: @id should be an unsigned integer", node); + ::P4::error(ErrorType::ERR_INVALID, "%1%: @id should be an unsigned integer", node); return std::nullopt; } return static_cast(idConstant->value); @@ -67,7 +67,7 @@ static std::optional externalId(const P4RuntimeSymbolType &type, const auto typePrefix = static_cast(type) << 24; const auto prefixMask = static_cast(0xff) << 24; if ((id & prefixMask) != 0 && (id & prefixMask) != typePrefix) { - ::error(ErrorType::ERR_INVALID, "%1%: @id has the wrong 8-bit prefix", declaration); + ::P4::error(ErrorType::ERR_INVALID, "%1%: @id has the wrong 8-bit prefix", declaration); return std::nullopt; } id |= typePrefix; @@ -222,7 +222,7 @@ P4::ControlPlaneAPI::p4rt_id_t P4::ControlPlaneAPI::P4RuntimeSymbolTable::tryToA } if (assignedIds.find(*id) != assignedIds.end()) { - ::error(ErrorType::ERR_INVALID, "@id %1% is assigned to multiple declarations", *id); + ::P4::error(ErrorType::ERR_INVALID, "@id %1% is assigned to multiple declarations", *id); return INVALID_ID; } @@ -263,8 +263,8 @@ void P4::ControlPlaneAPI::P4RuntimeSymbolTable::computeIdsForSymbols(P4RuntimeSy nameId, [=](uint32_t nameId) { return (resourceType << 24) | (nameId & 0xffffff); }); if (!id) { - ::error(ErrorType::ERR_OVERLIMIT, "No available id to represent %1% in P4Runtime", - name); + ::P4::error(ErrorType::ERR_OVERLIMIT, "No available id to represent %1% in P4Runtime", + name); return; } diff --git a/control-plane/p4RuntimeSymbolTable.h b/control-plane/p4RuntimeSymbolTable.h index e690b75f34..3ac2aa1238 100644 --- a/control-plane/p4RuntimeSymbolTable.h +++ b/control-plane/p4RuntimeSymbolTable.h @@ -32,9 +32,9 @@ class WriteRequest; } // namespace v1 } // namespace p4 -namespace IR { +namespace P4::IR { class P4Program; -} // namespace IR +} // namespace P4::IR namespace P4 { diff --git a/control-plane/p4infoApi.cpp b/control-plane/p4infoApi.cpp index 1c443727d5..53615628dd 100644 --- a/control-plane/p4infoApi.cpp +++ b/control-plane/p4infoApi.cpp @@ -277,7 +277,7 @@ std::optional getP4RuntimeId(const p4::config::v1::P4Info &p4Info, return p4RuntimeExternOpt->extern_type_id(); } - ::error("Unsupported P4Runtime ID type"); + ::P4::error("Unsupported P4Runtime ID type"); return std::nullopt; } diff --git a/control-plane/typeSpecConverter.cpp b/control-plane/typeSpecConverter.cpp index 875953bcd0..57ae67d076 100644 --- a/control-plane/typeSpecConverter.cpp +++ b/control-plane/typeSpecConverter.cpp @@ -93,7 +93,7 @@ TypeSpecConverter::TypeSpecConverter(const P4::ReferenceMap *refMap, P4::TypeMap } bool TypeSpecConverter::preorder(const IR::Type *type) { - ::error(ErrorType::ERR_UNEXPECTED, "Unexpected type %1%", type); + ::P4::error(ErrorType::ERR_UNEXPECTED, "Unexpected type %1%", type); map.emplace(type, new P4DataTypeSpec()); return false; } @@ -180,10 +180,11 @@ bool TypeSpecConverter::preorder(const IR::Type_Newtype *type) { TranslationAnnotation ann; bool isTranslatedType = hasTranslationAnnotation(type, &ann); if (isTranslatedType && !underlyingType->is()) { - ::error(ErrorType::ERR_INVALID, - "%1%: P4Runtime requires the underlying type for a user-defined type with " - "the @p4runtime_translation annotation to be bit; it cannot be '%2%'", - type, underlyingType); + ::P4::error( + ErrorType::ERR_INVALID, + "%1%: P4Runtime requires the underlying type for a user-defined type with " + "the @p4runtime_translation annotation to be bit; it cannot be '%2%'", + type, underlyingType); // no need to return early here } visit(underlyingType); @@ -359,8 +360,8 @@ bool TypeSpecConverter::preorder(const IR::Type_SerEnum *type) { auto member = enumTypeSpec->add_members(); member->set_name(m->controlPlaneName()); if (!m->value->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported SerEnum member value", - m->value); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% unsupported SerEnum member value", + m->value); continue; } auto value = stringRepr(m->value->to(), width); diff --git a/docs/README.md b/docs/README.md index 427e9ee814..9463c90163 100644 --- a/docs/README.md +++ b/docs/README.md @@ -296,7 +296,7 @@ To add a new input test with a sample P4 code file (under `testdata/p4_16_sample * Use `BUG_CHECK()` instead of `assert`, and always supply an informative error message. - * Use `::error()` and `::warning()` for error reporting. See the + * Use `error()` and `warning()` for error reporting. See the [guidelines](CodingStandardPhilosophy.md#handling-errors) for more details. diff --git a/frontends/common/applyOptionsPragmas.cpp b/frontends/common/applyOptionsPragmas.cpp index 1ea9288c92..07fe9de774 100644 --- a/frontends/common/applyOptionsPragmas.cpp +++ b/frontends/common/applyOptionsPragmas.cpp @@ -72,15 +72,15 @@ std::optional P4COptionPragmaParser::pa } if (pragmaArgs->size() != 2) { - ::warning(ErrorType::WARN_MISSING, "@diagnostic takes two arguments: %1%", annotation); + ::P4::warning(ErrorType::WARN_MISSING, "@diagnostic takes two arguments: %1%", annotation); return std::nullopt; } auto *diagnosticName = pragmaArgs->at(0)->to(); auto *diagnosticAction = pragmaArgs->at(1)->to(); if (!diagnosticName || !diagnosticAction) { - ::warning(ErrorType::WARN_MISSING, "@diagnostic arguments must be strings: %1%", - annotation); + ::P4::warning(ErrorType::WARN_MISSING, "@diagnostic arguments must be strings: %1%", + annotation); return std::nullopt; } @@ -92,10 +92,10 @@ std::optional P4COptionPragmaParser::pa } else if (diagnosticAction->value == "error") { diagnosticOption = "--Werror="_cs; } else { - ::warning(ErrorType::WARN_MISMATCH, - "@diagnostic's second argument must be 'disable', " - "'warn', or 'error': %1%", - annotation); + ::P4::warning(ErrorType::WARN_MISMATCH, + "@diagnostic's second argument must be 'disable', " + "'warn', or 'error': %1%", + annotation); return std::nullopt; } diff --git a/frontends/common/constantFolding.cpp b/frontends/common/constantFolding.cpp index 184e54cf93..7c3fc12fbf 100644 --- a/frontends/common/constantFolding.cpp +++ b/frontends/common/constantFolding.cpp @@ -114,13 +114,13 @@ const IR::Node *DoConstantFolding::postorder(IR::Type_Bits *type) { type->size = cst->asInt(); type->expression = nullptr; if (type->width_bits() < 0 || (type->width_bits() == 0 && type->isSigned)) { - ::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); // Convert it to something legal so we don't get // weird errors elsewhere. type->size = 64; } } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", type->expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", type->expression); } } return type; @@ -131,9 +131,9 @@ const IR::Node *DoConstantFolding::postorder(IR::Type_Varbits *type) { if (auto cst = type->expression->to()) { type->size = cst->asInt(); type->expression = nullptr; - if (type->size < 0) ::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); + if (type->size < 0) ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); } else { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", type->expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a constant", type->expression); } } return type; @@ -143,8 +143,8 @@ const IR::Node *DoConstantFolding::postorder(IR::Declaration_Constant *d) { auto init = getConstant(d->initializer); if (init == nullptr) { if (typesKnown) - ::error(ErrorType::ERR_INVALID, "%1%: Cannot evaluate initializer for constant", - d->initializer); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Cannot evaluate initializer for constant", + d->initializer); return d; } if (!typesKnown) { @@ -156,8 +156,8 @@ const IR::Node *DoConstantFolding::postorder(IR::Declaration_Constant *d) { if (auto dtype = d->type->to()) { auto cstBits = cst->type->to(); if (cstBits && !(*dtype == *cstBits)) - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: initializer has wrong type %2%", d, - cst->type); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: initializer has wrong type %2%", d, + cst->type); else if (cst->type->is()) init = new IR::Constant(init->srcInfo, d->type, cst->value, cst->base); } else if (!d->type->is()) { @@ -213,24 +213,25 @@ const IR::Node *DoConstantFolding::preorder(IR::ArrayIndex *e) { auto init = getConstant(e->right); if (init == nullptr) { if (typesKnown) - ::error(ErrorType::ERR_INVALID, "%1%: Index must evaluate to a constant", e->right); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Index must evaluate to a constant", + e->right); return e; } if (auto cst = init->to()) { if (!cst->fitsInt()) { - ::error(ErrorType::ERR_INVALID, "Index too large: %1%", cst); + ::P4::error(ErrorType::ERR_INVALID, "Index too large: %1%", cst); return e; } int index = cst->asInt(); if (index < 0) { - ::error(ErrorType::ERR_INVALID, "Tuple index %1% must be constant", e->right); + ::P4::error(ErrorType::ERR_INVALID, "Tuple index %1% must be constant", e->right); return e; } auto value = getConstant(e->left); if (!value) return e; if (auto list = value->to()) { if (static_cast(index) >= list->size()) { - ::error(ErrorType::ERR_INVALID, "Tuple index %1% out of bounds", e->right); + ::P4::error(ErrorType::ERR_INVALID, "Tuple index %1% out of bounds", e->right); return e; } return CloneConstants::clone(list->components.at(static_cast(index)), this); @@ -283,15 +284,15 @@ const IR::Node *DoConstantFolding::postorder(IR::Cmpl *e) { auto cst = op->to(); if (cst == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", op); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", op); return e; } const IR::Type *t = op->type; if (t->is()) { - ::error(ErrorType::ERR_INVALID, - "%1%: Operation cannot be applied to values with unknown width;\n" - "please specify width explicitly", - e); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Operation cannot be applied to values with unknown width;\n" + "please specify width explicitly", + e); return e; } auto tb = t->to(); @@ -310,7 +311,7 @@ const IR::Node *DoConstantFolding::postorder(IR::Neg *e) { auto cst = op->to(); if (cst == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", op); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", op); return e; } const IR::Type *t = op->type; @@ -332,7 +333,7 @@ const IR::Node *DoConstantFolding::postorder(IR::UPlus *e) { auto cst = op->to(); if (cst == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", op); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", op); return e; } return cst; @@ -398,11 +399,12 @@ const IR::Node *DoConstantFolding::postorder(IR::Geq *e) { const IR::Node *DoConstantFolding::postorder(IR::Div *e) { return binary(e, [e](big_int a, big_int b) -> big_int { if (a < 0 || b < 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Division is not defined for negative numbers", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Division is not defined for negative numbers", + e); return 0; } if (b == 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Division by zero", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Division by zero", e); return 0; } return a / b; @@ -412,11 +414,12 @@ const IR::Node *DoConstantFolding::postorder(IR::Div *e) { const IR::Node *DoConstantFolding::postorder(IR::Mod *e) { return binary(e, [e](big_int a, big_int b) -> big_int { if (a < 0 || b < 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Modulo is not defined for negative numbers", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Modulo is not defined for negative numbers", + e); return 0; } if (b == 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Modulo by zero", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Modulo by zero", e); return 0; } return a % b; @@ -440,7 +443,7 @@ const IR::Node *DoConstantFolding::compare(const IR::Operation_Binary *e) { if (const auto *left = eleft->to()) { const auto *right = eright->to(); if (right == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: both operands must be Boolean", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: both operands must be Boolean", e); return e; } bool bresult = (left->value == right->value) == eqTest; @@ -449,7 +452,7 @@ const IR::Node *DoConstantFolding::compare(const IR::Operation_Binary *e) { if (const auto *left = eleft->to()) { const auto *right = eright->to(); if (right == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: both operands must be String", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: both operands must be String", e); return e; } bool bresult = (left->value == right->value) == eqTest; @@ -468,7 +471,7 @@ const IR::Node *DoConstantFolding::compare(const IR::Operation_Binary *e) { auto rlist = eright->to(); if (llist != nullptr && rlist != nullptr) { if (llist->components.size() != rlist->components.size()) { - ::error(ErrorType::ERR_INVALID, "%1%: comparing lists of different size", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: comparing lists of different size", e); return e; } @@ -540,8 +543,8 @@ const IR::Node *DoConstantFolding::binary(const IR::Operation_Binary *e, if (!lunk && !runk) { // both typed if (!ltb->operator==(*rtb)) { - ::error(ErrorType::ERR_INVALID, "%1%: operands have different types: %2% and %3%", e, - ltb->toString(), rtb->toString()); + ::P4::error(ErrorType::ERR_INVALID, "%1%: operands have different types: %2% and %3%", + e, ltb->toString(), rtb->toString()); return e; } resultType = rtb; @@ -570,7 +573,7 @@ const IR::Node *DoConstantFolding::binary(const IR::Operation_Binary *e, } if (value >= limit) value = limit - 1; } else { - ::error(ErrorType::ERR_INVALID, "%1%: saturating operation on untyped values", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: saturating operation on untyped values", e); } } @@ -586,7 +589,7 @@ const IR::Node *DoConstantFolding::postorder(IR::LAnd *e) { auto lcst = left->to(); if (lcst == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a boolean value", left); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a boolean value", left); return e; } if (lcst->value) { @@ -601,7 +604,7 @@ const IR::Node *DoConstantFolding::postorder(IR::LOr *e) { auto lcst = left->to(); if (lcst == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a boolean value", left); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a boolean value", left); return e; } if (!lcst->value) { @@ -612,8 +615,8 @@ const IR::Node *DoConstantFolding::postorder(IR::LOr *e) { static bool overflowWidth(const IR::Node *node, int width) { if (width > P4CContext::getConfig().maximumWidthSupported()) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Compiler only supports widths up to %2%", node, - P4CContext::getConfig().maximumWidthSupported()); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Compiler only supports widths up to %2%", + node, P4CContext::getConfig().maximumWidthSupported()); return true; } return false; @@ -624,14 +627,14 @@ const IR::Node *DoConstantFolding::postorder(IR::Slice *e) { const IR::Expression *lsb = getConstant(e->e2); if (msb == nullptr) { if (typesKnown) - ::error(ErrorType::ERR_EXPECTED, "%1%: slice indexes must be compile-time constants", - e->e1); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: slice indexes must be compile-time constants", e->e1); return e; } if (lsb == nullptr) { if (typesKnown) - ::error(ErrorType::ERR_EXPECTED, "%1%: slice indexes must be compile-time constants", - e->e2); + ::P4::error(ErrorType::ERR_EXPECTED, + "%1%: slice indexes must be compile-time constants", e->e2); return e; } @@ -640,28 +643,30 @@ const IR::Node *DoConstantFolding::postorder(IR::Slice *e) { auto cmsb = msb->to(); if (cmsb == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", msb); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", msb); return e; } auto clsb = lsb->to(); if (clsb == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", lsb); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", lsb); return e; } auto cbase = e0->to(); if (cbase == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", e->e0); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", e->e0); return e; } int m = cmsb->asInt(); int l = clsb->asInt(); if (m < l) { - ::error(ErrorType::ERR_EXPECTED, "%1%: bit slicing should be specified as [msb:lsb]", e); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: bit slicing should be specified as [msb:lsb]", + e); return e; } if (l < 0) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected slice indexes to be non-negative", e->e2); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected slice indexes to be non-negative", + e->e2); return e; } if (overflowWidth(e, m) || overflowWidth(e, l)) return e; @@ -739,7 +744,7 @@ const IR::Node *DoConstantFolding::postorder(IR::Concat *e) { auto lt = left->type->to(); auto rt = right->type->to(); if (lt == nullptr || rt == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: both operand widths must be known", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: both operand widths must be known", e); return e; } @@ -756,7 +761,7 @@ const IR::Node *DoConstantFolding::postorder(IR::LNot *e) { auto cst = op->to(); if (cst == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a boolean value", op); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a boolean value", op); return e; } return new IR::BoolLiteral(cst->srcInfo, IR::Type_Boolean::get(), !cst->value); @@ -767,7 +772,7 @@ const IR::Node *DoConstantFolding::postorder(IR::Mux *e) { if (cond == nullptr) return e; auto b = cond->to(); if (b == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a Boolean", cond); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a Boolean", cond); return e; } if (b->value) @@ -798,7 +803,8 @@ const IR::Node *DoConstantFolding::shift(const IR::Operation_Binary *e) { CHECK_NULL(shift_amt); if (shift_amt->value < 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Shifts with negative amounts are not permitted", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Shifts with negative amounts are not permitted", + e); return e; } @@ -809,7 +815,7 @@ const IR::Node *DoConstantFolding::shift(const IR::Operation_Binary *e) { auto cl = left->to(); if (cl == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", left); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected an integer value", left); return e; } @@ -825,8 +831,8 @@ const IR::Node *DoConstantFolding::shift(const IR::Operation_Binary *e) { if (const auto *tb = left->type->to()) { if ((static_cast(tb->width_bits()) <= shift)) { if (warnings) { - ::warning(ErrorType::WARN_OVERFLOW, "%1%: Shifting %2%-bit value with %3%", e, - tb->width_bits(), shift); + ::P4::warning(ErrorType::WARN_OVERFLOW, "%1%: Shifting %2%-bit value with %3%", e, + tb->width_bits(), shift); } // According to the P4 specification, the result of a left-shift that is larger than the // width of the bit type is 0. For a right-shift of a negative signed value that is @@ -874,8 +880,8 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) { if (const auto *constant = expr->to()) { const auto *ctype = constant->type; if (!ctype->is() && !ctype->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: Cannot cast %1% to arbitrary presion integer", - ctype); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Cannot cast %1% to arbitrary presion integer", ctype); return e; } return new IR::Constant(e->srcInfo, etype, constant->value, constant->base); @@ -888,12 +894,13 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) { if (ctype->is()) { auto tb = ctype->to(); if (tb->isSigned) { - ::error(ErrorType::ERR_INVALID, "%1%: Cannot cast signed value to boolean", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Cannot cast signed value to boolean", + e); return e; } if (tb->width_bits() != 1) { - ::error(ErrorType::ERR_INVALID, "%1%: Only bit<1> values can be cast to bool", - e); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Only bit<1> values can be cast to bool", e); return e; } } else { @@ -903,7 +910,7 @@ const IR::Node *DoConstantFolding::postorder(IR::Cast *e) { int v = cst->asInt(); if (v < 0 || v > 1) { - ::error(ErrorType::ERR_INVALID, "%1%: Only 0 and 1 can be cast to booleans", e); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Only 0 and 1 can be cast to booleans", e); return e; } return new IR::BoolLiteral(e->srcInfo, IR::Type_Boolean::get(), v == 1); @@ -935,8 +942,8 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression *k if (select->is()) { auto key = getConstant(keySet); if (key == nullptr) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant", - keySet); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant", + keySet); return Result::No; } BUG_CHECK(key->is(), "%1%: expected a boolean", key); @@ -949,8 +956,8 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression *k // This must be an enum value auto key = getConstant(keySet); if (key == nullptr) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant", - keySet); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: expression must evaluate to a constant", + keySet); return Result::No; } auto sel = getConstant(select); @@ -969,14 +976,14 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression *k } else if (auto range = keySet->to()) { auto left = getConstant(range->left); if (left == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", - range->left); + ::P4::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", + range->left); return Result::DontKnow; } auto right = getConstant(range->right); if (right == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", - range->right); + ::P4::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", + range->right); return Result::DontKnow; } if (left->to()->value <= cst->value && @@ -987,14 +994,14 @@ DoConstantFolding::Result DoConstantFolding::setContains(const IR::Expression *k // check if left & right == cst & right auto left = getConstant(mask->left); if (left == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", - mask->left); + ::P4::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", + mask->left); return Result::DontKnow; } auto right = getConstant(mask->right); if (right == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", - mask->right); + ::P4::error(ErrorType::ERR_INVALID, "%1%: expression must evaluate to a constant", + mask->right); return Result::DontKnow; } if ((left->to()->value & right->to()->value) == diff --git a/frontends/common/constantParsing.cpp b/frontends/common/constantParsing.cpp index 5851a0eed6..33c8b36b54 100644 --- a/frontends/common/constantParsing.cpp +++ b/frontends/common/constantParsing.cpp @@ -21,6 +21,8 @@ limitations under the License. #include "lib/big_int_util.h" #include "lib/source_file.h" +namespace P4 { + std::ostream &operator<<(std::ostream &out, const UnparsedConstant &constant) { out << "UnparsedConstant(" << constant.text << ',' << constant.skip << ',' << constant.base << ',' << constant.hasWidth << ')'; @@ -36,11 +38,12 @@ static IR::Constant *parseConstantWithWidth(Util::SourceInfo srcInfo, const char sep += strspn(sep, " \t\r\n"); if (!*sep) BUG("Expected to find separator %1%", text); if (size < 0) { - ::error(ErrorType::ERR_INVALID, "%1%: invalid width; %2% must be positive", srcInfo, size); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid width; %2% must be positive", srcInfo, + size); return nullptr; } if (size > P4CContext::getConfig().maximumWidthSupported()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1%: %2% size too large", srcInfo, size); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1%: %2% size too large", srcInfo, size); return nullptr; } @@ -68,9 +71,11 @@ IR::Constant *parseConstant(const Util::SourceInfo &srcInfo, const UnparsedConst int parseConstantChecked(const Util::SourceInfo &srcInfo, const UnparsedConstant &constant) { auto cst = parseConstant(srcInfo, constant, 0); if (!cst->fitsInt()) { - ::error(ErrorType::ERR_OVERLIMIT, - "%1$x: this implementation does not support bitstrings this large", cst); + ::P4::error(ErrorType::ERR_OVERLIMIT, + "%1$x: this implementation does not support bitstrings this large", cst); return 8; // this is a fine value for a width; compilation will stop anyway } return cst->asInt(); } + +} // namespace P4 diff --git a/frontends/common/constantParsing.h b/frontends/common/constantParsing.h index 00b34111f0..ee7cbe7800 100644 --- a/frontends/common/constantParsing.h +++ b/frontends/common/constantParsing.h @@ -19,13 +19,15 @@ limitations under the License. #include "lib/cstring.h" -namespace IR { +namespace P4::IR { class Constant; -} // namespace IR +} // namespace P4::IR -namespace Util { +namespace P4::Util { class SourceInfo; -} // namespace Util +} // namespace P4::Util + +namespace P4 { /** * An unparsed numeric constant. We produce these as token values during @@ -86,4 +88,6 @@ IR::Constant *parseConstant(const Util::SourceInfo &srcInfo, const UnparsedConst */ int parseConstantChecked(const Util::SourceInfo &srcInfo, const UnparsedConstant &constant); +} // namespace P4 + #endif /* FRONTENDS_COMMON_CONSTANTPARSING_H_ */ diff --git a/frontends/common/copySrcInfo.h b/frontends/common/copySrcInfo.h index 45f39bcd02..6a31ad553d 100644 --- a/frontends/common/copySrcInfo.h +++ b/frontends/common/copySrcInfo.h @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -namespace P4 { - #ifndef FRONTENDS_COMMON_COPYSRCINFO_H_ #define FRONTENDS_COMMON_COPYSRCINFO_H_ #include "ir/ir.h" +namespace P4 { + /// This simple visitor copies the specified source information /// to the root node of the IR tree that it is invoked on. class CopySrcInfo : public Transform { diff --git a/frontends/common/model.h b/frontends/common/model.h index c9770814b0..c848417e75 100644 --- a/frontends/common/model.h +++ b/frontends/common/model.h @@ -22,7 +22,7 @@ limitations under the License. // Classes for representing various P4 program models inside the compiler -namespace Model { +namespace P4::Model { // Model element struct Elem { @@ -63,6 +63,6 @@ struct Param_Model : public Elem { class Model {}; -} // namespace Model +} // namespace P4::Model #endif /* FRONTENDS_COMMON_MODEL_H_ */ diff --git a/frontends/common/name_gateways.h b/frontends/common/name_gateways.h index 027e2fbb0b..3b14eb90a0 100644 --- a/frontends/common/name_gateways.h +++ b/frontends/common/name_gateways.h @@ -19,9 +19,13 @@ limitations under the License. #include "ir/ir.h" +namespace P4 { + class NameGateways : public Transform { const IR::Node *preorder(IR::If *n) override { return new IR::NamedCond(*n); } const IR::Node *preorder(IR::NamedCond *n) override { return n; } }; +} // namespace P4 + #endif /* FRONTENDS_COMMON_NAME_GATEWAYS_H_ */ diff --git a/frontends/common/options.cpp b/frontends/common/options.cpp index 24e172d4fb..0fd83f9978 100644 --- a/frontends/common/options.cpp +++ b/frontends/common/options.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "frontends/p4/frontend.h" +namespace P4 { + CompilerOptions::CompilerOptions(std::string_view defaultMessage) : ParserOptions(defaultMessage) { registerOption( "--excludeFrontendPasses", "pass1[,pass2]", @@ -124,7 +126,7 @@ CompilerOptions::CompilerOptions(std::string_view defaultMessage) : ParserOption } else if (!strcmp(arg, "text")) { p4RuntimeFormat = P4::P4RuntimeFormat::TEXT; } else { - ::error(ErrorType::ERR_INVALID, "Illegal P4Runtime format %1%", arg); + ::P4::error(ErrorType::ERR_INVALID, "Illegal P4Runtime format %1%", arg); return false; } return true; @@ -178,14 +180,16 @@ bool CompilerOptions::enable_intrinsic_metadata_fix() { return true; } bool CompilerOptions::validateOptions() const { if (!p4RuntimeFile.isNullOrEmpty()) { - ::warning(ErrorType::WARN_DEPRECATED, - "'--p4runtime-file' and '--p4runtime-format' are deprecated, " - "consider using '--p4runtime-files' instead"); + ::P4::warning(ErrorType::WARN_DEPRECATED, + "'--p4runtime-file' and '--p4runtime-format' are deprecated, " + "consider using '--p4runtime-files' instead"); } if (!p4RuntimeEntriesFile.isNullOrEmpty()) { - ::warning(ErrorType::WARN_DEPRECATED, - "'--p4runtime-entries-file' is deprecated, " - "consider using '--p4runtime-entries-files' instead"); + ::P4::warning(ErrorType::WARN_DEPRECATED, + "'--p4runtime-entries-file' is deprecated, " + "consider using '--p4runtime-entries-files' instead"); } return ParserOptions::validateOptions(); } + +} // namespace P4 diff --git a/frontends/common/options.h b/frontends/common/options.h index 5b59162bf3..a383c7ca27 100644 --- a/frontends/common/options.h +++ b/frontends/common/options.h @@ -25,6 +25,8 @@ limitations under the License. // for p4::P4RuntimeFormat definition #include "control-plane/p4RuntimeTypes.h" +namespace P4 { + class CompilerOptions : public ParserOptions { protected: bool validateOptions() const override; @@ -86,4 +88,7 @@ class CompilerOptions : public ParserOptions { virtual bool enable_intrinsic_metadata_fix(); }; + +} // namespace P4 + #endif /* FRONTENDS_COMMON_OPTIONS_H_ */ diff --git a/frontends/common/parseInput.cpp b/frontends/common/parseInput.cpp index 9fd64239e6..c12e0b8abd 100644 --- a/frontends/common/parseInput.cpp +++ b/frontends/common/parseInput.cpp @@ -34,9 +34,9 @@ const IR::P4Program *parseP4String(const char *sourceFile, unsigned sourceLine, ? parseV1Program(stream, sourceFile, sourceLine) : P4ParserDriver::parse(stream, sourceFile, sourceLine); - if (::errorCount() > 0) { - ::error(ErrorType::ERR_OVERLIMIT, "%1% errors encountered, aborting compilation", - ::errorCount()); + if (::P4::errorCount() > 0) { + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1% errors encountered, aborting compilation", + ::P4::errorCount()); return nullptr; } BUG_CHECK(result != nullptr, "Parsing failed, but we didn't report an error"); diff --git a/frontends/common/parseInput.h b/frontends/common/parseInput.h index 29736fa85c..84e44918d8 100644 --- a/frontends/common/parseInput.h +++ b/frontends/common/parseInput.h @@ -23,9 +23,9 @@ limitations under the License. #include "frontends/parsers/parserDriver.h" #include "lib/error.h" -namespace IR { +namespace P4::IR { class P4Program; -} // namespace IR +} // namespace P4::IR namespace P4 { @@ -41,12 +41,12 @@ static const IR::P4Program *parseV1Program(Input stream, std::string_view source // Parse. const IR::Node *v1 = V1::V1ParserDriver::parse(stream, sourceFile, sourceLine); - if (::errorCount() > 0 || v1 == nullptr) return nullptr; + if (::P4::errorCount() > 0 || v1 == nullptr) return nullptr; // Convert to P4-16. if (Log::verbose()) std::cerr << "Converting to P4-16" << std::endl; v1 = v1->apply(converter); - if (::errorCount() > 0 || v1 == nullptr) return nullptr; + if (::P4::errorCount() > 0 || v1 == nullptr) return nullptr; BUG_CHECK(v1->is(), "Conversion returned %1%", v1); return v1->to(); } @@ -69,7 +69,7 @@ const IR::P4Program *parseP4File(const ParserOptions &options) { if (options.doNotPreprocess) { auto *file = fopen(options.file.c_str(), "r"); if (file == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: No such file or directory.", options.file); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: No such file or directory.", options.file); return nullptr; } result = options.isv1() ? parseV1Program(file, options.file.string(), 1, @@ -78,7 +78,7 @@ const IR::P4Program *parseP4File(const ParserOptions &options) { fclose(file); } else { auto preprocessorResult = options.preprocess(); - if (::errorCount() > 0 || !preprocessorResult.has_value()) { + if (::P4::errorCount() > 0 || !preprocessorResult.has_value()) { return nullptr; } // Need to assign file here because the parser requires an lvalue. @@ -89,9 +89,9 @@ const IR::P4Program *parseP4File(const ParserOptions &options) { : P4ParserDriver::parse(preprocessorResult.value().get(), options.file.string()); } - if (::errorCount() > 0) { - ::error(ErrorType::ERR_OVERLIMIT, "%1% errors encountered, aborting compilation", - ::errorCount()); + if (::P4::errorCount() > 0) { + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1% errors encountered, aborting compilation", + ::P4::errorCount()); return nullptr; } BUG_CHECK(result != nullptr, "Parsing failed, but we didn't report an error"); diff --git a/frontends/common/parser_options.cpp b/frontends/common/parser_options.cpp index 91ddaf2b5d..1a73dd1a47 100644 --- a/frontends/common/parser_options.cpp +++ b/frontends/common/parser_options.cpp @@ -36,6 +36,8 @@ limitations under the License. #include "lib/log.h" #include "lib/nullstream.h" +namespace P4 { + /* CONFIG_PKGDATADIR is defined by cmake at compile time to be the same as * CMAKE_INSTALL_PREFIX This is only valid when the compiler is built and * installed from source locally. If the compiled binary is moved to another @@ -52,12 +54,12 @@ void ParserOptions::closeFile(FILE *file) { } int exitCode = pclose(file); if (WIFEXITED(exitCode) && WEXITSTATUS(exitCode) == 4) { - ::error(ErrorType::ERR_IO, "input file does not exist"); + ::P4::error(ErrorType::ERR_IO, "input file does not exist"); return; } if (exitCode != 0) { - ::error(ErrorType::ERR_IO, "Preprocessor returned exit code %d; aborting compilation", - exitCode); + ::P4::error(ErrorType::ERR_IO, "Preprocessor returned exit code %d; aborting compilation", + exitCode); return; } } @@ -167,7 +169,7 @@ ParserOptions::ParserOptions(std::string_view defaultMessage) : Util::Options(de } else if (!strcmp(arg, "1.2") || !strcmp(arg, "16")) { langVersion = ParserOptions::FrontendVersion::P4_16; } else { - ::error(ErrorType::ERR_INVALID, "Illegal language version %1%", arg); + ::P4::error(ErrorType::ERR_INVALID, "Illegal language version %1%", arg); return false; } return true; @@ -181,7 +183,7 @@ ParserOptions::ParserOptions(std::string_view defaultMessage) : Util::Options(de } else if (!strcmp(arg, "16") || !strcmp(arg, "p4-16")) { langVersion = ParserOptions::FrontendVersion::P4_16; } else { - ::error(ErrorType::ERR_INVALID, "Illegal language version %1%", arg); + ::P4::error(ErrorType::ERR_INVALID, "Illegal language version %1%", arg); return false; } return true; @@ -211,7 +213,7 @@ ParserOptions::ParserOptions(std::string_view defaultMessage) : Util::Options(de [](const char *diagnostic) { if (diagnostic) { if (ErrorCatalog::getCatalog().isError(diagnostic)) { - ::error(ErrorType::ERR_INVALID, "Error %1% cannot be demoted.", diagnostic); + ::P4::error(ErrorType::ERR_INVALID, "Error %1% cannot be demoted.", diagnostic); return false; } P4CContext::get().setDiagnosticAction(diagnostic, DiagnosticAction::Ignore); @@ -229,7 +231,7 @@ ParserOptions::ParserOptions(std::string_view defaultMessage) : Util::Options(de [](const char *diagnostic) { if (diagnostic) { if (ErrorCatalog::getCatalog().isError(diagnostic)) { - ::error(ErrorType::ERR_INVALID, "Error %1% cannot be demoted.", diagnostic); + ::P4::error(ErrorType::ERR_INVALID, "Error %1% cannot be demoted.", diagnostic); return false; } P4CContext::get().setDiagnosticAction(diagnostic, DiagnosticAction::Info); @@ -242,7 +244,7 @@ ParserOptions::ParserOptions(std::string_view defaultMessage) : Util::Options(de [](const char *diagnostic) { if (diagnostic) { if (ErrorCatalog::getCatalog().isError(diagnostic)) { - ::error(ErrorType::ERR_INVALID, "Error %1% cannot be demoted.", diagnostic); + ::P4::error(ErrorType::ERR_INVALID, "Error %1% cannot be demoted.", diagnostic); return false; } P4CContext::get().setDiagnosticAction(diagnostic, DiagnosticAction::Warn); @@ -338,12 +340,12 @@ ParserOptions::ParserOptions(std::string_view defaultMessage) : Util::Options(de void ParserOptions::setInputFile() { if (remainingOptions.size() > 1) { - ::error(ErrorType::ERR_OVERLIMIT, "Only one input file must be specified: %s", - cstring::join(remainingOptions.begin(), remainingOptions.end(), ",")); + ::P4::error(ErrorType::ERR_OVERLIMIT, "Only one input file must be specified: %s", + cstring::join(remainingOptions.begin(), remainingOptions.end(), ",")); usage(); exit(1); } else if (remainingOptions.size() == 0) { - ::error(ErrorType::ERR_EXPECTED, "No input files specified"); + ::P4::error(ErrorType::ERR_EXPECTED, "No input files specified"); usage(); exit(1); } else { @@ -435,7 +437,7 @@ std::optional ParserOptions::preprocess() con if (Log::verbose()) std::cerr << "Invoking preprocessor " << std::endl << cmd << std::endl; in = popen(cmd.c_str(), "r"); if (in == nullptr) { - ::error(ErrorType::ERR_IO, "Error invoking preprocessor"); + ::P4::error(ErrorType::ERR_IO, "Error invoking preprocessor"); perror(""); return std::nullopt; } @@ -483,10 +485,10 @@ void ParserOptions::dumpPass(const char *manager, unsigned seq, const char *pass // regex_search checks if the regex is contained as substring match = std::regex_search(name.begin(), name.end(), s_regex); } catch (const std::regex_error &e) { - ::error(ErrorType::ERR_INVALID, - "Malformed toP4 regex string \"%s\".\n" - "The regex matcher follows ECMAScript syntax.", - s); + ::P4::error(ErrorType::ERR_INVALID, + "Malformed toP4 regex string \"%s\".\n" + "The regex matcher follows ECMAScript syntax.", + s); exit(1); } if (match) { @@ -515,7 +517,8 @@ void ParserOptions::dumpPass(const char *manager, unsigned seq, const char *pass bool ParserOptions::isAnnotationDisabled(const IR::Annotation *a) const { if (disabledAnnotations.count(a->name.name) > 0) { - ::warning(ErrorType::WARN_IGNORE, "%1% is ignored because it was explicitly disabled", a); + ::P4::warning(ErrorType::WARN_IGNORE, "%1% is ignored because it was explicitly disabled", + a); return true; } return false; @@ -541,3 +544,5 @@ bool P4CContext::isRecognizedDiagnostic(cstring diagnostic) { return recognizedDiagnostics.count(diagnostic); } const P4CConfiguration &P4CContext::getConfigImpl() { return DefaultP4CConfiguration::get(); } + +} // namespace P4 diff --git a/frontends/common/parser_options.h b/frontends/common/parser_options.h index bd393e247a..d57cb0066f 100644 --- a/frontends/common/parser_options.h +++ b/frontends/common/parser_options.h @@ -29,6 +29,8 @@ limitations under the License. #include "lib/cstring.h" #include "lib/options.h" +namespace P4 { + /// Standard include paths for .p4 header files. The values are determined by /// `configure`. extern const char *p4includePath; @@ -119,22 +121,22 @@ class P4CContext : public BaseCompileContext { /// @return the compiler options for this compilation context. virtual ParserOptions &options() = 0; - /// @return the default diagnostic action for calls to `::info()`. + /// @return the default diagnostic action for calls to `::P4::info()`. DiagnosticAction getDefaultInfoDiagnosticAction() final { return errorReporter().getDefaultInfoDiagnosticAction(); } - /// set the default diagnostic action for calls to `::info()`. + /// set the default diagnostic action for calls to `::P4::info()`. void setDefaultInfoDiagnosticAction(DiagnosticAction action) { errorReporter().setDefaultInfoDiagnosticAction(action); } - /// @return the default diagnostic action for calls to `::warning()`. + /// @return the default diagnostic action for calls to `::P4::warning()`. DiagnosticAction getDefaultWarningDiagnosticAction() final { return errorReporter().getDefaultWarningDiagnosticAction(); } - /// set the default diagnostic action for calls to `::warning()`. + /// set the default diagnostic action for calls to `::P4::warning()`. void setDefaultWarningDiagnosticAction(DiagnosticAction action) { errorReporter().setDefaultWarningDiagnosticAction(action); } @@ -192,4 +194,7 @@ class P4CContextWithOptions final : public P4CContext { /// Compiler options for this compilation context. OptionsType optionsInstance; }; + +} // namespace P4 + #endif /* FRONTENDS_COMMON_PARSER_OPTIONS_H_*/ diff --git a/frontends/common/resolveReferences/resolveReferences.cpp b/frontends/common/resolveReferences/resolveReferences.cpp index 32f4437777..5ce6dbff49 100644 --- a/frontends/common/resolveReferences/resolveReferences.cpp +++ b/frontends/common/resolveReferences/resolveReferences.cpp @@ -93,9 +93,9 @@ std::vector ResolutionContext::lookup(const IR::INames if (type == ResolutionType::Type) { if (auto *type_decl = findOrigCtxt()) if (type_decl->getNode() == d->getNode()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "Self-referencing types not supported: '%1%' within '%2%'", - name, d->getNode()); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Self-referencing types not supported: '%1%' within '%2%'", + name, d->getNode()); } } else if (type == ResolutionType::Any) { if (auto *decl_ctxt = findOrigCtxt()) @@ -243,7 +243,7 @@ const IR::IDeclaration *ResolutionContext::resolveUnique(const IR::ID &name, } if (decls.empty()) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: declaration not found", name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: declaration not found", name); return nullptr; } if (decls.size() == 1) { @@ -251,8 +251,8 @@ const IR::IDeclaration *ResolutionContext::resolveUnique(const IR::ID &name, return decls.front(); } - ::error(ErrorType::ERR_DUPLICATE, "%1%: multiple matching declarations", name); - for (const auto *a : decls) ::error(ErrorType::ERR_DUPLICATE, "Candidate: %1%", a); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: multiple matching declarations", name); + for (const auto *a : decls) ::P4::error(ErrorType::ERR_DUPLICATE, "Candidate: %1%", a); return nullptr; } @@ -264,10 +264,11 @@ const IR::IDeclaration *ResolutionContext::getDeclaration(const IR::Path *path, // looking up a matchType in a key, so need to do a special lookup auto decls = lookupMatchKind(path->name); if (decls.empty()) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: declaration not found", path->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: declaration not found", path->name); } else if (decls.size() != 1) { - ::error(ErrorType::ERR_DUPLICATE, "%1%: multiple matching declarations", path->name); - for (const auto *a : decls) ::error(ErrorType::ERR_DUPLICATE, "Candidate: %1%", a); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: multiple matching declarations", + path->name); + for (const auto *a : decls) ::P4::error(ErrorType::ERR_DUPLICATE, "Candidate: %1%", a); } else { result = decls.front(); } @@ -288,8 +289,8 @@ const IR::IDeclaration *ResolutionContext::getDeclaration(const IR::This *pointe bool notNull) const { auto result = findOrigCtxt(); if (findOrigCtxt() == nullptr || result == nullptr) - ::error(ErrorType::ERR_INVALID, - "%1% can only be used in the definition of an abstract method", pointer); + ::P4::error(ErrorType::ERR_INVALID, + "%1% can only be used in the definition of an abstract method", pointer); if (notNull) BUG_CHECK(result != nullptr, "Cannot find declaration for %1%", pointer); return result; } @@ -340,8 +341,8 @@ void ResolveReferences::checkShadowing(const IR::INamespace *ns) const { continue; if (prev_in_scope.count(decl->getName())) - ::warning(ErrorType::WARN_SHADOWING, "'%1%' shadows '%2%'", node, - prev_in_scope.at(decl->getName())); + ::P4::warning(ErrorType::WARN_SHADOWING, "'%1%' shadows '%2%'", node, + prev_in_scope.at(decl->getName())); else if (!node->is() && !node->is()) prev_in_scope[decl->getName()] = node; auto prev = resolve(decl->getName(), ResolutionType::Any); @@ -366,11 +367,11 @@ void ResolveReferences::checkShadowing(const IR::INamespace *ns) const { const auto *decl_node = node->to(); if (const auto *param = pnode->to()) if (decl_node->name.name == param->name.name) - ::error(ErrorType::WARN_SHADOWING, - "declaration of '%1%' shadows a parameter '%2%'", node, pnode); + ::P4::error(ErrorType::WARN_SHADOWING, + "declaration of '%1%' shadows a parameter '%2%'", node, pnode); } - ::warning(ErrorType::WARN_SHADOWING, "'%1%' shadows '%2%'", node, pnode); + ::P4::warning(ErrorType::WARN_SHADOWING, "'%1%' shadows '%2%'", node, pnode); } } } @@ -396,8 +397,8 @@ void ResolveReferences::postorder(const IR::P4Program *) { LOG2("Reference map " bool ResolveReferences::preorder(const IR::This *pointer) { auto decl = findContext(); if (findContext() == nullptr || decl == nullptr) { - ::error(ErrorType::ERR_INVALID, - "'%1%' can only be used in the definition of an abstract method", pointer); + ::P4::error(ErrorType::ERR_INVALID, + "'%1%' can only be used in the definition of an abstract method", pointer); return false; } refMap->setDeclaration(pointer, decl); @@ -409,12 +410,13 @@ bool ResolveReferences::preorder(const IR::KeyElement *ke) { visit(ke->expression, "expression"); auto decls = lookupMatchKind(ke->matchType->path->name); if (decls.empty()) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: declaration not found", ke->matchType->path->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: declaration not found", + ke->matchType->path->name); refMap->usedName(ke->matchType->path->name.name); } else if (decls.size() != 1) { - ::error(ErrorType::ERR_DUPLICATE, "%1%: multiple matching declarations", - ke->matchType->path->name); - for (const auto *a : decls) ::error(ErrorType::ERR_DUPLICATE, "Candidate: %1%", a); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: multiple matching declarations", + ke->matchType->path->name); + for (const auto *a : decls) ::P4::error(ErrorType::ERR_DUPLICATE, "Candidate: %1%", a); } else { refMap->setDeclaration(ke->matchType->path, decls.front()); } diff --git a/frontends/p4-14/header_type.cpp b/frontends/p4-14/header_type.cpp index d2d57e8d67..a6b7bd855c 100644 --- a/frontends/p4-14/header_type.cpp +++ b/frontends/p4-14/header_type.cpp @@ -16,6 +16,8 @@ limitations under the License. #include "header_type.h" +namespace P4 { + using namespace P4::literals; bool HeaderTypeMaxLengthCalculator::preorder(IR::Type_StructLike *hdr_type) { @@ -37,3 +39,5 @@ bool HeaderTypeMaxLengthCalculator::preorder(IR::Type_StructLike *hdr_type) { if (annot) hdr_type->annotations = annot; return false; } + +} // namespace P4 diff --git a/frontends/p4-14/header_type.h b/frontends/p4-14/header_type.h index 88757e40e4..1abf8039e7 100644 --- a/frontends/p4-14/header_type.h +++ b/frontends/p4-14/header_type.h @@ -20,6 +20,8 @@ limitations under the License. #include "ir/ir.h" #include "ir/visitor.h" +namespace P4 { + class CheckHeaderTypes : public Modifier { const IR::V1Program *global = nullptr; @@ -51,4 +53,6 @@ class HeaderTypeMaxLengthCalculator : public Modifier { bool preorder(IR::Type_StructLike *hdr_type) override; }; +} // namespace P4 + #endif /* FRONTENDS_P4_14_HEADER_TYPE_H_ */ diff --git a/frontends/p4-14/inline_control_flow.h b/frontends/p4-14/inline_control_flow.h index 020a83aac2..6a214773b1 100644 --- a/frontends/p4-14/inline_control_flow.h +++ b/frontends/p4-14/inline_control_flow.h @@ -20,6 +20,8 @@ limitations under the License. #include "frontends/p4/evaluator/evaluator.h" #include "ir/ir.h" +namespace P4 { + class InlineControlFlow : public Transform { public: explicit InlineControlFlow(const IR::V1Program *gl) : global(gl) { @@ -52,4 +54,6 @@ class InlineControlFlow : public Transform { } }; +} // namespace P4 + #endif /* FRONTENDS_P4_14_INLINE_CONTROL_FLOW_H_ */ diff --git a/frontends/p4-14/typecheck.cpp b/frontends/p4-14/typecheck.cpp index c7226f56b8..56a35fe2cb 100644 --- a/frontends/p4-14/typecheck.cpp +++ b/frontends/p4-14/typecheck.cpp @@ -19,6 +19,8 @@ limitations under the License. #include "ir/dump.h" #include "lib/log.h" +namespace P4 { + using namespace P4::literals; /// P4-14 (v1.0 and v1.1) type checking algorithm @@ -327,7 +329,8 @@ class TypeCheck::InferExpressionsBottomUp : public Modifier { if (type->is() || type->is() || type->is()) return true; - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: not defined on operands of type %2%", node, type); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: not defined on operands of type %2%", node, + type); return false; } @@ -610,3 +613,5 @@ const IR::Node *TypeCheck::apply_visitor(const IR::Node *n, const char *name) { LOG5("After Typecheck:\n" << dumpToString(rv)); return rv; } + +} // namespace P4 diff --git a/frontends/p4-14/typecheck.h b/frontends/p4-14/typecheck.h index faa1abe59e..6a75cbf2a8 100644 --- a/frontends/p4-14/typecheck.h +++ b/frontends/p4-14/typecheck.h @@ -20,6 +20,8 @@ limitations under the License. #include "ir/ir.h" #include "ir/pass_manager.h" +namespace P4 { + /* This is the P4 v1.0/v1.1 typechecker/type inference algorithm */ class TypeCheck : public PassManager { std::map actionArgUseTypes; @@ -37,4 +39,6 @@ class TypeCheck : public PassManager { const IR::Node *apply_visitor(const IR::Node *, const char *) override; }; +} // namespace P4 + #endif /* FRONTENDS_P4_14_TYPECHECK_H_ */ diff --git a/frontends/p4/actionsInlining.cpp b/frontends/p4/actionsInlining.cpp index 364077bf21..7111af78e8 100644 --- a/frontends/p4/actionsInlining.cpp +++ b/frontends/p4/actionsInlining.cpp @@ -31,8 +31,8 @@ void DiscoverActionsInlining::postorder(const IR::MethodCallStatement *mcs) { auto caller = findContext(); if (caller == nullptr) { if (findContext() != nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: action invocation in parser not allowed", - mcs); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: action invocation in parser not allowed", + mcs); } else if (findContext() == nullptr) { BUG("%1%: unexpected action invocation", mcs); } @@ -101,8 +101,8 @@ const IR::Node *ActionsInliner::preorder(IR::MethodCallStatement *statement) { // This works because there can be no side-effects in the evaluation of this // argument. if (!argument) { - ::error(ErrorType::ERR_UNINITIALIZED, "%1%: No argument supplied for %2%", - statement, param); + ::P4::error(ErrorType::ERR_UNINITIALIZED, "%1%: No argument supplied for %2%", + statement, param); continue; } subst.add(param, argument); @@ -124,7 +124,7 @@ const IR::Node *ActionsInliner::preorder(IR::MethodCallStatement *statement) { SubstituteParameters sp(nullptr, &subst, &tvs); sp.setCalledBy(this); auto clone = callee->apply(sp, getContext()); - if (::errorCount() > 0) return statement; + if (::P4::errorCount() > 0) return statement; CHECK_NULL(clone); BUG_CHECK(clone->is(), "%1%: not an action", clone); auto actclone = clone->to(); @@ -134,7 +134,7 @@ const IR::Node *ActionsInliner::preorder(IR::MethodCallStatement *statement) { for (auto param : callee->parameters->parameters) { auto left = substitution.lookup(param); if (param->direction == IR::Direction::InOut || param->direction == IR::Direction::Out) { - cstring newName = ::get(paramRename, param); + cstring newName = ::P4::get(paramRename, param); auto right = new IR::PathExpression(newName); auto copyout = new IR::AssignmentStatement(left->expression, right); body.push_back(copyout); diff --git a/frontends/p4/actionsInlining.h b/frontends/p4/actionsInlining.h index 0856fc9024..e3a9961189 100644 --- a/frontends/p4/actionsInlining.h +++ b/frontends/p4/actionsInlining.h @@ -78,7 +78,7 @@ class InlineActions : public PassManager { } // namespace P4 -namespace P4_14 { +namespace P4::P4_14 { /// Special inliner which works directly on P4-14 representation class InlineActions : public Transform { @@ -108,6 +108,6 @@ class InlineActions : public Transform { } }; -} // namespace P4_14 +} // namespace P4::P4_14 #endif /* FRONTENDS_P4_ACTIONSINLINING_H_ */ diff --git a/frontends/p4/alias.h b/frontends/p4/alias.h index 49007afee4..39dbcf464f 100644 --- a/frontends/p4/alias.h +++ b/frontends/p4/alias.h @@ -120,8 +120,8 @@ class ReadsWrites : public Inspector, public ResolutionContext { ReadsWrites() { setName("ReadsWrites"); } void postorder(const IR::Operation_Binary *expression) override { - auto left = ::get(rw, expression->left); - auto right = ::get(rw, expression->right); + auto left = ::P4::get(rw, expression->left); + auto right = ::P4::get(rw, expression->right); CHECK_NULL(left); CHECK_NULL(right); rw.emplace(expression, left->join(right)); @@ -135,27 +135,27 @@ class ReadsWrites : public Inspector, public ResolutionContext { } void postorder(const IR::Operation_Unary *expression) override { - auto e = ::get(rw, expression->expr); + auto e = ::P4::get(rw, expression->expr); CHECK_NULL(e); rw.emplace(expression, e); } void postorder(const IR::Member *expression) override { - auto e = ::get(rw, expression->expr); + auto e = ::P4::get(rw, expression->expr); CHECK_NULL(e); auto result = e->append(expression->member); rw.emplace(expression, result); } void postorder(const IR::ArrayIndex *expression) override { - auto e = ::get(rw, expression->left); + auto e = ::P4::get(rw, expression->left); CHECK_NULL(e); const SetOfLocations *result; if (expression->right->is()) { int index = expression->right->to()->asInt(); result = e->append(Util::toString(index)); } else { - auto index = ::get(rw, expression->right); + auto index = ::P4::get(rw, expression->right); result = e->append("*"_cs)->join(index); } rw.emplace(expression, result); @@ -182,9 +182,9 @@ class ReadsWrites : public Inspector, public ResolutionContext { } void postorder(const IR::Operation_Ternary *expression) override { - auto e0 = ::get(rw, expression->e0); - auto e1 = ::get(rw, expression->e1); - auto e2 = ::get(rw, expression->e2); + auto e0 = ::P4::get(rw, expression->e0); + auto e1 = ::P4::get(rw, expression->e1); + auto e2 = ::P4::get(rw, expression->e2); CHECK_NULL(e0); CHECK_NULL(e1); CHECK_NULL(e2); @@ -192,15 +192,15 @@ class ReadsWrites : public Inspector, public ResolutionContext { } void postorder(const IR::Slice *expression) override { - auto e = ::get(rw, expression->e0); + auto e = ::P4::get(rw, expression->e0); CHECK_NULL(e); rw.emplace(expression, e); } void postorder(const IR::MethodCallExpression *expression) override { - auto e = ::get(rw, expression->method); + auto e = ::P4::get(rw, expression->method); for (auto a : *expression->arguments) { - auto s = ::get(rw, a->expression); + auto s = ::P4::get(rw, a->expression); CHECK_NULL(s); e = e->join(s); } @@ -210,7 +210,7 @@ class ReadsWrites : public Inspector, public ResolutionContext { void postorder(const IR::ConstructorCallExpression *expression) override { const SetOfLocations *result = new SetOfLocations(); for (auto e : *expression->arguments) { - auto s = ::get(rw, e->expression); + auto s = ::P4::get(rw, e->expression); CHECK_NULL(s); result = result->join(s); } @@ -220,7 +220,7 @@ class ReadsWrites : public Inspector, public ResolutionContext { void postorder(const IR::StructExpression *expression) override { const SetOfLocations *result = new SetOfLocations(); for (auto e : expression->components) { - auto s = ::get(rw, e->expression); + auto s = ::P4::get(rw, e->expression); CHECK_NULL(s); result = result->join(s); } @@ -230,7 +230,7 @@ class ReadsWrites : public Inspector, public ResolutionContext { void postorder(const IR::ListExpression *expression) override { const SetOfLocations *result = new SetOfLocations(); for (auto e : expression->components) { - auto s = ::get(rw, e); + auto s = ::P4::get(rw, e); CHECK_NULL(s); result = result->join(s); } @@ -243,7 +243,7 @@ class ReadsWrites : public Inspector, public ResolutionContext { const SetOfLocations *get(const IR::Expression *expression, const Visitor::Context *ctxt) { expression->apply(*this, ctxt); - auto result = ::get(rw, expression); + auto result = ::P4::get(rw, expression); CHECK_NULL(result); LOG3("SetOfLocations(" << expression << ")=" << result); return result; diff --git a/frontends/p4/callGraph.h b/frontends/p4/callGraph.h index 884da69292..7ddfbf79bd 100644 --- a/frontends/p4/callGraph.h +++ b/frontends/p4/callGraph.h @@ -117,11 +117,11 @@ class CallGraph { // Graph querying bool isCallee(T callee) const { - auto callees = ::get(in_edges, callee); + auto callees = ::P4::get(in_edges, callee); return callees != nullptr && !callees->empty(); } bool isCaller(T caller) const { - auto edges = ::get(out_edges, caller); + auto edges = ::P4::get(out_edges, caller); if (edges == nullptr) return false; return !edges->empty(); } diff --git a/frontends/p4/checkConstants.cpp b/frontends/p4/checkConstants.cpp index 3fa179f5c6..55ad535761 100644 --- a/frontends/p4/checkConstants.cpp +++ b/frontends/p4/checkConstants.cpp @@ -28,7 +28,7 @@ void DoCheckConstants::postorder(const IR::MethodCallExpression *expression) { expression); auto arg0 = expression->arguments->at(0)->expression; if (!arg0->is()) - ::error(ErrorType::ERR_INVALID, "%1%: argument must be a constant", arg0); + ::P4::error(ErrorType::ERR_INVALID, "%1%: argument must be a constant", arg0); } } } diff --git a/frontends/p4/checkNamedArgs.cpp b/frontends/p4/checkNamedArgs.cpp index 431592ae86..bf41aef35c 100644 --- a/frontends/p4/checkNamedArgs.cpp +++ b/frontends/p4/checkNamedArgs.cpp @@ -33,13 +33,14 @@ bool CheckNamedArgs::checkArguments(const IR::Vector *arguments) { first = false; } else { if (argHasName != hasName) - ::error(ErrorType::ERR_INVALID, - "%1%: either all or none of the arguments of a call must be named", arg); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: either all or none of the arguments of a call must be named", + arg); if (argHasName) { auto it = found.find(argName); if (it != found.end()) - ::error(ErrorType::ERR_DUPLICATE, "%1% and %2%: same argument name", it->second, - arg); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1% and %2%: same argument name", + it->second, arg); } } if (argHasName) found.emplace(argName, arg); @@ -50,7 +51,8 @@ bool CheckNamedArgs::checkArguments(const IR::Vector *arguments) { bool CheckNamedArgs::checkOptionalParameters(const IR::ParameterList *parameters) { for (auto parameter : parameters->parameters) { if (parameter->isOptional()) - ::error(ErrorType::ERR_INVALID, "%1%: optional parameter not allowed here", parameter); + ::P4::error(ErrorType::ERR_INVALID, "%1%: optional parameter not allowed here", + parameter); } return true; } @@ -58,11 +60,11 @@ bool CheckNamedArgs::checkOptionalParameters(const IR::ParameterList *parameters bool CheckNamedArgs::preorder(const IR::Parameter *parameter) { if (parameter->defaultValue != nullptr) { if (parameter->isOptional()) - ::error(ErrorType::ERR_INVALID, "%1%: optional parameters cannot have default values", - parameter); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: optional parameters cannot have default values", parameter); if (parameter->hasOut()) - ::error(ErrorType::ERR_INVALID, "%1%: out parameters cannot have default values", - parameter); + ::P4::error(ErrorType::ERR_INVALID, "%1%: out parameters cannot have default values", + parameter); } return true; } diff --git a/frontends/p4/commonInlining.h b/frontends/p4/commonInlining.h index 0c88388da6..60fac67662 100644 --- a/frontends/p4/commonInlining.h +++ b/frontends/p4/commonInlining.h @@ -194,7 +194,7 @@ class InlineDriver : public Visitor { LOG2("Processing " << todo); inliner->prepare(toInline, todo); program = program->apply(*inliner); - if (::errorCount() > 0) break; + if (::P4::errorCount() > 0) break; #if DEBUG_INLINER // debugging code; we don't have an easy way to dump the program here, diff --git a/frontends/p4/coreLibrary.h b/frontends/p4/coreLibrary.h index 3fbb9be5c4..de748b91e8 100644 --- a/frontends/p4/coreLibrary.h +++ b/frontends/p4/coreLibrary.h @@ -32,6 +32,8 @@ enum class StandardExceptions { }; } // namespace P4 +namespace P4 { + inline std::ostream &operator<<(std::ostream &out, P4::StandardExceptions e) { switch (e) { case P4::StandardExceptions::NoError: @@ -58,6 +60,8 @@ inline std::ostream &operator<<(std::ostream &out, P4::StandardExceptions e) { return out; } +} // namespace P4 + namespace P4 { using namespace literals; @@ -83,10 +87,11 @@ class PacketOut : public Model::Extern_Model { Model::Elem emit; }; -class P4Exception_Model : public ::Model::Elem { +class P4Exception_Model : public ::P4::Model::Elem { public: const StandardExceptions exc; - explicit P4Exception_Model(StandardExceptions exc) : ::Model::Elem(cstring::empty), exc(exc) { + explicit P4Exception_Model(StandardExceptions exc) + : ::P4::Model::Elem(cstring::empty), exc(exc) { std::stringstream str; str << exc; name = str.str(); @@ -95,7 +100,7 @@ class P4Exception_Model : public ::Model::Elem { // Model of P4 core library // To be kept in sync with core.p4 -class P4CoreLibrary : public ::Model::Model { +class P4CoreLibrary : public ::P4::Model::Model { protected: // NOLINTBEGIN(bugprone-throw-keyword-missing) P4CoreLibrary() @@ -115,11 +120,11 @@ class P4CoreLibrary : public ::Model::Model { static P4CoreLibrary *corelib = new P4CoreLibrary(); return *corelib; } - ::Model::Elem noAction; + ::P4::Model::Elem noAction; - ::Model::Elem exactMatch; - ::Model::Elem ternaryMatch; - ::Model::Elem lpmMatch; + ::P4::Model::Elem exactMatch; + ::P4::Model::Elem ternaryMatch; + ::P4::Model::Elem lpmMatch; PacketIn packetIn; PacketOut packetOut; diff --git a/frontends/p4/createBuiltins.cpp b/frontends/p4/createBuiltins.cpp index 47360fd7e5..3e0beaab5f 100644 --- a/frontends/p4/createBuiltins.cpp +++ b/frontends/p4/createBuiltins.cpp @@ -27,8 +27,8 @@ const IR::Node *CreateBuiltins::preorder(IR::P4Program *program) { auto vec = decls->toVector(); if (vec.empty()) return program; if (vec.size() > 1) { - ::error(ErrorType::ERR_MODEL, "Multiple declarations of %1%: %2% %3%", - P4::P4CoreLibrary::instance().noAction.str(), vec[0], vec[1]); + ::P4::error(ErrorType::ERR_MODEL, "Multiple declarations of %1%: %2% %3%", + P4::P4CoreLibrary::instance().noAction.str(), vec[0], vec[1]); } globalNoAction = vec[0]; return program; @@ -44,27 +44,27 @@ void CreateBuiltins::checkGlobalAction() { if (checked) return; checked = true; if (globalNoAction == nullptr) { - ::error(ErrorType::ERR_MODEL, - "Declaration of the action %1% not found; did you include core.p4?", - P4::P4CoreLibrary::instance().noAction.str()); + ::P4::error(ErrorType::ERR_MODEL, + "Declaration of the action %1% not found; did you include core.p4?", + P4::P4CoreLibrary::instance().noAction.str()); return; } if (auto action = globalNoAction->to()) { if (!action->parameters->empty()) { - ::error(ErrorType::ERR_MODEL, - "%1%: Expected an action with no parameters; did you include core.p4?", - globalNoAction); + ::P4::error(ErrorType::ERR_MODEL, + "%1%: Expected an action with no parameters; did you include core.p4?", + globalNoAction); return; } if (!action->body->empty()) { - ::error(ErrorType::ERR_MODEL, - "%1%: Expected an action with no body; did you include core.p4?", - globalNoAction); + ::P4::error(ErrorType::ERR_MODEL, + "%1%: Expected an action with no body; did you include core.p4?", + globalNoAction); return; } } else { - ::error(ErrorType::ERR_MODEL, "%1%: expected to be an action; did you include core.p4?", - globalNoAction); + ::P4::error(ErrorType::ERR_MODEL, "%1%: expected to be an action; did you include core.p4?", + globalNoAction); return; } } @@ -142,7 +142,7 @@ const IR::Node *CreateBuiltins::postorder(IR::Property *property) { if (auto key = property->value->to()) { if (key->keyElements.size() == 0) return nullptr; } else { - ::error(ErrorType::ERR_INVALID, "%1%: must be a key", property->value); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a key", property->value); return nullptr; } return property; diff --git a/frontends/p4/def_use.cpp b/frontends/p4/def_use.cpp index 2abff7cebe..fba2784756 100644 --- a/frontends/p4/def_use.cpp +++ b/frontends/p4/def_use.cpp @@ -124,7 +124,7 @@ void StructLocation::addLastIndexField(LocationSet *result) const { } void StructLocation::addField(cstring field, LocationSet *result) const { - auto f = ::get(fieldLocations, field); + auto f = ::P4::get(fieldLocations, field); CHECK_NULL(f); result->add(f); } @@ -304,7 +304,7 @@ Definitions *Definitions::joinDefinitions(const Definitions *other) const { for (auto d : other->definitions) { auto loc = d.first; auto defs = d.second; - auto current = ::get(definitions, loc); + auto current = ::P4::get(definitions, loc); if (current != nullptr) { auto merged = current->merge(defs); result->definitions.emplace(loc, merged); @@ -315,7 +315,7 @@ Definitions *Definitions::joinDefinitions(const Definitions *other) const { for (auto d : definitions) { auto loc = d.first; auto defs = d.second; - auto current = ::get(other->definitions, loc); + auto current = ::P4::get(other->definitions, loc); if (current == nullptr) result->definitions.emplace(loc, defs); // otherwise have have already done it in the loop above } @@ -364,7 +364,7 @@ Definitions *Definitions::writes(ProgramPoint point, const LocationSet *location bool Definitions::operator==(const Definitions &other) const { if (definitions.size() != other.definitions.size()) return false; for (auto d : definitions) { - auto od = ::get(other.definitions, d.first); + auto od = ::P4::get(other.definitions, d.first); if (od == nullptr) return false; if (!d.second->operator==(*od)) return false; } @@ -1134,6 +1134,8 @@ bool ComputeWriteSet::preorder(const IR::MethodCallStatement *statement) { } // namespace P4 +namespace P4 { + // functions for calling from gdb void dump(const P4::StorageLocation *s) { std::cout << *s << Log::endl; } void dump(const P4::StorageMap *s) { std::cout << *s << Log::endl; } @@ -1144,3 +1146,5 @@ void dump(const P4::ProgramPoints *p) { std::cout << *p << Log::endl; } void dump(const P4::ProgramPoints &p) { std::cout << p << Log::endl; } void dump(const P4::Definitions *d) { std::cout << *d << Log::endl; } void dump(const P4::AllDefinitions *d) { std::cout << *d << Log::endl; } + +} // namespace P4 diff --git a/frontends/p4/def_use.h b/frontends/p4/def_use.h index aa46ddfb1d..7853ba8e37 100644 --- a/frontends/p4/def_use.h +++ b/frontends/p4/def_use.h @@ -280,7 +280,7 @@ class StorageMap : public IHasDbPrint { } StorageLocation *getStorage(const IR::IDeclaration *decl) const { CHECK_NULL(decl); - auto result = ::get(storage, decl); + auto result = ::P4::get(storage, decl); return result; } void dbprint(std::ostream &out) const override { @@ -358,12 +358,12 @@ struct hash { } // namespace std -namespace Util { +namespace P4::Util { template <> struct Hasher { size_t operator()(const P4::ProgramPoint &p) const { return p.hash(); } }; -} // namespace Util +} // namespace P4::Util namespace P4 { class ProgramPoints : public IHasDbPrint { @@ -422,7 +422,7 @@ class Definitions : public IHasDbPrint { return definitions.find(location) != definitions.end(); } const ProgramPoints *getPoints(const BaseLocation *location) const { - auto r = ::get(definitions, location); + auto r = ::P4::get(definitions, location); BUG_CHECK(r != nullptr, "no definitions found for %1%", location); return r; } @@ -606,7 +606,7 @@ class ComputeWriteSet : public Inspector, public IHasDbPrint { // Get writes of a node that is a direct child of the currently being visited node. const LocationSet *getWrites(const IR::Expression *expression) { const loc_t &exprLoc = *getLoc(expression, getChildContext()); - auto result = ::get(writes, exprLoc); + auto result = ::P4::get(writes, exprLoc); BUG_CHECK(result != nullptr, "No location set known for %1%", expression); return result; } @@ -614,7 +614,7 @@ class ComputeWriteSet : public Inspector, public IHasDbPrint { // In this case, parentLoc is the loc of expression's direct parent node. const LocationSet *getWrites(const IR::Expression *expression, const loc_t *parentLoc) { const loc_t &exprLoc = *getLoc(expression, parentLoc); - auto result = ::get(writes, exprLoc); + auto result = ::P4::get(writes, exprLoc); BUG_CHECK(result != nullptr, "No location set known for %1%", expression); return result; } diff --git a/frontends/p4/defaultValues.cpp b/frontends/p4/defaultValues.cpp index 54f51346be..396fe0ee06 100644 --- a/frontends/p4/defaultValues.cpp +++ b/frontends/p4/defaultValues.cpp @@ -25,7 +25,7 @@ const IR::Expression *DoDefaultValues::defaultValue(const IR::Expression *expres if (const auto *anyType = type->to()) { type = typeMap->getSubstitution(anyType->to()); if (type == nullptr) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: could not find default value", expression); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: could not find default value", expression); return expression; } } diff --git a/frontends/p4/deprecated.cpp b/frontends/p4/deprecated.cpp index 3412c12ef9..02a04e9cdf 100644 --- a/frontends/p4/deprecated.cpp +++ b/frontends/p4/deprecated.cpp @@ -27,8 +27,8 @@ void Deprecated::warnIfDeprecated(const IR::IAnnotated *annotated, const IR::Nod for (const auto *a : anno->expr) { if (const auto *str = a->to()) message += str->value; } - ::warning(ErrorType::WARN_DEPRECATED, "%1%: Using deprecated feature %2%. %3%", errorNode, - annotated->getNode(), message); + ::P4::warning(ErrorType::WARN_DEPRECATED, "%1%: Using deprecated feature %2%. %3%", errorNode, + annotated->getNode(), message); } bool Deprecated::preorder(const IR::PathExpression *expression) { diff --git a/frontends/p4/dontcareArgs.cpp b/frontends/p4/dontcareArgs.cpp index e9a3374735..2bbc0d56e7 100644 --- a/frontends/p4/dontcareArgs.cpp +++ b/frontends/p4/dontcareArgs.cpp @@ -38,7 +38,7 @@ const IR::Node *DontcareArgs::postorder(IR::MethodCallExpression *expression) { cstring name = nameGen.newName("arg"); auto ptype = p->type; if (ptype->is()) { - ::error(ErrorType::ERR_TYPE_ERROR, "Could not infer type for %1%", a); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "Could not infer type for %1%", a); return expression; } auto decl = new IR::Declaration_Variable(IR::ID(name), ptype, nullptr); diff --git a/frontends/p4/entryPriorities.cpp b/frontends/p4/entryPriorities.cpp index eebff91370..4b097ced42 100644 --- a/frontends/p4/entryPriorities.cpp +++ b/frontends/p4/entryPriorities.cpp @@ -49,8 +49,8 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { if (ep->isConstant) { if (withPriority) - ::error(ErrorType::ERR_INVALID, - "%1%: Table with 'const' entries cannot have priorities", withPriority); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Table with 'const' entries cannot have priorities", withPriority); return entries; } @@ -61,7 +61,7 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { auto deltaProp = table->getConstantProperty("priority_delta"_cs); if (deltaProp) { if (!deltaProp->fitsUint()) { - ::error(ErrorType::ERR_INVALID, "%1% must be a positive value", deltaProp); + ::P4::error(ErrorType::ERR_INVALID, "%1% must be a positive value", deltaProp); return entries; } priorityDelta = deltaProp->asUnsigned(); @@ -80,7 +80,8 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { entries->entries[index] = newEntry; size_t nextPriority = currentPriority + priorityDelta; if (nextPriority < currentPriority) { - ::error(ErrorType::ERR_OVERLIMIT, "%1% Overflow in priority computation", table); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1% Overflow in priority computation", + table); return entries; } currentPriority = nextPriority; @@ -98,8 +99,8 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { } } if (!requiresPriorities) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1% key match type does not require priorities, but some are specified", key); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1% key match type does not require priorities, but some are specified", key); return entries; } @@ -111,13 +112,13 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { if (auto value = entry->priority->to()) { currentPriority = value->asUnsigned(); } else { - ::error(ErrorType::ERR_INVALID, "%1% must be a constant", entry->priority); + ::P4::error(ErrorType::ERR_INVALID, "%1% must be a constant", entry->priority); return entries; } } else { // First entry must have a priority. if (i == 0) { - ::error(ErrorType::ERR_EXPECTED, "%1% entry must have a priority", entry); + ::P4::error(ErrorType::ERR_EXPECTED, "%1% entry must have a priority", entry); return entries; } auto priority = new IR::Constant((uint64_t)currentPriority); @@ -143,7 +144,8 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { nextPriority = currentPriority - priorityDelta; if (nextPriority > currentPriority) { - ::error(ErrorType::ERR_OVERLIMIT, "%1% Overflow in priority computation", table); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1% Overflow in priority computation", + table); return entries; } } else { @@ -156,7 +158,8 @@ const IR::Node *EntryPriorities::preorder(IR::EntriesList *entries) { nextPriority = currentPriority + priorityDelta; if (nextPriority < currentPriority) { - ::error(ErrorType::ERR_OVERLIMIT, "%1% Overflow in priority computation", table); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1% Overflow in priority computation", + table); return entries; } } diff --git a/frontends/p4/evaluator/evaluator.cpp b/frontends/p4/evaluator/evaluator.cpp index a937e5e97a..ae4630b804 100644 --- a/frontends/p4/evaluator/evaluator.cpp +++ b/frontends/p4/evaluator/evaluator.cpp @@ -129,8 +129,8 @@ std::vector *Evaluator::evaluateArguments( CHECK_NULL(folded); visit(folded); // recursive evaluation if (!hasValue(folded)) { - ::error(ErrorType::ERR_INVALID, "%1%: Cannot evaluate to a compile-time constant", - arg->expression); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Cannot evaluate to a compile-time constant", + arg->expression); popBlock(context); return nullptr; } else { diff --git a/frontends/p4/externInstance.h b/frontends/p4/externInstance.h index f0aba86b92..bc568ef703 100644 --- a/frontends/p4/externInstance.h +++ b/frontends/p4/externInstance.h @@ -22,7 +22,7 @@ limitations under the License. #include "frontends/p4/parameterSubstitution.h" #include "lib/cstring.h" -namespace IR { +namespace P4::IR { class ConstructorCallExpression; class Expression; class IAnnotated; @@ -31,7 +31,7 @@ class Type_Extern; class TypeMap; template class Vector; -} // namespace IR +} // namespace P4::IR namespace P4 { diff --git a/frontends/p4/fromv1.0/converters.cpp b/frontends/p4/fromv1.0/converters.cpp index a14d730a3c..1670171bda 100644 --- a/frontends/p4/fromv1.0/converters.cpp +++ b/frontends/p4/fromv1.0/converters.cpp @@ -25,7 +25,7 @@ limitations under the License. #include "programStructure.h" #include "v1model.h" -namespace P4V1 { +namespace P4::P4V1 { const IR::Type *ExpressionConverter::getFieldType(const IR::Type_StructLike *ht, cstring fieldName) { @@ -37,7 +37,7 @@ const IR::Type *ExpressionConverter::getFieldType(const IR::Type_StructLike *ht, // These can only come from the key of a table. const IR::Node *ExpressionConverter::postorder(IR::Mask *expression) { if (!expression->right->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: Mask must be a constant", expression->right); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Mask must be a constant", expression->right); return expression; } @@ -94,13 +94,13 @@ const IR::Node *ExpressionConverter::postorder(IR::Primitive *primitive) { auto a = primitive->operands.at(0); auto b = primitive->operands.at(1); if (!a->is() || !b->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must have constant arguments", primitive); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must have constant arguments", primitive); return primitive; } auto aval = a->to()->asInt(); auto bval = b->to()->asInt(); if (aval < 0 || bval <= 0) { - ::error(ErrorType::ERR_INVALID, "%1%: negative offsets?", primitive); + ::P4::error(ErrorType::ERR_INVALID, "%1%: negative offsets?", primitive); return primitive; } @@ -133,7 +133,7 @@ const IR::Node *ExpressionConverter::postorder(IR::Primitive *primitive) { const IR::Node *ExpressionConverter::postorder(IR::PathExpression *ref) { if (ref->path->name.name == "latest") { if (structure->latest == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: latest not yet defined", ref); + ::P4::error(ErrorType::ERR_INVALID, "%1%: latest not yet defined", ref); return ref; } return structure->latest; @@ -212,8 +212,8 @@ const IR::Node *ExpressionConverter::postorder(IR::HeaderStackItemRef *ref) { return result; } - ::error(ErrorType::ERR_UNSUPPORTED, - "Illegal array index %1%: must be a constant, 'last', or 'next'.", ref); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Illegal array index %1%: must be a constant, 'last', or 'next'.", ref); return ref; } @@ -303,11 +303,11 @@ const IR::Node *StatementConverter::preorder(IR::Apply *apply) { for (auto a : apply->actions) { if (a.first == "hit") { if (hit != nullptr) - ::error(ErrorType::ERR_DUPLICATE, "%1%: Duplicate 'hit' label", hit); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: Duplicate 'hit' label", hit); hit = a.second; } else if (a.first == "miss") { if (miss != nullptr) - ::error(ErrorType::ERR_DUPLICATE, "%1%: Duplicate 'miss' label", hit); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: Duplicate 'miss' label", hit); miss = a.second; } else { otherLabels = true; @@ -315,7 +315,8 @@ const IR::Node *StatementConverter::preorder(IR::Apply *apply) { } if ((hit != nullptr || miss != nullptr) && otherLabels) - ::error(ErrorType::ERR_INVALID, "%1%: Cannot mix 'hit'/'miss' and other labels", apply); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Cannot mix 'hit'/'miss' and other labels", + apply); if (!otherLabels) { StatementConverter conv(structure, renameMap); @@ -364,7 +365,7 @@ const IR::Node *StatementConverter::preorder(IR::Apply *apply) { const IR::Node *StatementConverter::preorder(IR::Primitive *primitive) { auto control = structure->controls.get(primitive->name); if (control != nullptr) { - auto instanceName = ::get(renameMap, control->name); + auto instanceName = ::P4::get(renameMap, control->name); auto ctrl = new IR::PathExpression(IR::ID(instanceName)); auto method = new IR::Member(ctrl, IR::ID(IR::IApply::applyMethodName)); auto args = structure->createApplyArguments(control->name); @@ -444,9 +445,10 @@ class ValidateLenExpr : public Inspector { BUG_CHECK(!expression->path->absolute, "%1%: absolute path", expression); cstring name = expression->path->name.name; if (prior.find(name) == prior.end()) - ::error(ErrorType::ERR_INVALID, - "%1%: header length must depend only on fields prior to the varbit field %2%", - expression, varbitField); + ::P4::error( + ErrorType::ERR_INVALID, + "%1%: header length must depend only on fields prior to the varbit field %2%", + expression, varbitField); } }; @@ -674,4 +676,4 @@ Visitor::profile_t Converter::init_apply(const IR::Node *node) { return PassManager::init_apply(node); } -} // namespace P4V1 +} // namespace P4::P4V1 diff --git a/frontends/p4/fromv1.0/converters.h b/frontends/p4/fromv1.0/converters.h index 400e412c69..4295531e9f 100644 --- a/frontends/p4/fromv1.0/converters.h +++ b/frontends/p4/fromv1.0/converters.h @@ -27,7 +27,7 @@ limitations under the License. #include "lib/safe_vector.h" #include "programStructure.h" -namespace P4V1 { +namespace P4::P4V1 { // Converts expressions from P4-14 to P4-16 // However, the type in each expression is still a P4-14 type. @@ -186,8 +186,8 @@ class DiscoverStructure : public Inspector { auto it = reserved_names.find(nodeName); if (it == reserved_names.end()) return; if (it->second != kind) - ::error(ErrorType::ERR_INVALID, "%1%: invalid name; it can only be used for %2%", node, - it->second); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid name; it can only be used for %2%", + node, it->second); } void checkReserved(const IR::Node *node, cstring nodeName) const { checkReserved(node, nodeName, nullptr); @@ -329,7 +329,7 @@ class ComputeCallGraph : public Inspector { else if (auto nr = ctrref->to()) ctr = structure->counters.get(nr->path->name); if (ctr == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Cannot find counter", ctrref); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: Cannot find counter", ctrref); return; } auto parent = findContext(); @@ -344,7 +344,7 @@ class ComputeCallGraph : public Inspector { else if (auto nr = mtrref->to()) mtr = structure->meters.get(nr->path->name); if (mtr == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Cannot find meter", mtrref); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: Cannot find meter", mtrref); return; } auto parent = findContext(); @@ -363,7 +363,7 @@ class ComputeCallGraph : public Inspector { else if (auto nr = regref->to()) reg = structure->registers.get(nr->path->name); if (reg == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Cannot find register", regref); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: Cannot find register", regref); return; } auto parent = findContext(); @@ -416,12 +416,12 @@ class ComputeTableCallGraph : public Inspector { LOG3("Scanning " << apply->name); auto tbl = structure->tables.get(apply->name.name); if (tbl == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Could not find table", apply->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: Could not find table", apply->name); return; } auto parent = findContext(); if (!parent) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: Apply not within a control block?", apply); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: Apply not within a control block?", apply); return; } @@ -435,9 +435,9 @@ class ComputeTableCallGraph : public Inspector { if (ctrl != nullptr && ctrl != parent) { auto previous = get(structure->tableInvocation, tbl); - ::error(ErrorType::ERR_INVALID, - "%1%: Table invoked from two different controls: %2% and %3%", tbl, apply, - previous); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Table invoked from two different controls: %2% and %3%", tbl, apply, + previous); } LOG3("Invoking " << tbl << " in " << parent->name); structure->tableMapping.emplace(tbl, parent); @@ -528,7 +528,7 @@ class FixExtracts final : public Transform { /// Returns nullptr otherwise. HeaderSplit *splitHeaderType(const IR::Type_Header *type) { // Maybe we have seen this type already - auto fixed = ::get(fixedPart, type->name.name); + auto fixed = ::P4::get(fixedPart, type->name.name); if (fixed != nullptr) return fixed; const IR::Expression *headerLength = nullptr; @@ -540,9 +540,9 @@ class FixExtracts final : public Transform { if (f->type->is()) { cstring hname = structure->makeUniqueName(type->name.name); if (fixedHeaderType != nullptr) { - ::error(ErrorType::ERR_INVALID, - "%1%: header types with multiple varbit fields are not supported", - type); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: header types with multiple varbit fields are not supported", + type); return nullptr; } fixedHeaderType = new IR::Type_Header(IR::ID(hname), fields); @@ -623,7 +623,7 @@ class FixExtracts final : public Transform { const IR::Node *postorder(IR::MethodCallStatement *statement) override { auto mce = getOriginal()->methodCall; LOG3("Looking up in extracts " << dbp(mce)); - auto ht = ::get(structure->extractsSynthesized, mce); + auto ht = ::P4::get(structure->extractsSynthesized, mce); if (ht == nullptr) // not an extract return statement; @@ -746,11 +746,11 @@ class DetectDuplicates : public Inspector { auto e2 = n->second; if (e1->node_type_name() == e2->node_type_name()) { if (e1->srcInfo.getStart().isValid()) - ::error(ErrorType::ERR_DUPLICATE, "%1%: same name as %2%", e1, e2); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: same name as %2%", e1, e2); else // This name is probably standard_metadata_t, a built-in declaration - ::error(ErrorType::ERR_INVALID, "%1% is invalid; name %2% is reserved", - e2, key); + ::P4::error(ErrorType::ERR_INVALID, + "%1% is invalid; name %2% is reserved", e2, key); } } } @@ -930,7 +930,7 @@ class MoveIntrinsicMetadata : public Transform { BUG_CHECK(tn, "%1%: expected a Type_Name", intrTypeName); auto nt = program->getDeclsByName(tn->path->name)->nextOrDefault(); if (nt == nullptr || !nt->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: expected a structure", tn); + ::P4::error(ErrorType::ERR_INVALID, "%1%: expected a structure", tn); return program; } intrType = nt->to(); @@ -944,7 +944,7 @@ class MoveIntrinsicMetadata : public Transform { BUG_CHECK(tn, "%1%: expected a Type_Name", queueTypeName); auto nt = program->getDeclsByName(tn->path->name)->nextOrDefault(); if (nt == nullptr || !nt->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: expected a structure", tn); + ::P4::error(ErrorType::ERR_INVALID, "%1%: expected a structure", tn); return program; } queueType = nt->to(); @@ -958,8 +958,8 @@ class MoveIntrinsicMetadata : public Transform { if (intrType != nullptr) { for (auto f : intrType->fields) { if (type->fields.getDeclaration(f->name) == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: no such field in standard_metadata", - f->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: no such field in standard_metadata", f->name); LOG2("standard_metadata: " << type); } } @@ -967,8 +967,8 @@ class MoveIntrinsicMetadata : public Transform { if (queueType != nullptr) { for (auto f : queueType->fields) { if (type->fields.getDeclaration(f->name) == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: no such field in standard_metadata", - f->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "%1%: no such field in standard_metadata", f->name); LOG2("standard_metadata: " << type); } } @@ -1016,13 +1016,13 @@ class FindRecirculated : public Inspector { } auto expression = primitive->operands.at(operand); if (!expression->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a field list", expression); return; } auto nr = expression->to(); auto fl = structure->field_lists.get(nr->path->name); if (fl == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); return; } LOG3("Recirculated " << nr->path->name); @@ -1057,6 +1057,6 @@ class Converter : public PassManager { Visitor::profile_t init_apply(const IR::Node *node) override; }; -} // namespace P4V1 +} // namespace P4::P4V1 #endif /* FRONTENDS_P4_FROMV1_0_CONVERTERS_H_ */ diff --git a/frontends/p4/fromv1.0/programStructure.cpp b/frontends/p4/fromv1.0/programStructure.cpp index fcf90ba8ac..f98f94891d 100644 --- a/frontends/p4/fromv1.0/programStructure.cpp +++ b/frontends/p4/fromv1.0/programStructure.cpp @@ -29,7 +29,7 @@ limitations under the License. #include "lib/big_int_util.h" #include "lib/bitops.h" -namespace P4V1 { +namespace P4::P4V1 { using namespace P4::literals; static const IR::IDeclaration *getFirstDeclaration(const IR::Vector *nodes, @@ -116,7 +116,7 @@ void ProgramStructure::checkHeaderType(const IR::Type_StructLike *hdr, bool meta for (auto f : hdr->fields) { if (f->type->is()) { if (metadata) - ::error(ErrorType::ERR_INVALID, "%1%: varbit types illegal in metadata", f); + ::P4::error(ErrorType::ERR_INVALID, "%1%: varbit types illegal in metadata", f); } else if (!f->type->is()) { // These come from P4-14, so they cannot be anything else BUG("%1%: unexpected type", f); @@ -166,7 +166,7 @@ const IR::Vector *ProgramStructure::listIndexes(cstring type, cs const IR::Expression *ProgramStructure::listIndex(const IR::Expression *expression) const { auto pe = expression->to(); if (pe == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); return 0; } @@ -268,13 +268,13 @@ void ProgramStructure::createTypes() { const IR::Type_Struct *ProgramStructure::createFieldListType(const IR::Expression *expression) { if (!expression->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a field list", expression); return nullptr; } auto nr = expression->to(); auto fl = field_lists.get(nr->path->name); if (fl == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); return nullptr; } @@ -314,8 +314,8 @@ void ProgramStructure::createStructures() { if (metadataInstances.count(type_name)) continue; auto h = headers.get(it.first->name); if (h != nullptr) - ::warning(ErrorType::ERR_DUPLICATE, - "%1%: header and metadata instances %2% with the same name", it.first, h); + ::P4::warning(ErrorType::ERR_DUPLICATE, + "%1%: header and metadata instances %2% with the same name", it.first, h); auto ht = type->to(); auto path = new IR::Path(type_name); auto tn = new IR::Type_Name(ht->name.srcInfo, path); @@ -404,12 +404,13 @@ const IR::Statement *ProgramStructure::convertParserStatement(const IR::Expressi auto destType = dest->type; CHECK_NULL(destType); if (!destType->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: invalid argument. Expected a header not %2%", - primitive, destType->toString()); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid argument. Expected a header not %2%", primitive, + destType->toString()); return nullptr; } auto finalDestType = - ::get(finalHeaderType, destType->to()->externalName()); + ::P4::get(finalHeaderType, destType->to()->externalName()); BUG_CHECK(finalDestType != nullptr, "%1%: could not find final type", destType->to()->externalName()); destType = finalDestType; @@ -449,16 +450,16 @@ const IR::PathExpression *ProgramStructure::getState(IR::ID dest) { if (ctrl != nullptr) { if (ingress != nullptr) { if (ingress != ctrl) - ::error(ErrorType::ERR_UNSUPPORTED, - "Parser exits to two different control blocks: %1% and %2%", dest, - ingressReference); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "Parser exits to two different control blocks: %1% and %2%", dest, + ingressReference); } else { ingress = ctrl; ingressReference = dest; } return new IR::PathExpression(IR::ParserState::accept); } else { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: unknown state", dest); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: unknown state", dest); return nullptr; } } @@ -545,9 +546,9 @@ const IR::ParserState *ProgramStructure::convertParser( if (!first) continue; auto value_set = value_sets.get(first->path->name); if (!value_set) { - ::error(ErrorType::ERR_NOT_FOUND, - "Unable to find declaration for parser_value_set %s", - first->path->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "Unable to find declaration for parser_value_set %s", + first->path->name); return nullptr; } @@ -559,21 +560,21 @@ const IR::ParserState *ProgramStructure::convertParser( const IR::Constant *sizeConstant; if (sizeAnnotation) { if (sizeAnnotation->expr.size() != 1) { - ::error(ErrorType::ERR_INVALID, - "@size should be an integer for declaration %1%", value_set); + ::P4::error(ErrorType::ERR_INVALID, + "@size should be an integer for declaration %1%", value_set); return nullptr; } sizeConstant = sizeAnnotation->expr[0]->to(); if (sizeConstant == nullptr || !sizeConstant->fitsInt()) { - ::error(ErrorType::ERR_INVALID, - "@size should be an integer for declaration %1%", value_set); + ::P4::error(ErrorType::ERR_INVALID, + "@size should be an integer for declaration %1%", value_set); return nullptr; } } else { - ::warning(ErrorType::WARN_MISSING, - "%1%: parser_value_set has no @parser_value_set_size annotation." - "Using default size 4.", - c); + ::P4::warning(ErrorType::WARN_MISSING, + "%1%: parser_value_set has no @parser_value_set_size annotation." + "Using default size 4.", + c); sizeConstant = new IR::Constant(4); } auto annos = addGlobalNameAnnotation(value_set->name, value_set->annotations); @@ -589,8 +590,8 @@ const IR::ParserState *ProgramStructure::convertParser( auto c = v.second->to(); CHECK_NULL(c); // this is enforced elsewhere if (!c->fitsInt() || c->asInt() != -1) { - ::error(ErrorType::ERR_INVALID, "%1%: masks not supported for value sets", - c); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: masks not supported for value sets", c); continue; } auto sc = new IR::SelectCase(c->srcInfo, v.first, deststate); @@ -650,14 +651,14 @@ void ProgramStructure::createParser() { states.push_back(ps); } - if (states.empty()) ::error(ErrorType::ERR_INSUFFICIENT, "No parsers specified"); + if (states.empty()) ::P4::error(ErrorType::ERR_INSUFFICIENT, "No parsers specified"); auto result = new IR::P4Parser(v1model.parser.Id(), type, stateful, states); declarations->push_back(result); conversionContext->clear(); if (ingressReference.name.isNullOrEmpty()) - ::error(ErrorType::ERR_INSUFFICIENT, - "No transition from a parser to ingress pipeline found"); + ::P4::error(ErrorType::ERR_INSUFFICIENT, + "No transition from a parser to ingress pipeline found"); } void ProgramStructure::include(cstring filename, cstring ppoptions) { @@ -679,12 +680,12 @@ void ProgramStructure::include(cstring filename, cstring ppoptions) { } options.langVersion = CompilerOptions::FrontendVersion::P4_16; options.file = path; - if (::errorCount() == 0U) { + if (::P4::errorCount() == 0U) { auto preprocessorResult = options.preprocess(); if (preprocessorResult.has_value()) { const auto *code = P4::P4ParserDriver::parse(preprocessorResult.value().get(), options.file.string()); - if ((code != nullptr) && (::errorCount() == 0U)) { + if ((code != nullptr) && (::P4::errorCount() == 0U)) { for (const auto *decl : code->objects) { declarations->push_back(decl); } @@ -741,7 +742,8 @@ class HeaderRepresentation { stackNextElement[hdr] = new IR::Member(hdr, IR::ID("next")); return stackNextElement[hdr]; } else { - ::error(ErrorType::ERR_EXPRESSION, "%1%: Illegal extract stack expression", pe); + ::P4::error(ErrorType::ERR_EXPRESSION, "%1%: Illegal extract stack expression", + pe); return hdr; } } @@ -825,9 +827,9 @@ void ProgramStructure::createDeparserInternal( std::vector sortedHeaders; bool loop = headerOrder.sccSort(startHeader, sortedHeaders); if (loop) - ::warning(ErrorType::WARN_ORDERING, - "%1%: the order of headers in deparser is not uniquely determined by parser!", - startHeader); + ::P4::warning(ErrorType::WARN_ORDERING, + "%1%: the order of headers in deparser is not uniquely determined by parser!", + startHeader); auto params = new IR::ParameterList; params->push_back(packetOut); @@ -885,8 +887,8 @@ const IR::Declaration_Instance *ProgramStructure::convertActionProfile( const IR::ActionProfile *action_profile, cstring newName) { auto *action_selector = action_selectors.get(action_profile->selector.name); if (!action_profile->selector.name.isNullOrEmpty() && !action_selector) - ::error(ErrorType::ERR_NOT_FOUND, "Cannot locate action selector %1%", - action_profile->selector); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Cannot locate action selector %1%", + action_profile->selector); const IR::Type *type = nullptr; auto args = new IR::Vector(); auto annos = addGlobalNameAnnotation(action_profile->name); @@ -992,8 +994,8 @@ const IR::P4Table *ProgramStructure::convertTable(const IR::V1Table *table, cstr if (action_selector != nullptr) { auto flc = field_list_calculations.get(action_selector->key.name); if (flc == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "Cannot locate field list %1%", - action_selector->key); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Cannot locate field list %1%", + action_selector->key); } else { auto fl = getFieldLists(flc); if (fl != nullptr) { @@ -1104,7 +1106,7 @@ const IR::Expression *ProgramStructure::convertHashAlgorithm(Util::SourceInfo sr } else if (algorithm == "xor16") { result = v1model.algorithm.xor16.Id(); } else { - ::warning(ErrorType::WARN_UNSUPPORTED, "%1%: unexpected algorithm", algorithm); + ::P4::warning(ErrorType::WARN_UNSUPPORTED, "%1%: unexpected algorithm", algorithm); result = algorithm; } auto pe = new IR::TypeNameExpression(v1model.algorithm.Id()); @@ -1116,10 +1118,10 @@ const IR::Expression *ProgramStructure::convertHashAlgorithms(const IR::NameList if (!algorithm || algorithm->names.empty()) return nullptr; if (algorithm->names.size() > 1) { #if 1 - ::warning(ErrorType::WARN_UNSUPPORTED, - "%s: Multiple algorithms in a field list not supported in P4_16 -- using " - "only the first", - algorithm->names[0].srcInfo); + ::P4::warning(ErrorType::WARN_UNSUPPORTED, + "%s: Multiple algorithms in a field list not supported in P4_16 -- using " + "only the first", + algorithm->names[0].srcInfo); #else auto rv = new IR::ListExpression({}); for (auto &alg : algorithm->names) rv->push_back(convertHashAlgorithm(alg)); @@ -1134,8 +1136,8 @@ static bool sameBitsType(const IR::Node *errorPosition, const IR::Type *left, if (left->typeId() != right->typeId()) return false; if (const auto *leftBitsType = left->to()) return leftBitsType->operator==(right->as()); - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: operation only defined for bit/int types", - errorPosition); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: operation only defined for bit/int types", + errorPosition); return true; // to prevent inserting a cast } @@ -1159,7 +1161,7 @@ const IR::Statement *ProgramStructure::sliceAssign(const IR::Primitive *primitiv if (mask->is()) { auto cst = mask->to(); if (cst->value < 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Negative mask not supported", mask); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Negative mask not supported", mask); return nullptr; } if (cst->value != 0) { @@ -1188,13 +1190,13 @@ const IR::Expression *ProgramStructure::convertFieldList(const IR::Expression *e ExpressionConverter conv(this); if (!expression->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected a field list", expression); return expression; } auto nr = expression->to(); auto fl = field_lists.get(nr->path->name); if (fl == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field list", expression); return expression; } auto result = conv.convert(fl); @@ -1500,18 +1502,19 @@ static const IR::Constant *push_pop_size(ExpressionConverter &conv, const IR::Pr auto op1 = prim->operands.at(1); auto count = conv.convert(op1); if (!count->is()) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Only %2% with a constant value is supported", op1, - prim->name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Only %2% with a constant value is supported", + op1, prim->name); return new IR::Constant(1); } auto cst = count->to(); auto number = cst->asInt(); if (number < 0) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: %2% requires a positive amount", op1, prim->name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: %2% requires a positive amount", op1, + prim->name); return new IR::Constant(1); } if (number > 0xFFFF) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: %2% amount is too large", op1, prim->name); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: %2% amount is too large", op1, prim->name); return new IR::Constant(1); } return cst; @@ -1555,7 +1558,7 @@ CONVERT_PRIMITIVE(count, ) { // NOLINT(whitespace/parens), remove with C++20 up else if (auto nr = ref->to()) counter = structure->counters.get(nr->path->name); if (counter == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "Expected a counter reference %1%", ref); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a counter reference %1%", ref); return nullptr; } auto newname = structure->counters.get(counter); @@ -1710,12 +1713,12 @@ CONVERT_PRIMITIVE(execute_meter, ) { // NOLINT(whitespace/parens), remove with else if (auto nr = ref->to()) meter = structure->meters.get(nr->path->name); if (!meter) { - ::error(ErrorType::ERR_EXPECTED, "Expected a meter reference %1%", ref); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a meter reference %1%", ref); return nullptr; } if (!meter->implementation.name.isNullOrEmpty()) - ::warning(ErrorType::WARN_IGNORE_PROPERTY, "Ignoring `implementation' field of meter %1%", - meter); + ::P4::warning(ErrorType::WARN_IGNORE_PROPERTY, + "Ignoring `implementation' field of meter %1%", meter); auto newname = structure->meters.get(meter); auto meterref = new IR::PathExpression(newname); auto methodName = structure->v1model.meter.executeMeter.Id(primitive->srcInfo, primitive->name); @@ -1742,8 +1745,8 @@ CONVERT_PRIMITIVE(modify_field_with_hash_based_offset, ) { // NOLINT(whitespace auto flc = structure->getFieldListCalculation(primitive->operands.at(2)); if (flc == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field_list_calculation", - primitive->operands.at(2)); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Expected a field_list_calculation", + primitive->operands.at(2)); return nullptr; } auto ttype = IR::Type_Bits::get(flc->output_width); @@ -1823,7 +1826,7 @@ CONVERT_PRIMITIVE(register_read, ) { // NOLINT(whitespace/parens), remove with else if (auto nr = ref->to()) reg = structure->registers.get(nr->path->name); if (!reg) { - ::error(ErrorType::ERR_EXPECTED, "Expected a register reference %1%", ref); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a register reference %1%", ref); return nullptr; } auto newname = structure->registers.get(reg); @@ -1849,7 +1852,7 @@ CONVERT_PRIMITIVE(register_write, ) { // NOLINT(whitespace/parens), remove with else if (auto nr = ref->to()) reg = structure->registers.get(nr->path->name); if (!reg) { - ::error(ErrorType::ERR_EXPECTED, "Expected a register reference %1%", ref); + ::P4::error(ErrorType::ERR_EXPECTED, "Expected a register reference %1%", ref); return nullptr; } @@ -1947,8 +1950,8 @@ const IR::P4Action *ProgramStructure::convertAction(const IR::ActionFunction *ac direction = p->write ? IR::Direction::InOut : IR::Direction::None; auto type = p->type; if (type == IR::Type_Unknown::get()) { - ::warning(ErrorType::WARN_TYPE_INFERENCE, "Could not infer type for %1%, using bit<8>", - p); + ::P4::warning(ErrorType::WARN_TYPE_INFERENCE, + "Could not infer type for %1%, using bit<8>", p); type = IR::Type_Bits::get(8); } else if (type->is()) { auto path = new IR::Path(type->to()->name); @@ -2046,12 +2049,12 @@ const IR::Declaration_Instance *ProgramStructure::convert(const IR::Register *re } else if (reg->width > 0) { regElementType = IR::Type_Bits::get(reg->width, reg->signed_); } else if (reg->layout) { - cstring newName = ::get(registerLayoutType, reg->layout); + cstring newName = ::P4::get(registerLayoutType, reg->layout); if (newName.isNullOrEmpty()) newName = reg->layout; regElementType = new IR::Type_Name(new IR::Path(newName)); } else { - ::warning(ErrorType::WARN_MISSING, "%1%: Register width unspecified; using %2%", reg, - defaultRegisterWidth); + ::P4::warning(ErrorType::WARN_MISSING, "%1%: Register width unspecified; using %2%", reg, + defaultRegisterWidth); regElementType = IR::Type_Bits::get(defaultRegisterWidth); } @@ -2108,7 +2111,7 @@ const IR::Declaration_Instance *ProgramStructure::convertDirectMeter(const IR::M LOG3("Synthesizing " << m); auto meterOutput = m->result; if (meterOutput == nullptr) { - ::error(ErrorType::ERR_EXPECTED, "%1%: direct meter with no result", m); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: direct meter with no result", m); return nullptr; } @@ -2187,12 +2190,13 @@ const IR::P4Control *ProgramStructure::convertControl(const IR::V1Control *contr for (auto c : counters) { if (c.first->direct) { if (c.first->table.name.isNullOrEmpty()) { - ::error(ErrorType::ERR_INVALID, "%1%: Direct counter with no table", c.first); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Direct counter with no table", c.first); return nullptr; } auto tbl = tables.get(c.first->table.name); if (tbl == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "Cannot locate table %1%", c.first->table.name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Cannot locate table %1%", + c.first->table.name); return nullptr; } if (std::find(usedTables.begin(), usedTables.end(), tbl) != usedTables.end()) { @@ -2217,12 +2221,13 @@ const IR::P4Control *ProgramStructure::convertControl(const IR::V1Control *contr for (auto m : meters) { if (m.first->direct) { if (m.first->table.name.isNullOrEmpty()) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: Direct meter with no table", m.first); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: Direct meter with no table", m.first); return nullptr; } auto tbl = tables.get(m.first->table.name); if (tbl == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "Cannot locate table %1%", m.first->table.name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Cannot locate table %1%", + m.first->table.name); return nullptr; } if (std::find(usedTables.begin(), usedTables.end(), tbl) != usedTables.end()) { @@ -2278,7 +2283,7 @@ const IR::P4Control *ProgramStructure::convertControl(const IR::V1Control *contr for (auto a : actionsToDo) { auto act = actions.get(a); if (act == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "Cannot locate action %1%", a); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Cannot locate action %1%", a); return nullptr; } auto action = convertAction(act, actions.get(act), nullptr, nullptr); @@ -2330,7 +2335,7 @@ void ProgramStructure::createControls() { bool cycles = calledControls.sort(knownControls, controlsToDo); if (cycles) { // TODO: give a better error message - ::error(ErrorType::ERR_UNSUPPORTED, "Program contains recursive control blocks"); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "Program contains recursive control blocks"); return; } @@ -2430,14 +2435,15 @@ const IR::FieldListCalculation *ProgramStructure::getFieldListCalculation(const const IR::FieldList *ProgramStructure::getFieldLists(const IR::FieldListCalculation *flc) { // FIXME -- this duplicates P4_14::TypeCheck. Why not just use flc->input_fields? if (flc->input->names.size() == 0) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: field_list_calculation with zero inputs", flc); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: field_list_calculation with zero inputs", + flc); return nullptr; } if (flc->input->names.size() == 1) { auto name = flc->input->names.at(0); auto result = field_lists.get(name); if (result == nullptr) - ::error(ErrorType::ERR_NOT_FOUND, "Could not find field_list %1%", name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Could not find field_list %1%", name); return result; } @@ -2446,7 +2452,7 @@ const IR::FieldList *ProgramStructure::getFieldLists(const IR::FieldListCalculat for (auto name : flc->input->names) { auto fl = field_lists.get(name); if (fl == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "Could not find field_list %1%", name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "Could not find field_list %1%", name); return nullptr; } result->fields.insert(result->fields.end(), fl->fields.begin(), fl->fields.end()); @@ -2607,14 +2613,14 @@ const IR::P4Program *ProgramStructure::create(Util::SourceInfo info) { createStructures(); createExterns(); createParser(); - if (::errorCount()) return nullptr; + if (::P4::errorCount()) return nullptr; createControls(); - if (::errorCount()) return nullptr; + if (::P4::errorCount()) return nullptr; createDeparser(); createChecksumVerifications(); createChecksumUpdates(); createMain(); - if (::errorCount()) return nullptr; + if (::P4::errorCount()) return nullptr; auto program = new IR::P4Program(info, *declarations); return program; } @@ -2654,4 +2660,4 @@ void ProgramStructure::populateOutputNames() { ; } -} // namespace P4V1 +} // namespace P4::P4V1 diff --git a/frontends/p4/fromv1.0/programStructure.h b/frontends/p4/fromv1.0/programStructure.h index 045fcb334e..cdd3512bb3 100644 --- a/frontends/p4/fromv1.0/programStructure.h +++ b/frontends/p4/fromv1.0/programStructure.h @@ -27,7 +27,7 @@ limitations under the License. #include "lib/map.h" #include "v1model.h" -namespace P4V1 { +namespace P4::P4V1 { class ConversionContext { public: @@ -99,9 +99,11 @@ class ProgramStructure { objectToNewName.emplace(obj, newName); } /// Lookup using the original name - T get(cstring name) const { return ::get(nameToObject, name); } + T get(cstring name) const { return ::P4::get(nameToObject, name); } /// Get the new name - cstring get(T object) const { return ::get(objectToNewName, object, object->name.name); } + cstring get(T object) const { + return ::P4::get(objectToNewName, object, object->name.name); + } /// Get the new name from the old name cstring newname(cstring name) const { return get(get(name)); } bool contains(cstring name) const { return nameToObject.find(name) != nameToObject.end(); } @@ -326,6 +328,6 @@ class ProgramStructure { virtual const IR::P4Program *create(Util::SourceInfo info); }; -} // namespace P4V1 +} // namespace P4::P4V1 #endif /* FRONTENDS_P4_FROMV1_0_PROGRAMSTRUCTURE_H_ */ diff --git a/frontends/p4/fromv1.0/v1model.h b/frontends/p4/fromv1.0/v1model.h index 667d7fdd2b..4fb8f0eff4 100644 --- a/frontends/p4/fromv1.0/v1model.h +++ b/frontends/p4/fromv1.0/v1model.h @@ -24,7 +24,7 @@ limitations under the License. #include "lib/cstring.h" #include "lib/json.h" -namespace P4V1 { +namespace P4::P4V1 { using namespace P4::literals; @@ -32,7 +32,7 @@ using namespace P4::literals; // In a perfect world this would be generated automatically from // p4includes/v1model.p4 -struct Parser_Model : public ::Model::Elem { +struct Parser_Model : public ::P4::Model::Elem { Parser_Model(Model::Type_Model headersType, Model::Type_Model userMetaType, Model::Type_Model standardMetadataType) : Model::Elem("ParserImpl"_cs), @@ -40,68 +40,68 @@ struct Parser_Model : public ::Model::Elem { headersParam("hdr"_cs, headersType, 1), metadataParam("meta"_cs, userMetaType, 2), standardMetadataParam("standard_metadata"_cs, standardMetadataType, 3) {} - ::Model::Param_Model packetParam; - ::Model::Param_Model headersParam; - ::Model::Param_Model metadataParam; - ::Model::Param_Model standardMetadataParam; + ::P4::Model::Param_Model packetParam; + ::P4::Model::Param_Model headersParam; + ::P4::Model::Param_Model metadataParam; + ::P4::Model::Param_Model standardMetadataParam; }; -struct Deparser_Model : public ::Model::Elem { +struct Deparser_Model : public ::P4::Model::Elem { explicit Deparser_Model(Model::Type_Model headersType) : Model::Elem("DeparserImpl"_cs), packetParam("packet"_cs, P4::P4CoreLibrary::instance().packetOut, 0), headersParam("hdr"_cs, headersType, 1) {} - ::Model::Param_Model packetParam; - ::Model::Param_Model headersParam; + ::P4::Model::Param_Model packetParam; + ::P4::Model::Param_Model headersParam; }; // Models ingress and egress -struct Control_Model : public ::Model::Elem { +struct Control_Model : public ::P4::Model::Elem { Control_Model(cstring name, Model::Type_Model headersType, Model::Type_Model metadataType, Model::Type_Model standardMetadataType) : Model::Elem(name), headersParam("hdr"_cs, headersType, 0), metadataParam("meta"_cs, metadataType, 1), standardMetadataParam("standard_metadata"_cs, standardMetadataType, 2) {} - ::Model::Param_Model headersParam; - ::Model::Param_Model metadataParam; - ::Model::Param_Model standardMetadataParam; + ::P4::Model::Param_Model headersParam; + ::P4::Model::Param_Model metadataParam; + ::P4::Model::Param_Model standardMetadataParam; }; -struct VerifyUpdate_Model : public ::Model::Elem { +struct VerifyUpdate_Model : public ::P4::Model::Elem { VerifyUpdate_Model(cstring name, Model::Type_Model headersType) : Model::Elem(name), headersParam("hdr"_cs, headersType, 0) {} - ::Model::Param_Model headersParam; + ::P4::Model::Param_Model headersParam; }; -struct CounterType_Model : public ::Model::Enum_Model { +struct CounterType_Model : public ::P4::Model::Enum_Model { CounterType_Model() - : ::Model::Enum_Model("CounterType"_cs), + : ::P4::Model::Enum_Model("CounterType"_cs), packets("packets"_cs), bytes("bytes"_cs), both("packets_and_bytes"_cs) {} - ::Model::Elem packets; - ::Model::Elem bytes; - ::Model::Elem both; + ::P4::Model::Elem packets; + ::P4::Model::Elem bytes; + ::P4::Model::Elem both; }; -struct MeterType_Model : public ::Model::Enum_Model { +struct MeterType_Model : public ::P4::Model::Enum_Model { MeterType_Model() - : ::Model::Enum_Model("MeterType"_cs), packets("packets"_cs), bytes("bytes"_cs) {} - ::Model::Elem packets; - ::Model::Elem bytes; + : ::P4::Model::Enum_Model("MeterType"_cs), packets("packets"_cs), bytes("bytes"_cs) {} + ::P4::Model::Elem packets; + ::P4::Model::Elem bytes; }; -struct ActionProfile_Model : public ::Model::Extern_Model { +struct ActionProfile_Model : public ::P4::Model::Extern_Model { ActionProfile_Model() : Extern_Model("action_profile"_cs), sizeType(IR::Type_Bits::get(32)), sizeParam("size"_cs) {} const IR::Type *sizeType; - ::Model::Elem sizeParam; + ::P4::Model::Elem sizeParam; }; -struct ActionSelector_Model : public ::Model::Extern_Model { +struct ActionSelector_Model : public ::P4::Model::Extern_Model { ActionSelector_Model() : Extern_Model("action_selector"_cs), sizeType(IR::Type_Bits::get(32)), @@ -109,14 +109,14 @@ struct ActionSelector_Model : public ::Model::Extern_Model { widthType(IR::Type_Bits::get(32)), algorithmParam("algorithm"_cs) {} const IR::Type *sizeType; - ::Model::Elem sizeParam; + ::P4::Model::Elem sizeParam; const IR::Type *widthType; - ::Model::Elem algorithmParam; + ::P4::Model::Elem algorithmParam; }; -struct Random_Model : public ::Model::Elem { +struct Random_Model : public ::P4::Model::Elem { Random_Model() : Elem("random"_cs), modify_field_rng_uniform("modify_field_rng_uniform"_cs) {} - ::Model::Elem modify_field_rng_uniform; + ::P4::Model::Elem modify_field_rng_uniform; }; class Truncate : public Model::Extern_Model { @@ -125,77 +125,77 @@ class Truncate : public Model::Extern_Model { const IR::Type *length_type; }; -struct CounterOrMeter_Model : public ::Model::Extern_Model { +struct CounterOrMeter_Model : public ::P4::Model::Extern_Model { explicit CounterOrMeter_Model(cstring name) : Extern_Model(name), sizeParam("size"_cs), typeParam("type"_cs), size_type(IR::Type_Bits::get(32)) {} - ::Model::Elem sizeParam; - ::Model::Elem typeParam; + ::P4::Model::Elem sizeParam; + ::P4::Model::Elem typeParam; const IR::Type *size_type; CounterType_Model counterType; MeterType_Model meterType; }; -struct Register_Model : public ::Model::Extern_Model { +struct Register_Model : public ::P4::Model::Extern_Model { Register_Model() : Extern_Model("register"_cs), sizeParam("size"_cs), read("read"_cs), write("write"_cs), size_type(IR::Type_Bits::get(32)) {} - ::Model::Elem sizeParam; - ::Model::Elem read; - ::Model::Elem write; + ::P4::Model::Elem sizeParam; + ::P4::Model::Elem read; + ::P4::Model::Elem write; const IR::Type *size_type; }; -struct DigestReceiver_Model : public ::Model::Elem { +struct DigestReceiver_Model : public ::P4::Model::Elem { DigestReceiver_Model() : Elem("digest"_cs), receiverType(IR::Type_Bits::get(32)) {} const IR::Type *receiverType; }; struct Counter_Model : public CounterOrMeter_Model { Counter_Model() : CounterOrMeter_Model("counter"_cs), increment("count"_cs) {} - ::Model::Elem increment; + ::P4::Model::Elem increment; }; struct Meter_Model : public CounterOrMeter_Model { Meter_Model() : CounterOrMeter_Model("meter"_cs), executeMeter("execute_meter"_cs) {} - ::Model::Elem executeMeter; + ::P4::Model::Elem executeMeter; }; struct DirectMeter_Model : public CounterOrMeter_Model { DirectMeter_Model() : CounterOrMeter_Model("direct_meter"_cs), read("read"_cs) {} - ::Model::Elem read; + ::P4::Model::Elem read; }; struct DirectCounter_Model : public CounterOrMeter_Model { DirectCounter_Model() : CounterOrMeter_Model("direct_counter"_cs), count("count"_cs) {} - ::Model::Elem count; + ::P4::Model::Elem count; }; -struct StandardMetadataType_Model : public ::Model::Type_Model { +struct StandardMetadataType_Model : public ::P4::Model::Type_Model { explicit StandardMetadataType_Model(cstring name) - : ::Model::Type_Model(name), + : ::P4::Model::Type_Model(name), dropBit("drop"_cs), recirculate("recirculate_port"_cs), egress_spec("egress_spec"_cs) {} - ::Model::Elem dropBit; - ::Model::Elem recirculate; - ::Model::Elem egress_spec; + ::P4::Model::Elem dropBit; + ::P4::Model::Elem recirculate; + ::P4::Model::Elem egress_spec; }; -struct CloneType_Model : public ::Model::Enum_Model { - CloneType_Model() : ::Model::Enum_Model("CloneType"_cs), i2e("I2E"_cs), e2e("E2E"_cs) {} - ::Model::Elem i2e; - ::Model::Elem e2e; +struct CloneType_Model : public ::P4::Model::Enum_Model { + CloneType_Model() : ::P4::Model::Enum_Model("CloneType"_cs), i2e("I2E"_cs), e2e("E2E"_cs) {} + ::P4::Model::Elem i2e; + ::P4::Model::Elem e2e; }; -struct Algorithm_Model : public ::Model::Enum_Model { +struct Algorithm_Model : public ::P4::Model::Enum_Model { Algorithm_Model() - : ::Model::Enum_Model("HashAlgorithm"_cs), + : ::P4::Model::Enum_Model("HashAlgorithm"_cs), crc32("crc32"_cs), crc32_custom("crc32_custom"_cs), crc16("crc16"_cs), @@ -204,32 +204,32 @@ struct Algorithm_Model : public ::Model::Enum_Model { identity("identity"_cs), csum16("csum16"_cs), xor16("xor16"_cs) {} - ::Model::Elem crc32; - ::Model::Elem crc32_custom; - ::Model::Elem crc16; - ::Model::Elem crc16_custom; - ::Model::Elem random; - ::Model::Elem identity; - ::Model::Elem csum16; - ::Model::Elem xor16; + ::P4::Model::Elem crc32; + ::P4::Model::Elem crc32_custom; + ::P4::Model::Elem crc16; + ::P4::Model::Elem crc16_custom; + ::P4::Model::Elem random; + ::P4::Model::Elem identity; + ::P4::Model::Elem csum16; + ::P4::Model::Elem xor16; }; -struct Hash_Model : public ::Model::Elem { - Hash_Model() : ::Model::Elem("hash"_cs) {} +struct Hash_Model : public ::P4::Model::Elem { + Hash_Model() : ::P4::Model::Elem("hash"_cs) {} }; -struct Cloner_Model : public ::Model::Extern_Model { +struct Cloner_Model : public ::P4::Model::Extern_Model { Cloner_Model() : Extern_Model("clone"_cs), clone3("clone_preserving_field_list"_cs), sessionType(IR::Type_Bits::get(32)) {} - ::Model::Elem clone3; + ::P4::Model::Elem clone3; CloneType_Model cloneType; const IR::Type *sessionType; }; -struct Switch_Model : public ::Model::Elem { +struct Switch_Model : public ::P4::Model::Elem { Switch_Model() : Model::Elem("V1Switch"_cs), parser("p"_cs), @@ -238,12 +238,12 @@ struct Switch_Model : public ::Model::Elem { egress("eg"_cs), compute("ck"_cs), deparser("dep"_cs) {} - ::Model::Elem parser; // names of the package arguments - ::Model::Elem verify; - ::Model::Elem ingress; - ::Model::Elem egress; - ::Model::Elem compute; - ::Model::Elem deparser; + ::P4::Model::Elem parser; // names of the package arguments + ::P4::Model::Elem verify; + ::P4::Model::Elem ingress; + ::P4::Model::Elem egress; + ::P4::Model::Elem compute; + ::P4::Model::Elem deparser; }; struct TableAttributes_Model { @@ -253,15 +253,15 @@ struct TableAttributes_Model { meters("meters"_cs), size("size"_cs), supportTimeout("support_timeout"_cs) {} - ::Model::Elem tableImplementation; - ::Model::Elem counters; - ::Model::Elem meters; - ::Model::Elem size; - ::Model::Elem supportTimeout; + ::P4::Model::Elem tableImplementation; + ::P4::Model::Elem counters; + ::P4::Model::Elem meters; + ::P4::Model::Elem size; + ::P4::Model::Elem supportTimeout; const unsigned defaultTableSize = 1024; }; -class V1Model : public ::Model::Model { +class V1Model : public Model::Model { protected: V1Model() : file("v1model.p4"_cs), @@ -306,12 +306,12 @@ class V1Model : public ::Model::Model { directCounter() {} public: - const ::Model::Elem file; - const ::Model::Elem standardMetadata; - const ::Model::Elem intrinsicMetadata; - const ::Model::Elem queueingMetadata; - const ::Model::Type_Model headersType; - const ::Model::Type_Model metadataType; + const ::P4::Model::Elem file; + const ::P4::Model::Elem standardMetadata; + const ::P4::Model::Elem intrinsicMetadata; + const ::P4::Model::Elem queueingMetadata; + const ::P4::Model::Type_Model headersType; + const ::P4::Model::Type_Model metadataType; const StandardMetadataType_Model standardMetadataType; const Parser_Model parser; const Deparser_Model deparser; @@ -326,24 +326,24 @@ class V1Model : public ::Model::Model { const ActionProfile_Model action_profile; const ActionSelector_Model action_selector; const Cloner_Model clone; - const ::Model::Elem resubmit; + const ::P4::Model::Elem resubmit; const TableAttributes_Model tableAttributes; - const ::Model::Elem rangeMatchType; - const ::Model::Elem optionalMatchType; - const ::Model::Elem selectorMatchType; + const ::P4::Model::Elem rangeMatchType; + const ::P4::Model::Elem optionalMatchType; + const ::P4::Model::Elem selectorMatchType; const VerifyUpdate_Model verify; const VerifyUpdate_Model compute; const DigestReceiver_Model digest_receiver; const Hash_Model hash; const Algorithm_Model algorithm; const Register_Model registers; - const ::Model::Elem drop; - const ::Model::Elem recirculate; - const ::Model::Elem verify_checksum; - const ::Model::Elem update_checksum; - const ::Model::Elem verify_checksum_with_payload; - const ::Model::Elem update_checksum_with_payload; - const ::Model::Elem log_msg; + const ::P4::Model::Elem drop; + const ::P4::Model::Elem recirculate; + const ::P4::Model::Elem verify_checksum; + const ::P4::Model::Elem update_checksum; + const ::P4::Model::Elem verify_checksum_with_payload; + const ::P4::Model::Elem update_checksum_with_payload; + const ::P4::Model::Elem log_msg; const DirectMeter_Model directMeter; const DirectCounter_Model directCounter; @@ -369,6 +369,6 @@ class getV1ModelVersion : public Inspector { unsigned version = 0; }; -} // namespace P4V1 +} // namespace P4::P4V1 #endif /* FRONTENDS_P4_FROMV1_0_V1MODEL_H_ */ diff --git a/frontends/p4/functionsInlining.cpp b/frontends/p4/functionsInlining.cpp index 5b2ed4c1d2..78ce544150 100644 --- a/frontends/p4/functionsInlining.cpp +++ b/frontends/p4/functionsInlining.cpp @@ -235,7 +235,7 @@ const IR::Statement *FunctionsInliner::inlineBefore(const IR::Node *calleeNode, // all possible callees in replMap. SubstituteParameters sp(nullptr, &subst, &tvs); auto clone = callee->apply(sp, getChildContext()); - if (::errorCount() > 0) return statement; + if (::P4::errorCount() > 0) return statement; CHECK_NULL(clone); BUG_CHECK(clone->is(), "%1%: not an function", clone); auto funclone = clone->to(); @@ -245,7 +245,7 @@ const IR::Statement *FunctionsInliner::inlineBefore(const IR::Node *calleeNode, for (auto param : callee->type->parameters->parameters) { auto left = substitution.lookup(param); if (param->direction == IR::Direction::InOut || param->direction == IR::Direction::Out) { - cstring newName = ::get(paramRename, param); + cstring newName = ::P4::get(paramRename, param); auto right = new IR::PathExpression(newName); auto copyout = new IR::AssignmentStatement(left->expression, right); body.push_back(copyout); diff --git a/frontends/p4/inlining.cpp b/frontends/p4/inlining.cpp index 43e25a8f52..5f1e2b06d0 100644 --- a/frontends/p4/inlining.cpp +++ b/frontends/p4/inlining.cpp @@ -38,7 +38,7 @@ class FindLocationSets : public Inspector { std::map loc; const LocationSet *get(const IR::Expression *expression) const { - auto result = ::get(loc, expression); + auto result = ::P4::get(loc, expression); BUG_CHECK(result != nullptr, "No location set known for %1%", expression); return result; } @@ -342,10 +342,10 @@ void InlineList::analyze() { if (!allowMultipleCalls && inl->invocations.size() > 1) { ++it; auto second = *it; - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "Multiple invocations of the same object " - "not supported on this target: %1%, %2%", - first, second); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "Multiple invocations of the same object " + "not supported on this target: %1%, %2%", + first, second); continue; } cg.calls(inl->caller, inl->callee); @@ -402,14 +402,14 @@ void DiscoverInlining::visit_all(const IR::Block *block) { if (it.second->is()) { visit(it.second->getNode()); } - if (::errorCount() > 0) return; + if (::P4::errorCount() > 0) return; } } bool DiscoverInlining::preorder(const IR::ControlBlock *block) { LOG4("Visiting " << block); if (getContext()->node->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: instantiation of control in parser", block->node); + ::P4::error(ErrorType::ERR_INVALID, "%1%: instantiation of control in parser", block->node); return false; } else if (getContext()->node->is() && allowControls) { auto parent = getContext()->node->to(); @@ -420,7 +420,7 @@ bool DiscoverInlining::preorder(const IR::ControlBlock *block) { } visit_all(block); - if (::errorCount() > 0) return false; + if (::P4::errorCount() > 0) return false; visit(block->container->body); return false; } @@ -428,7 +428,7 @@ bool DiscoverInlining::preorder(const IR::ControlBlock *block) { bool DiscoverInlining::preorder(const IR::ParserBlock *block) { LOG4("Visiting " << block); if (getContext()->node->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: instantiation of parser in control", block->node); + ::P4::error(ErrorType::ERR_INVALID, "%1%: instantiation of parser in control", block->node); return false; } else if (getContext()->node->is()) { auto parent = getContext()->node->to(); @@ -438,7 +438,7 @@ bool DiscoverInlining::preorder(const IR::ParserBlock *block) { inlineList->addInstantiation(parent->container, callee, instance); } visit_all(block); - if (::errorCount() > 0) return false; + if (::P4::errorCount() > 0) return false; visit(block->container->states, "states"); return false; } @@ -538,10 +538,10 @@ void GeneralInliner::inline_subst(P4Block *caller, } for (auto param1 : *mi->substitution.getParametersInArgumentOrder()) { - auto ls1 = ::get(locationSets, param1); + auto ls1 = ::P4::get(locationSets, param1); for (auto param2 : *mi->substitution.getParametersInArgumentOrder()) { if (param1 == param2) continue; - auto ls2 = ::get(locationSets, param2); + auto ls2 = ::P4::get(locationSets, param2); if (ls1->overlaps(ls2)) { LOG4("Arg for " << dbp(param1) << " aliases with arg for " << dbp(param2) << ": using temp"); @@ -652,11 +652,11 @@ const IR::Node *GeneralInliner::preorder(IR::MethodCallStatement *statement) { if (!initializer->equiv(*prev)) // This is a compile-time constant, since this is a non-directional // parameter, so the value should be independent on the context. - ::error(ErrorType::ERR_INVALID, - "%1%: non-directional parameters must be substitued with the " - "same value in all invocations; two different substitutions are " - "%2% and %3%", - param, initializer, prev); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: non-directional parameters must be substitued with the " + "same value in all invocations; two different substitutions are " + "%2% and %3%", + param, initializer, prev); continue; } } @@ -731,7 +731,7 @@ class RenameStates : public Transform { } const IR::Node *preorder(IR::Path *path) override { // This is certainly a state name, by the way we organized the visitors - cstring newName = ::get(stateRenameMap, path->name); + cstring newName = ::P4::get(stateRenameMap, path->name); path->name = IR::ID(path->name.srcInfo, newName, path->name.originalName); return path; } @@ -751,7 +751,7 @@ class RenameStates : public Transform { prune(); return state; } - cstring newName = ::get(stateRenameMap, state->name.name); + cstring newName = ::P4::get(stateRenameMap, state->name.name); state->name.name = newName; if (state->selectExpression != nullptr) visit(state->selectExpression); prune(); @@ -818,11 +818,11 @@ const IR::Node *GeneralInliner::preorder(IR::ParserState *state) { if (!initializer->equiv(*prev)) // This is a compile-time constant, since this is a non-directional // parameter, so the value should be independent on the context. - ::error(ErrorType::ERR_INVALID, - "%1%: non-directional parameters must be substitued with the " - "same value in all invocations; two different substitutions are " - "%2% and %3%", - param, initializer, prev); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: non-directional parameters must be substitued with the " + "same value in all invocations; two different substitutions are " + "%2% and %3%", + param, initializer, prev); continue; } } @@ -860,7 +860,7 @@ const IR::Node *GeneralInliner::preorder(IR::ParserState *state) { RenameStates rs(&renameMap); rs.setCalledBy(this); auto renamed = callee->apply(rs); - IR::ID newStartName(::get(renameMap, IR::ParserState::start), IR::ParserState::start); + IR::ID newStartName(::P4::get(renameMap, IR::ParserState::start), IR::ParserState::start); auto newState = new IR::ParserState(srcInfo, name, annotations, current, new IR::PathExpression(newStartName)); states->push_back(newState); diff --git a/frontends/p4/inlining.h b/frontends/p4/inlining.h index a0199df1b7..0fa3bed68b 100644 --- a/frontends/p4/inlining.h +++ b/frontends/p4/inlining.h @@ -70,13 +70,13 @@ class SymRenameMap { cstring getName(const IR::IDeclaration *decl) const { CHECK_NULL(decl); BUG_CHECK(internalName.find(decl) != internalName.end(), "%1%: no new name", decl); - auto result = ::get(internalName, decl); + auto result = ::P4::get(internalName, decl); return result; } cstring getExtName(const IR::IDeclaration *decl) const { CHECK_NULL(decl); BUG_CHECK(externalName.find(decl) != externalName.end(), "%1%: no external name", decl); - auto result = ::get(externalName, decl); + auto result = ::P4::get(externalName, decl); return result; } bool isRenamed(const IR::IDeclaration *decl) const { diff --git a/frontends/p4/localizeActions.cpp b/frontends/p4/localizeActions.cpp index 9ddb45d210..3ae11913a6 100644 --- a/frontends/p4/localizeActions.cpp +++ b/frontends/p4/localizeActions.cpp @@ -91,7 +91,7 @@ bool FindGlobalActionUses::preorder(const IR::PathExpression *path) { } const IR::Node *LocalizeActions::postorder(IR::P4Control *control) { - auto actions = ::get(repl->repl, getOriginal()); + auto actions = ::P4::get(repl->repl, getOriginal()); if (actions == nullptr) return control; IR::IndexedVector newDecls; for (auto pair : *actions) { @@ -205,7 +205,7 @@ const IR::Node *DuplicateActions::postorder(IR::P4Control *control) { } const IR::Node *DuplicateActions::postorder(IR::PathExpression *expression) { - auto replacement = ::get(repl->repl, getOriginal()); + auto replacement = ::P4::get(repl->repl, getOriginal()); if (replacement != nullptr) { LOG1("Rewriting " << dbp(expression) << " to " << dbp(replacement)); expression = new IR::PathExpression( diff --git a/frontends/p4/localizeActions.h b/frontends/p4/localizeActions.h index e74e090a5f..554f2575f6 100644 --- a/frontends/p4/localizeActions.h +++ b/frontends/p4/localizeActions.h @@ -35,7 +35,7 @@ class GlobalActionReplacements { const IR::P4Action *getReplacement(const IR::P4Action *action, const IR::P4Control *control) const { - auto map = ::get(repl, control); + auto map = ::P4::get(repl, control); if (map == nullptr) return nullptr; if (map->find(action) != map->end()) return (*map)[action]; return nullptr; diff --git a/frontends/p4/modelInstances.cpp b/frontends/p4/modelInstances.cpp index d7d860c4bc..fd1633a2eb 100644 --- a/frontends/p4/modelInstances.cpp +++ b/frontends/p4/modelInstances.cpp @@ -19,10 +19,10 @@ limitations under the License. /* These must be in the same compiliation unit to ensure that P4CoreLibrary::instance * is initialized before V1Model::instance */ -namespace P4V1 { +namespace P4::P4V1 { V1Model V1Model::instance; const char *V1Model::versionInitial = "20180101"; const char *V1Model::versionCurrent = "20200408"; -} // namespace P4V1 +} // namespace P4::P4V1 diff --git a/frontends/p4/optimizeExpressions.h b/frontends/p4/optimizeExpressions.h index 980babd734..73204cfa47 100644 --- a/frontends/p4/optimizeExpressions.h +++ b/frontends/p4/optimizeExpressions.h @@ -14,7 +14,7 @@ inline const IR::Expression *optimizeExpression(const IR::Expression *node) { new P4::ConstantFolding(nullptr, nullptr, false), }); node = node->apply(pass); - BUG_CHECK(::errorCount() == 0, "Encountered errors while trying to optimize expressions."); + BUG_CHECK(::P4::errorCount() == 0, "Encountered errors while trying to optimize expressions."); return node; } diff --git a/frontends/p4/parameterSubstitution.cpp b/frontends/p4/parameterSubstitution.cpp index d3866ec892..96b07aa338 100644 --- a/frontends/p4/parameterSubstitution.cpp +++ b/frontends/p4/parameterSubstitution.cpp @@ -44,7 +44,7 @@ void ParameterSubstitution::populate(const IR::ParameterList *params, if (a->name) { p = params->getParameter(a->name); if (p == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "No parameter named %1%", a->name); + ::P4::error(ErrorType::ERR_NOT_FOUND, "No parameter named %1%", a->name); continue; } } else { diff --git a/frontends/p4/parseAnnotations.cpp b/frontends/p4/parseAnnotations.cpp index 2810d44f34..a0d218044e 100644 --- a/frontends/p4/parseAnnotations.cpp +++ b/frontends/p4/parseAnnotations.cpp @@ -57,7 +57,7 @@ bool ParseAnnotations::parseSkip(IR::Annotation *) { return false; } bool ParseAnnotations::parseEmpty(IR::Annotation *annotation) { if (!annotation->body.empty()) { - ::error(ErrorType::ERR_OVERLIMIT, "%1% should not have any arguments", annotation); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1% should not have any arguments", annotation); return false; } diff --git a/frontends/p4/removeParameters.cpp b/frontends/p4/removeParameters.cpp index a6d2eb1d50..adcd4a0960 100644 --- a/frontends/p4/removeParameters.cpp +++ b/frontends/p4/removeParameters.cpp @@ -129,8 +129,8 @@ const IR::Node *DoRemoveActionParameters::postorder(IR::P4Action *action) { result->push_back(decl); auto arg = substitution.lookup(p); if (arg == nullptr) { - ::error(ErrorType::ERR_UNINITIALIZED, "action %1%: parameter %2% must be bound", - invocation, p); + ::P4::error(ErrorType::ERR_UNINITIALIZED, "action %1%: parameter %2% must be bound", + invocation, p); continue; } diff --git a/frontends/p4/removeParameters.h b/frontends/p4/removeParameters.h index 65a366f710..505a45823d 100644 --- a/frontends/p4/removeParameters.h +++ b/frontends/p4/removeParameters.h @@ -50,14 +50,14 @@ class ActionInvocation { void bindDefaultAction(const IR::P4Action *action, const IR::MethodCallExpression *defaultInvocation) { // We must have a binding for this action already. - auto actionCallInvocation = ::get(invocations, action); + auto actionCallInvocation = ::P4::get(invocations, action); CHECK_NULL(actionCallInvocation); // We must remove all arguments which are bound in the action list. unsigned boundArgs = actionCallInvocation->arguments->size(); defaultActions.emplace(defaultInvocation, boundArgs); } const IR::MethodCallExpression *get(const IR::P4Action *action) const { - return ::get(invocations, action); + return ::P4::get(invocations, action); } bool removeAllParameters(const IR::P4Action *action) const { return all.find(action) != all.end(); @@ -67,7 +67,7 @@ class ActionInvocation { } unsigned argsToRemove(const IR::MethodCallExpression *defaultCall) const { if (defaultActions.find(defaultCall) == defaultActions.end()) return 0; - return ::get(defaultActions, defaultCall); + return ::P4::get(defaultActions, defaultCall); } }; diff --git a/frontends/p4/resetHeaders.cpp b/frontends/p4/resetHeaders.cpp index c9adcdce72..e714ea9a51 100644 --- a/frontends/p4/resetHeaders.cpp +++ b/frontends/p4/resetHeaders.cpp @@ -38,8 +38,8 @@ void DoResetHeaders::generateResets(const TypeMap *typeMap, const IR::Type *type } else if (type->is()) { auto tstack = type->to(); if (!tstack->sizeKnown()) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: stack size is not a compile-time constant", - tstack); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: stack size is not a compile-time constant", tstack); return; } for (unsigned i = 0; i < tstack->getSize(); i++) { diff --git a/frontends/p4/sideEffects.cpp b/frontends/p4/sideEffects.cpp index 116d0afb01..9e50ebd252 100644 --- a/frontends/p4/sideEffects.cpp +++ b/frontends/p4/sideEffects.cpp @@ -787,7 +787,7 @@ const IR::Node *KeySideEffect::preorder(IR::P4Table *table) { } const IR::Node *KeySideEffect::postorder(IR::P4Table *table) { - auto insertions = ::get(toInsert, getOriginal()); + auto insertions = ::P4::get(toInsert, getOriginal()); if (insertions == nullptr) return table; auto result = new IR::IndexedVector(); diff --git a/frontends/p4/sideEffects.h b/frontends/p4/sideEffects.h index 0c07094196..8844bebc24 100644 --- a/frontends/p4/sideEffects.h +++ b/frontends/p4/sideEffects.h @@ -381,8 +381,8 @@ class TablesInActions : public Inspector { hta.setCalledBy(this); (void)expression->apply(hta, getContext()); if (hta.table != nullptr) { - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: table invocation in action argument", - expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: table invocation in action argument", + expression); } } } diff --git a/frontends/p4/simplifyDefUse.cpp b/frontends/p4/simplifyDefUse.cpp index e13df64a54..04383e018e 100644 --- a/frontends/p4/simplifyDefUse.cpp +++ b/frontends/p4/simplifyDefUse.cpp @@ -117,7 +117,7 @@ class DeclarationToExpression { CHECK_NULL(refMap); CHECK_NULL(typeMap); - auto expr = ::get(paths, decl); + auto expr = ::P4::get(paths, decl); if (!expr) { expr = new IR::PathExpression(decl->name); } @@ -293,7 +293,7 @@ class HeaderDefinitions : public IHasDbPrint { if (notReport.find(storage) != notReport.end()) return TernaryBool::Yes; - return ::get(defs, storage, TernaryBool::Maybe); + return ::P4::get(defs, storage, TernaryBool::Maybe); } // result is OR operation on valid bits of all locations @@ -332,7 +332,7 @@ class HeaderDefinitions : public IHasDbPrint { HeaderDefinitions *intersect(const HeaderDefinitions *other) const { HeaderDefinitions *result = new HeaderDefinitions(refMap, typeMap, storageMap); for (auto def : defs) { - auto valid = ::get(other->defs, def.first, TernaryBool::Maybe); + auto valid = ::P4::get(other->defs, def.first, TernaryBool::Maybe); result->defs.emplace(def.first, valid == def.second ? valid : TernaryBool::Maybe); } return result; @@ -381,7 +381,7 @@ class FindUninitialized : public Inspector { bool reportInvalidHeaders = true; const LocationSet *getReads(const IR::Expression *expression, bool nonNull = false) const { - const auto *result = ::get(readLocations, expression); + const auto *result = ::P4::get(readLocations, expression); if (nonNull) BUG_CHECK(result != nullptr, "no locations known for %1%", dbp(expression)); return result; } @@ -525,8 +525,8 @@ class FindUninitialized : public Inspector { // contain "unreachable", otherwise it means that we have // not executed a 'return' on all possible paths. if (!defs->isUnreachable()) - ::error(ErrorType::ERR_INSUFFICIENT, - "Function '%1%' does not return a value on all paths", func); + ::P4::error(ErrorType::ERR_INSUFFICIENT, + "Function '%1%' does not return a value on all paths", func); } currentPoint = point.after(); diff --git a/frontends/p4/simplifyParsers.cpp b/frontends/p4/simplifyParsers.cpp index 7a93d87dcb..d707511c77 100644 --- a/frontends/p4/simplifyParsers.cpp +++ b/frontends/p4/simplifyParsers.cpp @@ -42,7 +42,8 @@ class RemoveUnreachableStates : public Transform { const IR::Node *preorder(IR::P4Parser *parser) override { auto start = parser->getDeclByName(IR::ParserState::start); if (start == nullptr) { - ::error(ErrorType::ERR_NOT_FOUND, "%1%: parser does not have a `start' state", parser); + ::P4::error(ErrorType::ERR_NOT_FOUND, "%1%: parser does not have a `start' state", + parser); } else { transitions->reachable(start->to(), reachable); // Remove unreachable states from call-graph @@ -59,8 +60,8 @@ class RemoveUnreachableStates : public Transform { acceptReachable = true; } if (!rejectReachable && !acceptReachable) - ::error(ErrorType::ERR_UNREACHABLE, - "%1%: Parser never reaches accept or reject state", parser); + ::P4::error(ErrorType::ERR_UNREACHABLE, + "%1%: Parser never reaches accept or reject state", parser); LOG1("Parser " << dbp(parser) << " has " << transitions->size() << " reachable states"); } return parser; @@ -164,7 +165,7 @@ class CollapseChains : public Transform { while (true) { components->append(crt->components); select = crt->selectExpression; - crt = ::get(chain, crt); + crt = ::P4::get(chain, crt); if (crt == nullptr) break; LOG1("Adding " << dbp(crt) << " to chain"); } diff --git a/frontends/p4/specialize.h b/frontends/p4/specialize.h index 80b837dd3e..4722c5daef 100644 --- a/frontends/p4/specialize.h +++ b/frontends/p4/specialize.h @@ -87,7 +87,7 @@ class SpecializationMap { IR::Vector *getSpecializations(const IR::Node *insertion, const Visitor::Context *ctxt) const; cstring getName(const IR::Node *insertion) const { - auto s = ::get(specializations, insertion); + auto s = ::P4::get(specializations, insertion); if (s == nullptr) return nullptr; return s->name; } diff --git a/frontends/p4/specializeGenericFunctions.h b/frontends/p4/specializeGenericFunctions.h index 4f283f0bc4..75f0193979 100644 --- a/frontends/p4/specializeGenericFunctions.h +++ b/frontends/p4/specializeGenericFunctions.h @@ -63,7 +63,7 @@ struct FunctionSpecializationMap { map.emplace(mce, new FunctionSpecialization(name, mce, func, insert)); } FunctionSpecialization *get(const IR::MethodCallExpression *mce) const { - return ::get(map, mce); + return ::P4::get(map, mce); } IR::Vector *getInsertions(const IR::Node *insertionPoint) { IR::Vector *result = nullptr; diff --git a/frontends/p4/specializeGenericTypes.cpp b/frontends/p4/specializeGenericTypes.cpp index a046f59c78..fd8e85bce3 100644 --- a/frontends/p4/specializeGenericTypes.cpp +++ b/frontends/p4/specializeGenericTypes.cpp @@ -170,10 +170,10 @@ const IR::Node *ReplaceTypeUses::postorder(IR::Type_Specialized *type) { const IR::Node *ReplaceTypeUses::postorder(IR::StructExpression *expression) { auto st = getOriginal()->structType; if (!st) { - ::error(ErrorType::ERR_TYPE_ERROR, - "%1%: could not infer a type for expression; " - "please specify it explicitly", - expression); + ::P4::error(ErrorType::ERR_TYPE_ERROR, + "%1%: could not infer a type for expression; " + "please specify it explicitly", + expression); return expression; } auto spec = st->to(); diff --git a/frontends/p4/staticAssert.h b/frontends/p4/staticAssert.h index 5b89c5f61a..d4fed003b5 100644 --- a/frontends/p4/staticAssert.h +++ b/frontends/p4/staticAssert.h @@ -49,8 +49,8 @@ class DoStaticAssert : public Transform, public ResolutionContext { auto subst = ef->substitution; auto params = subst.getParametersInOrder(); if (!params->moveNext()) { - ::warning(ErrorType::WARN_INVALID, "static_assert with no arguments: %1%", - method); + ::P4::warning(ErrorType::WARN_INVALID, "static_assert with no arguments: %1%", + method); return method; } auto param = params->getCurrent(); @@ -69,7 +69,7 @@ class DoStaticAssert : public Transform, public ResolutionContext { message = sl->value.string_view(); } } - ::error(ErrorType::ERR_EXPECTED, "%1%: %2%", method, message); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: %2%", method, message); return method; } if (getContext()->node->is()) { @@ -78,8 +78,8 @@ class DoStaticAssert : public Transform, public ResolutionContext { } return new IR::BoolLiteral(method->srcInfo, true); } else { - ::error(ErrorType::ERR_UNEXPECTED, - "Could not evaluate static_assert to a constant: %1%", arg); + ::P4::error(ErrorType::ERR_UNEXPECTED, + "Could not evaluate static_assert to a constant: %1%", arg); return method; } } diff --git a/frontends/p4/strengthReduction.cpp b/frontends/p4/strengthReduction.cpp index e9e2dbc587..fe4b559065 100644 --- a/frontends/p4/strengthReduction.cpp +++ b/frontends/p4/strengthReduction.cpp @@ -257,7 +257,7 @@ const IR::Node *DoStrengthReduction::postorder(IR::Mul *expr) { const IR::Node *DoStrengthReduction::postorder(IR::Div *expr) { if (isZero(expr->right)) { - ::error(ErrorType::ERR_EXPRESSION, "%1%: Division by zero", expr); + ::P4::error(ErrorType::ERR_EXPRESSION, "%1%: Division by zero", expr); return expr; } if (isOne(expr->right)) return expr->left; @@ -273,7 +273,7 @@ const IR::Node *DoStrengthReduction::postorder(IR::Div *expr) { const IR::Node *DoStrengthReduction::postorder(IR::Mod *expr) { if (isZero(expr->right)) { - ::error(ErrorType::ERR_EXPRESSION, "%1%: Modulo by zero", expr); + ::P4::error(ErrorType::ERR_EXPRESSION, "%1%: Modulo by zero", expr); return expr; } if (isZero(expr->left) && !hasSideEffects(expr->right)) return expr->left; @@ -336,7 +336,7 @@ const IR::Node *DoStrengthReduction::postorder(IR::ArrayIndex *expr) { if (auto cst = expr->right->to()) { auto index = cst->asInt(); if (index < 0 || static_cast(index) >= hse->components.size()) { - ::error(ErrorType::ERR_EXPRESSION, "%1%: Index %2% out of bounds", index, expr); + ::P4::error(ErrorType::ERR_EXPRESSION, "%1%: Index %2% out of bounds", index, expr); return expr; } return hse->components.at(index); diff --git a/frontends/p4/symbol_table.cpp b/frontends/p4/symbol_table.cpp index 5d64425f07..167d7befce 100644 --- a/frontends/p4/symbol_table.cpp +++ b/frontends/p4/symbol_table.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/log.h" -namespace Util { +namespace P4::Util { using namespace P4::literals; @@ -76,16 +76,16 @@ class Namespace : public NamedSymbol { if (it != contents.end()) { // Check that both declarations have the same type if (!it->second->sameType(symbol)) { - ::error(ErrorType::ERR_DUPLICATE, - "Re-declaration of %1%%2% with different type: %3%", symbol->getName(), - symbol->getSourceInfo(), it->second->getSourceInfo()); + ::P4::error(ErrorType::ERR_DUPLICATE, + "Re-declaration of %1%%2% with different type: %3%", symbol->getName(), + symbol->getSourceInfo(), it->second->getSourceInfo()); return; } if (!allowDuplicates) { - ::error(ErrorType::ERR_DUPLICATE, - "Duplicate declaration of %1%%2%; previous at %3%", symbol->getName(), - symbol->getSourceInfo(), it->second->getSourceInfo()); + ::P4::error(ErrorType::ERR_DUPLICATE, + "Duplicate declaration of %1%%2%; previous at %3%", symbol->getName(), + symbol->getSourceInfo(), it->second->getSourceInfo()); return; } } @@ -288,4 +288,4 @@ void ProgramStructure::clear() { currentNamespace = rootNamespace; debugStream = stderr; } -} // namespace Util +} // namespace P4::Util diff --git a/frontends/p4/symbol_table.h b/frontends/p4/symbol_table.h index 3efba3a506..d89927e0a3 100644 --- a/frontends/p4/symbol_table.h +++ b/frontends/p4/symbol_table.h @@ -29,7 +29,7 @@ limitations under the License. #include "lib/cstring.h" #include "lib/source_file.h" -namespace Util { +namespace P4::Util { class NamedSymbol; class Namespace; @@ -87,5 +87,5 @@ class ProgramStructure final { void clear(); }; -} // namespace Util +} // namespace P4::Util #endif /* P4_SYMBOL_TABLE_H_ */ diff --git a/frontends/p4/tableKeyNames.cpp b/frontends/p4/tableKeyNames.cpp index 6be5f23fcf..dfc30daa1d 100644 --- a/frontends/p4/tableKeyNames.cpp +++ b/frontends/p4/tableKeyNames.cpp @@ -21,8 +21,8 @@ namespace P4 { using namespace literals; void KeyNameGenerator::error(const IR::Expression *expression) { - ::error(ErrorType::ERR_EXPECTED, "%1%: Complex key expression requires a @name annotation", - expression); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: Complex key expression requires a @name annotation", + expression); } void KeyNameGenerator::postorder(const IR::Expression *expression) { error(expression); } diff --git a/frontends/p4/tableKeyNames.h b/frontends/p4/tableKeyNames.h index 0a0627fb5d..5898e52b44 100644 --- a/frontends/p4/tableKeyNames.h +++ b/frontends/p4/tableKeyNames.h @@ -46,7 +46,7 @@ class KeyNameGenerator : public Inspector { void postorder(const IR::Slice *expression) override; void postorder(const IR::BAnd *expression) override; void postorder(const IR::MethodCallExpression *expression) override; - cstring getName(const IR::Expression *expression) { return ::get(name, expression); } + cstring getName(const IR::Expression *expression) { return ::P4::get(name, expression); } }; /** Adds a "@name" annotation to each table key that does not have a name. diff --git a/frontends/p4/typeChecking/bindVariables.cpp b/frontends/p4/typeChecking/bindVariables.cpp index 85a8b17a1b..4252aea40a 100644 --- a/frontends/p4/typeChecking/bindVariables.cpp +++ b/frontends/p4/typeChecking/bindVariables.cpp @@ -12,7 +12,7 @@ class ErrorOnInfInt : public Inspector { void postorder(const IR::Expression *expression) override { auto t = typeMap->getType(expression, true); if (t->is()) - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: could not infer a width", expression); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: could not infer a width", expression); } }; @@ -59,8 +59,8 @@ const IR::Type *DoBindTypeVariables::getVarValue(const IR::Type_Var *var, const IR::Node *errorPosition) const { auto type = typeMap->getSubstitution(var); if (type == nullptr) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: could not infer a type for variable %2%", - errorPosition, var); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: could not infer a type for variable %2%", + errorPosition, var); return nullptr; } auto result = validateType(type, typeMap, errorPosition, this); diff --git a/frontends/p4/typeChecking/constantTypeSubstitution.h b/frontends/p4/typeChecking/constantTypeSubstitution.h index 1d18eece3b..0048c16c8d 100644 --- a/frontends/p4/typeChecking/constantTypeSubstitution.h +++ b/frontends/p4/typeChecking/constantTypeSubstitution.h @@ -61,7 +61,7 @@ class ConstantTypeSubstitution : public Transform, ResolutionContext { const IR::Expression *convert(const IR::Expression *expr, const Visitor::Context *ctxt) { auto result = expr->apply(*this, ctxt)->to(); - if (result != expr && (::errorCount() == 0)) tc->learn(result, this, ctxt); + if (result != expr && (::P4::errorCount() == 0)) tc->learn(result, this, ctxt); return result; } const IR::Vector *convert(const IR::Vector *vec, diff --git a/frontends/p4/typeChecking/typeCheckDecl.cpp b/frontends/p4/typeChecking/typeCheckDecl.cpp index f440d65c6f..c4da306438 100644 --- a/frontends/p4/typeChecking/typeCheckDecl.cpp +++ b/frontends/p4/typeChecking/typeCheckDecl.cpp @@ -260,7 +260,7 @@ const IR::Node *TypeInference::preorder(IR::Declaration_Instance *decl) { return decl; } if (!simpleType->is() && (findContext() == nullptr)) { - ::error(ErrorType::ERR_INVALID, "%1%: cannot instantiate at top-level", decl); + ::P4::error(ErrorType::ERR_INVALID, "%1%: cannot instantiate at top-level", decl); return decl; } auto typeAndArgs = diff --git a/frontends/p4/typeChecking/typeCheckExpr.cpp b/frontends/p4/typeChecking/typeCheckExpr.cpp index f7ecbd7a34..2876edb875 100644 --- a/frontends/p4/typeChecking/typeCheckExpr.cpp +++ b/frontends/p4/typeChecking/typeCheckExpr.cpp @@ -460,7 +460,7 @@ const IR::Node *TypeInference::postorder(IR::Entry *entry) { if (tvs == nullptr) return entry; ConstantTypeSubstitution cts(tvs, typeMap, this); auto ks = cts.convert(keyset, getChildContext()); - if (::errorCount() > 0) return entry; + if (::P4::errorCount() > 0) return entry; if (ks != keyset) entry = new IR::Entry(entry->srcInfo, entry->annotations, entry->isConst, entry->priority, @@ -1456,7 +1456,7 @@ const IR::Node *TypeInference::postorder(IR::Mux *expression) { ConstantTypeSubstitution cts(tvs, typeMap, this); auto e1 = cts.convert(expression->e1, getChildContext()); auto e2 = cts.convert(expression->e2, getChildContext()); - if (::errorCount() > 0) return expression; + if (::P4::errorCount() > 0) return expression; expression->e1 = e1; expression->e2 = e2; secondType = typeMap->getType(e1); @@ -1790,7 +1790,7 @@ const IR::Expression *TypeInference::actionCall(bool inActionList, // This is like an assignment; may make additional conversions. newExpr = assignment(arg, param->type, arg->expression); } - if (::errorCount() > 0) return actionCall; + if (::P4::errorCount() > 0) return actionCall; if (newExpr != arg->expression) { LOG2("Changing action argument to " << newExpr); changed = true; @@ -1826,7 +1826,7 @@ const IR::Expression *TypeInference::actionCall(bool inActionList, ConstantTypeSubstitution cts(tvs, typeMap, this); actionCall = cts.convert(actionCall, getChildContext()) ->to(); // cast arguments - if (::errorCount() > 0) return actionCall; + if (::P4::errorCount() > 0) return actionCall; LOG2("Converted action " << actionCall); setType(actionCall, resultType); @@ -2027,7 +2027,7 @@ const IR::Node *TypeInference::postorder(IR::MethodCallExpression *expression) { // Insert casts for 'int' values. newExpr = cts.convert(newExpr, getChildContext())->to(); } - if (::errorCount() > 0) return expression; + if (::P4::errorCount() > 0) return expression; if (newExpr != arg->expression) { LOG2("Changing method argument to " << newExpr); changed = true; @@ -2159,7 +2159,7 @@ const IR::SelectCase *TypeInference::matchCase(const IR::SelectExpression *selec if (tvs == nullptr) return nullptr; ConstantTypeSubstitution cts(tvs, typeMap, this); auto ks = cts.convert(selectCase->keyset, getChildContext()); - if (::errorCount() > 0) return selectCase; + if (::P4::errorCount() > 0) return selectCase; if (ks != selectCase->keyset) selectCase = new IR::SelectCase(selectCase->srcInfo, ks, selectCase->state); diff --git a/frontends/p4/typeChecking/typeCheckTypes.cpp b/frontends/p4/typeChecking/typeCheckTypes.cpp index 56f3e48cd4..c2ef36c714 100644 --- a/frontends/p4/typeChecking/typeCheckTypes.cpp +++ b/frontends/p4/typeChecking/typeCheckTypes.cpp @@ -341,10 +341,11 @@ static bool checkEnumValueInitializer(const IR::Type_Bits *type, const IR::Expre constant->value % required % (type->isSigned ? "signed" : "unsigned") % type->toString() % type->size); } - ::error(ErrorType::ERR_TYPE_ERROR, - "%1%: Serialized enum constant value %2% is out of bounds of the underlying " - "type %3%; %4%", - member, constant->value, serEnum->type, extraMsg); + ::P4::error( + ErrorType::ERR_TYPE_ERROR, + "%1%: Serialized enum constant value %2% is out of bounds of the underlying " + "type %3%; %4%", + member, constant->value, serEnum->type, extraMsg); return false; } } diff --git a/frontends/p4/typeChecking/typeChecker.cpp b/frontends/p4/typeChecking/typeChecker.cpp index bd4f55944d..7098302221 100644 --- a/frontends/p4/typeChecking/typeChecker.cpp +++ b/frontends/p4/typeChecking/typeChecker.cpp @@ -42,9 +42,9 @@ bool TypeInference::learn(const IR::Node *node, Visitor *caller, const Visitor:: auto *learner = clone(); learner->setCalledBy(caller); learner->setName("TypeInference learner"); - unsigned previous = ::errorCount(); + unsigned previous = ::P4::errorCount(); (void)node->apply(*learner, ctxt); - unsigned errCount = ::errorCount(); + unsigned errCount = ::P4::errorCount(); bool result = errCount > previous; if (result) typeError("Error while analyzing %1%", node); return result; @@ -143,7 +143,7 @@ const IR::Type *TypeInference::getType(const IR::Node *element) const { // This should be happening only when type-checking already failed // for some node; we are now just trying to typecheck a parent node. // So an error should have already been signalled. - if ((result == nullptr) && (::errorCount() == 0)) + if ((result == nullptr) && (::P4::errorCount() == 0)) BUG("Could not find type of %1% %2%", dbp(element), element); return result; } @@ -152,7 +152,7 @@ const IR::Type *TypeInference::getTypeType(const IR::Node *element) const { const IR::Type *result = typeMap->getType(element); // See comment in getType() above. if (result == nullptr) { - if (::errorCount() == 0) BUG("Could not find type of %1%", element); + if (::P4::errorCount() == 0) BUG("Could not find type of %1%", element); return nullptr; } BUG_CHECK(result->is(), "%1%: expected a TypeType", dbp(result)); @@ -263,7 +263,7 @@ const IR::Type *TypeInference::canonicalize(const IR::Type *type) { auto et = canonicalize(set->elementType); if (et == nullptr) return nullptr; if (et->is() || et->is() || et->is()) - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: Sets of %2% are not supported", type, et); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: Sets of %2% are not supported", type, et); if (et == set->elementType) return type; const IR::Type *canon = new IR::Type_Set(type->srcInfo, et); return canon; @@ -473,7 +473,7 @@ const IR::Type *TypeInference::canonicalize(const IR::Type *type) { learn(result, this, getChildContext()); return result; } else { - BUG_CHECK(::errorCount(), "Unexpected type %1%", dbp(type)); + BUG_CHECK(::P4::errorCount(), "Unexpected type %1%", dbp(type)); } // If we reach this point some type error must have occurred, because @@ -780,7 +780,7 @@ std::pair *> TypeInference::che auto tvs = unify(errorPosition, methodType, callType, "Constructor invocation %1% does not match constructor declaration %2%", {callType, constructor}); - BUG_CHECK(tvs != nullptr || ::errorCount(), "Unification failed with no error"); + BUG_CHECK(tvs != nullptr || ::P4::errorCount(), "Unification failed with no error"); if (tvs == nullptr) return none; LOG2("Constructor type before specialization " << methodType << " with " << tvs); @@ -823,7 +823,7 @@ std::pair *> TypeInference::che // Insert casts for 'int' values. newExpr = cts.convert(newExpr, getChildContext())->to(); } - if (::errorCount() > 0) return none; + if (::P4::errorCount() > 0) return none; if (newExpr != arg->expression) { LOG2("Changing method argument to " << newExpr); changed = true; @@ -899,7 +899,7 @@ std::pair *> TypeInference::con auto tvs = unify(container->getNode(), constructor, callType, "Constructor invocation '%1%' does not match declaration '%2%'", {callType, constructor}); - BUG_CHECK(tvs != nullptr || ::errorCount(), "Null substitution"); + BUG_CHECK(tvs != nullptr || ::P4::errorCount(), "Null substitution"); if (tvs == nullptr) return std::pair *>(nullptr, nullptr); diff --git a/frontends/p4/typeChecking/typeChecker.h b/frontends/p4/typeChecking/typeChecker.h index ba53367075..8850b47be0 100644 --- a/frontends/p4/typeChecking/typeChecker.h +++ b/frontends/p4/typeChecking/typeChecker.h @@ -60,7 +60,7 @@ class TypeChecking : public PassManager { template void typeError(const char *format, Args &&...args) { - ::error(ErrorType::ERR_TYPE_ERROR, format, std::forward(args)...); + ::P4::error(ErrorType::ERR_TYPE_ERROR, format, std::forward(args)...); } /// True if the type contains any varbit or header_union subtypes bool hasVarbitsOrUnions(const TypeMap *typeMap, const IR::Type *type); diff --git a/frontends/p4/typeChecking/typeConstraints.cpp b/frontends/p4/typeChecking/typeConstraints.cpp index 71144722bb..adb0f7ad91 100644 --- a/frontends/p4/typeChecking/typeConstraints.cpp +++ b/frontends/p4/typeChecking/typeConstraints.cpp @@ -131,24 +131,24 @@ std::string TypeConstraint::localError(Explain *explainer) const { break; case 1: absl::StrAppend(&explanation, explain(0, explainer)); - message = ::error_helper(fmt, errArguments.at(0)).toString(); + message = ::P4::error_helper(fmt, errArguments.at(0)).toString(); break; case 2: absl::StrAppend(&explanation, explain(0, explainer), explain(1, explainer)); - message = ::error_helper(fmt, errArguments.at(0), errArguments.at(1)).toString(); + message = ::P4::error_helper(fmt, errArguments.at(0), errArguments.at(1)).toString(); break; case 3: absl::StrAppend(&explanation, explain(0, explainer), explain(1, explainer), explain(2, explainer)); message = - ::error_helper(fmt, errArguments.at(0), errArguments.at(1), errArguments.at(2)) + ::P4::error_helper(fmt, errArguments.at(0), errArguments.at(1), errArguments.at(2)) .toString(); break; case 4: absl::StrAppend(&explanation, explain(0, explainer), explain(1, explainer), explain(2, explainer), explain(3, explainer)); - message = ::error_helper(fmt, errArguments.at(0), errArguments.at(1), - errArguments.at(2), errArguments.at(3)) + message = ::P4::error_helper(fmt, errArguments.at(0), errArguments.at(1), + errArguments.at(2), errArguments.at(3)) .toString(); break; default: @@ -180,7 +180,7 @@ bool TypeConstraint::reportErrorImpl(const TypeVariableSubstitution *subst, if (lastIsEmpty) message += "\n"; CHECK_NULL(o); - ::errorWithSuffix(ErrorType::ERR_TYPE_ERROR, "'%1%'", message.c_str(), o); + ::P4::errorWithSuffix(ErrorType::ERR_TYPE_ERROR, "'%1%'", message.c_str(), o); return false; } diff --git a/frontends/p4/typeChecking/typeConstraints.h b/frontends/p4/typeChecking/typeConstraints.h index 17c99b8dfb..6cda85f4ad 100644 --- a/frontends/p4/typeChecking/typeConstraints.h +++ b/frontends/p4/typeChecking/typeConstraints.h @@ -93,9 +93,9 @@ class TypeConstraint : public IHasDbPrint, public ICastable { /// has no 'derivedFrom' field, and it contains the actual source /// position where the analysis started. boost::format fmt(format); - return reportErrorImpl( - subst, - " ---- Actual error:\n" + ::error_helper(fmt, std::forward(args)...).toString()); + return reportErrorImpl(subst, + " ---- Actual error:\n" + + ::P4::error_helper(fmt, std::forward(args)...).toString()); } // Default error message; returns 'false' virtual bool reportError(const TypeVariableSubstitution *subst) const = 0; diff --git a/frontends/p4/typeChecking/typeSubstitution.cpp b/frontends/p4/typeChecking/typeSubstitution.cpp index 75d3009602..281e13f49e 100644 --- a/frontends/p4/typeChecking/typeSubstitution.cpp +++ b/frontends/p4/typeChecking/typeSubstitution.cpp @@ -107,8 +107,8 @@ bool TypeVariableSubstitution::setBindings(const IR::Node *errorLocation, if (params == nullptr || args == nullptr) BUG("Nullptr argument to setBindings"); if (params->parameters.size() != args->size()) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1% has %2% type parameters, invoked with %3%", - errorLocation, params->parameters.size(), args->size()); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1% has %2% type parameters, invoked with %3%", + errorLocation, params->parameters.size(), args->size()); return false; } @@ -119,7 +119,8 @@ bool TypeVariableSubstitution::setBindings(const IR::Node *errorLocation, bool success = setBinding(tp, t); if (!success) { - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: Cannot bind %2% to %3%", errorLocation, tp, t); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: Cannot bind %2% to %3%", errorLocation, tp, + t); return false; } } diff --git a/frontends/p4/typeChecking/typeSubstitution.h b/frontends/p4/typeChecking/typeSubstitution.h index 42309d7efc..639cf907dc 100644 --- a/frontends/p4/typeChecking/typeSubstitution.h +++ b/frontends/p4/typeChecking/typeSubstitution.h @@ -38,8 +38,8 @@ class TypeSubstitution : public IHasDbPrint { /** True if this is the empty substitution, which does not replace anything. */ bool isIdentity() const { return binding.size() == 0; } - const IR::Type *lookup(T t) const { return ::get(binding, t); } - const IR::Type *get(T t) const { return ::get(binding, t); } + const IR::Type *lookup(T t) const { return ::P4::get(binding, t); } + const IR::Type *get(T t) const { return ::P4::get(binding, t); } bool containsKey(T key) const { return binding.find(key) != binding.end(); } diff --git a/frontends/p4/typeChecking/typeSubstitutionVisitor.h b/frontends/p4/typeChecking/typeSubstitutionVisitor.h index 57a4814612..6b3e216536 100644 --- a/frontends/p4/typeChecking/typeSubstitutionVisitor.h +++ b/frontends/p4/typeChecking/typeSubstitutionVisitor.h @@ -93,4 +93,5 @@ class TypeSubstitutionVisitor : public TypeVariableSubstitutionVisitor { }; } // namespace P4 + #endif /* TYPECHECKING_TYPESUBSTITUTIONVISITOR_H_ */ diff --git a/frontends/p4/typeMap.cpp b/frontends/p4/typeMap.cpp index 196ed2a4b5..9d0c91bb61 100644 --- a/frontends/p4/typeMap.cpp +++ b/frontends/p4/typeMap.cpp @@ -160,13 +160,13 @@ bool TypeMap::equivalent(const IR::Type *left, const IR::Type *right, bool stric if (auto ls = left->to()) { auto rs = right->to(); if (!ls->sizeKnown()) { - ::error(ErrorType::ERR_TYPE_ERROR, - "%1%: Size of header stack type should be a constant", left); + ::P4::error(ErrorType::ERR_TYPE_ERROR, + "%1%: Size of header stack type should be a constant", left); return false; } if (!rs->sizeKnown()) { - ::error(ErrorType::ERR_TYPE_ERROR, - "%1%: Size of header stack type should be a constant", right); + ::P4::error(ErrorType::ERR_TYPE_ERROR, + "%1%: Size of header stack type should be a constant", right); return false; } return equivalent(ls->elementType, rs->elementType, strict) && @@ -294,7 +294,7 @@ bool TypeMap::equivalent(const IR::Type *left, const IR::Type *right, bool stric return equivalent(lf->type, rf->type); } - BUG_CHECK(::errorCount(), "%1%: Unexpected type check for equivalence", dbp(left)); + BUG_CHECK(::P4::errorCount(), "%1%: Unexpected type check for equivalence", dbp(left)); // The following are not expected to be compared for equivalence: // Type_Dontcare, Type_Unknown, Type_Name, Type_Specialized, Type_Typedef return false; @@ -395,8 +395,8 @@ int TypeMap::widthBits(const IR::Type *type, const IR::Node *errorPosition, bool auto w = widthBits(ths->elementType, errorPosition, max); return w * ths->getSize(); } - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: width not well-defined for values of type %2%", - errorPosition, t); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: width not well-defined for values of type %2%", + errorPosition, t); return -1; } diff --git a/frontends/p4/uniqueNames.cpp b/frontends/p4/uniqueNames.cpp index f94317b42d..3a97aeb3cb 100644 --- a/frontends/p4/uniqueNames.cpp +++ b/frontends/p4/uniqueNames.cpp @@ -32,7 +32,7 @@ void RenameMap::setNewName(const IR::IDeclaration *decl, cstring name, bool allo const IR::P4Action *RenameMap::actionCalled(const IR::MethodCallExpression *expression) const { CHECK_NULL(expression); - return ::get(actionCall, expression); + return ::P4::get(actionCall, expression); } void RenameMap::markActionCall(const IR::P4Action *action, const IR::MethodCallExpression *call) { diff --git a/frontends/p4/validateMatchAnnotations.h b/frontends/p4/validateMatchAnnotations.h index 3f2a953a9d..0485ca70bb 100644 --- a/frontends/p4/validateMatchAnnotations.h +++ b/frontends/p4/validateMatchAnnotations.h @@ -37,13 +37,13 @@ class ValidateMatchAnnotations final : public Inspector { if (annotation->name != IR::Annotation::matchAnnotation) return; if (!findContext()) return; if (annotation->expr.size() != 1) - ::error(ErrorType::ERR_INVALID, "%1%: annotation must have exactly 1 argument", - annotation); + ::P4::error(ErrorType::ERR_INVALID, "%1%: annotation must have exactly 1 argument", + annotation); auto e0 = annotation->expr.at(0); auto type = typeMap->getType(e0, true); if (type == nullptr) return; if (!type->is()) - ::error(ErrorType::ERR_TYPE_ERROR, "%1%: value must be a match_kind", e0); + ::P4::error(ErrorType::ERR_TYPE_ERROR, "%1%: value must be a match_kind", e0); } }; diff --git a/frontends/p4/validateParsedProgram.cpp b/frontends/p4/validateParsedProgram.cpp index 038c5d82b7..a05df83add 100644 --- a/frontends/p4/validateParsedProgram.cpp +++ b/frontends/p4/validateParsedProgram.cpp @@ -30,20 +30,21 @@ void ValidateParsedProgram::postorder(const IR::Constant *c) { /// Check that extern constructor names match the enclosing extern void ValidateParsedProgram::postorder(const IR::Method *m) { if (m->name.isDontCare()) - ::error(ErrorType::ERR_INVALID, "%1%: invalid method/function name.", m->name); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid method/function name.", m->name); if (auto ext = findContext()) { if (m->name == ext->name && m->type->returnType != nullptr) - ::error(ErrorType::ERR_INVALID, "%1%: invalid constructor; cannot have a return type.", - m); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid constructor; cannot have a return type.", m); if (m->type->returnType == nullptr) { if (m->name != ext->name) { - ::error(ErrorType::ERR_INVALID, "%1%: invalid type; method has no return type.", m); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type; method has no return type.", + m); return; } for (auto p : *m->type->parameters) if (p->direction != IR::Direction::None) - ::error(ErrorType::ERR_INVALID, - "%1%: Constructor parameters cannot have a direction.", p); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: Constructor parameters cannot have a direction.", p); } } } @@ -56,13 +57,15 @@ void ValidateParsedProgram::postorder(const IR::Annotations *annotations) { for (auto a : annotations->annotations) { if (!a->structured) continue; if (namesUsed.count(a->name) > 1) - ::error(ErrorType::ERR_DUPLICATE, "%1%: duplicate name for structured annotation", a); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: duplicate name for structured annotation", + a); } } /// Struct field names cannot be underscore void ValidateParsedProgram::postorder(const IR::StructField *f) { - if (f->name.isDontCare()) ::error(ErrorType::ERR_INVALID, "%1%: invalid field name", f->name); + if (f->name.isDontCare()) + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid field name", f->name); } /// Width of a bit<> or int<> type is greater than 0 @@ -70,23 +73,23 @@ void ValidateParsedProgram::postorder(const IR::Type_Bits *type) { if (type->expression) // cannot validate yet return; - if (type->size < 0) ::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); + if (type->size < 0) ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); if (type->size == 0 && type->isSigned) - ::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); } void ValidateParsedProgram::postorder(const IR::Type_Varbits *type) { if (type->expression) // cannot validate yet return; - if (type->size < 0) ::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); + if (type->size < 0) ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type size", type); } /// The accept and reject states cannot be implemented void ValidateParsedProgram::postorder(const IR::ParserState *s) { if (s->name == IR::ParserState::accept || s->name == IR::ParserState::reject) - ::error(ErrorType::ERR_INVALID, - "Invalid parser state: %1% should not be implemented, it is built-in", s->name); + ::P4::error(ErrorType::ERR_INVALID, + "Invalid parser state: %1% should not be implemented, it is built-in", s->name); } /// All parameters of a constructor must be directionless. @@ -94,16 +97,17 @@ void ValidateParsedProgram::postorder(const IR::ParserState *s) { void ValidateParsedProgram::container(const IR::IContainer *type) { for (auto p : type->getConstructorParameters()->parameters) if (p->direction != IR::Direction::None) - ::error(ErrorType::ERR_INVALID, - "%1%: invalid direction. Constructor parameters cannot have a direction", p); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid direction. Constructor parameters cannot have a direction", + p); } /// Tables must have an 'actions' property. void ValidateParsedProgram::postorder(const IR::P4Table *t) { auto ac = t->getActionList(); if (ac == nullptr) - ::error(ErrorType::ERR_EXPECTED, "%1%: expected '%2%' property", t->name, - IR::TableProperties::actionsPropertyName); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected '%2%' property", t->name, + IR::TableProperties::actionsPropertyName); } /// Checks that the names of the three parameter lists for some constructs @@ -116,12 +120,12 @@ void ValidateParsedProgram::distinctParameters(const IR::TypeParameters *typePar for (auto p : typeParams->parameters) found.emplace(p->getName(), p); for (auto p : apply->parameters) { auto [it, inserted] = found.emplace(p->getName(), p); - if (!inserted) ::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.", it->second, p); + if (!inserted) ::P4::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.", it->second, p); } for (auto p : constr->parameters) { auto it = found.find(p->getName()); if (it != found.end()) - ::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.", it->second, p); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.", it->second, p); } } @@ -129,14 +133,14 @@ void ValidateParsedProgram::distinctParameters(const IR::TypeParameters *typePar void ValidateParsedProgram::postorder(const IR::ConstructorCallExpression *expression) { auto inAction = findContext(); if (inAction != nullptr) - ::error(ErrorType::ERR_INVALID, - "%1%: invalid call. Constructor calls not allowed in actions.", expression); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid call. Constructor calls not allowed in actions.", expression); } /// Variable names cannot be underscore void ValidateParsedProgram::postorder(const IR::Declaration_Variable *decl) { if (decl->name.isDontCare()) - ::error(ErrorType::ERR_INVALID, "%1%: invalid variable name.", decl); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid variable name.", decl); } /// Instance names cannot be don't care @@ -144,40 +148,40 @@ void ValidateParsedProgram::postorder(const IR::Declaration_Variable *decl) { void ValidateParsedProgram::postorder(const IR::Declaration_Instance *decl) { if (!decl->type->is() && !decl->type->is() && !decl->type->is()) // P4_14 only? - ::error(ErrorType::ERR_INVALID, "%1%: invalid type for declaration", decl->type); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid type for declaration", decl->type); if (decl->name.isDontCare()) - ::error(ErrorType::ERR_INVALID, "%1%: invalid instance name.", decl); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid instance name.", decl); if (findContext() && // we're looking for the apply block findContext() && // of a control !findContext()) { // but not in an instance initializer - ::error(ErrorType::ERR_INVALID, - "%1%: invalid declaration. Instantiations cannot be in a control 'apply' block.", - decl); + ::P4::error( + ErrorType::ERR_INVALID, + "%1%: invalid declaration. Instantiations cannot be in a control 'apply' block.", decl); } if (findContext()) - ::error(ErrorType::ERR_INVALID, - "%1%: invalid declaration. Instantiations cannot be in a parser state.", decl); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid declaration. Instantiations cannot be in a parser state.", decl); if (findContext() || findContext()) - ::error(ErrorType::ERR_INVALID, - "%1%: invalid declaration. Instantiations cannot be in a function or method.", - decl); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid declaration. Instantiations cannot be in a function or method.", + decl); auto inAction = findContext(); if (inAction != nullptr) - ::error(ErrorType::ERR_INVALID, "%1%: declaration. Instantiations not allowed in actions.", - decl); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: declaration. Instantiations not allowed in actions.", decl); } /// Constant names cannot be underscore void ValidateParsedProgram::postorder(const IR::Declaration_Constant *decl) { if (decl->name.isDontCare()) - ::error(ErrorType::ERR_INVALID, "%1%: invalid constant name.", decl); + ::P4::error(ErrorType::ERR_INVALID, "%1%: invalid constant name.", decl); } void ValidateParsedProgram::postorder(const IR::EntriesList *l) { auto table = findContext(); if (table == nullptr) { - ::error(ErrorType::ERR_INVALID, - "%1%: invalid entries list. Table entries must belong to a table.", l); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid entries list. Table entries must belong to a table.", l); return; } } @@ -188,12 +192,13 @@ void ValidateParsedProgram::postorder(const IR::SwitchStatement *statement) { for (auto c : statement->cases) { if (defaultFound != nullptr) { if (c->label->is()) - ::error(ErrorType::ERR_INVALID, "%1%switch has multiple 'default' labels:%2%%3%", - statement->srcInfo, defaultFound->label->srcInfo, c->label->srcInfo); + ::P4::error(ErrorType::ERR_INVALID, + "%1%switch has multiple 'default' labels:%2%%3%", statement->srcInfo, + defaultFound->label->srcInfo, c->label->srcInfo); else - ::error(ErrorType::ERR_INVALID, - "%1%switch label %2% follows 'default' label, which is not allowed.%3%", - statement->srcInfo, c->label, defaultFound->label->srcInfo); + ::P4::error(ErrorType::ERR_INVALID, + "%1%switch label %2% follows 'default' label, which is not allowed.%3%", + statement->srcInfo, c->label, defaultFound->label->srcInfo); break; } if (c->label->is()) defaultFound = c; @@ -205,9 +210,9 @@ void ValidateParsedProgram::postorder(const IR::ReturnStatement *statement) { if (!findContext()) { auto inParser = findContext(); if (inParser != nullptr) - ::error(ErrorType::ERR_INVALID, - "%1%: invalid statement. 'return' statements not allowed in parsers.", - statement); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid statement. 'return' statements not allowed in parsers.", + statement); } } @@ -215,11 +220,12 @@ void ValidateParsedProgram::postorder(const IR::ReturnStatement *statement) { void ValidateParsedProgram::postorder(const IR::ExitStatement *statement) { auto inParser = findContext(); if (inParser != nullptr) - ::error(ErrorType::ERR_INVALID, - "%1%: invalid statement. 'exit' statements not allowed in parsers.", statement); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: invalid statement. 'exit' statements not allowed in parsers.", statement); if (findContext()) - ::error(ErrorType::ERR_INVALID, - "%1% invalid statement. 'exit' statements not allowed in functions.", statement); + ::P4::error(ErrorType::ERR_INVALID, + "%1% invalid statement. 'exit' statements not allowed in functions.", + statement); } void ValidateParsedProgram::postorder(const IR::P4Program *program) { @@ -230,8 +236,8 @@ void ValidateParsedProgram::postorder(const IR::P4Program *program) { if (existing != nullptr) { if (!existing->is() || !decl->is() || existing->typeId() != decl->typeId() || decl->is()) { - ::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.", decl->getName(), - existing->getName()); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1% duplicates %2%.", decl->getName(), + existing->getName()); } } else { declarations.push_back(decl->getNode()); @@ -245,21 +251,21 @@ void ValidateParsedProgram::postorder(const IR::Dots *dots) { if (context->node->is()) { auto list = context->node->to(); if (context->child_index != (int)list->size() - 1) - ::error(ErrorType::ERR_INVALID, "%1% must be the last element", dots); + ::P4::error(ErrorType::ERR_INVALID, "%1% must be the last element", dots); } } /// Check that continue and break statements are only used in the context of a for statement. void ValidateParsedProgram::postorder(const IR::BreakStatement *s) { if (!findContext() && !findContext()) - ::error(ErrorType::ERR_INVALID, - "%1%: break statement must be used in the context of a for statement.", s); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: break statement must be used in the context of a for statement.", s); } void ValidateParsedProgram::postorder(const IR::ContinueStatement *s) { if (!findContext() && !findContext()) - ::error(ErrorType::ERR_INVALID, - "%1%: continue statement must be used in the context of a for statement.", s); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: continue statement must be used in the context of a for statement.", s); } } // namespace P4 diff --git a/frontends/p4/validateParsedProgram.h b/frontends/p4/validateParsedProgram.h index 62d1ac41be..7eb0b23d52 100644 --- a/frontends/p4/validateParsedProgram.h +++ b/frontends/p4/validateParsedProgram.h @@ -85,7 +85,7 @@ class ValidateParsedProgram final : public Inspector { void postorder(const IR::P4Parser *parser) override { auto start = parser->states.getDeclaration(IR::ParserState::start); if (!start) { - ::error(ErrorType::ERR_INVALID, "Parser %1% has no 'start' state", parser); + ::P4::error(ErrorType::ERR_INVALID, "Parser %1% has no 'start' state", parser); } container(parser); distinctParameters(parser->getTypeParameters(), parser->getApplyParameters(), diff --git a/frontends/p4/validateValueSets.h b/frontends/p4/validateValueSets.h index 65963853bf..5a706ceb57 100644 --- a/frontends/p4/validateValueSets.h +++ b/frontends/p4/validateValueSets.h @@ -31,8 +31,8 @@ class ValidateValueSets final : public Inspector { ValidateValueSets() { setName("ValidateValueSets"); } void postorder(const IR::P4ValueSet *valueSet) override { if (!valueSet->size->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: value_set size must be constant", - valueSet->size); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: value_set size must be constant", + valueSet->size); } } }; diff --git a/frontends/parsers/p4/p4lexer.ll b/frontends/parsers/p4/p4lexer.ll index c4143540b6..89acaca2d8 100644 --- a/frontends/parsers/p4/p4lexer.ll +++ b/frontends/parsers/p4/p4lexer.ll @@ -4,6 +4,8 @@ #include "frontends/parsers/p4/p4lexer_internal.hpp" #include "frontends/parsers/p4/p4parser.hpp" +using namespace P4; + using Parser = P4::P4Parser; #undef YY_DECL diff --git a/frontends/parsers/p4/p4parser.ypp b/frontends/parsers/p4/p4parser.ypp index 512323eab7..b43b091a66 100644 --- a/frontends/parsers/p4/p4parser.ypp +++ b/frontends/parsers/p4/p4parser.ypp @@ -73,9 +73,8 @@ struct OptionalConst { explicit OptionalConst(bool isConst) : isConst(isConst) { } bool isConst = false; }; -} // namespace P4 -inline std::ostream& operator<<(std::ostream& out, const P4::OptionalConst& oc) { +inline std::ostream& operator<<(std::ostream& out, const OptionalConst& oc) { out << "OptionalConst(" << oc.isConst << ')'; return out; } @@ -87,6 +86,8 @@ inline std::ostream& operator<<(std::ostream& out, const P4::OptionalConst& oc) // forbidden in C++. We avoid the problem using a typedef. typedef const IR::Type ConstType; +} // namespace P4 + #ifndef YYDEBUG #define YYDEBUG 1 #endif @@ -114,12 +115,13 @@ class Token { : type(type), text(text), unparsedConstant(unparsedConstant) { } }; -} // namespace P4 - -inline std::ostream& operator<<(std::ostream& out, const P4::Token& t) { +inline std::ostream& operator<<(std::ostream& out, const Token& t) { out << t.text; return out; } + +} // namespace P4 + } %param { P4::P4ParserDriver& driver } @@ -134,6 +136,8 @@ inline std::ostream& operator<<(std::ostream& out, const P4::Token& t) { #include "frontends/parsers/p4/p4lexer.hpp" #include "frontends/parsers/p4/p4parser.hpp" +using namespace P4; + #define YYLLOC_DEFAULT(Cur, Rhs, N) \ ((Cur) = (N) ? YYRHSLOC(Rhs, 1) + YYRHSLOC(Rhs, N) \ : Util::SourceInfo(driver.sources, YYRHSLOC(Rhs, 0).getEnd())) @@ -1701,7 +1705,11 @@ r_angle : ">" | R_ANGLE_SHIFT ; %% -void P4::P4Parser::error(const Util::SourceInfo& location, - const std::string& message) { +namespace P4 { + +void P4Parser::error(const Util::SourceInfo& location, + const std::string& message) { driver.onParseError(location, message); } + +} // namespace P4 diff --git a/frontends/parsers/parserDriver.cpp b/frontends/parsers/parserDriver.cpp index e63e6e008f..96e9d3a2a9 100644 --- a/frontends/parsers/parserDriver.cpp +++ b/frontends/parsers/parserDriver.cpp @@ -43,10 +43,12 @@ struct AutoStdioInputStream { std::istream stream; }; -} // anonymous namespace +} // namespace #else +namespace { + /// A RAII helper class that provides an istream wrapper for a stdio FILE*. This /// is an inefficient fallback implementation. struct AutoStdioInputStream { @@ -61,6 +63,8 @@ struct AutoStdioInputStream { std::stringstream stream; }; +} // namespace + #endif namespace P4 { @@ -280,7 +284,7 @@ void P4ParserDriver::onReadErrorDeclaration(IR::Type_Error *error) { } // namespace P4 -namespace V1 { +namespace P4::V1 { V1ParserDriver::V1ParserDriver() : global(new IR::V1Program) {} @@ -343,4 +347,4 @@ const IR::Annotations *V1ParserDriver::takePragmasAsAnnotations() { return rv; } -} // namespace V1 +} // namespace P4::V1 diff --git a/frontends/parsers/parserDriver.h b/frontends/parsers/parserDriver.h index 9b22e65aaa..c930794ecb 100644 --- a/frontends/parsers/parserDriver.h +++ b/frontends/parsers/parserDriver.h @@ -219,7 +219,7 @@ class P4ParserDriver final : public AbstractParserDriver { } // namespace P4 -namespace V1 { +namespace P4::V1 { class V1Lexer; class V1Parser; @@ -290,6 +290,6 @@ class V1ParserDriver final : public P4::AbstractParserDriver { V1ParserDriver(); }; -} // namespace V1 +} // namespace P4::V1 #endif /* FRONTENDS_PARSERS_PARSERDRIVER_H_ */ diff --git a/frontends/parsers/v1/v1lexer.ll b/frontends/parsers/v1/v1lexer.ll index 7688281df0..4a9c86c1a6 100644 --- a/frontends/parsers/v1/v1lexer.ll +++ b/frontends/parsers/v1/v1lexer.ll @@ -4,6 +4,8 @@ #include "frontends/parsers/v1/v1lexer_internal.hpp" #include "frontends/parsers/v1/v1parser.hpp" +using namespace P4; + using Parser = V1::V1Parser; #undef YY_DECL diff --git a/frontends/parsers/v1/v1lexer_internal.hpp b/frontends/parsers/v1/v1lexer_internal.hpp index 4a38df013e..d8e06dec57 100644 --- a/frontends/parsers/v1/v1lexer_internal.hpp +++ b/frontends/parsers/v1/v1lexer_internal.hpp @@ -7,7 +7,7 @@ #include "frontends/parsers/v1/v1parser.hpp" #include "lib/source_file.h" -namespace V1 { +namespace P4::V1 { class V1ParserDriver; @@ -49,6 +49,6 @@ class V1Lexer : public v1FlexLexer { int yylex() override { return v1FlexLexer::yylex(); } }; -} // namespace V1 +} // namespace P4::V1 #endif /* FRONTENDS_PARSERS_V1_V1LEXER_INTERNAL_HPP_ */ diff --git a/frontends/parsers/v1/v1parser.ypp b/frontends/parsers/v1/v1parser.ypp index 189ed441e4..140a687332 100644 --- a/frontends/parsers/v1/v1parser.ypp +++ b/frontends/parsers/v1/v1parser.ypp @@ -20,8 +20,9 @@ limitations under the License. // Set up names. %defines -%define api.namespace {V1} +%define api.namespace {P4::V1} // TODO: Update, once we drop Ubuntu 18.04 support. +// %define api.parser.class {V1Parser} %define parser_class_name {V1Parser} // Use the C++-native variant representation of tokens. @@ -38,6 +39,7 @@ limitations under the License. %code requires { #include "ir/ir.h" +namespace P4 { namespace V1 { class V1Lexer; class V1ParserDriver; @@ -95,6 +97,8 @@ inline std::ostream& operator<<(std::ostream& out, const CaseValue& caseValue) { // forbidden in C++. We avoid the problem using a typedef. typedef const IR::Type ConstType; +} // namespace P4 + #ifndef YYDEBUG #define YYDEBUG 1 #endif @@ -107,12 +111,12 @@ typedef const IR::Type ConstType; #include "lib/source_file.h" } -%param { V1::V1ParserDriver& driver } -%parse-param { V1::V1Lexer& lexer } +%param { P4::V1::V1ParserDriver& driver } +%parse-param { P4::V1::V1Lexer& lexer } // Use location tracking with our custom location type. %locations -%define api.location.type {Util::SourceInfo} +%define api.location.type {P4::Util::SourceInfo} %{ /* -*-C++-*- */ #include // NOLINT(build/include_order) @@ -122,13 +126,22 @@ typedef const IR::Type ConstType; #include "frontends/parsers/v1/v1parser.hpp" #include "ir/ir.h" +using namespace P4; + #define YYLLOC_DEFAULT(Cur, Rhs, N) \ ((Cur) = (N) ? YYRHSLOC(Rhs, 1) + YYRHSLOC(Rhs, N) \ : Util::SourceInfo(driver.sources, YYRHSLOC(Rhs, 0).getEnd())) #undef yylex #define yylex lexer.yylex + +namespace P4 { + static const IR::Expression *removeRedundantValid(const IR::Expression *e); + +} // namespace P4 + + %} // Use iostreams to print all values. We have a number of semantic actions that @@ -430,21 +443,21 @@ field_list_calculation_body: /* epsilon */ { $$ = new IR::FieldListCalculation(driver.takePragmasAsAnnotations()); } | field_list_calculation_body INPUT "{" field_list_list "}" { if ($1->input) - ::error(ErrorType::ERR_INVALID, "%s: multiple 'input' in field_list_calculation", @2); + ::P4::error(ErrorType::ERR_INVALID, "%s: multiple 'input' in field_list_calculation", @2); ($$=$1)->input = $4; } | field_list_calculation_body ALGORITHM ":" name ";" { if ($1->algorithm) - ::error(ErrorType::ERR_INVALID, + ::P4::error(ErrorType::ERR_INVALID, "%s: multiple 'algorithm' in field_list_calculation", @2); ($$=$1)->algorithm = new IR::NameList(@4, IR::ID(@4, $4)); } | field_list_calculation_body ALGORITHM "{" action_list "}" { if ($1->algorithm) - ::error(ErrorType::ERR_INVALID, + ::P4::error(ErrorType::ERR_INVALID, "%s: multiple 'algorithm' in field_list_calculation", @2); ($$=$1)->algorithm = $4; } | field_list_calculation_body OUTPUT_WIDTH ":" const_expression ";" { if ($1->output_width) - ::error(ErrorType::ERR_INVALID, + ::P4::error(ErrorType::ERR_INVALID, "%s: multiple 'output_width' in field_list_calculation", @2); ($$=$1)->output_width = $4 ? $4->asInt() : 0; } | field_list_calculation_body error ";" { $$ = $1; } @@ -545,7 +558,7 @@ case_value: parser_exception_declaration: PARSER_EXCEPTION name "{" parser_statement_list "}" { driver.clearPragmas(); - ::warning(ErrorType::WARN_UNSUPPORTED, + ::P4::warning(ErrorType::WARN_UNSUPPORTED, "%1%: parser exception is not translated to P4-16", $1); } | PARSER_EXCEPTION name "{" parser_statement_list error END @@ -565,12 +578,12 @@ counter_spec_list: { ($$ = new IR::Counter(driver.takePragmasAsAnnotations()))->settype($3); } | counter_spec_list DIRECT ":" name ";" { if (($$=$1)->table) - ::error(ErrorType::ERR_INVALID, "%s: Can't attach counter to two tables", @2+@4); + ::P4::error(ErrorType::ERR_INVALID, "%s: Can't attach counter to two tables", @2+@4); $$->table = IR::ID(@4, $4); $$->direct = true; } | counter_spec_list STATIC ":" name ";" { if (($$=$1)->table) - ::error(ErrorType::ERR_INVALID, "%s: Can't attach counter to two tables", @2+@4); + ::P4::error(ErrorType::ERR_INVALID, "%s: Can't attach counter to two tables", @2+@4); $$->table = IR::ID(@4, $4); $$->direct = false; } | counter_spec_list INSTANCE_COUNT ":" const_expression ";" @@ -604,12 +617,12 @@ meter_spec_list: { ($$=$1)->pre_color = $4; } | meter_spec_list DIRECT ":" name ";" { if (($$=$1)->table) - ::error(ErrorType::ERR_INVALID, "%s: Can't attach meter to two tables", @2+@4); + ::P4::error(ErrorType::ERR_INVALID, "%s: Can't attach meter to two tables", @2+@4); $$->table = IR::ID(@4, $4); $$->direct = true; } | meter_spec_list STATIC ":" name ";" { if (($$=$1)->table) - ::error(ErrorType::ERR_INVALID, "%s: Can't attach meter to two tables", @2+@4); + ::P4::error(ErrorType::ERR_INVALID, "%s: Can't attach meter to two tables", @2+@4); $$->table = IR::ID(@4, $4); $$->direct = false; } | meter_spec_list INSTANCE_COUNT ":" const_expression ";" @@ -641,12 +654,12 @@ register_spec_list: $$->layout = IR::ID(@3, $3); } | register_spec_list DIRECT ":" name ";" { if (($$=$1)->table) - ::error(ErrorType::ERR_INVALID, "%s: Can't attach register to two tables", @2+@4); + ::P4::error(ErrorType::ERR_INVALID, "%s: Can't attach register to two tables", @2+@4); $$->table = IR::ID(@4, $4); $$->direct = true; } | register_spec_list STATIC ":" name ";" { if (($$=$1)->table) - ::error(ErrorType::ERR_INVALID, "%s: Can't attach register to two tables", @2+@4); + ::P4::error(ErrorType::ERR_INVALID, "%s: Can't attach register to two tables", @2+@4); $$->table = IR::ID(@4, $4); $$->direct = false; } | register_spec_list INSTANCE_COUNT ":" const_expression ";" @@ -1041,7 +1054,7 @@ field_ref: header_ref "." name const_expression: expression { if (!($$ = driver.constantFold(&*$1))) - ::error(ErrorType::ERR_INVALID, "%s: Non constant expression", @1); } + ::P4::error(ErrorType::ERR_INVALID, "%s: Non constant expression", @1); } ; expression_list: @@ -1127,6 +1140,8 @@ name: IDENTIFIER { $$ = IR::ID(@1, $1); } %% +namespace P4 { + void V1::V1Parser::error(const Util::SourceInfo& location, const std::string& message) { driver.onParseError(location, message); @@ -1138,3 +1153,5 @@ static const IR::Expression *removeRedundantValid(const IR::Expression *e) { return prim->operands.at(0); } return e; } + +} // namespace P4 diff --git a/ir/base.cpp b/ir/base.cpp index 1511224024..69d45f32ee 100644 --- a/ir/base.cpp +++ b/ir/base.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "lib/error_catalog.h" #include "lib/exceptions.h" -namespace IR { +namespace P4::IR { cstring Annotation::getName() const { BUG_CHECK(name == IR::Annotation::nameAnnotation, "%1%: Only works on name annotations", this); @@ -36,12 +36,12 @@ cstring Annotation::getName() const { cstring Annotation::getSingleString() const { if (expr.size() != 1) { - ::error(ErrorType::ERR_INVALID, "%1%: should contain a string", this); + ::P4::error(ErrorType::ERR_INVALID, "%1%: should contain a string", this); return cstring::empty; } auto str = expr[0]->to(); if (str == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: should contain a string", this); + ::P4::error(ErrorType::ERR_INVALID, "%1%: should contain a string", this); return cstring::empty; } return str->value; @@ -61,4 +61,4 @@ cstring IDeclaration::controlPlaneName(cstring replace /* = cstring() */) const return name.startsWith(".") ? name.substr(1) : name; } -} // namespace IR +} // namespace P4::IR diff --git a/ir/bitrange.cpp b/ir/bitrange.cpp index b864601906..19053fb2e9 100644 --- a/ir/bitrange.cpp +++ b/ir/bitrange.cpp @@ -17,7 +17,7 @@ limitations under the License. #include "ir/json_generator.h" #include "ir/json_loader.h" -namespace BitRange { +namespace P4::BitRange { void rangeToJSON(JSONGenerator &json, int lo, int hi) { json.toJSON(std::make_pair(lo, hi)); } @@ -27,4 +27,4 @@ std::pair rangeFromJSON(JSONLoader &json) { return endpoints; } -} // namespace BitRange +} // namespace P4::BitRange diff --git a/ir/compare.h b/ir/compare.h index 8e067f7fee..4327619cde 100644 --- a/ir/compare.h +++ b/ir/compare.h @@ -3,7 +3,7 @@ #include "ir/ir.h" -namespace IR { +namespace P4::IR { /// Equals for SymbolicVariable pointers. We only compare the label. struct SymbolicVariableEqual { @@ -25,5 +25,6 @@ struct SymbolicVariableLess { } }; -} // namespace IR +} // namespace P4::IR + #endif /* IR_COMPARE_H_ */ diff --git a/ir/configuration.h b/ir/configuration.h index 8721266be0..96b86903d3 100644 --- a/ir/configuration.h +++ b/ir/configuration.h @@ -17,6 +17,8 @@ limitations under the License. #ifndef IR_CONFIGURATION_H_ #define IR_CONFIGURATION_H_ +namespace P4 { + /// A P4CConfiguration is a set of parameters to the compiler that cannot be changed via user /// options. Implementations should be singleton classes. class P4CConfiguration { @@ -43,4 +45,6 @@ class DefaultP4CConfiguration : public P4CConfiguration { DefaultP4CConfiguration() {} }; +} // namespace P4 + #endif /* IR_CONFIGURATION_H_ */ diff --git a/ir/dbprint-expression.cpp b/ir/dbprint-expression.cpp index 18a29dcd84..07914eae2a 100644 --- a/ir/dbprint-expression.cpp +++ b/ir/dbprint-expression.cpp @@ -24,6 +24,8 @@ limitations under the License. #include "lib/indent.h" #include "lib/log.h" +namespace P4 { + #define ALL_UNARY_OPS(M, ...) \ M(UPlus, +, ##__VA_ARGS__) \ M(Neg, -, ##__VA_ARGS__) M(Cmpl, ~, ##__VA_ARGS__) M(LNot, !, ##__VA_ARGS__) @@ -304,3 +306,5 @@ void IR::SelectExpression::dbprint(std::ostream &out) const { for (auto c : selectCases) out << Log::endl << c; out << " }" << unindent << setprec(prec); } + +} // namespace P4 diff --git a/ir/dbprint-p4.cpp b/ir/dbprint-p4.cpp index e55d5eadab..4d3e42c172 100644 --- a/ir/dbprint-p4.cpp +++ b/ir/dbprint-p4.cpp @@ -24,6 +24,8 @@ limitations under the License. #include "lib/log.h" #include "lib/map.h" +namespace P4 { + using namespace DBPrint; using namespace IndentCtl; @@ -266,3 +268,5 @@ void IR::Declaration_Instance::dbprint(std::ostream &out) const { out << " }" << unindent; } } + +} // namespace P4 diff --git a/ir/dbprint-stmt.cpp b/ir/dbprint-stmt.cpp index e3a1f5caa9..e4799e7b09 100644 --- a/ir/dbprint-stmt.cpp +++ b/ir/dbprint-stmt.cpp @@ -21,6 +21,8 @@ limitations under the License. #include "lib/indent.h" #include "lib/log.h" +namespace P4 { + using namespace DBPrint; using namespace IndentCtl; @@ -116,3 +118,5 @@ void IR::ForInStatement::dbprint(std::ostream &out) const { out << " in " << collection << ") {" << indent << Log::endl << body << " }" << unindent << setprec(prec); } + +} // namespace P4 diff --git a/ir/dbprint-type.cpp b/ir/dbprint-type.cpp index f6f36fc7c1..103e27184e 100644 --- a/ir/dbprint-type.cpp +++ b/ir/dbprint-type.cpp @@ -23,6 +23,8 @@ limitations under the License. #include "lib/indent.h" #include "lib/log.h" +namespace P4 { + using namespace DBPrint; using namespace IndentCtl; @@ -176,3 +178,5 @@ void IR::Type_MethodCall::dbprint(std::ostream &out) const { } void IR::Type_ActionEnum::dbprint(std::ostream &out) const { Node::dbprint(out); } + +} // namespace P4 diff --git a/ir/dbprint.cpp b/ir/dbprint.cpp index a129011266..6271e52d2f 100644 --- a/ir/dbprint.cpp +++ b/ir/dbprint.cpp @@ -32,7 +32,9 @@ limitations under the License. #include "lib/log.h" #include "lib/ordered_map.h" -using namespace DBPrint; +namespace P4 { + +using namespace P4::DBPrint; using namespace IndentCtl; static int dbprint_index = -1; @@ -113,3 +115,5 @@ void dbprint(const std::set s) { for (auto el : s) std::cout << Log::endl << '[' << i++ << "] " << el; std::cout << " }" << unindent << Log::endl; } + +} // namespace P4 diff --git a/ir/dbprint.h b/ir/dbprint.h index f1e7ef1f80..594bd6a4b1 100644 --- a/ir/dbprint.h +++ b/ir/dbprint.h @@ -22,7 +22,7 @@ limitations under the License. #include "lib/log.h" -namespace DBPrint { +namespace P4::DBPrint { // Support for debug print, needed by the LOG* macros. // TODO: These should be part of a def file @@ -93,6 +93,6 @@ inline std::ostream &operator<<(std::ostream &out, const DBPrint::dbprint_flags return out; } -} // end namespace DBPrint +} // end namespace P4::DBPrint #endif /* IR_DBPRINT_H_ */ diff --git a/ir/declaration.h b/ir/declaration.h index e0cdfbb3f5..99a577768a 100644 --- a/ir/declaration.h +++ b/ir/declaration.h @@ -20,7 +20,7 @@ limitations under the License. #include "ir/id.h" #include "ir/node.h" -namespace IR { +namespace P4::IR { /// The Declaration interface, representing objects with names. class IDeclaration : public virtual INode { @@ -51,6 +51,6 @@ class IDeclaration : public virtual INode { DECLARE_TYPEINFO_WITH_TYPEID(IDeclaration, NodeKind::IDeclaration, INode); }; -} // namespace IR +} // namespace P4::IR #endif /* IR_DECLARATION_H_ */ diff --git a/ir/dump.cpp b/ir/dump.cpp index e161ea29a4..d59ddc10da 100644 --- a/ir/dump.cpp +++ b/ir/dump.cpp @@ -25,6 +25,8 @@ limitations under the License. #include "lib/indent.h" #include "lib/source_file.h" +namespace P4 { + using namespace P4::literals; namespace { @@ -134,3 +136,5 @@ std::string dumpToString(const IR::Node *n) { dump(str, n); return str.str(); } + +} // namespace P4 diff --git a/ir/dump.h b/ir/dump.h index 70ec052fe2..2ff3607d77 100644 --- a/ir/dump.h +++ b/ir/dump.h @@ -24,6 +24,8 @@ limitations under the License. #include "ir/node.h" #include "ir/visitor.h" +namespace P4 { + /* overloads rather than optional arguments to make it easier to call from the debugger */ void dump(std::ostream &out, const IR::Node *n); void dump(std::ostream &out, const IR::Node *n, unsigned maxdepth); @@ -63,4 +65,6 @@ inline std::ostream &operator<<(std::ostream &out, const Dump &d) { return out; } +} // namespace P4 + #endif /* IR_DUMP_H_ */ diff --git a/ir/expression.cpp b/ir/expression.cpp index de333e1213..c9314b5cc0 100644 --- a/ir/expression.cpp +++ b/ir/expression.cpp @@ -26,6 +26,8 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/log.h" +namespace P4 { + const IR::Expression *IR::Slice::make(const IR::Expression *e, unsigned lo, unsigned hi) { if (auto k = e->to()) { auto rv = ((*k >> lo) & IR::Constant((1U << (hi - lo + 1)) - 1)).clone(); @@ -87,8 +89,8 @@ void IR::Constant::handleOverflow(bool noWarning) { big_int min = -(one << (width - 1)); if (value < min || value > max) { if (!noWarning) - ::warning(ErrorType::WARN_OVERFLOW, "%1%: signed value does not fit in %2% bits", - this, width); + ::P4::warning(ErrorType::WARN_OVERFLOW, + "%1%: signed value does not fit in %2% bits", this, width); LOG2("value=" << value << ", min=" << min << ", max=" << max << ", masked=" << (value & mask) << ", adj=" << ((value & mask) - (one << width))); value = value & mask; @@ -97,11 +99,12 @@ void IR::Constant::handleOverflow(bool noWarning) { } else { if (value < 0) { if (!noWarning) - ::warning(ErrorType::WARN_MISMATCH, "%1%: negative value with unsigned type", this); + ::P4::warning(ErrorType::WARN_MISMATCH, "%1%: negative value with unsigned type", + this); } else if ((value & mask) != value) { if (!noWarning) - ::warning(ErrorType::WARN_MISMATCH, "%1%: value does not fit in %2% bits", this, - width); + ::P4::warning(ErrorType::WARN_MISMATCH, "%1%: value does not fit in %2% bits", this, + width); } value = value & mask; @@ -185,3 +188,5 @@ const IR::StringLiteral *IR::StringLiteral::get(cstring value, const IR::Type *t } return result; } + +} // namespace P4 diff --git a/ir/expression.def b/ir/expression.def index d25d26acf5..d2e7255ac2 100644 --- a/ir/expression.def +++ b/ir/expression.def @@ -234,25 +234,25 @@ class Constant : Literal { bool fitsInt64() const { return value >= INT64_MIN && value <= INT64_MAX; } long asLong() const { if (!fitsLong()) - ::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for long", this); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for long", this); return static_cast(value); } int asInt() const { if (!fitsInt()) - ::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for int", this); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for int", this); return static_cast(value); } unsigned asUnsigned() const { if (!fitsUint()) - ::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for unsigned int", this); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for unsigned int", this); return static_cast(value); } uint64_t asUint64() const { if (!fitsUint64()) - ::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for uint64", this); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for uint64", this); return static_cast(value); } int64_t asInt64() const { if (!fitsInt64()) - ::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for int64", this); + ::P4::error(ErrorType::ERR_OVERLIMIT, "%1$x: Value too large for int64", this); return static_cast(value); } // The following operators are only used in special circumstances. diff --git a/ir/id.h b/ir/id.h index e1c37f58cd..edcb932ea1 100644 --- a/ir/id.h +++ b/ir/id.h @@ -22,7 +22,7 @@ limitations under the License. #include "lib/hash.h" #include "lib/source_file.h" -namespace IR { +namespace P4::IR { // An identifier. struct ID : Util::IHasSourceInfo, public IHasDbPrint { @@ -61,13 +61,13 @@ struct ID : Util::IHasSourceInfo, public IHasDbPrint { cstring toString() const override { return originalName.isNullOrEmpty() ? name : originalName; } }; -} // namespace IR +} // namespace P4::IR -namespace Util { +namespace P4::Util { template <> struct Hasher { size_t operator()(const IR::ID &id) const { return Util::Hash{}(id.name); } }; -} // namespace Util +} // namespace P4::Util #endif /* IR_ID_H_ */ diff --git a/ir/indexed_vector.h b/ir/indexed_vector.h index fd1cc9dd19..a1c40dfb5c 100644 --- a/ir/indexed_vector.h +++ b/ir/indexed_vector.h @@ -26,9 +26,11 @@ limitations under the License. #include "lib/safe_vector.h" #include "lib/string_map.h" +namespace P4 { class JSONLoader; +} // namespace P4 -namespace IR { +namespace P4::IR { /** * A Vector which holds objects which are instances of IDeclaration, and keeps @@ -47,7 +49,7 @@ class IndexedVector : public Vector { auto [it, inserted] = declarations.emplace(name, decl); if (!inserted) { invalid = true; - ::error(ErrorType::ERR_DUPLICATE, "%1%: Duplicates declaration %2%", a, it->second); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: Duplicates declaration %2%", a, it->second); } } void removeFromMap(const T *a) { @@ -223,6 +225,6 @@ class IndexedVector : public Vector { Vector); }; -} // namespace IR +} // namespace P4::IR #endif /* IR_INDEXED_VECTOR_H_ */ diff --git a/ir/ir-inline.h b/ir/ir-inline.h index f775285d79..5afcf3cbe5 100644 --- a/ir/ir-inline.h +++ b/ir/ir-inline.h @@ -23,6 +23,10 @@ limitations under the License. #include "ir/namemap.h" #include "ir/nodemap.h" #include "ir/visitor.h" +#include "lib/ordered_map.h" + +namespace P4 { + #define DEFINE_APPLY_FUNCTIONS(CLASS, TEMPLATE, TT, INLINE) \ TEMPLATE INLINE bool IR::CLASS TT::apply_visitor_preorder(Modifier &v) { \ Node::traceVisit("Mod pre"); \ @@ -198,7 +202,6 @@ void IR::IndexedVector::toJSON(JSONGenerator &json) const { } IRNODE_DEFINE_APPLY_OVERLOAD(IndexedVector, template , ) -#include "lib/ordered_map.h" template static inline void namemap_insert_helper(typename MAP::iterator, typename MAP::key_type k, typename MAP::mapped_type v, MAP &, MAP &new_symbols) { @@ -325,4 +328,7 @@ void IR::NodeMap::visit_children(Visitor &v) const v.visit(k.second); } } + +} // namespace P4 + #endif /* IR_IR_INLINE_H_ */ diff --git a/ir/ir-tree-macros.h b/ir/ir-tree-macros.h index 5d4eb25e4c..943a867cc6 100644 --- a/ir/ir-tree-macros.h +++ b/ir/ir-tree-macros.h @@ -21,7 +21,7 @@ limitations under the License. * whenever a new IR Node subclass is added, it MUST be added to this table. Target * specific subclasses might be broken out into a separate table and included here * Because we want to be able to forward-declare all these types, the class type MUST - * be a simple identifier that will be declared in namespace IR. Aliases can be defined + * be a simple identifier that will be declared in namespace P4::IR. Aliases can be defined * in other namespaces if desired. * When there's a templated subclass of Node, all of its instantiations need to appear in this * table, and it also needs to be in the IRNODE_ALL_TEMPLATES_AND_DIRECT_AND_INDIRECT_BASES diff --git a/ir/ir.cpp b/ir/ir.cpp index 002482c5ed..e146075414 100644 --- a/ir/ir.cpp +++ b/ir/ir.cpp @@ -39,7 +39,7 @@ limitations under the License. #include "lib/null.h" #include "lib/ordered_map.h" -namespace IR { +namespace P4::IR { const cstring ParserState::accept = "accept"_cs; const cstring ParserState::reject = "reject"_cs; @@ -120,8 +120,9 @@ void IGeneralNamespace::checkDuplicateDeclarations() const { IR::ID name = decl->getName(); auto [it, inserted] = seen.emplace(name); if (!inserted) { - ::error(ErrorType::ERR_DUPLICATE, - "Duplicate declaration of %1%: previous declaration at %2%", name, it->srcInfo); + ::P4::error(ErrorType::ERR_DUPLICATE, + "Duplicate declaration of %1%: previous declaration at %2%", name, + it->srcInfo); } } } @@ -130,7 +131,7 @@ void P4Parser::checkDuplicates() const { for (auto decl : states) { auto prev = parserLocals.getDeclaration(decl->getName().name); if (prev != nullptr) - ::error(ErrorType::ERR_DUPLICATE, "State %1% has same name as %2%", decl, prev); + ::P4::error(ErrorType::ERR_DUPLICATE, "State %1% has same name as %2%", decl, prev); } } @@ -140,12 +141,12 @@ size_t Type_Stack::getSize() const { if (!sizeKnown()) BUG("%1%: Size not yet known", size); auto cst = size->to(); if (!cst->fitsInt()) { - ::error(ErrorType::ERR_OVERLIMIT, "Index too large: %1%", cst); + ::P4::error(ErrorType::ERR_OVERLIMIT, "Index too large: %1%", cst); return 0; } auto size = cst->asInt(); if (size < 0) { - ::error(ErrorType::ERR_OVERLIMIT, "Illegal array size: %1%", cst); + ::P4::error(ErrorType::ERR_OVERLIMIT, "Illegal array size: %1%", cst); return 0; } return static_cast(size); @@ -160,12 +161,12 @@ const Method *Type_Extern::lookupMethod(IR::ID name, const Vector *arg if (result == nullptr) { result = m; } else { - ::error(ErrorType::ERR_DUPLICATE, "Ambiguous method %1%", name); + ::P4::error(ErrorType::ERR_DUPLICATE, "Ambiguous method %1%", name); if (!reported) { - ::error(ErrorType::ERR_DUPLICATE, "Candidate is %1%", result); + ::P4::error(ErrorType::ERR_DUPLICATE, "Candidate is %1%", result); reported = true; } - ::error(ErrorType::ERR_DUPLICATE, "Candidate is %1%", m); + ::P4::error(ErrorType::ERR_DUPLICATE, "Candidate is %1%", m); return nullptr; } } @@ -192,7 +193,7 @@ const Type_Method *P4Table::getApplyMethodType() const { // Synthesize a new type for the return auto actions = properties->getProperty(IR::TableProperties::actionsPropertyName); if (actions == nullptr) { - ::error(ErrorType::ERR_INVALID, "%1%: table does not contain a list of actions", this); + ::P4::error(ErrorType::ERR_INVALID, "%1%: table does not contain a list of actions", this); return nullptr; } if (!actions->value->is()) @@ -274,27 +275,27 @@ const IR::PackageBlock *ToplevelBlock::getMain() const { auto program = getProgram(); auto mainDecls = program->getDeclsByName(IR::P4Program::main)->toVector(); if (mainDecls.empty()) { - ::warning(ErrorType::WARN_MISSING, "Program does not contain a `%s' module", - IR::P4Program::main); + ::P4::warning(ErrorType::WARN_MISSING, "Program does not contain a `%s' module", + IR::P4Program::main); return nullptr; } auto main = mainDecls[0]; if (mainDecls.size() > 1) { - ::error(ErrorType::ERR_DUPLICATE, "Program has multiple `%s' instances: %1%, %2%", - IR::P4Program::main, main->getNode(), mainDecls[1]->getNode()); + ::P4::error(ErrorType::ERR_DUPLICATE, "Program has multiple `%s' instances: %1%, %2%", + IR::P4Program::main, main->getNode(), mainDecls[1]->getNode()); return nullptr; } if (!main->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be a package declaration", main->getNode()); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a package declaration", main->getNode()); return nullptr; } auto block = getValue(main->getNode()); if (block == nullptr) return nullptr; if (!block->is()) { - ::error(ErrorType::ERR_EXPECTED, "%1%: expected package declaration", block); + ::P4::error(ErrorType::ERR_EXPECTED, "%1%: expected package declaration", block); return nullptr; } return block->to(); } -} // namespace IR +} // namespace P4::IR diff --git a/ir/ir.def b/ir/ir.def index d0f1936fa5..fa05a51373 100644 --- a/ir/ir.def +++ b/ir/ir.def @@ -332,7 +332,7 @@ class P4Table : Declaration, IAnnotated, IApply { if (ap == nullptr) return nullptr; if (!ap->value->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be an action list", ap); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be an action list", ap); return nullptr; } return ap->value->to(); } Key getKey() const { @@ -340,7 +340,7 @@ class P4Table : Declaration, IAnnotated, IApply { if (kp == nullptr) return nullptr; if (!kp->value->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be a key", kp); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a key", kp); return nullptr; } return kp->value->to(); } Expression getDefaultAction() const { @@ -348,7 +348,7 @@ class P4Table : Declaration, IAnnotated, IApply { if (d == nullptr) return nullptr; if (!d->value->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be an expression", d); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be an expression", d); return nullptr; } return d->value->to()->expression; } Constant getConstantProperty(cstring name) const { @@ -373,7 +373,7 @@ class P4Table : Declaration, IAnnotated, IApply { if (ep == nullptr) return nullptr; if (!ep->value->is()) { - ::error(ErrorType::ERR_INVALID, "%1%: must be a list of entries", ep); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a list of entries", ep); return nullptr; } return ep->value->to(); diff --git a/ir/irutils.cpp b/ir/irutils.cpp index 19fbddd5bd..6b42e0476e 100644 --- a/ir/irutils.cpp +++ b/ir/irutils.cpp @@ -9,7 +9,7 @@ #include "ir/visitor.h" #include "lib/exceptions.h" -namespace IR { +namespace P4::IR { using namespace P4::literals; @@ -69,7 +69,7 @@ const IR::Expression *getDefaultValue(const IR::Type *type, const Util::SourceIn if (valueRequired) { P4C_UNIMPLEMENTED("%1%: No default value for varbit types.", srcInfo); } - ::error(ErrorType::ERR_UNSUPPORTED, "%1% default values for varbit types", srcInfo); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1% default values for varbit types", srcInfo); return nullptr; } if (const auto *ht = type->to()) { @@ -125,8 +125,8 @@ const IR::Expression *getDefaultValue(const IR::Type *type, const Util::SourceIn P4C_UNIMPLEMENTED("%1%: No default value for type %2% (%3%).", srcInfo, type, type->node_type_name()); } - ::error(ErrorType::ERR_INVALID, "%1%: No default value for type %2% (%3%)", srcInfo, type, - type->node_type_name()); + ::P4::error(ErrorType::ERR_INVALID, "%1%: No default value for type %2% (%3%)", srcInfo, type, + type->node_type_name()); return nullptr; } @@ -261,4 +261,4 @@ const IR::Node *inlineBlock(const Transform &t, IR::IndexedVector &); const IR::Node *inlineBlock(const Transform &, IR::IndexedVector &&); -} // namespace IR +} // namespace P4::IR #endif /* IR_IRUTILS_H_ */ diff --git a/ir/json_generator.h b/ir/json_generator.h index 5c7bed7c56..0e565fc480 100644 --- a/ir/json_generator.h +++ b/ir/json_generator.h @@ -31,6 +31,8 @@ limitations under the License. #include "lib/ordered_set.h" #include "lib/safe_vector.h" +namespace P4 { + class JSONGenerator { std::unordered_set node_refs; std::ostream &out; @@ -286,4 +288,6 @@ class JSONGenerator { } }; +} // namespace P4 + #endif /* IR_JSON_GENERATOR_H_ */ diff --git a/ir/json_loader.h b/ir/json_loader.h index c11ce5848f..e0a966c73b 100644 --- a/ir/json_loader.h +++ b/ir/json_loader.h @@ -33,6 +33,8 @@ limitations under the License. #include "lib/ordered_set.h" #include "lib/safe_vector.h" +namespace P4 { + class JSONLoader { template class has_fromJSON { @@ -204,21 +206,21 @@ class JSONLoader { template void unpack_json(std::pair &v) { const JsonObject *obj = json->checkedTo(); - load(::get(obj, "first"), v.first); - load(::get(obj, "second"), v.second); + load(::P4::get(obj, "first"), v.first); + load(::P4::get(obj, "second"), v.second); } template void unpack_json(std::optional &v) { const JsonObject *obj = json->checkedTo(); bool isValid = false; - load(::get(obj, "valid"), isValid); + load(::P4::get(obj, "valid"), isValid); if (!isValid) { v = std::nullopt; return; } T value; - load(::get(obj, "value"), value), v = std::move(value); + load(::P4::get(obj, "value"), value), v = std::move(value); } void unpack_json(bool &v) { v = json->as(); } @@ -385,4 +387,6 @@ IR::NameMap *IR::NameMap::fromJSON(JSO return new IR::NameMap(json); } +} // namespace P4 + #endif /* IR_JSON_LOADER_H_ */ diff --git a/ir/json_parser.cpp b/ir/json_parser.cpp index 5b401a0933..3a55f9b74b 100644 --- a/ir/json_parser.cpp +++ b/ir/json_parser.cpp @@ -21,6 +21,8 @@ limitations under the License. #include #include +namespace P4 { + int JsonObject::get_id() const { auto it = find("Node_ID"); if (it == end()) return -1; @@ -222,3 +224,5 @@ std::istream &operator>>(std::istream &in, JsonData *&json) { } return in; } + +} // namespace P4 diff --git a/ir/json_parser.h b/ir/json_parser.h index 22689c1395..073caca78e 100644 --- a/ir/json_parser.h +++ b/ir/json_parser.h @@ -10,6 +10,8 @@ #include "lib/cstring.h" #include "lib/ordered_map.h" +namespace P4 { + class JsonData : public ICastable { public: JsonData() {} @@ -96,4 +98,6 @@ std::string getIndent(int l); std::ostream &operator<<(std::ostream &out, JsonData *json); std::istream &operator>>(std::istream &in, JsonData *&json); +} // namespace P4 + #endif /* IR_JSON_PARSER_H_ */ diff --git a/ir/loop-visitor.cpp b/ir/loop-visitor.cpp index 79c49215ac..83447b0ba1 100644 --- a/ir/loop-visitor.cpp +++ b/ir/loop-visitor.cpp @@ -15,6 +15,8 @@ limitations under the License. */ #include "ir/ir.h" +namespace P4 { + template void IR::ForStatement::visit_children(THIS *self, Visitor &v) { v.visit(self->annotations, "annotations"); @@ -93,3 +95,5 @@ void IR::ContinueStatement::visit_children(Visitor &v) const { void IR::ContinueStatement::visit_children(Visitor &v) { return const_cast(this)->visit_children(v); } + +} // namespace P4 diff --git a/ir/namemap.h b/ir/namemap.h index 8463b8b1f7..b5581fda7a 100644 --- a/ir/namemap.h +++ b/ir/namemap.h @@ -26,9 +26,11 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/map.h" +namespace P4 { class JSONLoader; +} // namespace P4 -namespace IR { +namespace P4::IR { template class MAP = std::map, class COMP = std::less, @@ -110,8 +112,8 @@ class NameMap : public Node { void addUnique(cstring name, const T *n) { auto prev = symbols.find(name); if (prev != symbols.end()) - ::error(ErrorType::ERR_DUPLICATE, "%1%: duplicated name (%2% is previous instance)", n, - prev->second); + ::P4::error(ErrorType::ERR_DUPLICATE, "%1%: duplicated name (%2% is previous instance)", + n, prev->second); symbols.emplace(std::move(name), std::move(n)); } // Expects to have a single node with each name. @@ -161,6 +163,6 @@ class NameMap : public Node { DECLARE_TYPEINFO(NameMap, Node); }; -} // namespace IR +} // namespace P4::IR #endif /* IR_NAMEMAP_H_ */ diff --git a/ir/node.cpp b/ir/node.cpp index 13498216f0..0046acff2a 100644 --- a/ir/node.cpp +++ b/ir/node.cpp @@ -31,6 +31,8 @@ limitations under the License. #include "lib/json.h" #include "lib/log.h" +namespace P4 { + void IR::Node::traceVisit(const char *visitor) const { LOG3("Visiting " << visitor << " " << id << ":" << node_type_name()); } @@ -157,3 +159,5 @@ void IR::Node::sourceInfoToJSON(JSONGenerator &json) const { } IRNODE_DEFINE_APPLY_OVERLOAD(Node, , ) + +} // namespace P4 diff --git a/ir/node.h b/ir/node.h index 93b1ebb1da..bc6bb23af9 100644 --- a/ir/node.h +++ b/ir/node.h @@ -26,6 +26,7 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/source_file.h" +namespace P4 { class Visitor; struct Visitor_Context; class Inspector; @@ -33,12 +34,13 @@ class Modifier; class Transform; class JSONGenerator; class JSONLoader; +} // namespace P4 -namespace Util { +namespace P4::Util { class JsonObject; -} // namespace Util +} // namespace P4::Util -namespace IR { +namespace P4::IR { using namespace P4::literals; @@ -110,10 +112,10 @@ class Node : public virtual INode { protected: static int currentId; void traceVisit(const char *visitor) const; - friend class ::Visitor; - friend class ::Inspector; - friend class ::Modifier; - friend class ::Transform; + friend class ::P4::Visitor; + friend class ::P4::Inspector; + friend class ::P4::Modifier; + friend class ::P4::Transform; cstring prepareSourceInfoForJSON(Util::SourceInfo &si, unsigned *lineNumber, unsigned *columnNumber) const; @@ -223,6 +225,6 @@ inline bool equiv(const INode *a, const INode *b) { return tmp; \ } -} // namespace IR +} // namespace P4::IR #endif /* IR_NODE_H_ */ diff --git a/ir/nodemap.h b/ir/nodemap.h index d50d54fa0d..3ecac7e986 100644 --- a/ir/nodemap.h +++ b/ir/nodemap.h @@ -20,7 +20,7 @@ limitations under the License. #include "ir/node.h" #include "lib/cstring.h" -namespace IR { +namespace P4::IR { template class MAP = std::map, @@ -97,6 +97,6 @@ class NodeMap : public Node { DECLARE_TYPEINFO(NodeMap, Node); }; -} // namespace IR +} // namespace P4::IR #endif /* IR_NODEMAP_H_ */ diff --git a/ir/pass_manager.cpp b/ir/pass_manager.cpp index 5fe5c5fe93..d4efa167a4 100644 --- a/ir/pass_manager.cpp +++ b/ir/pass_manager.cpp @@ -32,6 +32,8 @@ limitations under the License. #include "lib/log.h" #include "lib/n4.h" +namespace P4 { + void PassManager::removePasses(const std::vector &exclude) { for (auto it : exclude) { bool excluded = false; @@ -67,7 +69,7 @@ const IR::Node *PassManager::apply_visitor(const IR::Node *program, const char * } nest_log_indent(log_indent); early_exit_flag = false; - unsigned initial_error_count = ::errorCount(); + unsigned initial_error_count = ::P4::errorCount(); BUG_CHECK(running, "not calling apply properly"); for (auto it = passes.begin(); it != passes.end();) { Visitor *v = *it; @@ -85,7 +87,8 @@ const IR::Node *PassManager::apply_visitor(const IR::Node *program, const char * LOG3(log_indent << "heap after " << v->name() << ": in use " << n4(mem) << "B, max " << n4(maxmem) << "B"); } - if (stop_on_error && ::errorCount() > initial_error_count) early_exit_flag = true; + if (stop_on_error && ::P4::errorCount() > initial_error_count) + early_exit_flag = true; if (program == nullptr) early_exit_flag = true; } catch (Backtrack::trigger::type_t &trig_type) { throw Backtrack::trigger(trig_type); @@ -146,13 +149,13 @@ void PassManager::runDebugHooks(const char *visitorName, const IR::Node *program const IR::Node *PassRepeated::apply_visitor(const IR::Node *program, const char *name) { bool done = false; unsigned iterations = 0; - unsigned initial_error_count = ::errorCount(); + unsigned initial_error_count = ::P4::errorCount(); while (!done) { LOG5("PassRepeated state is:\n" << dumpToString(program)); running = true; auto newprogram = PassManager::apply_visitor(program, name); if (program == newprogram || newprogram == nullptr) done = true; - if (stop_on_error && ::errorCount() > initial_error_count) return program; + if (stop_on_error && ::P4::errorCount() > initial_error_count) return program; iterations++; if (repeats != 0 && iterations > repeats) done = true; program = newprogram; @@ -175,3 +178,5 @@ const IR::Node *PassIf::apply_visitor(const IR::Node *program, const char *name) } return program; } + +} // namespace P4 diff --git a/ir/pass_manager.h b/ir/pass_manager.h index ca66b851ad..71327416a1 100644 --- a/ir/pass_manager.h +++ b/ir/pass_manager.h @@ -29,6 +29,8 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/safe_vector.h" +namespace P4 { + /// A hook called by pass manager after a pass finishes. /// @param node a result of the last pass, which can be the (transformed) node, or a nullptr. typedef std::function. using Constraint = IR::Expression; @@ -56,4 +58,6 @@ class AbstractSolver : public ICastable { DECLARE_TYPEINFO(AbstractSolver); }; +} // namespace P4 + #endif /* IR_SOLVER_H_ */ diff --git a/ir/type.cpp b/ir/type.cpp index f6ed7e4391..a75cdf4960 100644 --- a/ir/type.cpp +++ b/ir/type.cpp @@ -30,7 +30,7 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/source_file.h" -namespace IR { +namespace P4::IR { const cstring IR::Type_Stack::next = "next"_cs; const cstring IR::Type_Stack::last = "last"_cs; @@ -83,19 +83,19 @@ const Type_Bits *Type_Bits::get(int width, bool isSigned) { auto &result = (*type_map)[std::make_pair(width, isSigned)]; if (!result) result = new Type_Bits(width, isSigned); if (width > P4CContext::getConfig().maximumWidthSupported()) - ::error(ErrorType::ERR_UNSUPPORTED, "%1%: Compiler only supports widths up to %2%", result, - P4CContext::getConfig().maximumWidthSupported()); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%1%: Compiler only supports widths up to %2%", + result, P4CContext::getConfig().maximumWidthSupported()); return result; } const Type_Bits *Type_Bits::get(const Util::SourceInfo &si, int sz, bool isSigned) { if (sz < 0) { - ::error(ErrorType::ERR_INVALID, "%1%Width %2% of type cannot be negative", si, sz); + ::P4::error(ErrorType::ERR_INVALID, "%1%Width %2% of type cannot be negative", si, sz); // Return a value that will not cause crashes later on return new IR::Type_Bits(si, 1024, isSigned); } if (sz == 0 && isSigned) { - ::error(ErrorType::ERR_INVALID, "%1%Width of signed type cannot be zero", si); + ::P4::error(ErrorType::ERR_INVALID, "%1%Width of signed type cannot be zero", si); // Return a value that will not cause crashes later on return new IR::Type_Bits(si, 1024, isSigned); } @@ -147,7 +147,7 @@ const Type_Varbits *Type_Varbits::get(const Util::SourceInfo &si, const IR::Expr const Type_Varbits *Type_Varbits::get(const Util::SourceInfo &si, int sz) { auto result = new Type_Varbits(si, sz); if (sz < 0) { - ::error(ErrorType::ERR_INVALID, "%1%: Width cannot be negative or zero", result); + ::P4::error(ErrorType::ERR_INVALID, "%1%: Width cannot be negative or zero", result); // Return a value that will not cause crashes later on return new IR::Type_Varbits(si, 1024); } @@ -282,4 +282,4 @@ const Type *Type_SpecializedCanonical::getP4Type() const { return new IR::Type_Specialized(srcInfo, new IR::Type_Name(st->getName()), args); } -} // namespace IR +} // namespace P4::IR diff --git a/ir/type.def b/ir/type.def index 10c47537ca..6e753d0e98 100644 --- a/ir/type.def +++ b/ir/type.def @@ -9,6 +9,7 @@ */ #emit +namespace P4 { namespace IR { enum class Direction { None, @@ -61,6 +62,9 @@ inline bool operator>>(cstring s, IR::Direction &d) { else return false; return true; } + +} // namespace P4 + #end /// This represents a type that can unify with any other type. diff --git a/ir/v1.cpp b/ir/v1.cpp index 47a66782b2..e4173e64cf 100644 --- a/ir/v1.cpp +++ b/ir/v1.cpp @@ -29,6 +29,8 @@ limitations under the License. #include "lib/error_catalog.h" #include "lib/source_file.h" +namespace P4 { + #define SINGLETON_TYPE(NAME) \ const IR::Type_##NAME *IR::Type_##NAME::get() { \ static const Type_##NAME *singleton; \ @@ -211,3 +213,5 @@ IR::V1Program::V1Program() { scope.add("standard_metadata_t"_cs, new IR::v1HeaderType(standard_metadata_t)); scope.add("standard_metadata"_cs, new IR::Metadata("standard_metadata", standard_metadata_t)); } + +} // namespace P4 diff --git a/ir/v1.def b/ir/v1.def index 0cf0583ee1..c7a09a2e78 100644 --- a/ir/v1.def +++ b/ir/v1.def @@ -8,9 +8,10 @@ * @{ */ #emit +namespace P4 { namespace IR { enum class CounterType { NONE, PACKETS, BYTES, BOTH }; -} +} // namespace IR inline std::ostream& operator<<(std::ostream &out, IR::CounterType d) { switch (d) { @@ -40,6 +41,9 @@ inline bool operator>>(cstring s, IR::CounterType &ctr) { else return false; return true; } + +} // namespace P4 + #end class Type_Block : Type_Base { diff --git a/ir/vector.h b/ir/vector.h index 9e18b048ad..b92fb2a2e6 100644 --- a/ir/vector.h +++ b/ir/vector.h @@ -22,9 +22,11 @@ limitations under the License. #include "lib/null.h" #include "lib/safe_vector.h" +namespace P4 { class JSONLoader; +} // namespace P4 -namespace IR { +namespace P4::IR { // Specialization of vector which // - only stores const IR::Node* objects inside (T should derive from Node) @@ -209,13 +211,14 @@ class Vector : public VectorBase { DECLARE_TYPEINFO_WITH_DISCRIMINATOR(Vector, NodeDiscriminator::VectorT, T, VectorBase); }; -} // namespace IR +} // namespace P4::IR // XXX(seth): We use this namespace to hide our get() overloads from ADL. GCC // 4.8 has a bug which causes these overloads to be considered when get() is // called on a type in the global namespace, even if the number of arguments // doesn't match up, which can trigger template instantiations that cause // errors. +namespace P4 { namespace GetImpl { template @@ -235,4 +238,6 @@ const T *get(const IR::Vector *vec, U name) { } // namespace GetImpl using namespace GetImpl; // NOLINT(build/namespaces) +} // namespace P4 + #endif /* IR_VECTOR_H_ */ diff --git a/ir/visitor.cpp b/ir/visitor.cpp index efe98c845f..84c0c95685 100644 --- a/ir/visitor.cpp +++ b/ir/visitor.cpp @@ -16,6 +16,7 @@ limitations under the License. #include "visitor.h" +#include #include #include @@ -25,6 +26,10 @@ limitations under the License. #include "ir/ir-generated.h" #include "lib/hash.h" +#if HAVE_CXXABI_H +#include +#endif + #if HAVE_LIBGC #include #endif @@ -39,6 +44,8 @@ limitations under the License. #include "lib/log.h" #include "lib/map.h" +namespace P4 { + enum class VisitStatus : unsigned { New, Revisit, Busy, Done }; /** @class Visitor::ChangeTracker @@ -770,10 +777,7 @@ std::ostream &operator<<(std::ostream &out, const IR::Vector *v) return v ? out << *v : out << ""; } -#include #if HAVE_CXXABI_H -#include - cstring Visitor::demangle(const char *str) { int status; cstring rv; @@ -822,7 +826,7 @@ void Backtrack::trigger::register_for_gc(size_t Backtrack::trigger::~trigger() { #if HAVE_LIBGC - if (auto sz = ::get(trigger_gc_roots, this)) { + if (auto sz = ::P4::get(trigger_gc_roots, this)) { GC_remove_roots(this, reinterpret_cast(this) + sz); trigger_gc_roots.erase(this); } @@ -843,7 +847,7 @@ std::ostream &operator<<(std::ostream &out, const ControlFlowVisitor::flow_join_ if (info.vclone) out << Visitor::demangle(typeid(*info.vclone).name()) << " "; out << "count=" << info.count << " done=" << info.done; #if DEBUG_FLOW_JOIN - using namespace DBPrint; + using namespace P4::DBPrint; auto flags = dbgetflags(out); out << Brief; for (auto &i : info.parents) { @@ -857,7 +861,7 @@ std::ostream &operator<<(std::ostream &out, const ControlFlowVisitor::flow_join_ } std::ostream &operator<<(std::ostream &out, const ControlFlowVisitor::flow_join_points_t &fjp) { - using namespace DBPrint; + using namespace P4::DBPrint; auto flags = dbgetflags(out); out << Brief; bool first = true; @@ -880,3 +884,5 @@ void dump(const SplitFlowVisit_base *split) { split = split->prev; } } + +} // namespace P4 diff --git a/ir/visitor.h b/ir/visitor.h index 0c9fb34e19..15fdd14d65 100644 --- a/ir/visitor.h +++ b/ir/visitor.h @@ -41,6 +41,8 @@ limitations under the License. #include "lib/null.h" #include "lib/source_file.h" +namespace P4 { + // declare this outside of Visitor so it can be forward declared in node.h struct Visitor_Context { // We maintain a linked list of Context structures on the stack @@ -297,7 +299,7 @@ class Visitor { static bool warning_enabled(const Visitor *visitor, int warning_kind); template >, class... Args> void warn(const int kind, const char *format, const T *node, Args &&...args) { - if (warning_enabled(kind)) ::warning(kind, format, node, std::forward(args)...); + if (warning_enabled(kind)) ::P4::warning(kind, format, node, std::forward(args)...); } /// The const ref variant of the above @@ -305,7 +307,7 @@ class Visitor { typename = std::enable_if_t && !std::is_pointer_v>, class... Args> void warn(const int kind, const char *format, const T &node, Args &&...args) { - if (warning_enabled(kind)) ::warning(kind, format, node, std::forward(args)...); + if (warning_enabled(kind)) ::P4::warning(kind, format, node, std::forward(args)...); } protected: @@ -837,4 +839,6 @@ const IR::Node *transformAllMatching(const IR::Node *root, Func &&function) { return root->apply(NodeVisitor(std::forward(function))); } +} // namespace P4 + #endif /* IR_VISITOR_H_ */ diff --git a/ir/write_context.cpp b/ir/write_context.cpp index 6b023acc53..2832e3b810 100644 --- a/ir/write_context.cpp +++ b/ir/write_context.cpp @@ -19,6 +19,8 @@ limitations under the License. #include "ir/node.h" #include "ir/visitor.h" +namespace P4 { + /* Determine from the Visitor context whether the currently being visited IR node * denotes something that might be written to by the code. This is always conservative * (we don't know for certain that it is written) since even if it is, it might be @@ -98,3 +100,5 @@ bool P4WriteContext::isRead(bool root_value) { if (ctxt->node->is()) return ctxt->child_index == 0; return true; } + +} // namespace P4 diff --git a/lib/algorithm.h b/lib/algorithm.h index 2dcefd05f4..03b407d118 100644 --- a/lib/algorithm.h +++ b/lib/algorithm.h @@ -26,6 +26,7 @@ limitations under the License. #define ELEMENTS(a) (sizeof(a) / sizeof(a[0])) /* these should all be in , but are missing... */ +namespace P4 { template inline bool contains(C &c, const T &val) { @@ -92,4 +93,6 @@ Iter end(std::pair pr) { return pr.second; } +} // namespace P4 + #endif /* LIB_ALGORITHM_H_ */ diff --git a/lib/alloc_trace.cpp b/lib/alloc_trace.cpp index 4c8bc6b42a..4347dacb93 100644 --- a/lib/alloc_trace.cpp +++ b/lib/alloc_trace.cpp @@ -16,6 +16,8 @@ #include #endif +namespace P4 { + extern const char *addr2line(void *addr, const char *text); #if HAVE_LIBBACKTRACE @@ -110,3 +112,5 @@ std::ostream &operator<<(std::ostream &out, const AllocTrace &at) { } return out; } + +} // namespace P4 diff --git a/lib/alloc_trace.h b/lib/alloc_trace.h index eecd6258fb..93e282e914 100644 --- a/lib/alloc_trace.h +++ b/lib/alloc_trace.h @@ -24,6 +24,8 @@ limitations under the License. #include "exceptions.h" #include "gc.h" +namespace P4 { + class AllocTrace { struct backtrace { void *trace[ALLOC_TRACE_DEPTH]; @@ -76,4 +78,6 @@ class PauseTrace { #endif }; +} // namespace P4 + #endif /* LIB_ALLOC_TRACE_H_ */ diff --git a/lib/backtrace_exception.cpp b/lib/backtrace_exception.cpp index 7b4830870e..75ed9e693c 100644 --- a/lib/backtrace_exception.cpp +++ b/lib/backtrace_exception.cpp @@ -19,7 +19,6 @@ limitations under the License. #include #if HAVE_LIBBACKTRACE #include -extern struct backtrace_state *global_backtrace_state; #endif #include @@ -32,7 +31,11 @@ extern struct backtrace_state *global_backtrace_state; #include "exename.h" #include "hex.h" +namespace P4 { + #if HAVE_LIBBACKTRACE +extern struct backtrace_state *global_backtrace_state; + int append_message(void *msg_, uintptr_t pc, const char *file, int line, const char *func) { std::string &msg = *static_cast(msg_); std::stringstream tmp; @@ -72,6 +75,8 @@ void backtrace_fill_stacktrace(std::string &msg, void *const *backtrace, int siz #endif } +} // namespace P4 + #ifdef __GLIBC__ /* DANGER -- overrides for glibc++ exception throwers to include a stack trace. * correct functions depends on library internals, so may not work on some versions @@ -79,19 +84,21 @@ void backtrace_fill_stacktrace(std::string &msg, void *const *backtrace, int siz namespace std { -void __throw_bad_alloc() { throw backtrace_exception(); } +void __throw_bad_alloc() { throw ::P4::backtrace_exception(); } -void __throw_bad_cast() { throw backtrace_exception(); } +void __throw_bad_cast() { throw ::P4::backtrace_exception(); } -void __throw_bad_function_call() { throw backtrace_exception(); } +void __throw_bad_function_call() { throw ::P4::backtrace_exception(); } -void __throw_invalid_argument(char const *m) { throw backtrace_exception(m); } +void __throw_invalid_argument(char const *m) { + throw ::P4::backtrace_exception(m); +} -void __throw_length_error(char const *m) { throw backtrace_exception(m); } +void __throw_length_error(char const *m) { throw ::P4::backtrace_exception(m); } -void __throw_logic_error(char const *m) { throw backtrace_exception(m); } +void __throw_logic_error(char const *m) { throw ::P4::backtrace_exception(m); } -void __throw_out_of_range(char const *m) { throw backtrace_exception(m); } +void __throw_out_of_range(char const *m) { throw ::P4::backtrace_exception(m); } void __throw_out_of_range_fmt(char const *fmt, ...) { char buffer[1024]; // should be large enough for all cases? @@ -99,15 +106,15 @@ void __throw_out_of_range_fmt(char const *fmt, ...) { va_start(args, fmt); vsnprintf(buffer, sizeof(buffer), fmt, args); va_end(args); - throw backtrace_exception(buffer); + throw ::P4::backtrace_exception(buffer); } void __throw_regex_error(regex_constants::error_type err) { - throw backtrace_exception(err); + throw ::P4::backtrace_exception(err); } void __throw_system_error(int err) { - throw backtrace_exception(error_code(err, generic_category())); + throw ::P4::backtrace_exception(error_code(err, generic_category())); } } // namespace std diff --git a/lib/backtrace_exception.h b/lib/backtrace_exception.h index e18108e771..5c5ee064fe 100644 --- a/lib/backtrace_exception.h +++ b/lib/backtrace_exception.h @@ -26,6 +26,8 @@ limitations under the License. #include #endif +namespace P4 { + void backtrace_fill_stacktrace(std::string &msg, void *const *backtrace, int size); template @@ -57,4 +59,6 @@ class backtrace_exception : public E { } }; +} // namespace P4 + #endif /* LIB_BACKTRACE_EXCEPTION_H_ */ diff --git a/lib/big_int.h b/lib/big_int.h index c31f889719..befa0e5706 100644 --- a/lib/big_int.h +++ b/lib/big_int.h @@ -19,6 +19,10 @@ limitations under the License. #include +namespace P4 { + using big_int = boost::multiprecision::cpp_int; +} // namespace P4 + #endif /* LIB_BIG_INT_H_ */ diff --git a/lib/big_int_fwd.h b/lib/big_int_fwd.h index aeb96c640c..7b4cfb7921 100644 --- a/lib/big_int_fwd.h +++ b/lib/big_int_fwd.h @@ -19,6 +19,10 @@ limitations under the License. #include +namespace P4 { + using big_int = boost::multiprecision::cpp_int; +} // namespace P4 + #endif /* LIB_BIG_INT_FWD_H_ */ diff --git a/lib/big_int_util.cpp b/lib/big_int_util.cpp index eb45369c59..fef043cd0d 100644 --- a/lib/big_int_util.cpp +++ b/lib/big_int_util.cpp @@ -18,7 +18,7 @@ limitations under the License. #include -namespace Util { +namespace P4::Util { using namespace boost::multiprecision; @@ -109,7 +109,9 @@ big_int cvtInt(const char *s, unsigned base) { return rv; } -} // namespace Util +} // namespace P4::Util + +namespace P4 { void dump(const big_int &i) { std::cout << i << " ("; @@ -121,3 +123,5 @@ void dump(const big_int &i) { std::cout << ")" << std::endl; } void dump(const big_int *i) { dump(*i); } + +} // namespace P4 diff --git a/lib/big_int_util.h b/lib/big_int_util.h index 051ce7053b..de37547aff 100644 --- a/lib/big_int_util.h +++ b/lib/big_int_util.h @@ -26,7 +26,7 @@ limitations under the License. #include "big_int.h" #include "hash.h" -namespace Util { +namespace P4::Util { // Useful functions for manipulating GMP values // (arbitrary-precision values) @@ -69,7 +69,9 @@ inline unsigned scan1(const boost::multiprecision::cpp_int &val, unsigned pos) { return scan1_positive(val, pos); } -} // namespace Util +} // namespace P4::Util + +namespace P4 { static inline unsigned bitcount(big_int v) { if (v < 0) return ~0U; @@ -100,4 +102,6 @@ static inline int ceil_log2(big_int v) { return v ? floor_log2(v - 1) + 1 : -1; template <> struct Util::Hasher : Detail::StdHasher {}; +} // namespace P4 + #endif /* LIB_BIG_INT_UTIL_H_ */ diff --git a/lib/bitops.h b/lib/bitops.h index 7d6d473400..0d25c2d107 100644 --- a/lib/bitops.h +++ b/lib/bitops.h @@ -21,6 +21,8 @@ limitations under the License. #include "bitvec.h" +namespace P4 { + static inline unsigned bitcount(unsigned v) { #if defined(__GNUC__) || defined(__clang__) unsigned rv = __builtin_popcount(v); @@ -58,4 +60,6 @@ static inline unsigned bitmask2bytemask(const bitvec &a) { return rv; } +} // namespace P4 + #endif /* LIB_BITOPS_H_ */ diff --git a/lib/bitrange.cpp b/lib/bitrange.cpp index 55d545dee0..ffdec62098 100644 --- a/lib/bitrange.cpp +++ b/lib/bitrange.cpp @@ -19,6 +19,8 @@ limitations under the License. #include #include +namespace P4 { + std::ostream &toStream(std::ostream &out, RangeUnit unit, Endian order, int lo, int hi, bool closed) { if (unit == RangeUnit::Bit) @@ -39,3 +41,5 @@ std::ostream &toStream(std::ostream &out, RangeUnit unit, Endian order, int lo, return out; } + +} // namespace P4 diff --git a/lib/bitrange.h b/lib/bitrange.h index 0100cab7e4..7604f4c4ef 100644 --- a/lib/bitrange.h +++ b/lib/bitrange.h @@ -28,6 +28,8 @@ limitations under the License. #include "exceptions.h" #include "hash.h" +namespace P4 { + /* iterate over ranges of contiguous bits in a bitvector */ class bitranges { bitvec tmp; @@ -778,24 +780,26 @@ std::ostream &operator<<(std::ostream &out, const ClosedRange &rang return toStream(out, Unit, Order, range.lo, range.hi, true); } +} // namespace P4 + // Hashing specializations namespace std { -template -struct hash> { - std::size_t operator()(const HalfOpenRange &r) const { - return Util::Hash{}(r.lo, r.hi); +template +struct hash> { + std::size_t operator()(const P4::HalfOpenRange &r) const { + return P4::Util::Hash{}(r.lo, r.hi); } }; -template -struct hash> { - std::size_t operator()(const ClosedRange &r) const { - return Util::Hash{}(r.lo, r.hi); +template +struct hash> { + std::size_t operator()(const P4::ClosedRange &r) const { + return P4::Util::Hash{}(r.lo, r.hi); } }; } // namespace std -namespace Util { +namespace P4::Util { template struct Hasher> { size_t operator()(const HalfOpenRange &r) const { @@ -807,6 +811,6 @@ template struct Hasher> { size_t operator()(const ClosedRange &r) const { return Util::Hash{}(r.lo, r.hi); } }; -} // namespace Util +} // namespace P4::Util #endif /* LIB_BITRANGE_H_ */ diff --git a/lib/bitvec.cpp b/lib/bitvec.cpp index 05e1841863..459178d402 100644 --- a/lib/bitvec.cpp +++ b/lib/bitvec.cpp @@ -20,6 +20,8 @@ limitations under the License. #include "hex.h" +namespace P4 { + std::ostream &operator<<(std::ostream &os, const bitvec &bv) { if (bv.size == 1) { os << hex(bv.data); @@ -208,3 +210,5 @@ bitvec bitvec::rotate_right_copy(size_t start_bit, size_t rotation_idx, size_t e bitvec rv = rot_section | (*this - rot_mask); return rv; } + +} // namespace P4 diff --git a/lib/bitvec.h b/lib/bitvec.h index 42fea4703c..4063c6f98e 100644 --- a/lib/bitvec.h +++ b/lib/bitvec.h @@ -45,6 +45,7 @@ limitations under the License. #undef clrbit #endif +namespace P4 { namespace bv { #if defined(__GNUC__) || defined(__clang__) /* use builtin count leading/trailing bits of type-approprite size */ @@ -683,4 +684,6 @@ inline bitvec operator-(bitvec &&a, const bitvec &b) { return rv; } +} // namespace P4 + #endif /* LIB_BITVEC_H_ */ diff --git a/lib/bug_helper.h b/lib/bug_helper.h index b5f04a46f5..c8f52eec75 100644 --- a/lib/bug_helper.h +++ b/lib/bug_helper.h @@ -30,6 +30,7 @@ limitations under the License. #include "source_file.h" #include "stringify.h" +namespace P4 { namespace detail { static inline std::pair getPositionTail(const Util::SourceInfo &info, @@ -145,4 +146,6 @@ std::string bug_helper(boost::format &f, std::string_view position, std::string_ return detail::bug_helper(f, position, tail, std::forward(args)...); } +} // namespace P4 + #endif /* LIB_BUG_HELPER_H_ */ diff --git a/lib/castable.h b/lib/castable.h index 85f8fd732a..89a24c6524 100644 --- a/lib/castable.h +++ b/lib/castable.h @@ -22,6 +22,8 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/rtti.h" +namespace P4 { + /// Handy type conversion methods that can be inherited by various base classes. /// In order to use ICastable one also need to provide intrusive lightweight RTTI /// metadata for the given class hierarchy. See `docs/C++.md` for more information, @@ -64,4 +66,6 @@ class ICastable : public virtual RTTI::Base { } }; +} // namespace P4 + #endif /* LIB_CASTABLE_H_ */ diff --git a/lib/compile_context.cpp b/lib/compile_context.cpp index 3bdb385c79..d24f5506b6 100644 --- a/lib/compile_context.cpp +++ b/lib/compile_context.cpp @@ -19,6 +19,8 @@ limitations under the License. #include "lib/error.h" #include "lib/exceptions.h" +namespace P4 { + ICompileContext::~ICompileContext() {} /* static */ void CompileContextStack::push(ICompileContext *context) { @@ -78,3 +80,5 @@ DiagnosticAction BaseCompileContext::getDiagnosticAction(cstring /* diagnostic * DiagnosticAction defaultAction) { return defaultAction; } + +} // namespace P4 diff --git a/lib/compile_context.h b/lib/compile_context.h index 7ce536be41..f1ad069e12 100644 --- a/lib/compile_context.h +++ b/lib/compile_context.h @@ -23,6 +23,8 @@ limitations under the License. #include "lib/cstring.h" #include "lib/error_reporter.h" +namespace P4 { + /// An interface for objects which represent compiler settings and state for a /// translation unit. The compilation context might include things like compiler /// options which apply to the translation unit or errors and warnings generated @@ -94,13 +96,13 @@ class BaseCompileContext : public ICompileContext { /// @return the error reporter for this compilation context. virtual ErrorReporter &errorReporter(); - /// @return the default diagnostic action for calls to `::info()`. + /// @return the default diagnostic action for calls to `::P4::info()`. virtual DiagnosticAction getDefaultInfoDiagnosticAction(); - /// @return the default diagnostic action for calls to `::warning()`. + /// @return the default diagnostic action for calls to `::P4::warning()`. virtual DiagnosticAction getDefaultWarningDiagnosticAction(); - /// @return the default diagnostic action for calls to `::error()`. + /// @return the default diagnostic action for calls to `::P4::error()`. virtual DiagnosticAction getDefaultErrorDiagnosticAction(); /// @return the diagnostic action to use for @diagnosticName, or @@ -113,4 +115,6 @@ class BaseCompileContext : public ICompileContext { ErrorReporter errorReporterInstance; }; +} // namespace P4 + #endif /* LIB_COMPILE_CONTEXT_H_ */ diff --git a/lib/crash.cpp b/lib/crash.cpp index 4019e280dc..766cabd3bf 100644 --- a/lib/crash.cpp +++ b/lib/crash.cpp @@ -39,20 +39,25 @@ limitations under the License. #include +#ifdef MULTITHREAD +#include + +#include +#endif + #include "exceptions.h" #include "exename.h" #include "hex.h" #include "log.h" +namespace P4 { + static const char *signames[] = { "NONE", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "URG", "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "POLL", "PWR", "SYS"}; #ifdef MULTITHREAD -#include - -#include std::vector thread_ids; __thread int my_id; @@ -321,3 +326,5 @@ void setup_signals() { if (LOGGING(1)) global_backtrace_state = backtrace_create_state(exename(), 1, nullptr, nullptr); #endif } + +} // namespace P4 diff --git a/lib/crash.h b/lib/crash.h index 0e39f7687b..99c4c5a2fe 100644 --- a/lib/crash.h +++ b/lib/crash.h @@ -17,7 +17,11 @@ limitations under the License. #ifndef LIB_CRASH_H_ #define LIB_CRASH_H_ +namespace P4 { + void setup_signals(); const char *addr2line(void *addr, const char *text); +} // namespace P4 + #endif /* LIB_CRASH_H_ */ diff --git a/lib/cstring.cpp b/lib/cstring.cpp index cc7ccff95a..a00da5b163 100644 --- a/lib/cstring.cpp +++ b/lib/cstring.cpp @@ -41,6 +41,7 @@ limitations under the License. #include "hash.h" +namespace P4 { namespace { enum class table_entry_flags { none, @@ -324,3 +325,5 @@ cstring cstring::capitalize() const { st[0] = ::toupper(st[0]); return cstring(st); } + +} // namespace P4 diff --git a/lib/cstring.h b/lib/cstring.h index 59f99268fb..08da01e4d8 100644 --- a/lib/cstring.h +++ b/lib/cstring.h @@ -73,12 +73,15 @@ limitations under the License. * that mixing the two types of strings can trigger a lot of implicit copies. */ +namespace P4 { class cstring; +} // namespace P4 namespace P4::literals { inline cstring operator""_cs(const char *str, std::size_t len); } +namespace P4 { class cstring { const char *str = nullptr; @@ -394,6 +397,8 @@ inline std::ostream &operator<<(std::ostream &out, cstring s) { return out << (s ? s.c_str() : ""); } +} // namespace P4 + /// Let's prevent literal clashes. A user wishing to use the literal can do using namespace /// P4::literals, similarly as they can do using namespace std::literals for the standard once. namespace P4::literals { @@ -410,21 +415,21 @@ inline cstring operator""_cs(const char *str, std::size_t len) { namespace std { template <> -struct hash { - std::size_t operator()(const cstring &c) const { +struct hash { + std::size_t operator()(const P4::cstring &c) const { // cstrings are internalized, therefore their addresses are unique; we // can just use their address to produce hash. - return Util::Hash{}(c.c_str()); + return P4::Util::Hash{}(c.c_str()); } }; } // namespace std -namespace Util { +namespace P4::Util { template <> struct Hasher { size_t operator()(const cstring &c) const { return Util::Hash{}(c.c_str()); } }; -} // namespace Util +} // namespace P4::Util #endif /* LIB_CSTRING_H_ */ diff --git a/lib/enumerator.h b/lib/enumerator.h index bd71c48725..daeb477f2c 100644 --- a/lib/enumerator.h +++ b/lib/enumerator.h @@ -31,7 +31,7 @@ limitations under the License. #include "iterator_range.h" -namespace Util { +namespace P4::Util { enum class EnumeratorState { NotStarted, Valid, PastEnd }; template @@ -669,5 +669,6 @@ auto concat(Args &&...inputs) { return concat(init); } -} // namespace Util +} // namespace P4::Util + #endif /* LIB_ENUMERATOR_H_ */ diff --git a/lib/error.h b/lib/error.h index d2eb216295..4d87384718 100644 --- a/lib/error.h +++ b/lib/error.h @@ -28,6 +28,8 @@ limitations under the License. // This should eventually be turned to 0 when all the code is converted #define LEGACY 1 +namespace P4 { + /// @return the number of errors encountered so far in the current compilation /// context. inline unsigned errorCount() { return BaseCompileContext::get().errorReporter().getErrorCount(); } @@ -129,7 +131,7 @@ void warning(const int kind, const char *format, const T *node, Args &&...args) template && !std::is_pointer_v>, class... Args> void warning(const int kind, const char *format, const T &node, Args &&...args) { - ::warning(kind, format, &node, std::forward(args)...); + ::P4::warning(kind, format, &node, std::forward(args)...); } /// Report warnings of type kind, for messages that do not have a node. @@ -153,7 +155,7 @@ void info(const int kind, const char *format, const T *node, Args &&...args) { template && !std::is_pointer_v>, class... Args> void info(const int kind, const char *format, const T &node, Args &&...args) { - ::info(kind, format, &node, std::forward(args)...); + ::P4::info(kind, format, &node, std::forward(args)...); } /// Report info messages of type kind, for messages that do not have a node. @@ -175,7 +177,7 @@ void info(const int kind, const char *format, Args &&...args) { * generally use only lower-case letters and underscores * so the diagnostic name is a valid P4 identifier. * @param format A format for the diagnostic message, using the same style as - * '::warning' or '::error'. + * '::P4::warning' or '::P4::error'. * @param suffix A message that is appended at the end. */ template @@ -187,4 +189,6 @@ inline void diagnose(DiagnosticAction defaultAction, const char *diagnosticName, std::forward(args)...); } +} // namespace P4 + #endif /* LIB_ERROR_H_ */ diff --git a/lib/error_catalog.cpp b/lib/error_catalog.cpp index 5e1664f239..21c025042f 100644 --- a/lib/error_catalog.cpp +++ b/lib/error_catalog.cpp @@ -20,6 +20,8 @@ limitations under the License. #include "lib/cstring.h" +namespace P4 { + using namespace P4::literals; // -------- Errors ------------- @@ -122,3 +124,5 @@ std::map ErrorCatalog::errorCatalog = { // Info messages {ErrorType::INFO_INFERRED, "inferred"_cs}, {ErrorType::INFO_PROGRESS, "progress"_cs}}; + +} // namespace P4 diff --git a/lib/error_catalog.h b/lib/error_catalog.h index 8c71b94ad3..4a6e5edcb9 100644 --- a/lib/error_catalog.h +++ b/lib/error_catalog.h @@ -24,6 +24,8 @@ limitations under the License. #include "lib/error_message.h" #include "lib/exceptions.h" +namespace P4 { + using MessageType = ErrorMessage::MessageType; /// enumerate supported errors @@ -155,4 +157,6 @@ class ErrorCatalog { static std::map errorCatalog; }; +} // namespace P4 + #endif /* LIB_ERROR_CATALOG_H_ */ diff --git a/lib/error_helper.h b/lib/error_helper.h index b469c5d2c9..bedf17f09e 100644 --- a/lib/error_helper.h +++ b/lib/error_helper.h @@ -24,6 +24,7 @@ limitations under the License. #include "lib/source_file.h" #include "lib/stringify.h" +namespace P4 { namespace priv { // All these methods return std::string because this is the native format of boost::format @@ -89,20 +90,22 @@ auto error_helper(boost::format &f, ErrorMessage out, const T &t, template ErrorMessage error_helper(boost::format &f, Args &&...args) { ErrorMessage msg; - return ::priv::error_helper(f, msg, std::forward(args)...); + return priv::error_helper(f, msg, std::forward(args)...); } // Invoked from ErrorReporter template ErrorMessage error_helper(boost::format &f, ErrorMessage msg, Args &&...args) { - return ::priv::error_helper(f, std::move(msg), std::forward(args)...); + return priv::error_helper(f, std::move(msg), std::forward(args)...); } // This overload exists for backwards compatibility template ErrorMessage error_helper(boost::format &f, const std::string &prefix, const Util::SourceInfo &info, const std::string &suffix, Args &&...args) { - return ::priv::error_helper(f, ErrorMessage(prefix, info, suffix), std::forward(args)...); + return priv::error_helper(f, ErrorMessage(prefix, info, suffix), std::forward(args)...); } +} // namespace P4 + #endif /* LIB_ERROR_HELPER_H_ */ diff --git a/lib/error_message.cpp b/lib/error_message.cpp index 14f391c027..6284c22300 100644 --- a/lib/error_message.cpp +++ b/lib/error_message.cpp @@ -1,5 +1,7 @@ #include "error_message.h" +namespace P4 { + std::string ErrorMessage::getPrefix() const { std::string p = prefix; if (type == MessageType::Error) { @@ -45,3 +47,5 @@ std::string ParserErrorMessage::toString() const { return std::string(location.toPositionString().c_str()) + ":" + message + "\n" + location.toSourceFragment().c_str(); } + +} // namespace P4 diff --git a/lib/error_message.h b/lib/error_message.h index f951e4c784..2d09e2cc13 100644 --- a/lib/error_message.h +++ b/lib/error_message.h @@ -21,16 +21,18 @@ limitations under the License. #include "lib/source_file.h" +namespace P4 { + /** * Structure populated via error_helper functions * - * Typically, calls to ::error/::warning have many parameters, some of them - * might have SourceInfo attribute. ::error_helper parse those parameters, format + * Typically, calls to ::P4::error/::P4::warning have many parameters, some of them + * might have SourceInfo attribute. ::P4::error_helper parse those parameters, format * parameters to output message and extracts SourceInfo wherever possible. * * Populated structure can be serialized to canonical error message with toString() method. * - * This structure is mainly used inside ErrorReporter, but some uses invoke ::error_helper + * This structure is mainly used inside ErrorReporter, but some uses invoke ::P4::error_helper * directly and those uses need to call toString() on returned object. */ struct ErrorMessage { @@ -75,4 +77,6 @@ struct ParserErrorMessage { std::string toString() const; }; +} // namespace P4 + #endif /* LIB_ERROR_MESSAGE_H_ */ diff --git a/lib/error_reporter.h b/lib/error_reporter.h index 83a5c48a32..b0005c4b8c 100644 --- a/lib/error_reporter.h +++ b/lib/error_reporter.h @@ -31,6 +31,8 @@ limitations under the License. #include "error_helper.h" #include "exceptions.h" +namespace P4 { + /// An action to take when a diagnostic message is triggered. enum class DiagnosticAction { Ignore, /// Take no action and continue compilation. @@ -97,13 +99,13 @@ class ErrorReporter { boost::format fmt(format); // FIXME: This will implicitly take location of the first argument having // SourceInfo. Not sure if this always desireable or not. - return ::bug_helper(fmt, "", "", std::forward(args)...); + return ::P4::bug_helper(fmt, "", "", std::forward(args)...); } template std::string format_message(const char *format, Args &&...args) { boost::format fmt(format); - return ::error_helper(fmt, std::forward(args)...).toString(); + return ::P4::error_helper(fmt, std::forward(args)...).toString(); } template ()->getSourceInfo()), typename... Args> @@ -157,7 +159,7 @@ class ErrorReporter { boost::format fmt(format); ErrorMessage msg(msgType, diagnosticName ? diagnosticName : "", suffix); - msg = ::error_helper(fmt, msg, std::forward(args)...); + msg = ::P4::error_helper(fmt, msg, std::forward(args)...); emit_message(msg); if (errorCount > maxErrorCount) @@ -241,31 +243,33 @@ class ErrorReporter { diagnosticActions[cstring(diagnostic)] = action; } - /// @return the default diagnostic action for calls to `::warning()`. + /// @return the default diagnostic action for calls to `::P4::warning()`. DiagnosticAction getDefaultWarningDiagnosticAction() { return defaultWarningDiagnosticAction; } - /// set the default diagnostic action for calls to `::warning()`. + /// set the default diagnostic action for calls to `::P4::warning()`. void setDefaultWarningDiagnosticAction(DiagnosticAction action) { defaultWarningDiagnosticAction = action; } - /// @return the default diagnostic action for calls to `::info()`. + /// @return the default diagnostic action for calls to `::P4::info()`. DiagnosticAction getDefaultInfoDiagnosticAction() { return defaultInfoDiagnosticAction; } - /// set the default diagnostic action for calls to `::info()`. + /// set the default diagnostic action for calls to `::P4::info()`. void setDefaultInfoDiagnosticAction(DiagnosticAction action) { defaultInfoDiagnosticAction = action; } private: - /// The default diagnostic action for calls to `::info()`. + /// The default diagnostic action for calls to `::P4::info()`. DiagnosticAction defaultInfoDiagnosticAction; - /// The default diagnostic action for calls to `::warning()`. + /// The default diagnostic action for calls to `::P4::warning()`. DiagnosticAction defaultWarningDiagnosticAction; /// allow filtering of diagnostic actions std::unordered_map diagnosticActions; }; +} // namespace P4 + #endif /* LIB_ERROR_REPORTER_H_ */ diff --git a/lib/exceptions.h b/lib/exceptions.h index 09e45c45d4..0f62fde093 100644 --- a/lib/exceptions.h +++ b/lib/exceptions.h @@ -28,7 +28,7 @@ limitations under the License. #include "absl/strings/str_cat.h" #include "lib/bug_helper.h" -namespace Util { +namespace P4::Util { // colors to pretty print messages // \e is non-standard escape sequence, use codepoint \33 instead @@ -79,7 +79,7 @@ class P4CExceptionBase : public std::exception { boost::format fmt(format); // FIXME: This will implicitly take location of the first argument having // SourceInfo. Not sure if this always desireable or not. - message = ::bug_helper(fmt, "", "", std::forward(args)...); + message = ::P4::bug_helper(fmt, "", "", std::forward(args)...); } const char *what() const noexcept { return message.c_str(); } @@ -134,25 +134,25 @@ class CompilationError : public P4CExceptionBase { : P4CExceptionBase(format, std::forward(args)...) {} }; -#define BUG(...) \ - do { \ - throw Util::CompilerBug(__LINE__, __FILE__, __VA_ARGS__); \ +#define BUG(...) \ + do { \ + throw P4::Util::CompilerBug(__LINE__, __FILE__, __VA_ARGS__); \ } while (0) #define BUG_CHECK(e, ...) \ do { \ if (!(e)) BUG(__VA_ARGS__); \ } while (0) -#define P4C_UNIMPLEMENTED(...) \ - do { \ - throw Util::CompilerUnimplemented(__LINE__, __FILE__, __VA_ARGS__); \ +#define P4C_UNIMPLEMENTED(...) \ + do { \ + throw P4::Util::CompilerUnimplemented(__LINE__, __FILE__, __VA_ARGS__); \ } while (0) -} // namespace Util +} // namespace P4::Util /// Report an error and exit -#define FATAL_ERROR(...) \ - do { \ - throw Util::CompilationError(__VA_ARGS__); \ +#define FATAL_ERROR(...) \ + do { \ + throw P4::Util::CompilationError(__VA_ARGS__); \ } while (0) #endif /* LIB_EXCEPTIONS_H_ */ diff --git a/lib/exename.cpp b/lib/exename.cpp index e7678073e6..3fea49aaf4 100644 --- a/lib/exename.cpp +++ b/lib/exename.cpp @@ -26,6 +26,8 @@ limitations under the License. #include "exceptions.h" +namespace P4 { + template static void convertToAbsPath(const char *const relPath, char (&output)[N]) { output[0] = '\0'; // Default to the empty string, indicating failure. @@ -67,3 +69,5 @@ const char *exename(const char *argv0) { } return buffer; } + +} // namespace P4 diff --git a/lib/exename.h b/lib/exename.h index b1bef02ce4..5046f2ce4b 100644 --- a/lib/exename.h +++ b/lib/exename.h @@ -16,8 +16,12 @@ limitations under the License. #ifndef LIB_EXENAME_H_ #define LIB_EXENAME_H_ +namespace P4 { + /** Attempt to determine the executable name and return a static path to it. Will use * argv0 if provided and nothing better can be found */ const char *exename(const char *argv0 = nullptr); +} // namespace P4 + #endif /* LIB_EXENAME_H_ */ diff --git a/lib/gc.cpp b/lib/gc.cpp index c6d8bd65a5..ccecdc7238 100644 --- a/lib/gc.cpp +++ b/lib/gc.cpp @@ -47,6 +47,8 @@ limitations under the License. #include "log.h" #include "n4.h" +using namespace P4; + // One can disable the GC, e.g., to run under Valgrind, by editing config.h or toggling // -DENABLE_GC=OFF in CMake. #if HAVE_LIBGC diff --git a/lib/gc.h b/lib/gc.h index 8493cfeef6..0876508ac6 100644 --- a/lib/gc.h +++ b/lib/gc.h @@ -19,10 +19,11 @@ limitations under the License. #include +#define ALLOC_TRACE_DEPTH 5 + void setup_gc_logging(); size_t gc_mem_inuse(size_t *max = 0); // trigger GC, return inuse after -#define ALLOC_TRACE_DEPTH 5 struct alloc_trace_cb_t { void (*fn)(void *, void **, size_t); void *arg; diff --git a/lib/hash.cpp b/lib/hash.cpp index 5cf1079377..81ab438815 100644 --- a/lib/hash.cpp +++ b/lib/hash.cpp @@ -38,7 +38,7 @@ #include #include -namespace Util { +namespace P4::Util { namespace { using namespace Detail; @@ -343,4 +343,4 @@ uint64_t hash(const void *in, size_t len) { if (len <= XXH3_MIDSIZE_MAX) return XXH3_len_129to240_64b(data, len, kSecret, 0); return XXH3_hashLong_64b(data, len, kSecret, sizeof(kSecret)); } -} // namespace Util +} // namespace P4::Util diff --git a/lib/hash.h b/lib/hash.h index 46097833dc..9edaa77e6b 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -11,7 +11,7 @@ #include #include -namespace Util { +namespace P4::Util { namespace Detail { constexpr uint32_t PRIME32_1 = UINT32_C(0x9E3779B1); @@ -278,13 +278,13 @@ struct TupleHasher<0, Types...> { } }; } // namespace Detail -} // namespace Util +} // namespace P4::Util namespace std { template struct hash> { size_t operator()(const std::pair &x) const { - return Util::hash_combine(x.first, x.second); + return P4::Util::hash_combine(x.first, x.second); } }; @@ -292,7 +292,7 @@ template struct hash> { public: size_t operator()(std::tuple const &key) const { - Util::Detail::TupleHasher hasher; + P4::Util::Detail::TupleHasher hasher; return hasher(key); } diff --git a/lib/hashvec.cpp b/lib/hashvec.cpp index 49c78064e0..2031c49d0b 100644 --- a/lib/hashvec.cpp +++ b/lib/hashvec.cpp @@ -16,8 +16,14 @@ limitations under the License. #include "hashvec.h" +#ifdef DEBUG +#include +#endif + #include "exceptions.h" +namespace P4 { + /* FIXME -- there are almost certainly problems when the hashtable size * FIXME -- exceeds INT_MAX elements. That requires 16GB+ memory... */ @@ -458,8 +464,6 @@ void *hash_vector_base::lookup_cache::getval(hash_vector_base *ht) { } #ifdef DEBUG -#include - void hash_vector_base::dump(std::ostream &out) { int fs = 4, ls = 18; out << "hash_vector " << (void *)this << ": " << (info->ismap ? "map" : "set") @@ -487,3 +491,5 @@ void hash_vector_base::dump(std::ostream &out) { out << "\nerased=" << erased << std::endl; } #endif /* DEBUG */ + +} // namespace P4 diff --git a/lib/hashvec.h b/lib/hashvec.h index d11ee152f9..115bd5f4b5 100644 --- a/lib/hashvec.h +++ b/lib/hashvec.h @@ -24,6 +24,8 @@ limitations under the License. #include #endif +namespace P4 { + class hash_vector_base { struct internal; internal *info; @@ -88,4 +90,6 @@ class hash_vector_base { void redo_hash(); }; +} // namespace P4 + #endif /* LIB_HASHVEC_H_ */ diff --git a/lib/hex.cpp b/lib/hex.cpp index 46c5a3067b..37b32e11e6 100644 --- a/lib/hex.cpp +++ b/lib/hex.cpp @@ -19,6 +19,8 @@ limitations under the License. #include #include +namespace P4 { + std::ostream &operator<<(std::ostream &os, const hexvec &h) { auto save = os.flags(); auto save_fill = os.fill(); @@ -50,3 +52,5 @@ std::ostream &operator<<(std::ostream &os, const hexvec &h) { os.flags(save); return os; } + +} // namespace P4 diff --git a/lib/hex.h b/lib/hex.h index 85782662e0..939cf55c11 100644 --- a/lib/hex.h +++ b/lib/hex.h @@ -22,6 +22,8 @@ limitations under the License. #include #include +namespace P4 { + class hex { std::intmax_t val; int width; @@ -60,4 +62,6 @@ class hexvec { std::ostream &operator<<(std::ostream &os, const hexvec &h); +} // namespace P4 + #endif /* LIB_HEX_H_ */ diff --git a/lib/hvec_map.h b/lib/hvec_map.h index e2189ffc73..0dedcfb15e 100644 --- a/lib/hvec_map.h +++ b/lib/hvec_map.h @@ -24,6 +24,8 @@ limitations under the License. #include "exceptions.h" #include "hashvec.h" +namespace P4 { + template , class PRED = std::equal_to, class ALLOC = std::allocator>> class hvec_map : hash_vector_base { @@ -356,4 +358,6 @@ inline const V *getref(const hvec_map *m, T key) { return m ? getref(*m, key) : 0; } +} // namespace P4 + #endif /* LIB_HVEC_MAP_H_ */ diff --git a/lib/hvec_set.h b/lib/hvec_set.h index 3a9891685c..2d3242c660 100644 --- a/lib/hvec_set.h +++ b/lib/hvec_set.h @@ -24,6 +24,8 @@ limitations under the License. #include "exceptions.h" #include "hashvec.h" +namespace P4 { + template , class PRED = std::equal_to, class ALLOC = std::allocator> class hvec_set : hash_vector_base { @@ -252,4 +254,6 @@ class hvec_set : hash_vector_base { void moveentry(size_t to, size_t from) override { data[to] = data[from]; } }; +} // namespace P4 + #endif /* LIB_HVEC_SET_H_ */ diff --git a/lib/indent.cpp b/lib/indent.cpp index 7365477084..f3040554d0 100644 --- a/lib/indent.cpp +++ b/lib/indent.cpp @@ -23,6 +23,8 @@ limitations under the License. #endif /* HAVE_LIBGC */ #include "indent.h" +namespace P4 { + int indent_t::tabsz = 2; static int indentctl_index = -1; @@ -51,3 +53,5 @@ indent_t &indent_t::getindent(std::ostream &out) { } return *static_cast(p); } + +} // namespace P4 diff --git a/lib/indent.h b/lib/indent.h index 5f16217e09..0394825c7f 100644 --- a/lib/indent.h +++ b/lib/indent.h @@ -21,6 +21,8 @@ limitations under the License. #include #include +namespace P4 { + class indent_t { int indent; @@ -118,6 +120,7 @@ class TempIndent { } }; -} // end namespace IndentCtl +} // namespace IndentCtl +} // namespace P4 #endif /* LIB_INDENT_H_ */ diff --git a/lib/iterator_range.h b/lib/iterator_range.h index 445b9fa4f9..cc57511367 100644 --- a/lib/iterator_range.h +++ b/lib/iterator_range.h @@ -18,7 +18,7 @@ limitations under the License. #include #include -namespace Util { +namespace P4::Util { namespace Detail { using std::begin; using std::end; @@ -67,6 +67,6 @@ class iterator_range { template iterator_range(Container &&) -> iterator_range>; -} // namespace Util +} // namespace P4::Util #endif /* LIB_ITERATOR_RANGE_H_ */ diff --git a/lib/json.cpp b/lib/json.cpp index 9641b6e203..f2252502a4 100644 --- a/lib/json.cpp +++ b/lib/json.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "indent.h" #include "lib/big_int_util.h" -namespace Util { +namespace P4::Util { cstring IJson::toString() const { std::stringstream str; @@ -200,4 +200,4 @@ JsonObject *JsonObject::emplace_non_null(cstring label, IJson *value) { return this; } -} // namespace Util +} // namespace P4::Util diff --git a/lib/json.h b/lib/json.h index 5faee55960..939aa410bb 100644 --- a/lib/json.h +++ b/lib/json.h @@ -31,11 +31,11 @@ limitations under the License. #include "lib/map.h" #include "lib/string_map.h" -namespace Test { +namespace P4::Test { class TestJson; } -namespace Util { +namespace P4::Util { class IJson : public ICastable { public: @@ -181,8 +181,8 @@ class JsonObject final : public IJson, public string_map { return this; } - IJson *get(cstring label) const { return ::get(*this, label); } - IJson *get(std::string_view label) const { return ::get(*this, label); } + IJson *get(cstring label) const { return ::P4::get(*this, label); } + IJson *get(std::string_view label) const { return ::P4::get(*this, label); } template T *getAs(S label) const { return get(label)->template to(); @@ -191,6 +191,6 @@ class JsonObject final : public IJson, public string_map { DECLARE_TYPEINFO(JsonObject, IJson); }; -} // namespace Util +} // namespace P4::Util #endif /* LIB_JSON_H_ */ diff --git a/lib/log.cpp b/lib/log.cpp index 571fce9b7f..34283a950a 100644 --- a/lib/log.cpp +++ b/lib/log.cpp @@ -37,6 +37,7 @@ limitations under the License. #include #endif // MULTITHREAD +namespace P4 { namespace Log { namespace Detail { @@ -358,3 +359,4 @@ void increaseVerbosity() { } } // namespace Log +} // namespace P4 diff --git a/lib/log.h b/lib/log.h index 2524bfe4c8..15f437475b 100644 --- a/lib/log.h +++ b/lib/log.h @@ -31,6 +31,7 @@ limitations under the License. #define __attribute__(X) #endif +namespace P4 { namespace Log { namespace Detail { // The global verbosity level. @@ -75,9 +76,9 @@ inline std::ostream &endl(std::ostream &out) { Detail::OutputLogPrefix::indent(out); return out; } -using IndentCtl::indent; -using IndentCtl::TempIndent; -using IndentCtl::unindent; +using ::P4::IndentCtl::indent; +using ::P4::IndentCtl::TempIndent; +using ::P4::IndentCtl::unindent; inline bool fileLogLevelIsAtLeast(const char *file, int level) { // If there's no file with a log level of at least @level, we don't need to do @@ -100,6 +101,7 @@ inline bool enableLogging() { void increaseVerbosity(); } // namespace Log +} // namespace P4 #ifndef MAX_LOGGING_LEVEL // can be set on build command line and disables higher logging levels at compile time @@ -107,13 +109,13 @@ void increaseVerbosity(); #endif // NOLINTBEGIN(bugprone-macro-parentheses) -#define LOGGING(N) \ - ((N) <= MAX_LOGGING_LEVEL && ::Log::fileLogLevelIsAtLeast(__FILE__, N) && \ - ::Log::enableLogging()) -#define LOGN(N, X) \ - (LOGGING(N) ? ::Log::Detail::fileLogOutput(__FILE__) \ - << ::Log::Detail::OutputLogPrefix(__FILE__, N) << X \ - << ::Log::Detail::clearPrefix << std::endl \ +#define LOGGING(N) \ + ((N) <= MAX_LOGGING_LEVEL && P4::Log::fileLogLevelIsAtLeast(__FILE__, N) && \ + P4::Log::enableLogging()) +#define LOGN(N, X) \ + (LOGGING(N) ? P4::Log::Detail::fileLogOutput(__FILE__) \ + << P4::Log::Detail::OutputLogPrefix(__FILE__, N) << X \ + << P4::Log::Detail::clearPrefix << std::endl \ : std::clog) #define LOG1(X) LOGN(1, X) #define LOG2(X) LOGN(2, X) @@ -126,7 +128,7 @@ void increaseVerbosity(); #define LOG9(X) LOGN(9, X) #define LOGN_UNINDENT(N) \ - (LOGGING(N) ? ::Log::Detail::fileLogOutput(__FILE__) << IndentCtl::unindent : std::clog) + (LOGGING(N) ? P4::Log::Detail::fileLogOutput(__FILE__) << P4::IndentCtl::unindent : std::clog) #define LOG1_UNINDENT LOGN_UNINDENT(1) #define LOG2_UNINDENT LOGN_UNINDENT(2) #define LOG3_UNINDENT LOGN_UNINDENT(3) @@ -137,17 +139,19 @@ void increaseVerbosity(); #define LOG8_UNINDENT LOGN_UNINDENT(8) #define LOG9_UNINDENT LOGN_UNINDENT(9) -#define LOG_FEATURE(TAG, N, X) \ - ((N) <= MAX_LOGGING_LEVEL && ::Log::fileLogLevelIsAtLeast(TAG, N) \ - ? ::Log::Detail::fileLogOutput(TAG) \ - << ::Log::Detail::OutputLogPrefix(TAG, N) << X << std::endl \ +#define LOG_FEATURE(TAG, N, X) \ + ((N) <= MAX_LOGGING_LEVEL && P4::Log::fileLogLevelIsAtLeast(TAG, N) \ + ? P4::Log::Detail::fileLogOutput(TAG) \ + << P4::Log::Detail::OutputLogPrefix(TAG, N) << X << std::endl \ : std::clog) #define P4C_ERROR(X) (std::clog << "ERROR: " << X << std::endl) -#define P4C_WARNING(X) (::Log::verbose() ? std::clog << "WARNING: " << X << std::endl : std::clog) +#define P4C_WARNING(X) (P4::Log::verbose() ? std::clog << "WARNING: " << X << std::endl : std::clog) #define ERRWARN(C, X) ((C) ? P4C_ERROR(X) : P4C_WARNING(X)) // NOLINTEND(bugprone-macro-parentheses) +namespace P4 { + static inline std::ostream &operator<<(std::ostream &out, std::function fn) { return fn(out); @@ -200,4 +204,6 @@ std::ostream &operator<<(std::ostream &out, const std::set &set) { return format_container(out, set, '(', ')'); } +} // namespace P4 + #endif /* LIB_LOG_H_ */ diff --git a/lib/ltbitmatrix.h b/lib/ltbitmatrix.h index ee1dc26a56..cc02ab3860 100644 --- a/lib/ltbitmatrix.h +++ b/lib/ltbitmatrix.h @@ -19,6 +19,8 @@ limitations under the License. #include "bitvec.h" +namespace P4 { + /* A lower-triangular bit matrix, held in a bit vector */ class LTBitMatrix : private bitvec { public: @@ -112,4 +114,6 @@ inline bool operator>>(const char *p, LTBitMatrix &bm) { return true; } +} // namespace P4 + #endif /* LIB_LTBITMATRIX_H_ */ diff --git a/lib/map.h b/lib/map.h index 7128d9dbb7..0954ad967e 100644 --- a/lib/map.h +++ b/lib/map.h @@ -20,6 +20,8 @@ limitations under the License. #include #include +namespace P4 { + /// Given a map and a key, return the value corresponding to the key in the map, /// or a given default value if the key doesn't exist in the map. template @@ -247,4 +249,6 @@ MapForKey ValuesForKey(M &m, typename M::key_type k) { return MapForKey(m, k); } +} // namespace P4 + #endif /* LIB_MAP_H_ */ diff --git a/lib/match.cpp b/lib/match.cpp index 4b1978e298..b3fdb6fa36 100644 --- a/lib/match.cpp +++ b/lib/match.cpp @@ -16,6 +16,8 @@ limitations under the License. #include "match.h" +namespace P4 { + static int chkmask(const match_t &m, int maskbits) { big_int mask = (big_int(1) << maskbits) - 1; int shift = 0; @@ -133,3 +135,5 @@ void dump(const match_t *m) { std::cout << ""; std::cout << std::endl; } + +} // namespace P4 diff --git a/lib/match.h b/lib/match.h index 3166f7f6df..eea7da5277 100644 --- a/lib/match.h +++ b/lib/match.h @@ -23,6 +23,8 @@ limitations under the License. #include "big_int_util.h" +namespace P4 { + /// The ternary expression being matched, given as a pair of bitmasks: /// (word0, word1). The ternary expression cares about the value of an /// input bit if the corresponding bit is set in exactly one of the @@ -58,4 +60,6 @@ struct match_t { std::ostream &operator<<(std::ostream &, const match_t &); bool operator>>(const char *, match_t &); +} // namespace P4 + #endif /* LIB_MATCH_H_ */ diff --git a/lib/n4.h b/lib/n4.h index 5ed4fbefec..310d595830 100644 --- a/lib/n4.h +++ b/lib/n4.h @@ -5,6 +5,8 @@ #include #include +namespace P4 { + class n4 { /* format a value as 4 chars */ uint64_t val, div; @@ -58,4 +60,6 @@ class n4 { inline std::ostream &operator<<(std::ostream &os, n4 v) { return v.print(os); } +} // namespace P4 + #endif /* LIB_N4_H_ */ diff --git a/lib/nethash.cpp b/lib/nethash.cpp index 11911dab13..a58345356b 100644 --- a/lib/nethash.cpp +++ b/lib/nethash.cpp @@ -29,7 +29,7 @@ * http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code */ -namespace NetHash { +namespace P4::NetHash { /// Reflects/reverse n-bit number bit-by-bit. Note that it also solves as a slicing cast in the main /// calculation loop, where it extracts and reflect lowest byte. Written as templated function @@ -248,4 +248,4 @@ uint64_t identity(const uint8_t *buf, size_t len) { return res; } -} // namespace NetHash +} // namespace P4::NetHash diff --git a/lib/nethash.h b/lib/nethash.h index 8578ebcece..d141c11891 100644 --- a/lib/nethash.h +++ b/lib/nethash.h @@ -6,7 +6,7 @@ #include /// A collection of hashing functions commonly used in network protocols. -namespace NetHash { +namespace P4::NetHash { /// CRC-16 used in BMv2 (parameters: bit-reflection, polynomial 0x8005, init = 0 and xor_out = 0). uint16_t crc16(const uint8_t *buf, size_t len); @@ -35,6 +35,6 @@ uint16_t xor16(const uint8_t *buf, size_t len); /// Identity hash -- the first (up to) 64bits of the values (i.e. indexes 0 to 7). uint64_t identity(const uint8_t *buf, size_t len); -} // namespace NetHash +} // namespace P4::NetHash #endif /* LIB_NETHASH_H_ */ diff --git a/lib/nullstream.cpp b/lib/nullstream.cpp index 9436bbe9f3..2154c27114 100644 --- a/lib/nullstream.cpp +++ b/lib/nullstream.cpp @@ -20,17 +20,22 @@ limitations under the License. #include "lib/error.h" +namespace P4 { + std::ostream *openFile(const std::filesystem::path &name, bool nullOnError) { if (name.empty()) { if (nullOnError) return new nullstream(); - ::error(ErrorType::ERR_INVALID, "Empty name for openFile"); + ::P4::error(ErrorType::ERR_INVALID, "Empty name for openFile"); return nullptr; } std::ofstream *file = new std::ofstream(name); if (!file->good()) { - ::error(ErrorType::ERR_IO, "Error writing output to file %1%: %2%", name, strerror(errno)); + ::P4::error(ErrorType::ERR_IO, "Error writing output to file %1%: %2%", name, + strerror(errno)); if (nullOnError) return new nullstream(); return nullptr; } return file; } + +} // namespace P4 diff --git a/lib/nullstream.h b/lib/nullstream.h index 28973cb654..9804625b55 100644 --- a/lib/nullstream.h +++ b/lib/nullstream.h @@ -22,6 +22,8 @@ limitations under the License. #include #include +namespace P4 { + template > class basic_nullbuf final : public std::basic_streambuf { typename traits::int_type overflow(typename traits::int_type c) { @@ -47,4 +49,6 @@ typedef onullstream nullstream; // FIXME: This should return unique_ptr instead to track lifetime std::ostream *openFile(const std::filesystem::path &name, bool nullOnError); +} // namespace P4 + #endif /* LIB_NULLSTREAM_H_ */ diff --git a/lib/options.cpp b/lib/options.cpp index 610aa0c848..cc05daf7f9 100644 --- a/lib/options.cpp +++ b/lib/options.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "lib/null.h" +namespace P4 { + void Util::Options::registerOption(const char *option, const char *argName, OptionProcessor processor, const char *description, OptionFlags flags /* = OptionFlags::Default */) { @@ -65,7 +67,7 @@ std::vector *Util::Options::process(int argc, char *const argv[]) option = get(options, opt); if (!option && (arg = opt.find('='))) option = get(options, opt.before(arg++)); if (option == nullptr) { - ::error(ErrorType::ERR_UNKNOWN, "Unknown option %1%", opt); + ::P4::error(ErrorType::ERR_UNKNOWN, "Unknown option %1%", opt); usage(); return nullptr; } @@ -80,7 +82,7 @@ std::vector *Util::Options::process(int argc, char *const argv[]) option = get(options, opt); } if (option == nullptr) { - ::error(ErrorType::ERR_UNKNOWN, "Unknown option %1%", opt); + ::P4::error(ErrorType::ERR_UNKNOWN, "Unknown option %1%", opt); usage(); return nullptr; } @@ -94,8 +96,9 @@ std::vector *Util::Options::process(int argc, char *const argv[]) if (option->argName != nullptr && arg == nullptr && !(option->flags & OptionFlags::OptionalArgument)) { if (i == argc - 1) { - ::error(ErrorType::ERR_EXPECTED, "Option %1% is missing required argument %2%", - opt, option->argName); + ::P4::error(ErrorType::ERR_EXPECTED, + "Option %1% is missing required argument %2%", opt, + option->argName); usage(); return nullptr; } @@ -162,3 +165,5 @@ void Util::Options::usage() { } bool Util::Options::validateOptions() const { return true; } + +} // namespace P4 diff --git a/lib/options.h b/lib/options.h index 0eedf34cd9..00fc753417 100644 --- a/lib/options.h +++ b/lib/options.h @@ -28,7 +28,7 @@ limitations under the License. #include "error.h" #include "map.h" -namespace Util { +namespace P4::Util { // Command-line options processing class Options { @@ -107,6 +107,6 @@ class Options { virtual void usage(); }; -} // namespace Util +} // namespace P4::Util #endif /* LIB_OPTIONS_H_ */ diff --git a/lib/ordered_map.h b/lib/ordered_map.h index 0936151f8f..af950028b8 100644 --- a/lib/ordered_map.h +++ b/lib/ordered_map.h @@ -24,6 +24,8 @@ limitations under the License. #include #include +namespace P4 { + // Map is ordered by order of element insertion. template , class ALLOC = std::allocator>> @@ -254,4 +256,6 @@ class ordered_map { } }; +} // namespace P4 + #endif /* LIB_ORDERED_MAP_H_ */ diff --git a/lib/ordered_set.h b/lib/ordered_set.h index a9dbc2cffb..95d4625bfb 100644 --- a/lib/ordered_set.h +++ b/lib/ordered_set.h @@ -25,6 +25,8 @@ limitations under the License. #include #include +namespace P4 { + // Remembers items in insertion order template , class ALLOC = std::allocator> class ordered_set { @@ -311,4 +313,6 @@ inline auto intersects(const ordered_set &a, const U &b) -> decltype( return false; } +} // namespace P4 + #endif /* LIB_ORDERED_SET_H_ */ diff --git a/lib/range.h b/lib/range.h index 75528fb059..d515badeec 100644 --- a/lib/range.h +++ b/lib/range.h @@ -19,6 +19,8 @@ limitations under the License. #include +namespace P4 { + template class RangeIter { int incr; @@ -61,4 +63,6 @@ std::ostream &operator<<(std::ostream &out, const RangeIter &r) { return out; } +} // namespace P4 + #endif /* LIB_RANGE_H_ */ diff --git a/lib/rtti.h b/lib/rtti.h index 2fa19d5605..223118da9d 100644 --- a/lib/rtti.h +++ b/lib/rtti.h @@ -63,7 +63,7 @@ limitations under the License. /// of clang. Some of them likely would need to be marked as `consteval` when C++20 /// would be used across the codebase. -namespace RTTI { +namespace P4::RTTI { using TypeId = std::uint64_t; static constexpr TypeId InvalidTypeId = UINT64_C(0); @@ -237,7 +237,7 @@ struct Base { [[nodiscard]] virtual const void *toImpl(TypeId typeId) const noexcept = 0; }; -} // namespace RTTI +} // namespace P4::RTTI /// Declare typeinfo for a given class `T`. /// @@ -256,9 +256,9 @@ struct Base { /// ... /// DECLARE_TYPEINFO(Derived, Base1, Base2); /// }; -#define DECLARE_TYPEINFO(T, ...) \ - private: \ - static constexpr RTTI::TypeId static_typeId() { return RTTI::InvalidTypeId; } \ +#define DECLARE_TYPEINFO(T, ...) \ + private: \ + static constexpr P4::RTTI::TypeId static_typeId() { return P4::RTTI::InvalidTypeId; } \ DECLARE_TYPEINFO_COMMON(T, ##__VA_ARGS__) // static_typeId is private above in order to hide explicit typeId from the base // class, as in e.g. @@ -277,9 +277,9 @@ struct Base { /// ... /// DECLARE_TYPEINFO_WITH_TYPEID(Base, 42); /// }; -#define DECLARE_TYPEINFO_WITH_TYPEID(T, Id, ...) \ - public: \ - static constexpr RTTI::TypeId static_typeId() { return RTTI::TypeId(Id); } \ +#define DECLARE_TYPEINFO_WITH_TYPEID(T, Id, ...) \ + public: \ + static constexpr P4::RTTI::TypeId static_typeId() { return P4::RTTI::TypeId(Id); } \ DECLARE_TYPEINFO_COMMON(T, ##__VA_ARGS__) /// Declare typinfo for a given class `T` combining discriminator value and @@ -288,26 +288,26 @@ struct Base { /// Use with caution, no checks for typeid clashes, etc. are /// performed. Discriminator from inner typeid is stripped off. Examples of /// usage include `Vector` and `IndexedVector`. -#define DECLARE_TYPEINFO_WITH_DISCRIMINATOR(T, Discriminator, InnerT, ...) \ - public: \ - static constexpr RTTI::TypeId static_typeId() { \ - return RTTI::combineTypeIdWithDiscriminator(RTTI::TypeId(Discriminator), \ - RTTI::TypeInfo::id()); \ - }; \ +#define DECLARE_TYPEINFO_WITH_DISCRIMINATOR(T, Discriminator, InnerT, ...) \ + public: \ + static constexpr P4::RTTI::TypeId static_typeId() { \ + return P4::RTTI::combineTypeIdWithDiscriminator(P4::RTTI::TypeId(Discriminator), \ + P4::RTTI::TypeInfo::id()); \ + }; \ DECLARE_TYPEINFO_COMMON(T, ##__VA_ARGS__) -#define DECLARE_TYPEINFO_COMMON(T, ...) \ - public: \ - static constexpr T *rttiEnabledMarker(T *); \ - using TypeInfo = RTTI::TypeInfo; \ - [[nodiscard]] RTTI::TypeId typeId() const noexcept override { return TypeInfo::id(); } \ - [[nodiscard]] bool isA(RTTI::TypeId typeId) const noexcept override { \ - return TypeInfo::isA(typeId); \ - } \ - \ - protected: \ - [[nodiscard]] const void *toImpl(RTTI::TypeId typeId) const noexcept override { \ - return TypeInfo::isA(typeId) ? TypeInfo::dyn_cast(typeId, this) : nullptr; \ +#define DECLARE_TYPEINFO_COMMON(T, ...) \ + public: \ + static constexpr T *rttiEnabledMarker(T *); \ + using TypeInfo = P4::RTTI::TypeInfo; \ + [[nodiscard]] P4::RTTI::TypeId typeId() const noexcept override { return TypeInfo::id(); } \ + [[nodiscard]] bool isA(P4::RTTI::TypeId typeId) const noexcept override { \ + return TypeInfo::isA(typeId); \ + } \ + \ + protected: \ + [[nodiscard]] const void *toImpl(P4::RTTI::TypeId typeId) const noexcept override { \ + return TypeInfo::isA(typeId) ? TypeInfo::dyn_cast(typeId, this) : nullptr; \ } #endif /* LIB_RTTI_H_ */ diff --git a/lib/rtti_utils.h b/lib/rtti_utils.h index 84fa33a5fd..abdc4a216e 100644 --- a/lib/rtti_utils.h +++ b/lib/rtti_utils.h @@ -24,7 +24,7 @@ limitations under the License. #include "rtti.h" -namespace RTTI { +namespace P4::RTTI { /// A trait that check T is custom-RTTI-enabled. Works just like standard property type traits. /// One would normally use the _v variant. @@ -142,6 +142,6 @@ inline const Detail::IsType is; template inline const Detail::IsType isAny; -} // namespace RTTI +} // namespace P4::RTTI #endif // LIB_RTTI_UTILS_H_ diff --git a/lib/safe_vector.h b/lib/safe_vector.h index 935ce5d4d4..6a088aa237 100644 --- a/lib/safe_vector.h +++ b/lib/safe_vector.h @@ -19,6 +19,8 @@ limitations under the License. #include +namespace P4 { + /// An enhanced version of std::vector that performs bounds checking for /// operator[]. template > @@ -33,4 +35,6 @@ class safe_vector : public std::vector { const_reference operator[](size_type n) const { return this->at(n); } }; +} // namespace P4 + #endif /* LIB_SAFE_VECTOR_H_ */ diff --git a/lib/set.h b/lib/set.h index 41e3d672a2..21234fe0c4 100644 --- a/lib/set.h +++ b/lib/set.h @@ -4,6 +4,7 @@ #include /* stuff that should be in std::set but is missing... */ +namespace P4 { template inline auto operator|=(std::set &a, U &b) -> decltype(b.begin(), a) { @@ -39,4 +40,6 @@ inline auto intersects(std::set &a, U &b) -> decltype(b.begin(), true return false; } +} // namespace P4 + #endif /* LIB_SET_H_ */ diff --git a/lib/sourceCodeBuilder.h b/lib/sourceCodeBuilder.h index 78d12adaef..8016f67470 100644 --- a/lib/sourceCodeBuilder.h +++ b/lib/sourceCodeBuilder.h @@ -25,7 +25,7 @@ limitations under the License. #include "lib/exceptions.h" #include "lib/stringify.h" -namespace Util { +namespace P4::Util { class SourceCodeBuilder { int indentLevel; // current indent level unsigned indentAmount; @@ -115,6 +115,6 @@ class SourceCodeBuilder { void commentEnd() { append(" */"); } bool lastIsSpace() const { return endsInSpace; } }; -} // namespace Util +} // namespace P4::Util #endif /* LIB_SOURCECODEBUILDER_H_ */ diff --git a/lib/source_file.cpp b/lib/source_file.cpp index 496b106dd1..85d3e38ba4 100644 --- a/lib/source_file.cpp +++ b/lib/source_file.cpp @@ -27,12 +27,16 @@ limitations under the License. #include "lib/log.h" #include "lib/stringify.h" +namespace P4 { + void IHasDbPrint::print() const { dbprint(std::cout); std::cout << std::endl; } -namespace Util { +} // namespace P4 + +namespace P4::Util { SourcePosition::SourcePosition(unsigned lineNumber, unsigned columnNumber) : lineNumber(lineNumber), columnNumber(columnNumber) { if (lineNumber == 0) BUG("Line numbering should start at one"); @@ -320,12 +324,16 @@ cstring SourceFileLine::toString() const { return absl::StrFormat("%s(%d)", fileName.string_view(), sourceLine); } -} // namespace Util +} // namespace P4::Util //////////////////////////////////////////////////////// +namespace P4 { + [[gnu::used]] // ensure linker will not drop function even if unused void dbprint(const IHasDbPrint *o) { o->dbprint(std::cout); std::cout << std::endl << std::flush; } + +} // namespace P4 diff --git a/lib/source_file.h b/lib/source_file.h index e18f990ece..76927ee7c5 100644 --- a/lib/source_file.h +++ b/lib/source_file.h @@ -34,11 +34,11 @@ limitations under the License. #include "gtest/gtest_prod.h" #endif -namespace Test { +namespace P4::Test { class UtilSourceFile; } -namespace Util { +namespace P4::Util { using namespace P4::literals; struct SourceFileLine; @@ -329,8 +329,12 @@ class InputSources final { std::vector comments; }; -} // namespace Util +} // namespace P4::Util + +namespace P4 { void dbprint(const IHasDbPrint *o); +} // namespace P4 + #endif /* LIB_SOURCE_FILE_H_ */ diff --git a/lib/string_map.h b/lib/string_map.h index bab7c00c63..d0b801e53f 100644 --- a/lib/string_map.h +++ b/lib/string_map.h @@ -23,6 +23,8 @@ limitations under the License. #include "absl/container/flat_hash_map.h" #include "cstring.h" +namespace P4 { + /// Map with string keys that is ordered by order of element insertion. /// Use this map only when stable iteration order is significant. For everything /// else consider using some other unordered containers with cstring keys. Never @@ -236,4 +238,6 @@ class string_map { } }; +} // namespace P4 + #endif /* LIB_STRING_MAP_H_ */ diff --git a/lib/stringify.cpp b/lib/stringify.cpp index 55a86eec8a..4e9119e18e 100644 --- a/lib/stringify.cpp +++ b/lib/stringify.cpp @@ -24,7 +24,7 @@ limitations under the License. #include "cstring.h" #include "exceptions.h" -namespace Util { +namespace P4::Util { cstring toString(bool value) { return value ? cstring::literal("true") : cstring::literal("false"); } @@ -128,4 +128,4 @@ cstring toString(cstring value) { cstring toString(std::string_view value) { return cstring(value); } -} // namespace Util +} // namespace P4::Util diff --git a/lib/stringify.h b/lib/stringify.h index f3d026352e..56430cec66 100644 --- a/lib/stringify.h +++ b/lib/stringify.h @@ -28,6 +28,8 @@ limitations under the License. #include "big_int.h" #include "cstring.h" +namespace P4 { + class IHasDbPrint { public: virtual void dbprint(std::ostream &out) const = 0; @@ -120,6 +122,8 @@ cstring toString(const big_int &value, unsigned width, bool sign, unsigned int b cstring toString(const void *value); char DigitToChar(int digit); + } // namespace Util +} // namespace P4 #endif /* LIB_STRINGIFY_H_ */ diff --git a/lib/stringref.h b/lib/stringref.h index 9c0c2cd8d8..a47c1a5704 100644 --- a/lib/stringref.h +++ b/lib/stringref.h @@ -25,6 +25,8 @@ limitations under the License. #include "config.h" #include "cstring.h" +namespace P4 { + #if !HAVE_MEMRCHR static inline void *memrchr(const char *s, int c, size_t n) { for (auto *p = s + n - 1; p >= s; --p) @@ -311,4 +313,6 @@ class StringRef::Split { inline StringRef::Split StringRef::split(char ch) const { return Split(*this, nullptr, find(ch)); } inline StringRef::Split StringRef::split(const char *s) const { return Split(*this, s, find(s)); } +} // namespace P4 + #endif /* LIB_STRINGREF_H_ */ diff --git a/lib/symbitmatrix.h b/lib/symbitmatrix.h index e3c1c2e654..77dd2f854f 100644 --- a/lib/symbitmatrix.h +++ b/lib/symbitmatrix.h @@ -19,6 +19,8 @@ limitations under the License. #include "bitvec.h" +namespace P4 { + /* A symmetric bit matrix, held in a bit vector. We only store a triangular submatrix which * is used for both halves, so modifying one bit modifies both sides, keeping the matrix * always symmetric. Iterating over the matrix only iterates over the lower triangle */ @@ -101,4 +103,6 @@ class SymBitMatrix : private bitvec { bool operator|=(const SymBitMatrix &a) { return bitvec::operator|=(a); } }; +} // namespace P4 + #endif /* LIB_SYMBITMATRIX_H_ */ diff --git a/lib/timer.cpp b/lib/timer.cpp index f1b1317375..21d5667a98 100644 --- a/lib/timer.cpp +++ b/lib/timer.cpp @@ -6,7 +6,7 @@ #include #include -namespace Util { +namespace P4::Util { namespace { @@ -140,4 +140,4 @@ std::vector getTimers() { return ret; } -} // namespace Util +} // namespace P4::Util diff --git a/lib/timer.h b/lib/timer.h index 27fd5ef54c..2e04e7a543 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -7,7 +7,7 @@ #include #include -namespace Util { +namespace P4::Util { /// Runs specified function and measures it's execution duration under specified timer name. /// Timers can be nested. Measured durations are added under given timer name. In case of nested @@ -51,6 +51,6 @@ class ScopedTimer { std::unique_ptr ctx; }; -} // namespace Util +} // namespace P4::Util #endif /* LIB_TIMER_H_ */ diff --git a/midend/checkExternInvocationCommon.h b/midend/checkExternInvocationCommon.h index accd3bba3b..87e57a1bd7 100644 --- a/midend/checkExternInvocationCommon.h +++ b/midend/checkExternInvocationCommon.h @@ -141,11 +141,11 @@ class CheckExternInvocationCommon : public Inspector { auto constraint = pipeConstraints.at(extType) & bv; if (!bv.empty() && constraint.empty()) { if (extName != "") - ::error(ErrorType::ERR_UNSUPPORTED, "%s %s %s cannot be used in the %s %s", - expr->srcInfo, extType, extName, pipe, extractBlock(bv)); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%s %s %s cannot be used in the %s %s", + expr->srcInfo, extType, extName, pipe, extractBlock(bv)); else - ::error(ErrorType::ERR_UNSUPPORTED, "%s %s cannot be used in the %s %s", - expr->srcInfo, extType, pipe, extractBlock(bv)); + ::P4::error(ErrorType::ERR_UNSUPPORTED, "%s %s cannot be used in the %s %s", + expr->srcInfo, extType, pipe, extractBlock(bv)); } } diff --git a/midend/compileTimeOps.h b/midend/compileTimeOps.h index 9c570b9fc8..170a0d63e3 100644 --- a/midend/compileTimeOps.h +++ b/midend/compileTimeOps.h @@ -33,8 +33,8 @@ class CompileTimeOperations : public Inspector { public: CompileTimeOperations() { setName("CompileTimeOperations"); } void err(const IR::Node *expression) { - ::error(ErrorType::ERR_INVALID, "%1%: could not evaluate expression at compilation time", - expression); + ::P4::error(ErrorType::ERR_INVALID, + "%1%: could not evaluate expression at compilation time", expression); } void postorder(const IR::Mod *expression) override { err(expression); } void postorder(const IR::Div *expression) override { err(expression); } diff --git a/midend/convertEnums.cpp b/midend/convertEnums.cpp index 74aad47abf..c0f83debbf 100644 --- a/midend/convertEnums.cpp +++ b/midend/convertEnums.cpp @@ -27,7 +27,7 @@ const IR::Node *DoConvertEnums::postorder(IR::Type_Name *type) { // This will be resolved by the caller. return type; auto enumType = canontype->to(); - auto r = ::get(repr, enumType); + auto r = ::P4::get(repr, enumType); if (r == nullptr) return type; return r->type; } @@ -38,7 +38,7 @@ const IR::Node *DoConvertEnums::postorder(IR::Member *expression) { if (!ei) return expression; if (ei->is()) { auto type = ei->type->to(); - auto r = ::get(repr, type); + auto r = ::P4::get(repr, type); if (r == nullptr) return expression; unsigned value = r->get(ei->name.name); unsigned encoded_value = policy->encoding(type, value); diff --git a/midend/convertEnums.h b/midend/convertEnums.h index 0c0fbd8294..34f4df6d8f 100644 --- a/midend/convertEnums.h +++ b/midend/convertEnums.h @@ -51,7 +51,7 @@ class EnumRepresentation { type = IR::Type_Bits::get(srcInfo, width, false); } void add(cstring decl) { repr.emplace(decl, repr.size()); } - unsigned get(cstring decl) const { return ::get(repr, decl); } + unsigned get(cstring decl) const { return ::P4::get(repr, decl); } using iterator = decltype(repr)::iterator; using const_iterator = decltype(repr)::const_iterator; diff --git a/midend/convertErrors.cpp b/midend/convertErrors.cpp index 01ffe22e73..14e2985166 100644 --- a/midend/convertErrors.cpp +++ b/midend/convertErrors.cpp @@ -42,7 +42,7 @@ const IR::Node *DoConvertErrors::postorder(IR::Type_Name *type) { return type; } auto errorType = canontype->to()->name; - auto *r = ::get(repr, errorType); + auto *r = ::P4::get(repr, errorType); if (r == nullptr) { return type; } @@ -54,7 +54,7 @@ const IR::Node *DoConvertErrors::postorder(IR::Member *member) { if (!typeErr) { return member; } - auto *r = ::get(repr, typeErr->name); + auto *r = ::P4::get(repr, typeErr->name); CHECK_NULL(r); if (!member->expr->is()) { // variable diff --git a/midend/copyStructures.cpp b/midend/copyStructures.cpp index 3ec4ad169a..a7f1faa12f 100644 --- a/midend/copyStructures.cpp +++ b/midend/copyStructures.cpp @@ -80,10 +80,10 @@ const IR::Node *DoCopyStructures::postorder(IR::AssignmentStatement *statement) // Do not copy structures for method calls. if (statement->right->is()) { if (errorOnMethodCall) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: functions or methods returning structures " - "are not supported on this target", - statement->right); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: functions or methods returning structures " + "are not supported on this target", + statement->right); } return statement; } diff --git a/midend/def_use.cpp b/midend/def_use.cpp index 2fca1b137c..00fdd80256 100644 --- a/midend/def_use.cpp +++ b/midend/def_use.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "frontends/p4/methodInstance.h" +namespace P4 { + struct LogAbbrev { const Util::SourceInfo &si; explicit LogAbbrev(const Util::SourceInfo &si) : si(si) {} @@ -32,6 +34,8 @@ struct LogAbbrev { } }; +} // namespace P4 + namespace P4 { using namespace literals; @@ -747,7 +751,11 @@ std::ostream &operator<<(std::ostream &out, const ComputeDefUse::defuse_t &du) { } // namespace P4 +namespace P4 { + void dump(const P4::ComputeDefUse::loc_t &p) { std::cout << p << std::endl; } void dump(const hvec_set &p) { std::cout << p << std::endl; } void dump(const P4::ComputeDefUse &du) { std::cout << du << std::endl; } void dump(const P4::ComputeDefUse *du) { std::cout << *du << std::endl; } + +} // namespace P4 diff --git a/midend/eliminateInvalidHeaders.cpp b/midend/eliminateInvalidHeaders.cpp index c8b7a2e450..b0296a33a9 100644 --- a/midend/eliminateInvalidHeaders.cpp +++ b/midend/eliminateInvalidHeaders.cpp @@ -54,7 +54,7 @@ const IR::Node *DoEliminateInvalidHeaders::postorder(IR::InvalidHeader *expressi if (!findContext() && !findContext() && !findContext()) { // We need some place to insert the setInvalid call. - ::error("%1%: Cannot eliminate invalid header", expression); + ::P4::error("%1%: Cannot eliminate invalid header", expression); return expression; } cstring name = refMap->newName("ih"); @@ -74,7 +74,7 @@ const IR::Node *DoEliminateInvalidHeaders::postorder(IR::InvalidHeaderUnion *exp if (!findContext() && !findContext() && !findContext()) { // We need some place to insert the setInvalid call. - ::error("%1%: Cannot eliminate invalid header union", expression); + ::P4::error("%1%: Cannot eliminate invalid header union", expression); return expression; } cstring name = refMap->newName("ih"); diff --git a/midend/eliminateSwitch.cpp b/midend/eliminateSwitch.cpp index eed145da57..813c022987 100644 --- a/midend/eliminateSwitch.cpp +++ b/midend/eliminateSwitch.cpp @@ -28,9 +28,9 @@ const IR::Node *DoEliminateSwitch::postorder(IR::P4Program *program) { return program; } } - ::error(ErrorType::ERR_NOT_FOUND, - "Could not find declaration for 'match_kind.exact', which is needed to implement " - "switch statements; did you include core.p4?"); + ::P4::error(ErrorType::ERR_NOT_FOUND, + "Could not find declaration for 'match_kind.exact', which is needed to implement " + "switch statements; did you include core.p4?"); return program; } @@ -42,7 +42,7 @@ const IR::Node *DoEliminateSwitch::postorder(IR::P4Control *control) { const IR::Node *DoEliminateSwitch::postorder(IR::SwitchStatement *statement) { if (findContext()) { - ::error("%1%: switch statements not supported in actions on this target", statement); + ::P4::error("%1%: switch statements not supported in actions on this target", statement); return statement; } auto type = typeMap->getType(statement->expression); diff --git a/midend/expandEmit.cpp b/midend/expandEmit.cpp index 41750e4e44..0efbc3ad5c 100644 --- a/midend/expandEmit.cpp +++ b/midend/expandEmit.cpp @@ -66,7 +66,8 @@ const IR::Node *DoExpandEmit::postorder(IR::MethodCallStatement *statement) { if (em->originalExternType->name.name == P4::P4CoreLibrary::instance().packetOut.name && em->method->name.name == P4::P4CoreLibrary::instance().packetOut.emit.name) { if (em->expr->arguments->size() != 1) { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: expected exactly 1 argument", statement); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: expected exactly 1 argument", + statement); return statement; } diff --git a/midend/expandLookahead.cpp b/midend/expandLookahead.cpp index 59ba35818f..92e98a2319 100644 --- a/midend/expandLookahead.cpp +++ b/midend/expandLookahead.cpp @@ -59,7 +59,7 @@ void DoExpandLookahead::expand( expand(bitvector, etype, offset, member, output); } } else { - ::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type in lookahead argument", type); + ::P4::error(ErrorType::ERR_UNEXPECTED, "%1%: unexpected type in lookahead argument", type); } } diff --git a/midend/expr_uses.h b/midend/expr_uses.h index 25908667a4..3b227de957 100644 --- a/midend/expr_uses.h +++ b/midend/expr_uses.h @@ -19,6 +19,8 @@ limitations under the License. #include "ir/ir.h" +namespace P4 { + /* Should this be a method on IR::Expression? */ /// Functor to check if an expression uses an lvalue. The lvalue is specified as a @@ -81,4 +83,6 @@ class exprUses : public Inspector { explicit operator bool() const { return result; } }; +} // namespace P4 + #endif /* MIDEND_EXPR_USES_H_ */ diff --git a/midend/flattenHeaders.cpp b/midend/flattenHeaders.cpp index e67fdda2fe..bbcf79d60d 100644 --- a/midend/flattenHeaders.cpp +++ b/midend/flattenHeaders.cpp @@ -80,7 +80,7 @@ const IR::Node *ReplaceHeaders::postorder(IR::Member *expression) { } // At this point we know that e is an expression of the form // param.field1.etc.hdr, where hdr needs to be replaced. - auto newFieldName = ::get(repl->fieldNameRemap, prefix); + auto newFieldName = ::P4::get(repl->fieldNameRemap, prefix); const IR::Expression *result; if (newFieldName.isNullOrEmpty()) { auto type = typeMap->getType(getOriginal(), true); @@ -90,8 +90,9 @@ const IR::Node *ReplaceHeaders::postorder(IR::Member *expression) { // We only want to process the outermost Member return expression; if (isWrite()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: writing to a structure nested in a header is not supported", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: writing to a structure nested in a header is not supported", + expression); return expression; } result = repl->explode(e, prefix); diff --git a/midend/flattenHeaders.h b/midend/flattenHeaders.h index 216edec8ce..e5a6faae92 100644 --- a/midend/flattenHeaders.h +++ b/midend/flattenHeaders.h @@ -41,7 +41,7 @@ class FindHeaderTypesToReplace : public Inspector { bool preorder(const IR::Type_Header *type) override; void createReplacement(const IR::Type_Header *type, AnnotationSelectionPolicy *policy); StructTypeReplacement *getReplacement(const cstring name) const { - return ::get(replacement, name); + return ::P4::get(replacement, name); } bool empty() const { return replacement.empty(); } }; diff --git a/midend/flattenInterfaceStructs.cpp b/midend/flattenInterfaceStructs.cpp index cd854ce3bf..fdfce7d75b 100644 --- a/midend/flattenInterfaceStructs.cpp +++ b/midend/flattenInterfaceStructs.cpp @@ -32,7 +32,7 @@ static const IR::Type_Struct *isNestedStruct(const P4::TypeMap *typeMap, const I } // namespace void NestedStructMap::createReplacement(const IR::Type_Struct *type) { - auto repl = ::get(replacement, type); + auto repl = ::P4::get(replacement, type); if (repl != nullptr) return; repl = new StructTypeReplacement(typeMap, type, new AnnotationSelectionPolicy()); @@ -83,9 +83,9 @@ const IR::Node *ReplaceStructs::postorder(IR::Member *expression) { auto decl = replacementMap->refMap->getDeclaration(pe->path, true); auto param = decl->to(); if (param == nullptr) return expression; - auto repl = ::get(toReplace, param); + auto repl = ::P4::get(toReplace, param); if (repl == nullptr) return expression; - auto newFieldName = ::get(repl->fieldNameRemap, prefix); + auto newFieldName = ::P4::get(repl->fieldNameRemap, prefix); const IR::Expression *result; if (newFieldName.isNullOrEmpty()) { auto type = replacementMap->typeMap->getType(getOriginal(), true); @@ -95,8 +95,8 @@ const IR::Node *ReplaceStructs::postorder(IR::Member *expression) { // We only want to process the outermost Member return expression; if (isWrite()) { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: writing to a structure is not supported on this target", expression); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: writing to a structure is not supported on this target", expression); return expression; } // Prefix is a reference to a field of the original struct whose diff --git a/midend/flattenInterfaceStructs.h b/midend/flattenInterfaceStructs.h index 22aa15664b..c9798e9f88 100644 --- a/midend/flattenInterfaceStructs.h +++ b/midend/flattenInterfaceStructs.h @@ -136,11 +136,11 @@ struct StructTypeReplacement : public IHasDbPrint { /// { .s = { .a = R._t_s_a0, .b = R._t_s_b1 }, .y = R._t_y2 } const IR::StructExpression *explode(const IR::Expression *root, cstring prefix) { auto vec = new IR::IndexedVector(); - auto fieldType = ::get(structFieldMap, prefix); + auto fieldType = ::P4::get(structFieldMap, prefix); BUG_CHECK(fieldType, "No field for %1%", prefix); for (auto f : fieldType->fields) { cstring fieldName = prefix + "." + f->name.name; - auto newFieldname = ::get(fieldNameRemap, fieldName); + auto newFieldname = ::P4::get(fieldNameRemap, fieldName); const IR::Expression *expr; if (!newFieldname.isNullOrEmpty()) { expr = new IR::Member(root, newFieldname); @@ -171,7 +171,7 @@ struct NestedStructMap { } void createReplacement(const IR::Type_Struct *type); StructTypeReplacement *getReplacement(const IR::Type *type) const { - return ::get(replacement, type); + return ::P4::get(replacement, type); } bool empty() const { return replacement.empty(); } }; diff --git a/midend/flattenLogMsg.h b/midend/flattenLogMsg.h index f356898411..8e0fd7a8ab 100644 --- a/midend/flattenLogMsg.h +++ b/midend/flattenLogMsg.h @@ -28,10 +28,10 @@ class FindTypesInLogMsgInvocationToReplace : public Inspector { const IR::MethodCallStatement *prepareLogMsgStatement( const IR::MethodCallStatement *methodCallStatement); const IR::Type_StructLike *getReplacement(const cstring name) const { - return ::get(replacement, name); + return ::P4::get(replacement, name); } const IR::MethodCallStatement *getReplacementMethodCall(unsigned id) const { - return ::get(logMsgReplacement, id); + return ::P4::get(logMsgReplacement, id); } bool empty() const { return replacement.empty(); } bool hasStructInParameter(const IR::MethodCallStatement *methodCallStatement); diff --git a/midend/flattenUnions.cpp b/midend/flattenUnions.cpp index 0edb9ea700..15123a462b 100644 --- a/midend/flattenUnions.cpp +++ b/midend/flattenUnions.cpp @@ -262,13 +262,14 @@ const IR::Node *DoFlattenHeaderUnionStack::postorder(IR::ArrayIndex *e) { unsigned stackSize = stack->size->to()->asUnsigned(); if (stack->elementType->is()) { if (!e->right->is()) - ::error(ErrorType::ERR_INVALID, - "Target expects constant array indices for accessing header union stack " - "elements, %1% is not a constant", - e->right); + ::P4::error( + ErrorType::ERR_INVALID, + "Target expects constant array indices for accessing header union stack " + "elements, %1% is not a constant", + e->right); unsigned cst = e->right->to()->asUnsigned(); if (cst >= stackSize) - ::error(ErrorType::ERR_OVERLIMIT, "Array index out of bound for %1%", e); + ::P4::error(ErrorType::ERR_OVERLIMIT, "Array index out of bound for %1%", e); if (auto mem = e->left->to()) { auto uName = stackMap[mem->member.name]; BUG_CHECK(uName.size() > cst, "Header stack element mapping not found for %1", e); diff --git a/midend/has_side_effects.h b/midend/has_side_effects.h index 2d583c580b..ec47331b02 100644 --- a/midend/has_side_effects.h +++ b/midend/has_side_effects.h @@ -21,6 +21,8 @@ limitations under the License. #include "frontends/p4/methodInstance.h" #include "ir/ir.h" +namespace P4 { + /* Should this be a method on IR::Expression? Maybe after the refMap/typeMap go away */ class hasSideEffects : public Inspector { @@ -73,4 +75,6 @@ class hasSideEffects : public Inspector { explicit operator bool() { return result; } }; +} // namespace P4 + #endif /* MIDEND_HAS_SIDE_EFFECTS_H_ */ diff --git a/midend/interpreter.cpp b/midend/interpreter.cpp index 6b6fd61e61..3be8096367 100644 --- a/midend/interpreter.cpp +++ b/midend/interpreter.cpp @@ -1141,7 +1141,7 @@ void ExpressionEvaluator::postorder(const IR::MethodCallExpression *expression) BUG_CHECK(hdr->is(), "%1%: Not a header?", hdr); auto sh = hdr->to(); if (sh->valid->isKnown() && sh->valid->value) { - ::warning( + ::P4::warning( ErrorType::WARN_MULTI_HDR_EXTRACT, "%1%: Performing an extraction more than once on the same header will " "nearly always cause all but the last extracted header to be deleted " diff --git a/midend/interpreter.h b/midend/interpreter.h index 669e25f675..7fabfe72ec 100644 --- a/midend/interpreter.h +++ b/midend/interpreter.h @@ -89,7 +89,7 @@ class ValueMap final : public IHasDbPrint { } SymbolicValue *get(const IR::IDeclaration *left) const { CHECK_NULL(left); - return ::get(map, left); + return ::P4::get(map, left); } void dbprint(std::ostream &out) const { @@ -166,7 +166,7 @@ class ExpressionEvaluator : public Inspector { SymbolicValue *evaluate(const IR::Expression *expression, bool leftValue); SymbolicValue *get(const IR::Expression *expression) const { - auto r = ::get(value, expression); + auto r = ::P4::get(value, expression); BUG_CHECK(r != nullptr, "no evaluation for %1%", expression); return r; } @@ -397,7 +397,7 @@ class SymbolicStruct : public SymbolicValue { SymbolicStruct(const IR::Type_StructLike *type, bool uninitialized, const SymbolicValueFactory *factory); virtual SymbolicValue *get(const IR::Node *, cstring field) const { - auto r = ::get(fieldValue, field); + auto r = ::P4::get(fieldValue, field); CHECK_NULL(r); return r; } diff --git a/midend/local_copyprop.cpp b/midend/local_copyprop.cpp index b6e97bf47a..f7c393a86c 100644 --- a/midend/local_copyprop.cpp +++ b/midend/local_copyprop.cpp @@ -72,7 +72,7 @@ class DoLocalCopyPropagation::ElimDead : public Transform { * of the block, so it only removes those vars declared in the block */ DoLocalCopyPropagation &self; const IR::Node *preorder(IR::Declaration_Variable *var) override { - if (auto local = ::getref(self.available, var->name)) { + if (auto local = ::P4::getref(self.available, var->name)) { if (local->local && !local->live) { LOG3(" removing dead local " << var->name); return nullptr; @@ -82,7 +82,7 @@ class DoLocalCopyPropagation::ElimDead : public Transform { } const IR::Statement *postorder(IR::AssignmentStatement *as) override { if (auto dest = lvalue_out(as->left)->to()) { - if (auto var = ::getref(self.available, dest->path->name)) { + if (auto var = ::P4::getref(self.available, dest->path->name)) { if (var->local && !var->live) { LOG3(" removing dead assignment to " << dest->path->name); if (self.hasSideEffects(as->right)) return makeSideEffectStatement(as->right); @@ -184,7 +184,7 @@ void DoLocalCopyPropagation::flow_merge(Visitor &a_) { LOG8("flow_merge " << a.uid << " into " << uid); unreachable &= a.unreachable; for (auto &var : available) { - if (auto merge = ::getref(a.available, var.first)) { + if (auto merge = ::P4::getref(a.available, var.first)) { if (merge->val != var.second.val) { if (var.second.val) { LOG4(" dropping " << var.first << " = " << var.second.val @@ -336,7 +336,7 @@ const IR::Expression *DoLocalCopyPropagation::copyprop_name(cstring name, } return nullptr; } - if (auto var = ::getref(available, name)) { + if (auto var = ::P4::getref(available, name)) { if (var->val) { if (policy(getChildContext(), var->val)) { LOG3(" propagating value for " << name << ": " << var->val); @@ -532,7 +532,7 @@ IR::MethodCallExpression *DoLocalCopyPropagation::postorder(IR::MethodCallExpres // to provide per-extern flow info to this (and other) frontend passes. LOG3("extern method call " << name); for (auto *n : em->mayCall()) { - if (auto *method = ::getref(methods, obj + '.' + n->getName())) { + if (auto *method = ::P4::getref(methods, obj + '.' + n->getName())) { LOG4(" might call " << obj << '.' << n->getName()); apply_function(method); } @@ -625,7 +625,7 @@ void DoLocalCopyPropagation::LoopPrepass::postorder(const IR::MethodCallExpressi // to provide per-extern flow info to this (and other) frontend passes. LOG3("loop prepass extern method call " << name); for (auto *n : em->mayCall()) { - if (auto *method = ::getref(self.methods, obj + '.' + n->getName())) { + if (auto *method = ::P4::getref(self.methods, obj + '.' + n->getName())) { LOG4(" might call " << obj << '.' << n->getName()); apply_function(method); } diff --git a/midend/local_copyprop.h b/midend/local_copyprop.h index 68ac551a79..aeec22d878 100644 --- a/midend/local_copyprop.h +++ b/midend/local_copyprop.h @@ -99,7 +99,7 @@ class DoLocalCopyPropagation : public ControlFlowVisitor, Transform, P4WriteCont void forOverlapAvail(cstring, std::function); void dropValuesUsing(cstring); bool hasSideEffects(const IR::Expression *e) { - return bool(::hasSideEffects(refMap, typeMap, e)); + return bool(::P4::hasSideEffects(refMap, typeMap, e)); } bool isHeaderUnionIsValid(const IR::Expression *e); diff --git a/midend/nestedStructs.cpp b/midend/nestedStructs.cpp index be38559252..d4a51a6443 100644 --- a/midend/nestedStructs.cpp +++ b/midend/nestedStructs.cpp @@ -90,9 +90,10 @@ const IR::Node *RemoveNestedStructs::postorder(IR::MethodCallExpression *express for (auto p : mi->getActualParameters()->parameters) { if (!p->hasOut()) continue; if (values->isNestedStruct(p->type)) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: extern functions with 'out' nested struct argument (%2%) not supported", - expression, p); + ::P4::error( + ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: extern functions with 'out' nested struct argument (%2%) not supported", + expression, p); } } return expression; diff --git a/midend/nestedStructs.h b/midend/nestedStructs.h index 2053fc07f2..a20cceefad 100644 --- a/midend/nestedStructs.h +++ b/midend/nestedStructs.h @@ -59,7 +59,7 @@ class ComplexValues final { } return new IR::StructExpression(type->getP4Type(), vec); } - Component *getComponent(cstring name) override { return ::get(members, name); } + Component *getComponent(cstring name) override { return ::P4::get(members, name); } void dbprint(std::ostream &out) const override { out << Log::indent; for (auto m : members) out << m.first << "=>" << m.second; @@ -86,11 +86,11 @@ class ComplexValues final { Component *getTranslation(const IR::IDeclaration *decl) { auto dv = decl->to(); if (dv == nullptr) return nullptr; - return ::get(values, dv); + return ::P4::get(values, dv); } Component *getTranslation(const IR::Expression *expression) { LOG2("Check translation " << dbp(expression)); - return ::get(translation, expression); + return ::P4::get(translation, expression); } void setTranslation(const IR::Expression *expression, Component *comp) { translation.emplace(expression, comp); diff --git a/midend/noMatch.cpp b/midend/noMatch.cpp index 3671352c64..219eadf1c4 100644 --- a/midend/noMatch.cpp +++ b/midend/noMatch.cpp @@ -57,14 +57,14 @@ const IR::Node *DoHandleNoMatch::postorder(IR::P4Program *program) { auto decls = program->getDeclsByName(IR::ParserState::verify); auto vec = decls->toVector(); if (vec.empty()) { - ::error(ErrorType::ERR_MODEL, - "Declaration of function '%1%' not found; did you include core.p4?", - IR::ParserState::verify); + ::P4::error(ErrorType::ERR_MODEL, + "Declaration of function '%1%' not found; did you include core.p4?", + IR::ParserState::verify); return program; } if (vec.size() > 1) { - ::error(ErrorType::ERR_MODEL, "Multiple declarations of %1%: %2% %3%", - IR::ParserState::verify, vec[0], vec[1]); + ::P4::error(ErrorType::ERR_MODEL, "Multiple declarations of %1%: %2% %3%", + IR::ParserState::verify, vec[0], vec[1]); } return program; } diff --git a/midend/parserUnroll.cpp b/midend/parserUnroll.cpp index 684dba63b5..507e4e8f36 100644 --- a/midend/parserUnroll.cpp +++ b/midend/parserUnroll.cpp @@ -174,8 +174,8 @@ class ParserStateRewriter : public Transform { auto *value = ev.evaluate(expression->right, false); if (!value->is()) return expression; if (!value->to()->isKnown()) { - ::warning(ErrorType::ERR_INVALID, "Uninitialized value prevents loop unrolling:\n%1%", - expression->right); + ::P4::warning(ErrorType::ERR_INVALID, + "Uninitialized value prevents loop unrolling:\n%1%", expression->right); wasError = true; return expression; } @@ -183,7 +183,8 @@ class ParserStateRewriter : public Transform { newExpression->right = res; if (!res->fitsInt64()) { // we need to leave expression as is. - ::warning(ErrorType::ERR_EXPRESSION, "Index can't be concretized : %1%", expression); + ::P4::warning(ErrorType::ERR_EXPRESSION, "Index can't be concretized : %1%", + expression); return expression; } const auto *arrayType = basetype->to(); @@ -392,8 +393,8 @@ class ParserSymbolicInterpreter { if (value == nullptr) value = factory->create(type, true); if (value && value->is()) { - ::warning(ErrorType::ERR_EXPRESSION, "%1%: %2%", d, - value->to()->message()); + ::P4::warning(ErrorType::ERR_EXPRESSION, "%1%: %2%", d, + value->to()->message()); return nullptr; } if (value != nullptr) result->set(d, value); @@ -446,8 +447,8 @@ class ParserSymbolicInterpreter { if (!stateClone) // errors in the original state are signalled - ::warning(ErrorType::ERR_EXPRESSION, "%1%: error %2% will be triggered\n%3%", - exc->errorPosition, exc->message(), stateChain(state)); + ::P4::warning(ErrorType::ERR_EXPRESSION, "%1%: error %2% will be triggered\n%3%", + exc->errorPosition, exc->message(), stateChain(state)); // else this error will occur in a clone of the state produced // by unrolling - if the state is reached. So we don't give an error. return false; @@ -505,8 +506,8 @@ class ParserSymbolicInterpreter { } std::stringstream errorStr; errorStr << errorValue; - ::warning(ErrorType::WARN_IGNORE_PROPERTY, "Result of '%1%' is not defined: %2%", sord, - errorStr.str()); + ::P4::warning(ErrorType::WARN_IGNORE_PROPERTY, "Result of '%1%' is not defined: %2%", + sord, errorStr.str()); } ParserStateRewriter rewriter(structure, state, valueMap, refMap, typeMap, &ev, visitedStates); @@ -681,10 +682,10 @@ class ParserSymbolicInterpreter { } } if (equStackVariableMap(crt->statesIndexes, state->statesIndexes)) { - ::warning(ErrorType::ERR_INVALID, - "Parser cycle can't be unrolled, because ParserUnroll can't " - "detect the number of loop iterations:\n%1%", - stateChain(state)); + ::P4::warning(ErrorType::ERR_INVALID, + "Parser cycle can't be unrolled, because ParserUnroll can't " + "detect the number of loop iterations:\n%1%", + stateChain(state)); wasError = true; } return true; @@ -693,10 +694,10 @@ class ParserSymbolicInterpreter { // If no header validity has changed we can't really unroll if (!headerValidityChange(crt->before, state->before)) { if (equStackVariableMap(crt->statesIndexes, state->statesIndexes)) { - ::warning(ErrorType::ERR_INVALID, - "Parser cycle can't be unrolled, because ParserUnroll can't " - "detect the number of loop iterations:\n%1%", - stateChain(state)); + ::P4::warning(ErrorType::ERR_INVALID, + "Parser cycle can't be unrolled, because ParserUnroll can't " + "detect the number of loop iterations:\n%1%", + stateChain(state)); wasError = true; } return true; diff --git a/midend/parserUnroll.h b/midend/parserUnroll.h index 7e3e718cda..8704c5d309 100644 --- a/midend/parserUnroll.h +++ b/midend/parserUnroll.h @@ -156,7 +156,7 @@ class ParserStructure { start = nullptr; } void addState(const IR::ParserState *state) { stateMap.emplace(state->name, state); } - const IR::ParserState *get(cstring state) const { return ::get(stateMap, state); } + const IR::ParserState *get(cstring state) const { return ::P4::get(stateMap, state); } void calls(const IR::ParserState *caller, const IR::ParserState *callee) { callGraph->calls(caller, callee); } diff --git a/midend/predication.cpp b/midend/predication.cpp index 4b9bdf8e0c..d9a6d98c3e 100644 --- a/midend/predication.cpp +++ b/midend/predication.cpp @@ -94,9 +94,10 @@ void Predication::ExpressionReplacer::visitBranch(IR::Mux *mux, bool then) { auto elseExprName = Pred::lvalueName(mux->e2); if (leftName.isNullOrEmpty()) { - ::error(ErrorType::ERR_EXPRESSION, - "%1%: Assignment inside if statement can't be transformed to condition expression", - statement); + ::P4::error( + ErrorType::ERR_EXPRESSION, + "%1%: Assignment inside if statement can't be transformed to condition expression", + statement); } if (then && elseExprName == leftName && !visitingIndex) { diff --git a/midend/predication.h b/midend/predication.h index f08b9a64c3..378a9fd262 100644 --- a/midend/predication.h +++ b/midend/predication.h @@ -115,8 +115,9 @@ class Predication final : public Transform { std::map isStatementDependent; const IR::Statement *error(const IR::Statement *statement) const { if (inside_action && ifNestingLevel > 0) - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Conditional execution in actions unsupported on this target", statement); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Conditional execution in actions unsupported on this target", + statement); return statement; } diff --git a/midend/replaceSelectRange.cpp b/midend/replaceSelectRange.cpp index 13593c94f9..aa7fa66198 100644 --- a/midend/replaceSelectRange.cpp +++ b/midend/replaceSelectRange.cpp @@ -65,26 +65,26 @@ std::vector *DoReplaceSelectRange::rangeToMasks(const IR::Rang size_t keyIndex) { auto l = r->left->to(); if (!l) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Range boundaries must be a compile-time constants.", r->left); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Range boundaries must be a compile-time constants.", r->left); return nullptr; } auto left = l->value; auto ri = r->right->to(); if (!ri) { - ::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, - "%1%: Range boundaries must be a compile-time constants.", r->right); + ::P4::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, + "%1%: Range boundaries must be a compile-time constants.", r->right); return nullptr; } auto masks = new std::vector(); auto right = ri->value; if (right < left) { - ::warning(ErrorType::WARN_INVALID, - "%1%-%2%: Range with end less than start is " - "treated as an empty range", - r->left, r->right); + ::P4::warning(ErrorType::WARN_INVALID, + "%1%-%2%: Range with end less than start is " + "treated as an empty range", + r->left, r->right); return masks; } diff --git a/midend/replaceSelectRange.h b/midend/replaceSelectRange.h index 146c95e262..78536c4af7 100644 --- a/midend/replaceSelectRange.h +++ b/midend/replaceSelectRange.h @@ -68,4 +68,5 @@ class ReplaceSelectRange final : public PassManager { }; } // namespace P4 + #endif /* MIDEND_REPLACESELECTRANGE_H_ */ diff --git a/midend/simplifyKey.cpp b/midend/simplifyKey.cpp index b1f3738961..0a5c0c785d 100644 --- a/midend/simplifyKey.cpp +++ b/midend/simplifyKey.cpp @@ -68,7 +68,7 @@ const IR::Node *DoSimplifyKey::postorder(IR::KeyElement *element) { } const IR::Node *DoSimplifyKey::postorder(IR::P4Table *table) { - auto insertions = ::get(toInsert, getOriginal()); + auto insertions = ::P4::get(toInsert, getOriginal()); if (insertions == nullptr) return table; auto result = new IR::IndexedVector(); diff --git a/midend/simplifySelectCases.cpp b/midend/simplifySelectCases.cpp index d157173b99..87c3af7397 100644 --- a/midend/simplifySelectCases.cpp +++ b/midend/simplifySelectCases.cpp @@ -46,7 +46,7 @@ void DoSimplifySelectCases::checkSimpleConstant(const IR::Expression *expr) cons return; } } - ::error(ErrorType::ERR_INVALID, "%1%: must be a compile-time constant", expr); + ::P4::error(ErrorType::ERR_INVALID, "%1%: must be a compile-time constant", expr); } const IR::Node *DoSimplifySelectCases::preorder(IR::SelectExpression *expression) { diff --git a/midend/singleArgumentSelect.cpp b/midend/singleArgumentSelect.cpp index 407e80d07e..92672c69b4 100644 --- a/midend/singleArgumentSelect.cpp +++ b/midend/singleArgumentSelect.cpp @@ -63,8 +63,9 @@ void DoSingleArgumentSelect::checkExpressionType(const IR::Expression *expressio checkExpressionType(c); } } else { - ::error(ErrorType::ERR_UNSUPPORTED, - "%1%: expression type %2% not supported in select expression", expression, type); + ::P4::error(ErrorType::ERR_UNSUPPORTED, + "%1%: expression type %2% not supported in select expression", expression, + type); } } diff --git a/midend/unrollLoops.cpp b/midend/unrollLoops.cpp index 841c5ae054..c7abae6422 100644 --- a/midend/unrollLoops.cpp +++ b/midend/unrollLoops.cpp @@ -18,12 +18,16 @@ limitations under the License. #include "ir/pattern.h" +namespace P4 { + /** helper function to create a simple assignment to a boolean flag variable */ static IR::AssignmentStatement *setFlag(cstring name, bool val) { auto var = new IR::PathExpression(IR::Type::Boolean::get(), new IR::Path(name)); return new IR::AssignmentStatement(var, new IR::BoolLiteral(val)); } +} // namespace P4 + namespace P4 { using namespace literals; diff --git a/test/gtest/arch_test.cpp b/test/gtest/arch_test.cpp index a92d45d23e..786be39386 100644 --- a/test/gtest/arch_test.cpp +++ b/test/gtest/arch_test.cpp @@ -28,7 +28,7 @@ limitations under the License. using namespace P4; -namespace Test { +namespace P4::Test { class P4CArchitecture : public P4CTest {}; @@ -53,14 +53,14 @@ TEST_F(P4CArchitecture, packet_out) { PSA(MyDeparser()) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } // Potential bug @@ -94,7 +94,7 @@ TEST_F(P4CArchitecture, duplicatedDeclarationBug) { pgm = pgm->apply(passes); } - ASSERT_GT(::errorCount(), 0U); + ASSERT_GT(::P4::errorCount(), 0U); } TEST_F(P4CArchitecture, instantiation) { @@ -133,14 +133,14 @@ TEST_F(P4CArchitecture, instantiation) { PSA(MyParser(), MyIngress(), MyDeparser()) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } TEST_F(P4CArchitecture, psa_package_with_body) { @@ -170,7 +170,7 @@ TEST_F(P4CArchitecture, psa_package_with_body) { PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); } - ASSERT_GT(::errorCount(), 0U); + ASSERT_GT(::P4::errorCount(), 0U); } TEST_F(P4CArchitecture, psa_control_in_control) { @@ -199,13 +199,13 @@ TEST_F(P4CArchitecture, psa_control_in_control) { PSA(MyIngress()) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } TEST_F(P4CArchitecture, psa_clone_as_param_to_package) { @@ -223,13 +223,13 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_package) { PSA(c) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } TEST_F(P4CArchitecture, psa_clone_as_param_to_control) { @@ -256,13 +256,13 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_control) { PSA(MyIngress(clone>())) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } TEST_F(P4CArchitecture, psa_clone_as_param_to_extern) { @@ -297,13 +297,13 @@ TEST_F(P4CArchitecture, psa_clone_as_param_to_extern) { PSA(MyIngress(pre)) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } TEST_F(P4CArchitecture, clone_as_extern_method) { @@ -327,13 +327,13 @@ TEST_F(P4CArchitecture, clone_as_extern_method) { PSA(MyIngress()) main; )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; PassManager passes({new TypeChecking(&refMap, &typeMap)}); pgm = pgm->apply(passes); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/bitrange.cpp b/test/gtest/bitrange.cpp index 5097fee199..661b3af8e3 100644 --- a/test/gtest/bitrange.cpp +++ b/test/gtest/bitrange.cpp @@ -28,10 +28,10 @@ limitations under the License. // disable these tests for GCC-4.9, which for some reason // do not link with std::optional #if (__GNUC__ > 4) || defined(__clang__) -namespace Test { +namespace P4::Test { -using namespace BitRange; -using namespace BitRange::Detail; +using namespace P4::BitRange; +using namespace P4::BitRange::Detail; /// A GTest fixture base class for backend targets. class BitrangeTestBase : public ::testing::Test { @@ -1480,5 +1480,5 @@ TEST_F(IntegerMathUtilsTest, ModuloFloor) { } } -} // namespace Test +} // namespace P4::Test #endif // (__GNUC__ > 4) || defined(__clang__) diff --git a/test/gtest/bitvec_test.cpp b/test/gtest/bitvec_test.cpp index ee0286b71b..eee82c8f03 100644 --- a/test/gtest/bitvec_test.cpp +++ b/test/gtest/bitvec_test.cpp @@ -19,7 +19,7 @@ limitations under the License. #include -namespace Test { +namespace P4::Test { TEST(Bitvec, Shift) { bitvec simple(0, 1); @@ -141,4 +141,4 @@ TEST(Bitvec, io) { EXPECT_EQ(a, b); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/call_graph_test.cpp b/test/gtest/call_graph_test.cpp index 259928a973..ea72bfd980 100644 --- a/test/gtest/call_graph_test.cpp +++ b/test/gtest/call_graph_test.cpp @@ -20,7 +20,7 @@ limitations under the License. #include "frontends/p4/callGraph.h" -namespace Test { +namespace P4::Test { template static void sameSet(std::unordered_set &set, std::vector vector) { @@ -51,4 +51,4 @@ TEST(CallGraph, Acyclic) { EXPECT_EQ('a', sorted.at(2)); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/complex_bitwise.cpp b/test/gtest/complex_bitwise.cpp index f0e28102d8..2da0114da7 100644 --- a/test/gtest/complex_bitwise.cpp +++ b/test/gtest/complex_bitwise.cpp @@ -15,7 +15,7 @@ using namespace P4; -namespace Test { +namespace P4::Test { namespace { @@ -161,4 +161,4 @@ TEST_F(SimplifyBitwiseTest, SplitWithZero) { EXPECT_FALSE(program_string.find(value3) == std::string::npos); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/constant_expr_test.cpp b/test/gtest/constant_expr_test.cpp index 42f840547a..2d2b07e15e 100644 --- a/test/gtest/constant_expr_test.cpp +++ b/test/gtest/constant_expr_test.cpp @@ -19,7 +19,7 @@ limitations under the License. #include "helpers.h" #include "ir/ir.h" -namespace Test { +namespace P4::Test { class ConstantExpr : public P4CTest {}; @@ -142,4 +142,4 @@ TEST_F(ConstantExpr, TestIntegerFuncs) { EXPECT_EQ(neg_res.asInt(), -123); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/constant_folding.cpp b/test/gtest/constant_folding.cpp index e722ce086d..dd236838d0 100644 --- a/test/gtest/constant_folding.cpp +++ b/test/gtest/constant_folding.cpp @@ -11,7 +11,7 @@ using namespace P4; -namespace Test { +namespace P4::Test { struct P4CFrontend : P4CTest { void addPasses(std::initializer_list passes) { pm.addPasses(passes); } @@ -19,7 +19,7 @@ struct P4CFrontend : P4CTest { const IR::Node *parseAndProcess(std::string program) { const auto *pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); EXPECT_TRUE(pgm); - EXPECT_EQ(::errorCount(), 0); + EXPECT_EQ(::P4::errorCount(), 0); if (!pgm) { return nullptr; } @@ -133,4 +133,4 @@ TEST_F(P4CConstantFoldingValidation, filter) { EXPECT_TRUE(ts_2->size->is()); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/cstring.cpp b/test/gtest/cstring.cpp index 66f315b62c..42debd4ec6 100644 --- a/test/gtest/cstring.cpp +++ b/test/gtest/cstring.cpp @@ -18,7 +18,7 @@ limitations under the License. #include -namespace Test { +namespace P4::Test { using namespace P4::literals; @@ -158,4 +158,4 @@ TEST(cstring, get_cached) { EXPECT_FALSE(cstring::get_cached("test").isNullOrEmpty()); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/diagnostics.cpp b/test/gtest/diagnostics.cpp index 2febb2e6cf..b9d0d9908a 100644 --- a/test/gtest/diagnostics.cpp +++ b/test/gtest/diagnostics.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "frontends/common/applyOptionsPragmas.h" #include "test/gtest/helpers.h" -namespace Test { +namespace P4::Test { namespace { @@ -69,7 +69,7 @@ TEST_F(Diagnostics, P4_16_Disable) { @diagnostic("uninitialized_out_param", "disable") )")); EXPECT_TRUE(test); - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); } TEST_F(Diagnostics, P4_16_Warn) { @@ -77,8 +77,8 @@ TEST_F(Diagnostics, P4_16_Warn) { @diagnostic("uninitialized_out_param", "warn") )")); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } TEST_F(Diagnostics, P4_16_Error) { @@ -86,8 +86,8 @@ TEST_F(Diagnostics, P4_16_Error) { @diagnostic("uninitialized_out_param", "error") )")); EXPECT_FALSE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(1u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(1u, ::P4::errorCount()); } TEST_F(Diagnostics, DISABLED_P4_14_Disable) { @@ -95,7 +95,7 @@ TEST_F(Diagnostics, DISABLED_P4_14_Disable) { @pragma diagnostic uninitialized_use disable )")); EXPECT_TRUE(test); - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); } TEST_F(Diagnostics, DISABLED_P4_14_Warn) { @@ -103,8 +103,8 @@ TEST_F(Diagnostics, DISABLED_P4_14_Warn) { @pragma diagnostic uninitialized_use warn )")); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } TEST_F(Diagnostics, DISABLED_P4_14_Error) { @@ -112,8 +112,8 @@ TEST_F(Diagnostics, DISABLED_P4_14_Error) { @pragma diagnostic uninitialized_use error )")); EXPECT_FALSE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(1u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(1u, ::P4::errorCount()); } TEST_F(Diagnostics, NestedCompileContexts) { @@ -131,8 +131,8 @@ TEST_F(Diagnostics, NestedCompileContexts) { @diagnostic("uninitialized_out_param", "error") )")); EXPECT_FALSE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(1u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(1u, ::P4::errorCount()); } // Run a test with `uninitialized_out_param` disabled. The error from @@ -141,7 +141,7 @@ TEST_F(Diagnostics, NestedCompileContexts) { @diagnostic("uninitialized_out_param", "disable") )")); EXPECT_TRUE(test); - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); } // Run a test with no diagnostic pragma for `uninitialized_out_param`. It @@ -149,8 +149,8 @@ TEST_F(Diagnostics, NestedCompileContexts) { // by the previous tests should be gone. auto test = createP4_16DiagnosticsTestCase(P4_SOURCE(R"()")); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } TEST_F(Diagnostics, CompilerOptions) { @@ -170,23 +170,23 @@ TEST_F(Diagnostics, CompilerOptions) { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Wdisable"}); EXPECT_TRUE(test); - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); } { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Wwarn"}); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Werror"}); EXPECT_FALSE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(1u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(1u, ::P4::errorCount()); } // Check that `--Wdisable`, `--Wwarn`, and `--Werror`, when used with an @@ -196,39 +196,39 @@ TEST_F(Diagnostics, CompilerOptions) { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Wdisable=uninitialized_out_param"}); EXPECT_TRUE(test); - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); } { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Wdisable=unknown_diagnostic"}); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Wwarn=uninitialized_out_param"}); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Werror=uninitialized_out_param"}); EXPECT_FALSE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(1u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(1u, ::P4::errorCount()); } { AutoCompileContext autoContext(new GTestContext); auto test = parseWithCompilerOptions({"(test)", "--Werror=unknown_diagnostic"}); EXPECT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); - EXPECT_EQ(0u, ::errorCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); + EXPECT_EQ(0u, ::P4::errorCount()); } // Check that e.g. `--Wdisable foo` is treated as two arguments, rather than @@ -243,8 +243,8 @@ TEST_F(Diagnostics, CompilerOptions) { // treated as an argument to `--Wdisable`, then // `uninitialized_out_param` would still be enabled and a warning would // fire. - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); } } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/dumpjson.cpp b/test/gtest/dumpjson.cpp index f5f26440de..17fec30d5e 100644 --- a/test/gtest/dumpjson.cpp +++ b/test/gtest/dumpjson.cpp @@ -22,6 +22,8 @@ limitations under the License. #include "ir/json_loader.h" #include "ir/visitor.h" +using namespace P4; + TEST(IR, DumpJSON) { auto c = new IR::Constant(2); IR::Expression *e1 = new IR::Add(Util::SourceInfo(), c, c); diff --git a/test/gtest/enumerator_test.cpp b/test/gtest/enumerator_test.cpp index d233fd56b6..d261904e45 100644 --- a/test/gtest/enumerator_test.cpp +++ b/test/gtest/enumerator_test.cpp @@ -21,7 +21,7 @@ limitations under the License. #include #include -namespace Util { +namespace P4::Util { class UtilEnumerator : public ::testing::Test { protected: @@ -218,4 +218,4 @@ TEST_F(UtilEnumerator, Linq) { } } -} // namespace Util +} // namespace P4::Util diff --git a/test/gtest/equiv_test.cpp b/test/gtest/equiv_test.cpp index abcbafc51a..5ccc9e8d7c 100644 --- a/test/gtest/equiv_test.cpp +++ b/test/gtest/equiv_test.cpp @@ -18,6 +18,7 @@ limitations under the License. #include "ir/ir.h" +using namespace P4; using namespace P4::literals; TEST(IR, Equiv) { diff --git a/test/gtest/exception_test.cpp b/test/gtest/exception_test.cpp index 0c2e82f8ea..43d3c3799c 100644 --- a/test/gtest/exception_test.cpp +++ b/test/gtest/exception_test.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "lib/cstring.h" #include "lib/exceptions.h" -namespace Util { +namespace P4::Util { TEST(UtilException, Messages) { // Check that exception message formatting works as expected. @@ -45,4 +45,4 @@ TEST(UtilException, Messages) { } } -} // namespace Util +} // namespace P4::Util diff --git a/test/gtest/expr_uses_test.cpp b/test/gtest/expr_uses_test.cpp index ece56884c4..8b4f7c60b3 100644 --- a/test/gtest/expr_uses_test.cpp +++ b/test/gtest/expr_uses_test.cpp @@ -20,6 +20,7 @@ limitations under the License. #include "ir/ir.h" +using namespace P4; using namespace P4::literals; TEST(expr_uses, expr_uses) { diff --git a/test/gtest/format_test.cpp b/test/gtest/format_test.cpp index 0be5dab2a6..3b8759cde0 100644 --- a/test/gtest/format_test.cpp +++ b/test/gtest/format_test.cpp @@ -20,7 +20,7 @@ limitations under the License. #include "lib/error.h" #include "lib/stringify.h" -namespace Util { +namespace P4::Util { TEST(Util, Format) { auto &context = BaseCompileContext::get(); @@ -55,4 +55,4 @@ TEST(Util, Format) { EXPECT_EQ("x 5\n", message); } -} // namespace Util +} // namespace P4::Util diff --git a/test/gtest/frontend_test.cpp b/test/gtest/frontend_test.cpp index 31daf6bb57..fffe7b0925 100644 --- a/test/gtest/frontend_test.cpp +++ b/test/gtest/frontend_test.cpp @@ -11,7 +11,7 @@ #include "ir/pass_manager.h" #include "lib/log.h" -namespace Test { +namespace P4::Test { struct P4CFrontend : P4CTest { void addPasses(std::initializer_list passes) { pm.addPasses(passes); } @@ -19,7 +19,7 @@ struct P4CFrontend : P4CTest { const IR::Node *parseAndProcess(std::string program) { const auto *pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); EXPECT_TRUE(pgm); - EXPECT_EQ(::errorCount(), 0); + EXPECT_EQ(::P4::errorCount(), 0); if (!pgm) { return nullptr; } @@ -52,7 +52,7 @@ TEST_F(P4CFrontendEnumValidation, Bit) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 1); + ASSERT_EQ(::P4::errorCount(), 1); ASSERT_TRUE(errors.contains("unrepresentable = 256")); } @@ -68,7 +68,7 @@ TEST_F(P4CFrontendEnumValidation, BitNeg) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 1); + ASSERT_EQ(::P4::errorCount(), 1); ASSERT_TRUE(errors.contains("unrepresentable = -1")); } @@ -84,7 +84,7 @@ TEST_F(P4CFrontendEnumValidation, IntPos) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 1); + ASSERT_EQ(::P4::errorCount(), 1); ASSERT_TRUE(errors.contains("unrepresentable_p = 128")); } @@ -100,7 +100,7 @@ TEST_F(P4CFrontendEnumValidation, IntNeg) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 1); + ASSERT_EQ(::P4::errorCount(), 1); ASSERT_TRUE(errors.contains("unrepresentable_n = -129")); } @@ -120,7 +120,7 @@ TEST_F(P4CFrontendEnumValidation, TypeDef) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 2); + ASSERT_EQ(::P4::errorCount(), 2); ASSERT_TRUE(errors.contains("unrepresentable_p = 64")); ASSERT_TRUE(errors.contains("unrepresentable_n = -65")); std::clog << errors.str(); @@ -136,7 +136,7 @@ TEST_F(P4CFrontendEnumValidation, ExplicitCast) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 0); + ASSERT_EQ(::P4::errorCount(), 0); } TEST_F(P4CFrontendEnumValidation, InvalidUnderlyingUnsized) { @@ -149,7 +149,7 @@ TEST_F(P4CFrontendEnumValidation, InvalidUnderlyingUnsized) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 1); + ASSERT_EQ(::P4::errorCount(), 1); ASSERT_TRUE(errors.contains("Illegal type for enum;")); ASSERT_TRUE(errors.contains("is unsized integral")); } @@ -165,7 +165,7 @@ TEST_F(P4CFrontendEnumValidation, InvalidType) { const auto *prog = parseAndProcess(program); errors.dumpAndReset(); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 1); + ASSERT_EQ(::P4::errorCount(), 1); ASSERT_TRUE(errors.contains("Illegal type for enum;")); ASSERT_TRUE(errors.contains("type-declared types")); } @@ -184,7 +184,7 @@ TEST_F(P4CFrontendMoveInitializers, P4ControlSrcInfo) { )"); const auto *prog = parseAndProcess(program); ASSERT_TRUE(prog); - ASSERT_EQ(::errorCount(), 0); + ASSERT_EQ(::P4::errorCount(), 0); // The P4Control->body should have a valid srcInfo if the information // is correctly maintained by MoveInitializers. @@ -197,4 +197,4 @@ TEST_F(P4CFrontendMoveInitializers, P4ControlSrcInfo) { } } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/gtestp4c.cpp b/test/gtest/gtestp4c.cpp index 5af3218f25..4cab4001d1 100644 --- a/test/gtest/gtestp4c.cpp +++ b/test/gtest/gtestp4c.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "helpers.h" +using namespace P4; + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); AutoCompileContext autoGTestContext(new GTestContext); diff --git a/test/gtest/hash.cpp b/test/gtest/hash.cpp index e972523d46..04edcd8fe9 100644 --- a/test/gtest/hash.cpp +++ b/test/gtest/hash.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "lib/cstring.h" -namespace Test { +namespace P4::Test { TEST(Hash, SimpleHashCombine) { constexpr uint64_t upper = UINT64_C(0xDEADBEEF12345678); @@ -290,4 +290,4 @@ TEST(Hash, SharedPtr) { pointerTestWithHash(); } TEST(Hash, Pointer) { pointerTestWithHash(); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/helpers.cpp b/test/gtest/helpers.cpp index 8fe4a9ac5f..2beb6c3125 100644 --- a/test/gtest/helpers.cpp +++ b/test/gtest/helpers.cpp @@ -29,7 +29,7 @@ limitations under the License. #include "frontends/p4/frontend.h" #include "frontends/p4/parseAnnotations.h" -namespace TestDetail { +namespace P4::TestDetail { std::string makeP4Source(const char *file, unsigned line, P4Headers headers, const char *rawSource) { @@ -85,7 +85,9 @@ std::string makeP4Source(const char *file, unsigned line, const char *rawSource) return makeP4Source(file, line, P4Headers::NONE, rawSource); } -} // namespace TestDetail +} // namespace P4::TestDetail + +namespace P4 { /* static */ P4CTestEnvironment *P4CTestEnvironment::get() { static P4CTestEnvironment *instance = new P4CTestEnvironment; @@ -152,7 +154,9 @@ std::filesystem::path P4CTestEnvironment::getProjectRoot() { return std::filesystem::path(__FILE__).parent_path().parent_path().parent_path(); } -namespace Test { +} // namespace P4 + +namespace P4::Test { /* static */ std::optional FrontendTestCase::create( const std::string &source, @@ -168,17 +172,17 @@ namespace Test { std::cerr << "Couldn't parse test case source" << std::endl; return std::nullopt; } - if (::diagnosticCount() > 0) { - std::cerr << "Encountered " << ::diagnosticCount() << " errors while parsing test case" + if (::P4::diagnosticCount() > 0) { + std::cerr << "Encountered " << ::P4::diagnosticCount() << " errors while parsing test case" << std::endl; return std::nullopt; } P4::P4COptionPragmaParser optionsPragmaParser; program->apply(P4::ApplyOptionsPragmas(optionsPragmaParser)); - if (::errorCount() > 0) { - std::cerr << "Encountered " << ::errorCount() << " errors while collecting options pragmas" - << std::endl; + if (::P4::errorCount() > 0) { + std::cerr << "Encountered " << ::P4::errorCount() + << " errors while collecting options pragmas" << std::endl; return std::nullopt; } @@ -189,14 +193,14 @@ namespace Test { std::cerr << "Frontend failed" << std::endl; return std::nullopt; } - if (::errorCount() > 0) { - std::cerr << "Encountered " << ::errorCount() << " errors while executing frontend" + if (::P4::errorCount() > 0) { + std::cerr << "Encountered " << ::P4::errorCount() << " errors while executing frontend" << std::endl; return std::nullopt; } - if (::errorCount() > 0) { - std::cerr << "Encountered " << ::errorCount() + if (::P4::errorCount() > 0) { + std::cerr << "Encountered " << ::P4::errorCount() << " errors while parsing back-end annotations" << std::endl; return std::nullopt; } @@ -204,4 +208,4 @@ namespace Test { return FrontendTestCase{program}; } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/helpers.h b/test/gtest/helpers.h index 64b7a9ad6c..2dd26d7df6 100644 --- a/test/gtest/helpers.h +++ b/test/gtest/helpers.h @@ -26,9 +26,9 @@ limitations under the License. #include "frontends/common/options.h" #include "frontends/p4/parseAnnotations.h" -namespace IR { +namespace P4::IR { class P4Program; -} // namespace IR +} // namespace P4::IR namespace P4 { class FrontEndPolicy; @@ -42,7 +42,7 @@ enum class P4Headers { PSA // Both core.p4 and psa.p4 }; -namespace TestDetail { +namespace P4::TestDetail { /** * Transforms the P4 program (or program fragment) in @rawSource to turn it into @@ -65,12 +65,14 @@ std::string makeP4Source(const char *file, unsigned line, P4Headers headers, con /// `makeP4Source(file, line, P4Headers::NONE, rawSource);`. std::string makeP4Source(const char *file, unsigned line, const char *rawSource); -} // namespace TestDetail +} // namespace P4::TestDetail // A macro which should be used by unit tests to define P4 source code. It adds // additional information to the source code to aid in debugging; see // makeP4Source for more information and parameter details. -#define P4_SOURCE(...) TestDetail::makeP4Source(__FILE__, __LINE__, __VA_ARGS__) +#define P4_SOURCE(...) P4::TestDetail::makeP4Source(__FILE__, __LINE__, __VA_ARGS__) + +namespace P4 { class P4CTestEnvironment { // XXX(seth): Ideally this would be a ::testing::Environment subclass, but @@ -106,7 +108,9 @@ class P4CTestEnvironment { using GTestContext = P4CContextWithOptions; -namespace Test { +} // namespace P4 + +namespace P4::Test { /// A test fixture base class that automatically creates a new compilation /// context for the test to run in. @@ -163,6 +167,6 @@ struct RedirectStderr { std::streambuf *old = nullptr; }; -} // namespace Test +} // namespace P4::Test #endif /* TEST_GTEST_HELPERS_H_ */ diff --git a/test/gtest/hvec_map.cpp b/test/gtest/hvec_map.cpp index b28ce61822..1c1d84a050 100644 --- a/test/gtest/hvec_map.cpp +++ b/test/gtest/hvec_map.cpp @@ -18,7 +18,7 @@ limitations under the License. #include -namespace Test { +namespace P4::Test { TEST(hvec_map, map_equal) { hvec_map a; @@ -177,4 +177,4 @@ TEST(hvec_map, string_map) { } } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/hvec_set.cpp b/test/gtest/hvec_set.cpp index cb0a406f7f..bdf718bcac 100644 --- a/test/gtest/hvec_set.cpp +++ b/test/gtest/hvec_set.cpp @@ -18,7 +18,7 @@ limitations under the License. #include -namespace Test { +namespace P4::Test { TEST(hvec_set, map_equal) { hvec_set a; @@ -176,4 +176,4 @@ TEST(hvec_set, string_set) { } } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/indexed_vector.cpp b/test/gtest/indexed_vector.cpp index 7417c57ed5..2bf3e7493b 100644 --- a/test/gtest/indexed_vector.cpp +++ b/test/gtest/indexed_vector.cpp @@ -4,9 +4,9 @@ #include "ir/ir.h" -namespace Test { +namespace P4::Test { -using namespace IR; +using namespace P4::IR; using TestVector = IndexedVector; @@ -95,4 +95,4 @@ TEST(IndexedVector, Vector_ctor) { EXPECT_EQ(vec[1]->name.name, "bar"); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/json_test.cpp b/test/gtest/json_test.cpp index 0d4a5629b6..14d46a0005 100644 --- a/test/gtest/json_test.cpp +++ b/test/gtest/json_test.cpp @@ -20,7 +20,7 @@ limitations under the License. #include -namespace Util { +namespace P4::Util { template ::value, int>::type = 0> static cstring getNumStringRepr(T v) { @@ -72,4 +72,4 @@ TEST(Util, Json) { obj->toString()); } -} // namespace Util +} // namespace P4::Util diff --git a/test/gtest/load_ir_from_json.cpp b/test/gtest/load_ir_from_json.cpp index f499d79d5f..8620a7ac28 100644 --- a/test/gtest/load_ir_from_json.cpp +++ b/test/gtest/load_ir_from_json.cpp @@ -33,7 +33,7 @@ limitations under the License. using namespace P4; using namespace std; -namespace Test { +namespace P4::Test { class FromJSONTest : public P4CTest {}; @@ -58,4 +58,4 @@ TEST_F(FromJSONTest, load_ir_from_json) { ASSERT_FALSE(exitCode); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/map.cpp b/test/gtest/map.cpp index 1409e852f4..f03308a480 100644 --- a/test/gtest/map.cpp +++ b/test/gtest/map.cpp @@ -20,7 +20,7 @@ limitations under the License. #include -namespace Test { +namespace P4::Test { TEST(ValuesForKey, set_equal) { std::multimap a; @@ -50,4 +50,4 @@ TEST(ValuesForKey, set_equal) { EXPECT_TRUE(a == b); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/midend_def_use.cpp b/test/gtest/midend_def_use.cpp index 12df1e7a2e..ae4f4e29aa 100644 --- a/test/gtest/midend_def_use.cpp +++ b/test/gtest/midend_def_use.cpp @@ -27,7 +27,7 @@ limitations under the License. using namespace P4; -namespace Test { +namespace P4::Test { using P4TestContext = P4CContextWithOptions; @@ -40,7 +40,7 @@ P4::ComputeDefUse *computeDefUse(std::string source, CompilerOptions::FrontendVe auto *program = P4::parseP4String(source, langVersion); CHECK_NULL(program); - BUG_CHECK(::errorCount() == 0, "Unexpected errors"); + BUG_CHECK(::P4::errorCount() == 0, "Unexpected errors"); auto &options = P4TestContext::get().options(); const char *argv = "./gtestp4c"; @@ -413,4 +413,4 @@ TEST_F(P4CMidendDefUse, slice_1) { EXPECT_TRUE(check_def_use(uses, "inout ParsedHeaders h", 0, {0, 2, 3, 10, 11, 14})); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/midend_pass.cpp b/test/gtest/midend_pass.cpp index 407a521248..667727b01b 100644 --- a/test/gtest/midend_pass.cpp +++ b/test/gtest/midend_pass.cpp @@ -54,7 +54,7 @@ limitations under the License. #include "midend/simplifySelectList.h" #include "midend/tableHit.h" -namespace Test { +namespace P4::Test { MidEnd::MidEnd(CompilerOptions &options, std::ostream *outStream) { bool isv1 = options.langVersion == CompilerOptions::FrontendVersion::P4_14; @@ -151,4 +151,4 @@ IR::ToplevelBlock *MidEnd::process(const IR::P4Program *&program) { return toplevel; } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/midend_pass.h b/test/gtest/midend_pass.h index a7798b63d5..f850ce273f 100644 --- a/test/gtest/midend_pass.h +++ b/test/gtest/midend_pass.h @@ -32,9 +32,11 @@ class ComputeDefUse; class ToplevelBlock; } // namespace P4 +namespace P4 { class CompilerOptions; +} // namespace P4 -namespace Test { +namespace P4::Test { class SkipControls : public P4::ActionSynthesisPolicy { const std::set *skip; @@ -59,6 +61,6 @@ class MidEnd : public PassManager { IR::ToplevelBlock *process(const IR::P4Program *&program); }; -} // namespace Test +} // namespace P4::Test #endif /* TEST_GTEST_MIDEND_PASS_H_ */ diff --git a/test/gtest/midend_test.cpp b/test/gtest/midend_test.cpp index 88e5b3a8ca..3fbb351836 100644 --- a/test/gtest/midend_test.cpp +++ b/test/gtest/midend_test.cpp @@ -29,7 +29,7 @@ limitations under the License. using namespace P4; -namespace Test { +namespace P4::Test { namespace { @@ -51,7 +51,7 @@ TEST_F(P4CMidend, convertEnums_pass) { control m() { C(E.A) ctr; apply{} } )"); auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); // Example to enable logging in source // Log::addDebugSpec("convertEnums:0"); @@ -70,7 +70,7 @@ TEST_F(P4CMidend, convertEnums_used_before_declare) { )"); P4CContext::get().options().langVersion = CompilerOptions::FrontendVersion::P4_16; auto pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); - ASSERT_TRUE(pgm && ::errorCount() == 0); + ASSERT_TRUE(pgm && ::P4::errorCount() == 0); ReferenceMap refMap; TypeMap typeMap; @@ -78,7 +78,7 @@ TEST_F(P4CMidend, convertEnums_used_before_declare) { PassManager passes = {convertEnums}; pgm = pgm->apply(passes); // use enum before declaration should fail - ASSERT_GT(::errorCount(), 0U); + ASSERT_GT(::P4::errorCount(), 0U); } // use enumMap in convertEnums directly @@ -96,7 +96,7 @@ TEST_F(P4CMidend, getEnumMapping) { auto convertEnums = new P4::ConvertEnums(&refMap, &typeMap, new EnumOn32Bits()); PassManager passes_ = {convertEnums}; auto result = pgm->apply(passes_); - ASSERT_TRUE(result != nullptr && ::errorCount() == 0); + ASSERT_TRUE(result != nullptr && ::P4::errorCount() == 0); enumMap = convertEnums->getEnumMapping(); ASSERT_EQ(enumMap.size(), (unsigned long)1); @@ -166,7 +166,7 @@ static void testReplaceSelectRange(std::vector ranges, ExtraTests extraTe new P4::ReplaceSelectRange(&refMap, &typeMap)}; auto result = pgm->apply(passes_); ASSERT_TRUE(result != nullptr); - ASSERT_EQ(::errorCount(), 0u); + ASSERT_EQ(::P4::errorCount(), 0u); CollectRangesAndMasks collect; result->apply(collect); @@ -288,4 +288,4 @@ TEST_F(P4CMidend, replaceSelectRangeSigned5) { {{0, 15}}, [](CollectRangesAndMasks collect) { ASSERT_EQ(collect.masks.size(), 1u); }); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/nethash.cpp b/test/gtest/nethash.cpp index cd69d91a06..0d97f4db7b 100644 --- a/test/gtest/nethash.cpp +++ b/test/gtest/nethash.cpp @@ -5,9 +5,9 @@ #include #include -namespace Test { +namespace P4::Test { -using namespace NetHash; +using namespace P4::NetHash; template struct Hex { @@ -110,4 +110,4 @@ TEST(NetHash, identity) { 0x4500'0073'0000'4000_u64); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/opeq_test.cpp b/test/gtest/opeq_test.cpp index 4c45b08bbf..45e8bd2308 100644 --- a/test/gtest/opeq_test.cpp +++ b/test/gtest/opeq_test.cpp @@ -20,6 +20,8 @@ limitations under the License. #include "ir/visitor.h" #include "lib/exceptions.h" +using namespace P4; + TEST(IR, OperatorEq) { auto *t = IR::Type::Bits::get(16); IR::Constant *a = new IR::Constant(t, 10); diff --git a/test/gtest/ordered_map.cpp b/test/gtest/ordered_map.cpp index 50106a8ab5..70a751973c 100644 --- a/test/gtest/ordered_map.cpp +++ b/test/gtest/ordered_map.cpp @@ -20,7 +20,7 @@ limitations under the License. #include "lib/map.h" -namespace Test { +namespace P4::Test { TEST(OrderedMap, MapEqual) { ordered_map a; @@ -165,4 +165,4 @@ TEST(OrderedMap, NonExistingKey) { EXPECT_EQ(get(myMap, 4), ""); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/ordered_set.cpp b/test/gtest/ordered_set.cpp index 5d4fc9dcba..787d6598b5 100644 --- a/test/gtest/ordered_set.cpp +++ b/test/gtest/ordered_set.cpp @@ -20,7 +20,7 @@ limitations under the License. #include -namespace Test { +namespace P4::Test { TEST(ordered_set, set_equal) { ordered_set a; @@ -133,4 +133,4 @@ TEST(ordered_set, x_is_strict_prefix_of_y) { EXPECT_FALSE(y < x); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/p4runtime.cpp b/test/gtest/p4runtime.cpp index 22d9e902d3..657149e606 100644 --- a/test/gtest/p4runtime.cpp +++ b/test/gtest/p4runtime.cpp @@ -48,7 +48,7 @@ namespace p4configv1 = ::p4::config::v1; using namespace P4::literals; -namespace Test { +namespace P4::Test { namespace { @@ -197,7 +197,7 @@ TEST_F(P4Runtime, IdAssignment) { // We expect exactly two errors: // error: @id 33554740 is assigned to multiple declarations // error: ingress.igTableWithIdInvalidPrefix: @id has the wrong 8-bit prefix - EXPECT_EQ(2u, ::diagnosticCount()); + EXPECT_EQ(2u, ::P4::diagnosticCount()); { // Check that 'igTable' ended up in the P4Info output. @@ -371,7 +371,7 @@ TEST_F(P4Runtime, FieldIdAssignment) { // We expect exactly two errors: // error: KeyElement: @id 99 is used multiple times // error: KeyElement: 0 is not a valid @id value - EXPECT_EQ(2u, ::diagnosticCount()); + EXPECT_EQ(2u, ::P4::diagnosticCount()); { // Check the ids for igTable's match fields. @@ -484,7 +484,7 @@ TEST_F(P4Runtime, IdAssignmentCounters) { )")); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); // checks that myDirectCounter1 with the right ID prefix { @@ -634,7 +634,7 @@ TEST_F(P4Runtime, P416MatchFields) { )")); ASSERT_TRUE(test); - EXPECT_EQ(0u, ::diagnosticCount()); + EXPECT_EQ(0u, ::P4::diagnosticCount()); const auto *igTable = findP4RuntimeTable(*test->p4Info, "ingress.igTable"_cs); ASSERT_TRUE(igTable != nullptr); @@ -747,7 +747,7 @@ TEST_F(P4Runtime, DISABLED_P414MatchFields) { CompilerOptions::FrontendVersion::P4_14); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto *igTable = findP4RuntimeTable(*test->p4Info, "igTable"_cs); ASSERT_TRUE(igTable != nullptr); @@ -820,7 +820,7 @@ TEST_F(P4Runtime, Digests) { ASSERT_TRUE(test); // we expect one warning for the third digest, for which T is a tuple and we // have to auto-generate a name for the digest. - EXPECT_EQ(1U, ::diagnosticCount()); + EXPECT_EQ(1U, ::P4::diagnosticCount()); const auto &typeInfo = test->p4Info->type_info(); // Verify that that the digest() instances match the ones we expect from the @@ -942,7 +942,7 @@ TEST_F(P4Runtime, PSADigests) { ASSERT_TRUE(test); // 0 warnings - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto &typeInfo = test->p4Info->type_info(); // Verify that that the digest() instances match the ones we expect from the @@ -1030,7 +1030,7 @@ TEST_F(P4Runtime, StaticTableEntries) { ASSERT_TRUE(test); // we expect one warning for 0x1111 &&& 0xF (the match will be re-written // as 0x0001 &&& 0xF to conform to the P4Runtime spec) - EXPECT_EQ(1U, ::diagnosticCount()); + EXPECT_EQ(1U, ::P4::diagnosticCount()); const auto *entries = test->entries; const auto &updates = entries->updates(); @@ -1159,7 +1159,7 @@ TEST_F(P4Runtime, IsConstTable) { )")); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto *tableConst = findP4RuntimeTable(*test->p4Info, "ingress.t_const"_cs); ASSERT_TRUE(tableConst != nullptr); @@ -1202,7 +1202,7 @@ TEST_F(P4Runtime, TableActionsAnnotations) { )")); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto *table = findP4RuntimeTable(*test->p4Info, "ingress.t"_cs); ASSERT_TRUE(table != nullptr); @@ -1267,7 +1267,7 @@ TEST_F(P4Runtime, ValueSet) { new ParseAnnotations()); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto *vset = findP4RuntimeValueSet(*test->p4Info, "parse.pvs"_cs); ASSERT_TRUE(vset != nullptr); @@ -1328,7 +1328,7 @@ TEST_F(P4Runtime, Register) { new ParseAnnotations()); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); { // type parameter is tuple const auto *register_ = findP4RuntimeRegister(*test->p4Info, "ingress.my_register_1"_cs); @@ -1392,7 +1392,7 @@ TEST_F(P4Runtime, Documentation) { )")); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); { const auto *table = findP4RuntimeTable(*test->p4Info, "ingress.t"_cs); @@ -1460,7 +1460,7 @@ TEST_F(P4Runtime, JsonSerializationPrintOptions) { )")); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); { // Default options: expect whitespace @@ -1509,7 +1509,7 @@ std::optional P4RuntimePkgInfo::createTestCase(const char *ann TEST_F(P4RuntimePkgInfo, NoAnnotations) { auto test = createTestCase(""); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto &pkgInfo = test->p4Info->pkg_info(); EXPECT_EQ(pkgInfo.arch(), "v1model"); } @@ -1520,7 +1520,7 @@ TEST_F(P4RuntimePkgInfo, GeneralCase) { @pkginfo(contact="p4-dev@lists.p4.org") @brief("This is a P4 program"))"); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto &pkgInfo = test->p4Info->pkg_info(); EXPECT_EQ(pkgInfo.arch(), "v1model"); EXPECT_EQ(pkgInfo.name(), "prog.p4"); @@ -1532,7 +1532,7 @@ TEST_F(P4RuntimePkgInfo, OverrideArch) { auto test = createTestCase(R"(@pkginfo(arch="v1"))"); ASSERT_TRUE(test); // we expect 1 warning for overriding the architecture - EXPECT_EQ(1U, ::diagnosticCount()); + EXPECT_EQ(1U, ::P4::diagnosticCount()); const auto &pkgInfo = test->p4Info->pkg_info(); EXPECT_EQ(pkgInfo.arch(), "v1"); } @@ -1541,7 +1541,7 @@ TEST_F(P4RuntimePkgInfo, ValueNotAString) { auto test = createTestCase(R"(@pkginfo(name=77))"); ASSERT_TRUE(test); // we expect 1 error message - EXPECT_EQ(1U, ::diagnosticCount()); + EXPECT_EQ(1U, ::P4::diagnosticCount()); const auto &pkgInfo = test->p4Info->pkg_info(); EXPECT_EQ(pkgInfo.name(), ""); } @@ -1559,7 +1559,7 @@ TEST_F(P4RuntimePkgInfo, UnknownAnnotations) { @my_annotation_3(test) @my_annotation_4("test"))"); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto &pkgInfo = test->p4Info->pkg_info(); const auto &annotations = pkgInfo.annotations(); ASSERT_EQ(annotations.size(), 4); @@ -1578,7 +1578,7 @@ TEST_F(P4RuntimePkgInfo, UnknownStructuredAnnotations) { @my_annotation_2[1,"hello",true,1==2,5+6] @my_annotation_3[label="text", my_bool=true, int_val=2*3])"); ASSERT_TRUE(test); - EXPECT_EQ(0U, ::diagnosticCount()); + EXPECT_EQ(0U, ::P4::diagnosticCount()); const auto &pkgInfo = test->p4Info->pkg_info(); const auto &annotations = pkgInfo.structured_annotations(); ASSERT_EQ(annotations.size(), 3); @@ -1642,7 +1642,7 @@ TEST_F(P4RuntimePkgInfo, StructuredAnnotationLargeInt) { @my_annotation_1[foo=6666666666666666666666666666666])"); // error is in P4Info serializer ASSERT_TRUE(test); - EXPECT_EQ(1u, ::diagnosticCount()); + EXPECT_EQ(1u, ::P4::diagnosticCount()); } class P4RuntimeDataTypeSpec : public P4Runtime { @@ -1741,7 +1741,7 @@ TEST_F(P4RuntimeDataTypeSpec, Struct) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1767,7 +1767,7 @@ TEST_F(P4RuntimeDataTypeSpec, Header) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1793,7 +1793,7 @@ TEST_F(P4RuntimeDataTypeSpec, HeaderWithFlattening) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1822,7 +1822,7 @@ TEST_F(P4RuntimeDataTypeSpec, HeaderUnion) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1852,7 +1852,7 @@ TEST_F(P4RuntimeDataTypeSpec, HeaderStack) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1874,7 +1874,7 @@ TEST_F(P4RuntimeDataTypeSpec, HeaderUnionStack) { my_extern_t(32w1024) my_extern; )"); auto pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); auto type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1896,7 +1896,7 @@ TEST_F(P4RuntimeDataTypeSpec, Enum) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1919,7 +1919,7 @@ TEST_F(P4RuntimeDataTypeSpec, SerEnum) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1944,7 +1944,7 @@ TEST_F(P4RuntimeDataTypeSpec, Error) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1966,7 +1966,7 @@ TEST_F(P4RuntimeDataTypeSpec, StructWithTypedef) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -1999,7 +1999,7 @@ TEST_F(P4RuntimeDataTypeSpec, NewType) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -2060,7 +2060,7 @@ TEST_F(P4RuntimeDataTypeSpec, NewTypeInvalidTranslationAnnotations) { type bit<8> my_type5_t; )"); getProgram(program); - ASSERT_EQ(::errorCount(), 5U); + ASSERT_EQ(::P4::errorCount(), 5U); } TEST_F(P4RuntimeDataTypeSpec, NewTypeIllegalTranslationAnnotations) { @@ -2074,12 +2074,12 @@ TEST_F(P4RuntimeDataTypeSpec, NewTypeIllegalTranslationAnnotations) { )"); const auto *pgm = getProgram(program); ASSERT_TRUE(pgm != nullptr); - ASSERT_EQ(::errorCount(), 0U); // No syntax error. + ASSERT_EQ(::P4::errorCount(), 0U); // No syntax error. const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); P4::ControlPlaneAPI::TypeSpecConverter::convert(&refMap, &typeMap, type, &typeInfo); - EXPECT_EQ(1U, ::errorCount()); // But a type error. + EXPECT_EQ(1U, ::P4::errorCount()); // But a type error. } TEST_F(P4RuntimeDataTypeSpec, NewTypeValidTranslationAnnotations) { @@ -2099,7 +2099,7 @@ TEST_F(P4RuntimeDataTypeSpec, NewTypeValidTranslationAnnotations) { my_extern_t(32w1024) my_extern; )"); const auto *pgm = getProgram(program); - ASSERT_TRUE(pgm != nullptr && ::errorCount() == 0); + ASSERT_TRUE(pgm != nullptr && ::P4::errorCount() == 0); const auto *type = findExternTypeParameterName(pgm, "my_extern_t"_cs); ASSERT_TRUE(type != nullptr); @@ -2119,4 +2119,4 @@ TEST_F(P4RuntimeDataTypeSpec, NewTypeValidTranslationAnnotations) { } } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/parser_unroll.cpp b/test/gtest/parser_unroll.cpp index d80839ebd0..f096d34589 100644 --- a/test/gtest/parser_unroll.cpp +++ b/test/gtest/parser_unroll.cpp @@ -1,5 +1,10 @@ #include +// #define PARSER_UNROLL_TIME_CHECKING + +#ifdef PARSER_UNROLL_TIME_CHECKING +#include +#endif #include #include "frontends/common/parseInput.h" @@ -11,18 +16,12 @@ using namespace P4; -namespace Test { +namespace P4::Test { using P4TestContext = P4CContextWithOptions; class P4CParserUnroll : public P4CTest {}; -// #define PARSER_UNROLL_TIME_CHECKING - -#ifdef PARSER_UNROLL_TIME_CHECKING -#include -#endif - const IR::P4Parser *getParser(const IR::P4Program *program) { // FIXME: This certainly should be improved, it should be possible to check // and cast at the same time @@ -148,4 +147,4 @@ TEST_F(P4CParserUnroll, header_union) { ASSERT_EQ(parsers.first->states.size(), parsers.second->states.size()); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/remove_dontcare_args_test.cpp b/test/gtest/remove_dontcare_args_test.cpp index e495b8a4c4..6cc0c9fe24 100644 --- a/test/gtest/remove_dontcare_args_test.cpp +++ b/test/gtest/remove_dontcare_args_test.cpp @@ -8,13 +8,13 @@ using namespace P4; -namespace Test { +namespace P4::Test { struct RemoveDontcareArgsTest : P4CTest { const IR::Node *parseAndProcess(std::string program) { const auto *pgm = P4::parseP4String(program, CompilerOptions::FrontendVersion::P4_16); EXPECT_TRUE(pgm); - EXPECT_EQ(::errorCount(), 0); + EXPECT_EQ(::P4::errorCount(), 0); if (!pgm) { return nullptr; } @@ -77,7 +77,7 @@ top(C()) main; const auto *program = parseAndProcess(program_source); ASSERT_TRUE(program); - ASSERT_EQ(::errorCount(), 0); + ASSERT_EQ(::P4::errorCount(), 0); CollectActionAndControlLocals collect; program->apply(collect); @@ -112,4 +112,4 @@ top(C()) main; ASSERT_EQ(collect.controlDecls, 0); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/rtti_test.cpp b/test/gtest/rtti_test.cpp index 96e161a7a2..4610601f1f 100644 --- a/test/gtest/rtti_test.cpp +++ b/test/gtest/rtti_test.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "ir/vector.h" #include "lib/rtti_utils.h" -namespace Test { +namespace P4::Test { TEST(RTTI, TypeId) { auto *c = new IR::Constant(2); @@ -170,4 +170,4 @@ TEST(RttiUtils, isAny) { EXPECT_EQ(*it, from[1]); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/source_file_test.cpp b/test/gtest/source_file_test.cpp index 2c34b03b25..cca3666129 100644 --- a/test/gtest/source_file_test.cpp +++ b/test/gtest/source_file_test.cpp @@ -22,7 +22,7 @@ limitations under the License. #include "lib/cstring.h" #include "lib/exceptions.h" -namespace Util { +namespace P4::Util { TEST(UtilSourceFile, SourcePosition) { SourcePosition invalid; @@ -99,4 +99,4 @@ TEST(UtilSourceFile, SourceInfo) { EXPECT_FALSE(invalid.isValid()); } -} // namespace Util +} // namespace P4::Util diff --git a/test/gtest/strength_reduction.cpp b/test/gtest/strength_reduction.cpp index 725d40f428..5b5d160bdb 100644 --- a/test/gtest/strength_reduction.cpp +++ b/test/gtest/strength_reduction.cpp @@ -13,7 +13,7 @@ using namespace P4; -namespace Test { +namespace P4::Test { namespace { @@ -107,4 +107,4 @@ TEST_F(StrengthReductionTest, DisableSubConstToAddConst) { EXPECT_FALSE(program_string.find(value2) == std::string::npos); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/string_map.cpp b/test/gtest/string_map.cpp index d814b0b704..1da6bcdf85 100644 --- a/test/gtest/string_map.cpp +++ b/test/gtest/string_map.cpp @@ -26,7 +26,7 @@ using namespace P4::literals; using ::testing::ElementsAre; using ::testing::ElementsAreArray; -namespace Test { +namespace P4::Test { TEST(StringMap, RangeConstructor) { string_map::value_type myMap[] = {{"One"_cs, 1}, {"One"_cs, 2}, {"One"_cs, 3}, @@ -291,4 +291,4 @@ TEST(StringMap, NonExistingKey) { EXPECT_EQ(get(myMap, "Four"_cs), 0); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/transforms.cpp b/test/gtest/transforms.cpp index 9e83a894db..02af80805a 100644 --- a/test/gtest/transforms.cpp +++ b/test/gtest/transforms.cpp @@ -23,7 +23,7 @@ limitations under the License. #include "ir/visitor.h" #include "lib/source_file.h" -namespace Test { +namespace P4::Test { class P4C_IR : public P4CTest {}; @@ -82,4 +82,4 @@ TEST_F(P4C_IR, InlineBlock) { EXPECT_TRUE(ifs->ifFalse->is()); } -} // namespace Test +} // namespace P4::Test diff --git a/test/gtest/visitor.cpp b/test/gtest/visitor.cpp index 4921ed9c49..b69deb1af0 100644 --- a/test/gtest/visitor.cpp +++ b/test/gtest/visitor.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "ir/ir.h" #include "midend_pass.h" -namespace Test { +namespace P4::Test { using P4TestContext = P4CContextWithOptions; @@ -160,4 +160,4 @@ TEST_F(P4CVisitor, MultiVisitModifierLoop) { ASSERT_TRUE(program != nullptr); } -} // namespace Test +} // namespace P4::Test diff --git a/testdata/p4_14_errors/issue747.p4 b/testdata/p4_14_errors/issue747.p4 index 96cf15cff5..462977e5bb 100644 --- a/testdata/p4_14_errors/issue747.p4 +++ b/testdata/p4_14_errors/issue747.p4 @@ -27,7 +27,7 @@ parser start { // This test passes local_port (an untyped variable) to recirculate // which expects a field list. It exposed issue #747, where the code -// expected that calling ::error will exit out of the function. +// expected that calling ::P4::error will exit out of the function. action local_recirc(local_port) { resubmit( local_port ); } diff --git a/tools/ir-generator/generator.cpp b/tools/ir-generator/generator.cpp index d6fdb1f334..f42fa33ed9 100644 --- a/tools/ir-generator/generator.cpp +++ b/tools/ir-generator/generator.cpp @@ -23,6 +23,8 @@ limitations under the License. #include "irclass.h" #include "lib/nullstream.h" +using namespace P4; + void usage(const char *progname) { fprintf(stderr, "%s: generate C++ classes for representing\n" diff --git a/tools/ir-generator/ir-generator.h b/tools/ir-generator/ir-generator.h index 4c8f811f21..de9ce6a8ad 100644 --- a/tools/ir-generator/ir-generator.h +++ b/tools/ir-generator/ir-generator.h @@ -19,6 +19,10 @@ limitations under the License. #include "irclass.h" +namespace P4 { + IrDefinitions *parse(char **files, int count); +} // namespace P4 + #endif /* TOOLS_IR_GENERATOR_IR_GENERATOR_H_ */ diff --git a/tools/ir-generator/ir-generator.ypp b/tools/ir-generator/ir-generator.ypp index eab98c240b..05e6fe0347 100644 --- a/tools/ir-generator/ir-generator.ypp +++ b/tools/ir-generator/ir-generator.ypp @@ -36,6 +36,8 @@ limitations under the License. #define YYDEBUG 1 #endif +namespace P4 { + #define YYLTYPE Util::SourceInfo #define YYLLOC_DEFAULT(Cur, Rhs, N) \ ((Cur) = (N) ? YYRHSLOC(Rhs, 1) + YYRHSLOC(Rhs, N) \ @@ -434,7 +436,7 @@ IrDefinitions *parse(char** files, int count) { yydebug = atoi(p); #endif if (count <= 0) { - ::error(ErrorType::ERR_EXPECTED, "No input files specified"); + ::P4::error(ErrorType::ERR_EXPECTED, "No input files specified"); errors = 1; } for (int i = 0; i < count; i++) { @@ -448,9 +450,12 @@ IrDefinitions *parse(char** files, int count) { error(ErrorType::ERR_OVERLIMIT, "out of memory"); break; } } else { - ::error(ErrorType::ERR_IO, "Cannot open file %s", files[i]); + ::P4::error(ErrorType::ERR_IO, "Cannot open file %s", files[i]); perror(""); errors |= 1; } } return errors ? nullptr : new IrDefinitions(global); } + +} // namespace P4 + diff --git a/tools/ir-generator/irclass.cpp b/tools/ir-generator/irclass.cpp index 501c4f6774..3f1d6c2b81 100644 --- a/tools/ir-generator/irclass.cpp +++ b/tools/ir-generator/irclass.cpp @@ -19,6 +19,8 @@ limitations under the License. #include "lib/enumerator.h" #include "lib/exceptions.h" +namespace P4 { + const char *IrClass::indent = " "; IrNamespace &IrNamespace::global() { static IrNamespace irn({}, {}); @@ -115,6 +117,8 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i << "#include \"ir/visitor.h\" // IWYU pragma: keep\n" << "#include \"lib/algorithm.h\" // IWYU pragma: keep\n" << "#include \"lib/log.h\" // IWYU pragma: keep\n" + << std::endl + << "using namespace P4;\n" << std::endl; out << "#include \n" @@ -130,6 +134,8 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i << "#include \"ir/vector.h\" // IWYU pragma: keep\n" << "#include \"lib/ordered_map.h\" // IWYU pragma: keep\n" << std::endl + << "namespace P4 {\n" + << std::endl << "class JSONLoader;\n" << "using NodeFactoryFn = IR::Node*(*)(JSONLoader&);\n" << std::endl @@ -172,6 +178,7 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i << ">;" << std::endl; } } + out << "} // namespace P4" << std::endl; for (auto e : elements) { e->generate_hdr(out); @@ -217,7 +224,7 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i } t << std::endl; - t << "namespace IR {" << std::endl; + t << "namespace P4::IR {" << std::endl; // Emit forward declarations for (auto *cls : *getClasses()) { @@ -268,7 +275,7 @@ void IrDefinitions::generate(std::ostream &t, std::ostream &out, std::ostream &i "RTTI::TypeId(rhs); }\n" << " inline bool operator!=(NodeDiscriminator lhs, RTTI::TypeId rhs) { return " "RTTI::TypeId(lhs) != rhs; }\n"; - t << "} // namespace IR" << std::endl; + t << "} // namespace P4::IR" << std::endl; } void IrClass::generateTreeMacro(std::ostream &out) const { @@ -403,7 +410,7 @@ cstring IrClass::qualified_name(const IrNamespace *in) const { void IrClass::generate_hdr(std::ostream &out) const { if (kind != NodeKind::Nested) { - out << "namespace IR {" << std::endl; + out << "namespace P4::IR {" << std::endl; enter_namespace(out, containedIn); } for (auto cblock : comments) cblock->generate_hdr(out); @@ -453,7 +460,7 @@ void IrClass::generate_hdr(std::ostream &out) const { out << "};" << std::endl; if (kind != NodeKind::Nested) { exit_namespace(out, containedIn); - out << "} // namespace IR" << std::endl; + out << "} // namespace P4::IR" << std::endl; } } @@ -660,3 +667,5 @@ void ConstFieldInitializer::generate_hdr(std::ostream &out) const { else throw Util::CompilationError("Unexpected constant field %1%", this); } + +} // namespace P4 diff --git a/tools/ir-generator/irclass.h b/tools/ir-generator/irclass.h index 214d04efa9..30f588eac3 100644 --- a/tools/ir-generator/irclass.h +++ b/tools/ir-generator/irclass.h @@ -30,6 +30,8 @@ limitations under the License. #include "lib/source_file.h" #include "type.h" +namespace P4 { + class IrClass; class IrField; @@ -52,8 +54,8 @@ class IrNamespace { cstring name; static IrNamespace *get(IrNamespace *, cstring); static void add_class(IrClass *); - IrNamespace *lookupChild(cstring name) const { return ::get(children, name); } - IrClass *lookupClass(cstring name) const { return ::get(classes, name); } + IrNamespace *lookupChild(cstring name) const { return ::P4::get(children, name); } + IrClass *lookupClass(cstring name) const { return ::P4::get(classes, name); } bool lookupOther(cstring name) const { return othertypes.count(name) > 0; } void addOther(cstring name) { othertypes.insert(name); } cstring qualified_name(const IrNamespace *ctxt = nullptr) const; @@ -390,4 +392,6 @@ inline std::ostream &operator<<(std::ostream &out, const LineDirective &l) { return out; } +} // namespace P4 + #endif /* TOOLS_IR_GENERATOR_IRCLASS_H_ */ diff --git a/tools/ir-generator/methods.cpp b/tools/ir-generator/methods.cpp index a75ad86b1a..d2ddc407fa 100644 --- a/tools/ir-generator/methods.cpp +++ b/tools/ir-generator/methods.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "lib/algorithm.h" #include "lib/enumerator.h" +namespace P4 { + enum flags { // flags that control the creation of auto-created methods EXTEND = 1, // call the creation function to extend even when user-defined @@ -388,3 +390,5 @@ void IrClass::generateMethods() { } } } + +} // namespace P4 diff --git a/tools/ir-generator/type.cpp b/tools/ir-generator/type.cpp index ec3fec9b38..ae04c42a39 100644 --- a/tools/ir-generator/type.cpp +++ b/tools/ir-generator/type.cpp @@ -18,6 +18,8 @@ limitations under the License. #include "irclass.h" +namespace P4 { + LookupScope::LookupScope(const IrNamespace *ns) : in((ns && ns->name) ? new LookupScope(ns->parent) : nullptr), global(!ns || !ns->name), @@ -127,7 +129,7 @@ NamedType &NamedType::SourceInfo() { cstring NamedType::toString() const { if (resolved) return resolved->fullName(); - if (!lookup && name == "ID") return "IR::ID"_cs; // hack -- ID is in namespace IR + if (!lookup && name == "ID") return "IR::ID"_cs; // hack -- ID is in namespace P4::IR if (lookup) return lookup->toString() + name; if (foundin) return LookupScope(foundin).toString() + name; return name; @@ -191,3 +193,5 @@ cstring FunctionType::toString() const { result += ")"; return result; } + +} // namespace P4 diff --git a/tools/ir-generator/type.h b/tools/ir-generator/type.h index 58af07b429..f82e52595f 100644 --- a/tools/ir-generator/type.h +++ b/tools/ir-generator/type.h @@ -22,6 +22,8 @@ limitations under the License. #include "lib/cstring.h" #include "lib/source_file.h" +namespace P4 { + class IrClass; class IrNamespace; @@ -219,4 +221,6 @@ class FunctionType : public Type { } }; +} // namespace P4 + #endif /* TOOLS_IR_GENERATOR_TYPE_H_ */