Skip to content

Commit

Permalink
Fixes to lib/hash and lib/big_int_util. (#4655)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
fruffy authored May 9, 2024
1 parent d7748bd commit a5f9f9a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cc_library(
name = "config_h",
hdrs = ["config.h"],
include_prefix = ".",
deps = [":sed_config_h"],
)

cc_library(
Expand Down
6 changes: 2 additions & 4 deletions backends/p4tools/common/lib/symbolic_env.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
#include "backends/p4tools/common/lib/symbolic_env.h"

#include <algorithm>
#include <string>
#include <utility>
#include <vector>

#include <boost/container/vector.hpp>

#include "backends/p4tools/common/lib/model.h"
#include "ir/indexed_vector.h"
#include "ir/vector.h"
#include "ir/visitor.h"
#include "lib/cstring.h"
#include "lib/exceptions.h"

namespace P4Tools {
Expand All @@ -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<IR::Type_Unknown>(),
"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;
}

Expand Down
2 changes: 1 addition & 1 deletion ir/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/alloc_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
#include <map>
#include <ostream>

#include "config.h"
#include "exceptions.h"
#include "gc.h"

Expand Down
24 changes: 24 additions & 0 deletions lib/big_int.h
Original file line number Diff line number Diff line change
@@ -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 <boost/multiprecision/cpp_int.hpp>

using big_int = boost::multiprecision::cpp_int;

#endif /* LIB_BIG_INT_H_ */
9 changes: 5 additions & 4 deletions lib/big_int_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ limitations under the License.
#ifndef LIB_BIG_INT_UTIL_H_
#define LIB_BIG_INT_UTIL_H_

#include <boost/multiprecision/cpp_int.hpp>

#include "config.h"
typedef boost::multiprecision::cpp_int big_int;
#include "big_int.h"
#include "hash.h"

namespace Util {

Expand Down Expand Up @@ -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<big_int> : Detail::StdHasher {};

#endif /* LIB_BIG_INT_UTIL_H_ */
5 changes: 0 additions & 5 deletions lib/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <tuple>
#include <type_traits>

#include "lib/big_int_util.h"

namespace Util {

namespace Detail {
Expand Down Expand Up @@ -178,9 +176,6 @@ struct Hasher<signed char> : Detail::IntegerHasher<signed char> {};
template <>
struct Hasher<char> : Detail::IntegerHasher<char> {};

template <>
struct Hasher<big_int> : Detail::StdHasher {};

template <>
struct Hasher<float> : Detail::FloatHasher<float> {};

Expand Down

0 comments on commit a5f9f9a

Please sign in to comment.