ilasynth  1.0
ILASynth: Template-based ILA Synthesis Engine
type.hpp
Go to the documentation of this file.
1 #ifndef __TYPE_HPP_DEFINED__
2 #define __TYPE_HPP_DEFINED__
3 
4 #include <assert.h>
5 #include <iostream>
6 #include <string>
7 #include <vector>
8 
9 namespace ilasynth {
10 // Class for types of nodes.
11 struct NodeType {
13  int bitWidth;
14  int addrWidth;
15  int dataWidth;
16  std::vector<int> argsWidth;
17  size_t hash_val;
18 
19  // default constructor.
21  // construct a bool.
22  NodeType(Type t);
23  // construct a bitvector.
24  NodeType(Type t, int w);
25  // construct a memory.
26  NodeType(Type t, int aw, int dw);
27  // construct a func.
28  NodeType(Type t, int rw, const std::vector<int>& aw);
29 
30  bool operator!(void) const;
31 
32  // Is this a bool?
33  bool isBool() const { return type == BOOL; }
34  // Is this a bitvector with the specified width?
35  // -1 means any width.
36  bool isBitvector(int width = -1) const {
37  return type == BITVECTOR && (bitWidth == width || width == -1);
38  }
39  // Is this a memory with the correct dimensions?
40  bool isMem(int aw = -1, int dw = -1) const {
41  return (type == MEM) && (aw == -1 || addrWidth == aw) &&
42  (dw == -1 || dataWidth == dw);
43  }
44 
45  // Is this a func with the correct dimensions?
46  bool isFunc(int rw = -1, std::vector<int> aw = {}) const {
47  if (type != FUNC) {
48  return false;
49  } else if (rw == -1) {
50  return true;
51  } else if (aw.size() != argsWidth.size()) {
52  return false;
53  } else if (rw == bitWidth) {
54  for (unsigned i = 0; i != aw.size(); i++) {
55  if (aw[i] != argsWidth[i]) {
56  return false;
57  }
58  }
59  }
60  return true;
61  }
62 
63  bool operator==(const NodeType& t) const;
64  bool operator!=(const NodeType& t) const { return !operator==(t); }
65 
66  // static helper construction functions.
67  static NodeType getBool();
68  static NodeType getBitvector(int w);
69  static NodeType getMem(int aw, int dw);
70  static NodeType getFunc(int rw, const std::vector<int>& aw);
71 };
72 
73 // stream output operator, required for boost::lexical_cast<>
74 std::ostream& operator<<(std::ostream& out, NodeType const& ntype);
75 } // namespace ilasynth
76 
77 #endif // __TYPE_HPP_DEFINED__
bool isBool() const
Definition: type.hpp:33
int dataWidth
Definition: type.hpp:15
bool isFunc(int rw=-1, std::vector< int > aw={}) const
Definition: type.hpp:46
enum ilasynth::NodeType::Type type
Definition: type.hpp:12
NodeType()
Definition: type.hpp:20
int bitWidth
Definition: type.hpp:13
Definition: type.hpp:12
Definition: type.hpp:11
bool isMem(int aw=-1, int dw=-1) const
Definition: type.hpp:40
size_t hash_val
Definition: type.hpp:17
Definition: type.hpp:12
static NodeType getFunc(int rw, const std::vector< int > &aw)
bool operator==(const NodeType &t) const
Definition: type.hpp:12
bool operator!(void) const
static NodeType getBitvector(int w)
static NodeType getMem(int aw, int dw)
Definition: type.hpp:12
Definition: abstraction.hpp:21
static NodeType getBool()
bool operator!=(const NodeType &t) const
Definition: type.hpp:64
std::vector< int > argsWidth
Definition: type.hpp:16
int addrWidth
Definition: type.hpp:14
Type
Definition: type.hpp:12
bool isBitvector(int width=-1) const
Definition: type.hpp:36
std::ostream & operator<<(std::ostream &out, const Node &that)