Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/komaljai/p4c into change_en…
Browse files Browse the repository at this point in the history
…dianess
  • Loading branch information
komaljai committed Mar 26, 2024
2 parents 49ef685 + 1de63e6 commit 8c06a22
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 50 deletions.
50 changes: 0 additions & 50 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -620,53 +620,3 @@ SET(CPACK_SOURCE_IGNORE_FILES
INCLUDE(CPack)

ADD_CUSTOM_TARGET(dist COMMAND ${CMAKE_MAKE_PROGRAM} clean package_source)

#################### IWYU
# Needs to be part of the top-level to be able to find all targets in the compiler framework.
if(ENABLE_IWYU)
# Set up IWYU for P4C.
message("Enabling IWYU checks.")
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
set(iwyu_path
${iwyu_path}
-Xiwyu
--max_line_length=100
-Xiwyu
--no_fwd_decls
-Xiwyu
--cxx17ns
-Xiwyu
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/p4c.imp
)
message("IWYU command: ${iwyu_path}")
function(get_all_targets var)
set(targets)
get_all_targets_recursive(targets ${CMAKE_CURRENT_SOURCE_DIR})
set(${var} ${targets} PARENT_SCOPE)
endfunction()

macro(get_all_targets_recursive targets dir)
get_property(subdirectories DIRECTORY ${dir} PROPERTY SUBDIRECTORIES)
foreach(subdir ${subdirectories})
get_all_targets_recursive(${targets} ${subdir})
endforeach()

get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS)
list(APPEND ${targets} ${current_targets})
endmacro()

