ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
sort.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_ILA_AST_SORT_H__
5 #define ILANG_ILA_AST_SORT_H__
6 
7 #include <memory>
8 #include <ostream>
9 
10 #include <z3++.h>
11 
12 #include <ilang/ila/ast/ast.h>
13 
15 namespace ilang {
16 
18 enum AstUidSort { kBool = 1, kBv, kMem };
19 
22 class Sort : public Ast {
23 public:
25  typedef std::shared_ptr<Sort> SortPtr;
26 
27  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
29  Sort();
31  virtual ~Sort();
32 
33  // ------------------------- HELPERS -------------------------------------- //
35  static SortPtr MakeBoolSort();
37  static SortPtr MakeBvSort(const int& bit_width);
39  static SortPtr MakeMemSort(const int& addr_width, const int& data_width);
40 
41  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
43  virtual AstUidSort uid() const = 0;
45  virtual bool is_bool() const { return false; }
47  virtual bool is_bv(const int& width = 0) const { return false; }
49  virtual bool is_mem() const { return false; }
50 
52  virtual int bit_width() const;
54  virtual int addr_width() const;
56  virtual int data_width() const;
57 
58  // ------------------------- METHODS -------------------------------------- //
60  virtual z3::sort GetZ3Sort(z3::context& ctx) const = 0;
62  virtual z3::expr GetZ3Expr(z3::context& ctx,
63  const std::string& name) const = 0;
64 
66  virtual bool Equal(const SortPtr rhs) const = 0;
68  friend bool operator==(const SortPtr lhs, const SortPtr rhs) {
69  return lhs->Equal(rhs);
70  }
71 
73  virtual std::ostream& Print(std::ostream& out) const = 0;
75  friend std::ostream& operator<<(std::ostream& out, const SortPtr s) {
76  return s->Print(out);
77  }
78 
79 }; // class Sort
80 
83 
85 class SortBool : public Sort {
86 public:
87  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
89  SortBool();
91  ~SortBool();
92 
93  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
95  AstUidSort uid() const { return AstUidSort::kBool; }
97  bool is_bool() const { return true; }
98 
99  // ------------------------- METHODS -------------------------------------- //
101  z3::sort GetZ3Sort(z3::context& ctx) const;
103  z3::expr GetZ3Expr(z3::context& ctx, const std::string& name) const;
105  bool Equal(const SortPtr rhs) const;
107  std::ostream& Print(std::ostream& out) const;
108 }; // class SortBool
109 
111 class SortBv : public Sort {
112 public:
113  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
115  SortBv(const int& width);
117  ~SortBv();
118 
119  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
121  AstUidSort uid() const { return AstUidSort::kBv; }
123  bool is_bv(const int& width) const {
124  return (width == 0) ? true : (width == bit_width_);
125  }
126 
127  // ------------------------- METHODS -------------------------------------- //
129  int bit_width() const { return bit_width_; }
131  z3::sort GetZ3Sort(z3::context& ctx) const;
133  z3::expr GetZ3Expr(z3::context& ctx, const std::string& name) const;
135  bool Equal(const SortPtr rhs) const;
137  std::ostream& Print(std::ostream& out) const;
138 
139 private:
141  int bit_width_;
142 }; // class SortBv
143 
145 class SortMem : public Sort {
146 public:
147  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
149  SortMem(const int& addr_w, const int& data_w);
151  ~SortMem();
152 
153  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
155  AstUidSort uid() const { return AstUidSort::kMem; }
157  bool is_mem() const { return true; }
158 
159  // ------------------------- METHODS -------------------------------------- //
161  int addr_width() const { return addr_width_; }
163  int data_width() const { return data_width_; }
165  z3::sort GetZ3Sort(z3::context& ctx) const;
167  z3::expr GetZ3Expr(z3::context& ctx, const std::string& name) const;
169  bool Equal(const SortPtr rhs) const;
171  std::ostream& Print(std::ostream& out) const;
172 
173 private:
175  int addr_width_;
177  int data_width_;
178 }; // class SortMem
179 
180 } // namespace ilang
181 
182 #endif // ILANG_ILA_AST_SORT_H__
AstUidSort uid() const
Return the unified ID of SortBool.
Definition: sort.h:95
bool is_bool() const
Return true since it is Boolean Sort.
Definition: sort.h:97
static SortPtr MakeMemSort(const int &addr_width, const int &data_width)
Create a memory (array) Sort.
virtual int data_width() const
Return the bit-width of the data (value).
std::ostream & Print(std::ostream &out) const
Print out to output stream.
AstUidSort
Unified ID for Sort.
Definition: sort.h:18
Sort::SortPtr SortPtr
Pointer type for storing/passing Sort.
Definition: sort.h:82
int data_width() const
Return the bit-width of data (value).
Definition: sort.h:163
z3::expr GetZ3Expr(z3::context &ctx, const std::string &name) const
Return a z3 variable of the Sort.
virtual bool is_bool() const
Return true if have Boolean sort.
Definition: sort.h:45
virtual int bit_width() const
Return the bit-width of bit-vector sort.
static SortPtr MakeBoolSort()
Create a Boolean Sort.
z3::sort GetZ3Sort(z3::context &ctx) const
Return the z3::sort of array.
~SortBool()
Default destructor.
virtual int addr_width() const
Return the bit-width of the address (index).
std::ostream & Print(std::ostream &out) const
Print out to output stream.
std::shared_ptr< Sort > SortPtr
Pointer type for storing/passing Sort.
Definition: sort.h:25
AstUidSort uid() const
Return the unified ID of SortBv.
Definition: sort.h:121
virtual std::ostream & Print(std::ostream &out) const =0
Print out to output stream.
AstUidSort uid() const
Return the unified ID of SortMem.
Definition: sort.h:155
bool Equal(const SortPtr rhs) const
Compare with another Sort.
virtual z3::expr GetZ3Expr(z3::context &ctx, const std::string &name) const =0
Return a z3 variable of the Sort.
bool is_bv(const int &width) const
Return true since it is bit-vector Sort.
Definition: sort.h:123
int bit_width() const
Return the bit-width.
Definition: sort.h:129
The class for the Abstract Syntax Tree. An Ast object can be an expression or function definition (in...
Definition: ast.h:20
int addr_width() const
Return the bit-width of address (index).
Definition: sort.h:161
z3::expr GetZ3Expr(z3::context &ctx, const std::string &name) const
Return a z3 variable of the Sort.
Sort()
Default constructor.
z3::sort GetZ3Sort(z3::context &ctx) const
Return the z3::sort of bit-vector.
SortBv(const int &width)
Default constructor.
virtual bool Equal(const SortPtr rhs) const =0
Compare two Sorts.
The class for sort (type for expr, and the range/domain of functions).
Definition: sort.h:22
bool Equal(const SortPtr rhs) const
Compare with another Sort.
The class of memory (array) Sort.
Definition: sort.h:145
~SortBv()
Default destructor.
~SortMem()
Default destructor.
SortBool()
Default constructor.
z3::expr GetZ3Expr(z3::context &ctx, const std::string &name) const
Return a z3 variable of the Sort.
virtual bool is_mem() const
Return true if have memory (array) sort.
Definition: sort.h:49
virtual AstUidSort uid() const =0
Return the unified ID of Sort.
std::ostream & Print(std::ostream &out) const
Print out to output stream.
The class of bit-vector Sort.
Definition: sort.h:111
friend std::ostream & operator<<(std::ostream &out, const SortPtr s)
Overload output stream operator.
Definition: sort.h:75
bool is_mem() const
Return true since it is memory (array) Sort.
Definition: sort.h:157
bool Equal(const SortPtr rhs) const
Compare with another Sort.
virtual ~Sort()
Virtual default destructor.
virtual z3::sort GetZ3Sort(z3::context &ctx) const =0
Return z3::sort of the Sort.
virtual bool is_bv(const int &width=0) const
Return true if have bit-vector sort.
Definition: sort.h:47
z3::sort GetZ3Sort(z3::context &ctx) const
Return the z3::sort of Boolean Sort.
The class of Boolean Sort.
Definition: sort.h:85
friend bool operator==(const SortPtr lhs, const SortPtr rhs)
Overlaod comparison.
Definition: sort.h:68
static SortPtr MakeBvSort(const int &bit_width)
Create a bit-vector Sort.
SortMem(const int &addr_w, const int &data_w)
Default constructor.
const Symbol & name() const
Get the symbol (name).