From a5f9f9a91a0ff4daa0abc0d7942edf7cdd31abc1 Mon Sep 17 00:00:00 2001 From: Fabian Ruffy <5960321+fruffy@users.noreply.github.com> Date: Thu, 9 May 2024 15:41:50 +0200 Subject: [PATCH] Fixes to lib/hash and lib/big_int_util. (#4655) * Small fixes to hashing and big int. * Fix unused code in alloc_trace.cpp? * Add sed_config_h dependency to config.h for Bazel builds? * Include config in alloc trace. --- BUILD.bazel | 1 + backends/p4tools/common/lib/symbolic_env.cpp | 6 ++--- ir/expression.cpp | 2 +- lib/alloc_trace.h | 1 + lib/big_int.h | 24 ++++++++++++++++++++ lib/big_int_util.h | 9 ++++---- lib/hash.h | 5 ---- 7 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 lib/big_int.h diff --git a/BUILD.bazel b/BUILD.bazel index 1d80c296acb..3b087e1d710 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -41,6 +41,7 @@ cc_library( name = "config_h", hdrs = ["config.h"], include_prefix = ".", + deps = [":sed_config_h"], ) cc_library( diff --git a/backends/p4tools/common/lib/symbolic_env.cpp b/backends/p4tools/common/lib/symbolic_env.cpp index 0578338f6e3..e66ca624fc6 100644 --- a/backends/p4tools/common/lib/symbolic_env.cpp +++ b/backends/p4tools/common/lib/symbolic_env.cpp @@ -1,9 +1,7 @@ #include "backends/p4tools/common/lib/symbolic_env.h" #include -#include #include -#include #include @@ -11,7 +9,6 @@ #include "ir/indexed_vector.h" #include "ir/vector.h" #include "ir/visitor.h" -#include "lib/cstring.h" #include "lib/exceptions.h" namespace P4Tools { @@ -28,7 +25,8 @@ bool SymbolicEnv::exists(const IR::StateVariable &var) const { return map.find(v void SymbolicEnv::set(const IR::StateVariable &var, const IR::Expression *value) { BUG_CHECK(value->type && !value->type->is(), - "Cannot set value with unspecified type: %1%", value); + "Cannot set value for node %1% with unspecified type: %2%", value->node_type_name(), + value); map[var] = value; } diff --git a/ir/expression.cpp b/ir/expression.cpp index 63717ff746e..de333e12134 100644 --- a/ir/expression.cpp +++ b/ir/expression.cpp @@ -161,7 +161,7 @@ const IR::Constant *IR::Constant::get(const IR::Type *t, big_int v, Util::Source const IR::BoolLiteral *IR::BoolLiteral::get(bool value, const Util::SourceInfo &si) { // Do not cache values with a non-empty source info (yet). if (si.isValid()) { - return new IR::BoolLiteral(si, value); + return new IR::BoolLiteral(si, IR::Type_Boolean::get(), value); } // Boolean literals are interned. static IR::BoolLiteral TRUE_BOOLLITERAL(si, IR::Type_Boolean::get(), true); diff --git a/lib/alloc_trace.h b/lib/alloc_trace.h index 8b281fdda86..eecd6258fb0 100644 --- a/lib/alloc_trace.h +++ b/lib/alloc_trace.h @@ -20,6 +20,7 @@ limitations under the License. #include #include +#include "config.h" #include "exceptions.h" #include "gc.h" diff --git a/lib/big_int.h b/lib/big_int.h new file mode 100644 index 00000000000..c31f8897191 --- /dev/null +++ b/lib/big_int.h @@ -0,0 +1,24 @@ +/* +Copyright 2013-present Barefoot Networks, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#ifndef LIB_BIG_INT_H_ +#define LIB_BIG_INT_H_ + +#include + +using big_int = boost::multiprecision::cpp_int; + +#endif /* LIB_BIG_INT_H_ */ diff --git a/lib/big_int_util.h b/lib/big_int_util.h index 033067b4e4d..a7815188023 100644 --- a/lib/big_int_util.h +++ b/lib/big_int_util.h @@ -17,10 +17,8 @@ limitations under the License. #ifndef LIB_BIG_INT_UTIL_H_ #define LIB_BIG_INT_UTIL_H_ -#include - -#include "config.h" -typedef boost::multiprecision::cpp_int big_int; +#include "big_int.h" +#include "hash.h" namespace Util { @@ -93,4 +91,7 @@ static inline int floor_log2(big_int v) { static inline int ceil_log2(big_int v) { return v ? floor_log2(v - 1) + 1 : -1; } +template <> +struct Util::Hasher : Detail::StdHasher {}; + #endif /* LIB_BIG_INT_UTIL_H_ */ diff --git a/lib/hash.h b/lib/hash.h index 4e31c7cc6c3..46097833dc3 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -11,8 +11,6 @@ #include #include -#include "lib/big_int_util.h" - namespace Util { namespace Detail { @@ -178,9 +176,6 @@ struct Hasher : Detail::IntegerHasher {}; template <> struct Hasher : Detail::IntegerHasher {}; -template <> -struct Hasher : Detail::StdHasher {}; - template <> struct Hasher : Detail::FloatHasher {};