ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
func.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_ILA_AST_FUNC_H__
5 #define ILANG_ILA_AST_FUNC_H__
6 
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 #include <z3++.h>
12 
13 #include <ilang/ila/ast/ast.h>
14 #include <ilang/ila/ast/sort.h>
15 
17 namespace ilang {
18 
19 // Forward declaration.
20 class Expr;
21 
23 class Func : public Ast {
24 public:
26  typedef std::shared_ptr<Func> FuncPtr;
27 
28  // ------------------------- CONSTRUCTOR/DESTRUCTOR ----------------------- //
30  Func(const std::string& name, const SortPtr out,
31  const std::vector<SortPtr>& args);
32 
34  ~Func();
35 
36  // ------------------------- ACCESSORS/MUTATORS --------------------------- //
38  const SortPtr out() const { return out_; }
40  size_t arg_num() const { return args_.size(); }
42  const SortPtr arg(const int& i) const { return args_.at(i); }
43 
44  // ------------------------- METHODS -------------------------------------- //
46  static FuncPtr New(const std::string& name,
47  const SortPtr out = Sort::MakeBoolSort());
49  static FuncPtr New(const std::string& name, const SortPtr out,
50  const SortPtr arg0);
52  static FuncPtr New(const std::string& name, const SortPtr out,
53  const SortPtr arg0, const SortPtr arg1);
55  static FuncPtr New(const std::string& name, const SortPtr out,
56  const std::vector<SortPtr>& args);
57 
59  bool CheckSort(const std::vector<std::shared_ptr<Expr>>& args) const;
60 
62  z3::func_decl GetZ3FuncDecl(z3::context& ctx) const;
63 
65  std::ostream& Print(std::ostream& out) const;
66 
68  friend std::ostream& operator<<(std::ostream& out, const FuncPtr& f) {
69  return f->Print(out);
70  }
71 
72 private:
73  // ------------------------- MEMBERS -------------------------------------- //
75  SortPtr out_;
77  std::vector<SortPtr> args_;
78 
79  // ------------------------- HELPERS -------------------------------------- //
80 }; // class Func
81 
84 
87 class FuncHash {
88 public:
90  size_t operator()(const FuncPtr& func) const { return func->name().id(); }
91 }; // class FuncHash
92 
93 } // namespace ilang
94 
95 #endif // ILANG_ILA_AST_FUNC_H__
z3::func_decl GetZ3FuncDecl(z3::context &ctx) const
Return the z3 func_decl.
std::ostream & Print(std::ostream &out) const
Output to stream.
std::shared_ptr< Func > FuncPtr
Pointer type for normal use of Func.
Definition: func.h:26
const SortPtr arg(const int &i) const
Return the sort of the i-th argument.
Definition: func.h:42
static FuncPtr New(const std::string &name, const SortPtr out=Sort::MakeBoolSort())
Create an uninterpreted function (Func) with no input (nondet).
Sort::SortPtr SortPtr
Pointer type for storing/passing Sort.
Definition: sort.h:82
~Func()
Default destructor.
size_t arg_num() const
Return the number of arguments.
Definition: func.h:40
static SortPtr MakeBoolSort()
Create a Boolean Sort.
size_t operator()(const FuncPtr &func) const
Function object for hashing.
Definition: func.h:90
The function object for hashing Func. The hash value is the id of the symbol, which is supposed to be...
Definition: func.h:87
Func::FuncPtr FuncPtr
Pointer type for normal use of Func.
Definition: func.h:83
bool CheckSort(const std::vector< std::shared_ptr< Expr >> &args) const
Check if the input arguments match the specified sort.
The class for the Abstract Syntax Tree. An Ast object can be an expression or function definition (in...
Definition: ast.h:20
Func(const std::string &name, const SortPtr out, const std::vector< SortPtr > &args)
Constructor for multiple-argument function.
friend std::ostream & operator<<(std::ostream &out, const FuncPtr &f)
Overload output stream.
Definition: func.h:68
const SortPtr out() const
Return the output sort.
Definition: func.h:38
The class for uninterpreted function.
Definition: func.h:23
const Symbol & name() const
Get the symbol (name).