ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
chc_inv_in.h
1 // --- Hongce Zhang (hongcez@princeton.edu)
3 
4 #ifndef CHC_INV_IN_H__
5 #define CHC_INV_IN_H__
6 
7 #include <ilang/smt-inout/chc_inv_in_wrapper.h>
8 #include <ilang/smt-inout/yosys_smt_parser.h>
9 
10 #include <functional>
11 #include <map>
12 #include <string>
13 
14 extern "C" {
15 #include "smtparser/smtlib2abstractparser.h"
16 #include "smtparser/smtlib2abstractparser_private.h"
17 }
18 
19 namespace ilang {
20 namespace smt {
22 // we will need a pointer to the SmtlibInvariantParser
23 class SmtlibInvariantParser;
24 
29  smtlib2_abstract_parser parser;
32 }; // struct smtlib2_abstract_parser_wrapper
33 
35 template <class T> struct SmtTermInfo {
42  // --------------- CONSTRUCTOR -------------- //
46  SmtTermInfo(const T& trans, const var_type& p, SmtlibInvariantParser* c)
47  : _translate(trans), _type(p), _context(c) {}
48 }; // struct SmtContext
49 
52 typedef SmtTermInfo<std::string> SmtTermInfoVerilog;
54 typedef SmtTermInfoVerilog* SmtTermInfoVlgPtr;
55 
58 public:
59  // -------------- TYPEs ------------------- //
61  typedef std::function<std::string(const std::string&)>
64  typedef std::map<std::string, SmtTermInfoVerilog> term_container_t;
66  typedef std::map<std::string, SmtTermInfoVerilog> quantifier_temp_def_t;
68  typedef std::vector<quantifier_temp_def_t> quantifier_def_stack_t;
70  typedef std::map<std::string, var_type> sort_container_t;
72  typedef std::map<std::string, SmtTermInfoVerilog> local_vars_t;
74  typedef std::map<std::string, std::string> local_vars_lookup_t;
76  typedef std::map<std::string, int> free_vars_t;
77 
78 public:
79  // -------------- CONSTRUCTOR ------------------- //
80  SmtlibInvariantParser(YosysSmtParser* yosys_smt_info, bool _flatten_datatype,
81  bool _flatten_hierarchy,
82  const std::set<std::string>& _inv_pred_name,
83  const std::string& dut_instance_name,
84  bool discourageOutOfScopeVariable = true);
89 
90  // -------------- DESTRUCTOR ------------------- //
91  virtual ~SmtlibInvariantParser();
92 
93  // -------------- METHODS ------------------- //
94  // parse from a file, we will add something there to make
95  // if sat --> failed (return false)
96  // if unsat --> add the (assert ...)
97  bool virtual ParseInvResultFromFile(const std::string& fname) override;
98  // parse from a string: assume we have the (assert ...) there
99  void virtual ParseSmtResultFromString(const std::string& text) override;
101  std::string GetFinalTranslateResult() const override;
103  const local_vars_t& GetLocalVarDefs() const;
105  const free_vars_t& GetFreeVarDefs() const;
106 
107 protected:
108  // ----------------- MEMBERS ------------------- //
112  // we will allocate on this container
113  // there will be pointers going into it
120  unsigned mask;
122  const std::set<std::string> inv_pred_name;
124  std::vector<unsigned> quantifier_var_def_idx_stack;
134  const std::string dut_verilog_instance_name;
135 
139  const bool datatype_flattened;
144 
148  bool bad_state_return(void);
149 
150 public:
152  bool in_bad_state(void) const { return _bad_state; }
153 
154 public:
155  // ----------------- CALLBACK FUNS INTERFACE ------------------- //
161  virtual void declare_function(const std::string& name, var_type* sort);
163  virtual var_type* make_sort(const std::string& name, const std::vector<int>&);
165  virtual void declare_quantified_variable(const std::string& name,
166  var_type* sort);
169  virtual SmtTermInfoVlgPtr
170  mk_function(const std::string& name, var_type* sort,
171  const std::vector<int>& idx,
172  const std::vector<SmtTermInfoVlgPtr>& args);
174  virtual SmtTermInfoVlgPtr mk_number(const std::string& rep, int width,
175  int base);
177  virtual SmtTermInfoVlgPtr
178  search_quantified_var_stack(const std::string& name);
180  virtual void assert_formula(SmtTermInfoVlgPtr result);
182  virtual void define_function(const std::string& func_name,
183  const std::vector<SmtTermInfoVlgPtr>& args,
184  var_type* ret_type, SmtTermInfoVlgPtr func_body);
185 
186 #define DECLARE_OPERATOR(name) \
187  SmtTermInfoVlgPtr mk_##name(const std::string& symbol, var_type* sort, \
188  const std::vector<int>& idx, \
189  const std::vector<SmtTermInfoVlgPtr>& args)
190 
191  // I hope it will expand lexically
192  DECLARE_OPERATOR(true);
193  DECLARE_OPERATOR(false);
194 
195  DECLARE_OPERATOR(and);
196  DECLARE_OPERATOR(or);
197  DECLARE_OPERATOR(not);
198  DECLARE_OPERATOR(implies);
199  DECLARE_OPERATOR(eq);
200  DECLARE_OPERATOR(ite);
201  DECLARE_OPERATOR (xor);
202  DECLARE_OPERATOR(nand);
203  DECLARE_OPERATOR(concat);
204  DECLARE_OPERATOR(bvnot);
205  DECLARE_OPERATOR(bvand);
206  DECLARE_OPERATOR(bvnand);
207  DECLARE_OPERATOR(bvor);
208  DECLARE_OPERATOR(bvnor);
209  DECLARE_OPERATOR(bvxor);
210  DECLARE_OPERATOR(bvxnor);
211  DECLARE_OPERATOR(bvult);
212  DECLARE_OPERATOR(bvslt);
213  DECLARE_OPERATOR(bvule);
214  DECLARE_OPERATOR(bvsle);
215  DECLARE_OPERATOR(bvugt);
216  DECLARE_OPERATOR(bvsgt);
217  DECLARE_OPERATOR(bvuge);
218  DECLARE_OPERATOR(bvsge);
219  DECLARE_OPERATOR(bvcomp);
220  DECLARE_OPERATOR(bvneg);
221  DECLARE_OPERATOR(bvadd);
222  DECLARE_OPERATOR(bvsub);
223  DECLARE_OPERATOR(bvmul);
224  DECLARE_OPERATOR(bvudiv);
225  DECLARE_OPERATOR(bvsdiv);
226  DECLARE_OPERATOR(bvsmod);
227  DECLARE_OPERATOR(bvurem);
228  DECLARE_OPERATOR(bvsrem);
229  DECLARE_OPERATOR(bvshl);
230  DECLARE_OPERATOR(bvlshr);
231  DECLARE_OPERATOR(bvashr);
232  DECLARE_OPERATOR(extract);
233  DECLARE_OPERATOR(bit2bool);
234  DECLARE_OPERATOR(repeat);
235  DECLARE_OPERATOR(zero_extend);
236  DECLARE_OPERATOR(sign_extend);
237  DECLARE_OPERATOR(rotate_left);
238  DECLARE_OPERATOR(rotate_right);
239 
240 #undef DECLARE_OPERATOR
241 
242 }; // SmtlibInvariantParser
243 
244 }; // namespace smt
245 }; // namespace ilang
246 
247 #endif // CHC_INV_IN_H__
virtual SmtTermInfoVlgPtr mk_number(const std::string &rep, int width, int base)
call back function to make a number term
local_vars_lookup_t local_vars_lookup
to hold map for search string -&gt; local variables
Definition: chc_inv_in.h:128
std::map< std::string, int > free_vars_t
the container of all the free variables
Definition: chc_inv_in.h:76
std::function< std::string(const std::string &)> verilog_internal_name_lookup_fn_t
a function to map state name (internal name reference to verilog signal)
Definition: chc_inv_in.h:62
bool bad_state_return(void)
If it is bad state, return true and display a message.
SmtlibInvariantParser & operator=(const SmtlibInvariantParser &)=delete
no assignment
virtual void assert_formula(SmtTermInfoVlgPtr result)
this function receives the final assert result
the class for parsing invariant
Definition: chc_inv_in.h:57
a wrapper of the abstract parser so it is okay to do crazy stuff
Definition: chc_inv_in.h:27
the type of term info that needs to be carried
Definition: chc_inv_in.h:35
virtual SmtTermInfoVlgPtr search_quantified_var_stack(const std::string &name)
find if a certain var is a quantified variable
sort_container_t sort_container
we will allocate in this container
Definition: chc_inv_in.h:116
virtual void define_function(const std::string &func_name, const std::vector< SmtTermInfoVlgPtr > &args, var_type *ret_type, SmtTermInfoVlgPtr func_body)
this function receives the final result
std::map< std::string, SmtTermInfoVerilog > quantifier_temp_def_t
then we need stack for forall infos
Definition: chc_inv_in.h:66
std::map< std::string, std::string > local_vars_lookup_t
search_string to local var name
Definition: chc_inv_in.h:74
const local_vars_t & GetLocalVarDefs() const
get the local variable definitions
this a base class, should not be instantiated
Definition: chc_inv_in_wrapper.h:13
bool _bad_state
bad state
Definition: chc_inv_in.h:146
virtual SmtTermInfoVlgPtr pop_quantifier_scope()
call back function to handle ) of forall
smtlib2_abstract_parser_wrapper * parser_wrapper
the parser interface
Definition: chc_inv_in.h:110
to parse an smt file this will only work on the yosys&#39;s generated smt and not on the assembled CHC ...
Definition: yosys_smt_parser.h:22
std::vector< unsigned > quantifier_var_def_idx_stack
the quantifier declare index (order)
Definition: chc_inv_in.h:124
free_vars_t free_vars
to hold the free variables
Definition: chc_inv_in.h:130
virtual SmtTermInfoVlgPtr mk_function(const std::string &name, var_type *sort, const std::vector< int > &idx, const std::vector< SmtTermInfoVlgPtr > &args)
std::map< std::string, var_type > sort_container_t
the sort container
Definition: chc_inv_in.h:70
const bool datatype_flattened
whether we are on a design w. datatype flattened
Definition: chc_inv_in.h:139
the type Bool or (_ BitVec)
Definition: smt_ast.h:82
std::vector< quantifier_temp_def_t > quantifier_def_stack_t
and the stack
Definition: chc_inv_in.h:68
SmtlibInvariantParser * inv_parser
a pointer to allow us to access to the object-oriented part
Definition: chc_inv_in.h:31
unsigned mask
sentry – probably no use
Definition: chc_inv_in.h:120
term_container_t term_container
the term container
Definition: chc_inv_in.h:114
const std::set< std::string > inv_pred_name
a collection of functions that should be treated as inv predicates
Definition: chc_inv_in.h:122
var_type _type
the type uptill now
Definition: chc_inv_in.h:39
local_vars_t local_vars
to hold the local variables
Definition: chc_inv_in.h:126
virtual var_type * make_sort(const std::string &name, const std::vector< int > &)
call back function to create a sort
virtual void declare_function(const std::string &name, var_type *sort)
declare function (useful for Grain)
virtual SmtTermInfoVlgPtr push_quantifier_scope()
call back function to handle (forall
SmtlibInvariantParser * _context
the context – all predefined datatypes/predicates/functions
Definition: chc_inv_in.h:41
T _translate
the corresponding translation (for verilog: std::string)
Definition: chc_inv_in.h:37
std::string GetFinalTranslateResult() const override
get the translate result
const free_vars_t & GetFreeVarDefs() const
get the free variable definitions
const bool no_outside_var_refer
discourage out-of-scope variable referall
Definition: chc_inv_in.h:143
const bool hierarchy_flattened
whether we are on a design w. hierarchy flattened
Definition: chc_inv_in.h:141
YosysSmtParser * design_smt_info_ptr
a pointer to get the knowlege of the context
Definition: chc_inv_in.h:137
virtual void declare_quantified_variable(const std::string &name, var_type *sort)
call back function to create a temporary (quantified variable)
SmtTermInfo(const T &trans, const var_type &p, SmtlibInvariantParser *c)
complete constructor
Definition: chc_inv_in.h:46
smtlib2_abstract_parser parser
this is equivalent to its parent
Definition: chc_inv_in.h:29
std::string final_translate_result
the final translated result
Definition: chc_inv_in.h:132
bool in_bad_state(void) const
check if this module is in a bad state
Definition: chc_inv_in.h:152
std::map< std::string, SmtTermInfoVerilog > term_container_t
the type of container to hold the terms
Definition: chc_inv_in.h:64
std::map< std::string, SmtTermInfoVerilog > local_vars_t
the container of temporary variables
Definition: chc_inv_in.h:72
const std::string dut_verilog_instance_name
we need to store the right vlog instance name
Definition: chc_inv_in.h:134
quantifier_def_stack_t quantifier_def_stack
the temporary def stacks
Definition: chc_inv_in.h:118
SmtTermInfo()
default constructor
Definition: chc_inv_in.h:44