ilasynth  1.0
ILASynth: Template-based ILA Synthesis Engine
hash.hpp
Go to the documentation of this file.
1 // --------------------------------------------------------------
2 //
3 // Utilities for hashing nodes.
4 //
5 // --------------------------------------------------------------
6 #ifndef __AST_HASH_HPP_DEFINED__
7 #define __AST_HASH_HPP_DEFINED__
8 
9 #include <boost/functional/hash.hpp>
10 
11 #include <iostream>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 #include <assert.h>
17 #include <ilasynth/type.hpp>
18 #include <z3++.h>
19 
20 #include <boost/multiprecision/cpp_int.hpp>
21 #include <boost/python.hpp>
22 #include <boost/shared_ptr.hpp>
23 
24 #include <ilasynth/ast.hpp>
25 #include <ilasynth/ast/node.hpp>
26 
27 namespace ilasynth {
28 std::size_t hash_value(const Node& n);
29 std::size_t hash_value(const NodeType& ntype);
30 std::size_t compute_hash_value(const NodeType& ntype);
31 
32 template <typename T>
33 void choice_hash_combine(std::size_t& seed, const ChoiceExpr<T>* c) {
34  const ReadSlice* rs = dynamic_cast<const ReadSlice*>(c);
35  const WriteSlice* ws = dynamic_cast<const WriteSlice*>(c);
36 
37  if (rs != NULL) {
38  boost::hash_combine(seed, 103002410);
39  boost::hash_combine(seed, rs->bitvec.get());
40  boost::hash_combine(seed, rs->width);
41  boost::hash_combine(seed, rs->increment);
42  } else if (ws != NULL) {
43  boost::hash_combine(seed, 1505753267);
44  boost::hash_combine(seed, ws->bitvec.get());
45  boost::hash_combine(seed, ws->data.get());
46  boost::hash_combine(seed, ws->increment);
47  }
48  boost::hash_combine(seed, c->getName());
49 }
50 
51 template <class T> struct NodeHash;
52 template <> struct NodeHash<const Node*> {
53  size_t operator()(const Node* n) const { return hash_value(*n); }
54 };
55 
56 template <class T> struct NodeEqual;
57 template <> struct NodeEqual<const Node*> {
58  bool operator()(const Node* l, const Node* r) const { return l->equal(r); }
59 };
60 } // namespace ilasynth
61 
62 #endif
int width
Definition: choice.hpp:122
Definition: hash.hpp:56
nptr_t bitvec
Definition: choice.hpp:148
std::size_t hash_value(const Node &n)
size_t operator()(const Node *n) const
Definition: hash.hpp:53
Definition: choice.hpp:138
nptr_t bitvec
Definition: choice.hpp:120
Definition: choice.hpp:109
virtual bool equal(const Node *that) const
Definition: choice.hpp:47
std::size_t compute_hash_value(const NodeType &ntype)
nptr_t data
Definition: choice.hpp:150
Definition: abstraction.hpp:21
Definition: node.hpp:55
int increment
Definition: choice.hpp:152
bool operator()(const Node *l, const Node *r) const
Definition: hash.hpp:58
void choice_hash_combine(std::size_t &seed, const ChoiceExpr< T > *c)
Definition: hash.hpp:33
int increment
Definition: choice.hpp:124
Definition: hash.hpp:51