# Apply IWYU to all targets.
get_all_targets(all_targets)
# Remove generated files from IWYU.
list(FILTER all_targets EXCLUDE REGEX "controlplane-gen")
list(FILTER all_targets EXCLUDE REGEX "dpdk_runtime")
list(FILTER all_targets EXCLUDE REGEX "ir-generated")
list(FILTER all_targets EXCLUDE REGEX "genIR")
list(FILTER all_targets EXCLUDE REGEX "parser-gen")
list(FILTER all_targets EXCLUDE REGEX "gtest")
message("Applying IWYU to targets: ${all_targets}")
foreach(target ${all_targets})
set_property(TARGET ${target} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endforeach()

endif()
5 changes: 5 additions & 0 deletions backends/p4tools/modules/testgen/testgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ std::optional<AbstractTestList> generateTestsImpl(std::optional<std::string_view
compilerResultOpt = P4Tools::CompilerTarget::runCompiler();
}

if (!compilerResultOpt.has_value()) {
::error("Failed to run the compiler.");
return std::nullopt;
}

const auto *testgenCompilerResult =
compilerResultOpt.value().get().checkedTo<TestgenCompilerResult>();

Expand Down
10 changes: 10 additions & 0 deletions backends/tc/ebpfCodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1636,6 +1636,16 @@ void ControlBodyTranslatorPNA::processFunction(const P4::ExternFunction *functio
builder->emitIndent();
builder->appendLine(" .pipeid = p4tc_filter_fields.pipeid,");
builder->emitIndent();
builder->appendLine(" .handle = p4tc_filter_fields.handle,");
builder->emitIndent();
builder->appendLine(" .classid = p4tc_filter_fields.classid,");
builder->emitIndent();
builder->appendLine(" .chain = p4tc_filter_fields.chain,");
builder->emitIndent();
builder->appendLine(" .proto = p4tc_filter_fields.proto,");
builder->emitIndent();
builder->appendLine(" .prio = p4tc_filter_fields.prio,");
builder->emitIndent();
auto tableName = table->instanceName.substr(controlName.size() + 1);
auto tblId = tcIR->getTableId(tableName);
BUG_CHECK(tblId != 0, "Table ID not found");
Expand Down
5 changes: 5 additions & 0 deletions backends/tc/runtime/pna.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ struct p4tc_table_entry_create_bpf_params__local {
u32 pipeid;
u32 tblid;
u32 profile_id;
u32 handle;
u32 classid;
u32 chain;
u16 proto;
u16 prio;
};
extern struct p4tc_table_entry_act_bpf *bpf_p4tc_tbl_read(
struct __sk_buff *skb, struct p4tc_table_entry_act_bpf_params__local *params, void *key,
Expand Down
12 changes: 12 additions & 0 deletions cmake/Abseil.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ macro(p4c_obtain_abseil)
)
fetchcontent_makeavailable_but_exclude_install(abseil)

# Suppress warnings for all Abseil targets.
get_all_targets(ABSL_BUILD_TARGETS ${absl_SOURCE_DIR})
foreach(target in ${ABSL_BUILD_TARGETS})
if(target MATCHES "absl_*")
# Do not suppress warnings for Abseil library targets that are aliased.
get_target_property(target_type ${target} TYPE)
if (NOT ${target_type} STREQUAL "INTERFACE_LIBRARY")
set_target_properties(${target} PROPERTIES COMPILE_FLAGS "-Wno-error -w")
endif()
endif()
endforeach()

# Reset temporary variable modifications.
set(CMAKE_UNITY_BUILD ${CMAKE_UNITY_BUILD_PREV})
set(FETCHCONTENT_QUIET ${FETCHCONTENT_QUIET_PREV})
Expand Down
36 changes: 36 additions & 0 deletions cmake/Linters.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,39 @@ if(NOT ${BLACK_CMD} OR NOT (NOT ${ISORT_CMD}))
else()
message(WARNING "black or isort executable not found. Disabling black/isort checks. black/isort can be installed with \"pip3 install --user --upgrade black\" and \"pip3 install --user --upgrade isort\" ")
endif()

#################### IWYU
if(ENABLE_IWYU)
# Set up IWYU for P4C.
message("Enabling IWYU checks.")
find_program(iwyu_path NAMES include-what-you-use iwyu REQUIRED)
set(iwyu_path
${iwyu_path}
-Xiwyu
--max_line_length=100
-Xiwyu
--no_fwd_decls
-Xiwyu
--cxx17ns
-Xiwyu
--mapping_file=${P4C_SOURCE_DIR}/tools/iwyu_mappings/p4c.imp
)
message("IWYU command: ${iwyu_path}")


get_all_targets(ALL_IWYU_TARGETS ${CMAKE_CURRENT_SOURCE_DIR})
# Apply IWYU to all targets.
get_all_targets(ALL_IWYU_TARGETS)
# Remove generated files from IWYU.
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "controlplane-gen")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "dpdk_runtime")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "ir-generated")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "genIR")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "parser-gen")
list(FILTER ALL_IWYU_TARGETS EXCLUDE REGEX "gtest")
message("Applying IWYU to targets: ${all_targets}")
foreach(target ${ALL_IWYU_TARGETS})
set_property(TARGET ${target} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
endforeach()

endif()
15 changes: 15 additions & 0 deletions cmake/P4CUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -433,3 +433,18 @@ macro(fetchcontent_makeavailable_but_exclude_install content)
add_subdirectory(${${content}_SOURCE_DIR} ${${content}_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
endmacro(fetchcontent_makeavailable_but_exclude_install)

# Collect all currently added targets in all subdirectories
#
# Parameters: - _result the list containing all found targets - _dir root directory to start
# looking from
# Sourced from https://stackoverflow.com/a/60232044
function(get_all_targets _result _dir)
get_property(_subdirs DIRECTORY "${_dir}" PROPERTY SUBDIRECTORIES)
foreach(_subdir IN LISTS _subdirs)
get_all_targets(${_result} "${_subdir}")
endforeach()

get_directory_property(_sub_targets DIRECTORY "${_dir}" BUILDSYSTEM_TARGETS)
set(${_result} ${${_result}} ${_sub_targets} PARENT_SCOPE)
endfunction()
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ if (/* hdr->ipv4.isValid() */
/* construct key */
struct p4tc_table_entry_create_bpf_params__local update_params = {
.pipeid = p4tc_filter_fields.pipeid,
.handle = p4tc_filter_fields.handle,
.classid = p4tc_filter_fields.classid,
.chain = p4tc_filter_fields.chain,
.proto = p4tc_filter_fields.proto,
.prio = p4tc_filter_fields.prio,
.tblid = 1,
.profile_id = 2
};
Expand Down
10 changes: 10 additions & 0 deletions testdata/p4tc_samples_outputs/add_entry_example_control_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ if (/* hdr->ipv4.isValid() */
/* construct key */
struct p4tc_table_entry_create_bpf_params__local update_params = {
.pipeid = p4tc_filter_fields.pipeid,
.handle = p4tc_filter_fields.handle,
.classid = p4tc_filter_fields.classid,
.chain = p4tc_filter_fields.chain,
.proto = p4tc_filter_fields.proto,
.prio = p4tc_filter_fields.prio,
.tblid = 1,
.profile_id = 2
};
Expand Down Expand Up @@ -174,6 +179,11 @@ if (/* hdr->ipv4.isValid() */
/* construct key */
struct p4tc_table_entry_create_bpf_params__local update_params = {
.pipeid = p4tc_filter_fields.pipeid,
.handle = p4tc_filter_fields.handle,
.classid = p4tc_filter_fields.classid,
.chain = p4tc_filter_fields.chain,
.proto = p4tc_filter_fields.proto,
.prio = p4tc_filter_fields.prio,
.tblid = 2,
.profile_id = 2
};
Expand Down

0 comments on commit 8c06a22

Please sign in to comment.