ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
smt_ast.h
1 
5 #ifndef SMT_AST_H__
6 #define SMT_AST_H__
7 
8 #include <map>
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 namespace ilang {
14 namespace smt {
15 
17 struct str_iterator {
19  const std::string buf;
21  size_t pnt;
23  str_iterator(const std::string&, size_t p = 0);
25  str_iterator(const str_iterator&);
26 
27  // ------------- MEMBER FUNCTIONS ---------------- //
29  void jump_to_next(const std::string& c);
31  size_t next_non_space_pos(const std::string& s = " \t\n\r") const;
33  size_t next_non_space_pos(const std::string& s, size_t pos) const;
35  void skip(const std::string& s = " \t\n\r");
37  void skip_m(const std::string& s);
38  // return true if it is the end
39  bool is_end() const;
40  // return true if it is the end
41  bool is_end(size_t pos) const;
43  char head() const;
45  std::string head_word(const std::string& s = " \t\n\r") const;
47  void expect(const std::string& c) const;
49  size_t next(const std::string& s) const;
51  size_t next(const std::string& s, size_t pos) const;
53  void accept(const std::string& s);
56  std::string accept_current_and_read_untill(const std::string& delimiter);
58  std::string read_till_pos(size_t pos);
60  std::string extract_untill_stack_empty(char push_symbol, char pop_symbol);
63  std::string readline_no_eol();
64 
65 }; // struct str_iterator
66 
67 struct smt_item {
69  virtual std::string toString() const = 0;
70 }; // struct smt_item
71 
72 typedef std::shared_ptr<smt_item> smt_item_ptr;
73 
74 struct line_comment : public smt_item {
76  std::string comment;
78  virtual std::string toString() const override;
79 }; // struct line_comment
80 
82 struct var_type {
84  enum tp { Bool, BV, Datatype } _type;
86  unsigned _width;
88  std::string module_name;
89  // ------------- FUNCTIONS ---------------- //
91  static var_type ParseFromString(str_iterator&); // will update the iterator
93  std::string toString() const;
95  static std::string toString(const std::vector<var_type>&);
96  // ------------- MEMBER ---------------- //
98  static bool eqtype(const var_type& l, const var_type& r);
100  unsigned GetBoolBvWidth() const;
102  bool is_bv() const;
104  bool is_bool() const;
106  bool is_datatype() const;
107  // ------------- CONSTRUCTOR ---------------- //
108  // default constructor
109  var_type();
110  // complete constructor
111  var_type(tp vtype, unsigned width, const std::string mod_name);
112  // copy constructor
113  var_type(const var_type& vp);
114  // assignment operator
115  var_type& operator=(const var_type&) = default;
116 
117 }; // struct var_type
118 
120 struct state_var_t {
122  std::string internal_name;
124  std::string module_name;
126  std::string verilog_name;
129  // ------------- FUNCTIONS ---------------- //
132  str_iterator&,
133  const std::string& default_module_name); // will update the iterator
134 }; // struct state_var_t
135 
136 // declaration of datatypes
138 typedef std::map<std::string, std::vector<state_var_t>> datatypes_t;
140 typedef std::vector<std::string> data_type_order_t;
141 
143 struct arg_t {
145  std::string arg_name;
148  // ------------- CONSTRUCTOR -------------- //
149  arg_t(const std::string&, const var_type&);
150  // ------------- FUNCTIONS ---------------- //
151  std::string toString() const;
153  static std::string toString(const std::vector<arg_t>& va);
156 }; // struct arg_t
157 
159 struct func_def_t : public smt_item {
161  std::string func_name;
163  std::string func_module;
165  std::string args_text;
167  std::vector<arg_t> args;
171  std::string func_body;
173  std::string extra_comment;
174  // ------------- MEMBER FUNCTIONS ---------------- //
176  virtual std::string toString() const override;
178  static void ParseFromString(str_iterator&,
179  func_def_t&); // will update the iterator
180 }; // struct func_def_t
181 
183 struct smt_file {
185  std::vector<smt_item_ptr> items;
187  datatypes_t datatypes;
190  data_type_order_t data_type_order;
191  // ------------- MEMBER FUNCTIONS ---------------- //
193  std::string toString() const;
194 }; // struct smt_file
195 
197 std::string ParseFromString(str_iterator& it, datatypes_t& dtype);
199 void ParseFromString(str_iterator& it, smt_file& smt);
200 
202 std::string convert_to_binary(unsigned v, unsigned w); // if we have value here
204 std::string convert_to_binary(const std::string& v, unsigned radix, unsigned w);
205 }; // namespace smt
206 }; // namespace ilang
207 
208 #endif // SMT_AST_H__
static bool eqtype(const var_type &l, const var_type &r)
whether the types are the same
virtual std::string toString() const override
output to string
std::string func_module
func_module
Definition: smt_ast.h:163
var_type _type
its type
Definition: smt_ast.h:128
void jump_to_next(const std::string &c)
jump to the start of symbol c
std::string readline_no_eol()
static state_var_t ParseFromString(str_iterator &, const std::string &default_module_name)
contruct from
void accept(const std::string &s)
accept a token (expect and skip)
std::string toString() const
convert to string
str_iterator(const std::string &, size_t p=0)
constructor 1
static var_type ParseFromString(str_iterator &)
contruct from
char head() const
return the first
size_t pnt
the pointer
Definition: smt_ast.h:21
std::string func_body
its content – will be replaced
Definition: smt_ast.h:171
Definition: smt_ast.h:74
size_t next_non_space_pos(const std::string &s=" \t\n\r") const
returns the next non space pos
the class that holds the whole file
Definition: smt_ast.h:183
unsigned _width
bitwidth
Definition: smt_ast.h:86
std::string accept_current_and_read_untill(const std::string &delimiter)
and item in declare-datatype
Definition: smt_ast.h:120
virtual std::string toString() const override
output to string
Definition: smt_ast.h:67
bool is_datatype() const
test if it is bv
virtual std::string toString() const =0
output to string
std::string head_word(const std::string &s=" \t\n\r") const
return the head_word (if it the end, then empty string)
static arg_t ParseFromString(str_iterator &)
construct from input string
static void ParseFromString(str_iterator &, func_def_t &)
parse from file, but will not return but use a reference
var_type ret_type
its return type
Definition: smt_ast.h:169
the type Bool or (_ BitVec)
Definition: smt_ast.h:82
std::string args_text
the initial args text, will be replaced by state_var_vec
Definition: smt_ast.h:165
std::string comment
the comment
Definition: smt_ast.h:76
var_type arg_type
arg type // from the type
Definition: smt_ast.h:147
unsigned GetBoolBvWidth() const
return a verilog-use width
void skip_m(const std::string &s)
skip a symbol (w. blank also)
datatypes_t datatypes
the data types include in the smt_file
Definition: smt_ast.h:187
void expect(const std::string &c) const
expect the head token to be &#39;c&#39;
std::string arg_name
argument&#39;s name // from internal name
Definition: smt_ast.h:145
std::string toString() const
output to string
bool is_bool() const
test if it is bv
string iterator
Definition: smt_ast.h:17
std::string verilog_name
verilog name (not including )
Definition: smt_ast.h:126
void skip(const std::string &s=" \t\n\r")
skip some single charactor symbol
std::string read_till_pos(size_t pos)
read untill a pos
size_t next(const std::string &s) const
get the closest occurance of s from current point
std::string extract_untill_stack_empty(char push_symbol, char pop_symbol)
read until the stack is empty
a function
Definition: smt_ast.h:159
std::vector< arg_t > args
arguments
Definition: smt_ast.h:167
argument used in a function def
Definition: smt_ast.h:143
std::string module_name
its datatype name (not including | _s|)
Definition: smt_ast.h:88
tp
type
Definition: smt_ast.h:84
const std::string buf
the buffer
Definition: smt_ast.h:19
data_type_order_t data_type_order
Definition: smt_ast.h:190
std::string func_name
func name
Definition: smt_ast.h:161
std::string extra_comment
extra comment (optional)
Definition: smt_ast.h:173
std::vector< smt_item_ptr > items
collection of smt_items
Definition: smt_ast.h:185
std::string module_name
module_name
Definition: smt_ast.h:124
std::string internal_name
|module_name|...
Definition: smt_ast.h:122
bool is_bv() const
test if it is bv