ilang  1.1.4
ILAng: A Modeling and Verification Platform for SoCs
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros
ila_sim.h
Go to the documentation of this file.
1 
4 #ifndef ILANG_TARGET_SC_ILA_SIM_H__
5 #define ILANG_TARGET_SC_ILA_SIM_H__
6 
7 #include <set>
8 #include <sstream>
9 #include <stdexcept>
10 #include <string>
11 #include <vector>
12 
14 
15 #define EXTERNAL_MEM 0
16 
17 namespace ilang {
18 
19 // TODO(yuex): change id to instruction name for decode&state_update function
20 
27 class IlaSim {
28 public:
30  typedef struct {
31  std::string mem_str;
32  std::string addr_str;
33  std::string dest_str;
34  } ld_info;
35 
37  typedef struct {
38  std::string mem_str;
39  std::string mem_map;
40  } st_info;
41 
43  IlaSim();
45  IlaSim(const InstrLvlAbsPtr& model_ptr);
47  void set_instr_lvl_abs(const InstrLvlAbsPtr& model_ptr);
49  void set_systemc_path(std::string systemc_path);
50 
52  void enable_cmake_support();
53 
55  void sim_gen(std::string export_dir, bool external_mem = false,
56  bool readable = false, bool qemu_device = false);
57 
58 private:
59  // Initialize all member variables for a new simulator generation pass.
60  void sim_gen_init(std::string export_dir, bool external_mem, bool readable,
61  bool qemu_device);
62  // Create initial lines for the simulator's header file
63  void sim_gen_init_header();
64  void sim_gen_input();
65  void sim_gen_state();
66  void sim_gen_init();
67  void sim_gen_decode();
68  void sim_gen_state_update();
69  void sim_gen_execute_kernel();
70  void sim_gen_execute_invoke();
71  void sim_gen_export();
72 
73  void create_input(const ExprPtr& input_expr);
74  void create_bool_input(const ExprPtr& expr);
75  void create_bv_input(const ExprPtr& expr);
76 
77  void create_state(const ExprPtr& state_expr);
78  void create_child_state(const ExprPtr& state_expr);
79  void create_mem_state(const ExprPtr& expr);
80  void create_bool_state(const ExprPtr& expr, bool child = false);
81  void create_bv_state(const ExprPtr& expr, bool child = false);
82  void create_external_mem_port(const ExprPtr& expr);
83 
84  void create_init(const InstrLvlAbsPtr& ila);
85  void init_decl(std::stringstream& valid_function, std::string& indent,
86  std::string& valid_func_name);
87  void init_check_valid(std::stringstream& init_function, std::string& indent,
88  const ExprPtr& valid_expr, const InstrLvlAbsPtr& ila);
89  void init_return(std::stringstream& init_function, std::string& indent);
90  void init_export(std::stringstream& init_function,
91  std::string& init_func_name);
92  void init_mk_file(std::string& init_func_name);
93 
94  void create_decode(const InstrPtr& instr_expr);
95  void decode_decl(std::stringstream& decode_function, std::string& indent,
96  std::string& decode_func_name);
97  void decode_check_valid(std::stringstream& decode_function,
98  std::string& indent, const ExprPtr& valid_expr,
99  const InstrPtr& instr_expr);
100  void decode_return(std::stringstream& decode_function, std::string& indent,
101  const ExprPtr& decode_expr, const InstrPtr& instr_expr);
102  void decode_export(std::stringstream& decode_function,
103  std::string& decode_func_name);
104  void decode_mk_file(std::string& decode_func_name);
105 
106  void create_state_update(const InstrPtr& instr_expr);
107  void state_update_decl(std::stringstream& state_update_function,
108  std::string& indent, const ExprPtr& updated_state,
109  const ExprPtr& update_expr,
110  std::string& state_update_func_name);
111  void state_update_return(std::stringstream& state_update_function,
112  std::string& indent, const ExprPtr& updated_state,
113  const ExprPtr& update_expr);
114  void state_update_export(std::stringstream& state_update_function,
115  std::string& state_update_func_name);
116  void state_update_mk_file(std::string& state_update_func_name);
117  void mem_state_update_decl(std::stringstream& state_update_function,
118  std::string& indent, const ExprPtr& expr);
119 
120  void execute_init(std::stringstream& execute_kernel, std::string& indent);
121  void execute_parent_instructions(std::stringstream& execute_kernel,
122  std::string& indent);
123  void execute_child_instructions(std::stringstream& execute_kernel,
124  std::string& indent);
125  void execute_instruction(std::stringstream& execute_kernel,
126  std::string& indent, const InstrPtr& instr_expr,
127  bool child = false);
128  void execute_decode(std::stringstream& execute_kernel, std::string& indent,
129  const InstrPtr& instr_expr);
130  void execute_state_update_func(std::stringstream& execute_kernel,
131  std::string& indent,
132  const InstrPtr& instr_expr,
133  const ExprPtr& updated_state);
134  void execute_update_state(std::stringstream& execute_kernel,
135  std::string& indent, const InstrPtr& instr_expr,
136  const ExprPtr& updated_state);
137  void execute_external_mem_load_begin(std::stringstream& execute_kernel,
138  std::string& indent,
139  const InstrPtr& instr_expr);
140  void execute_external_mem_load_end(std::stringstream& execute_kernel,
141  std::string& indent);
142  void execute_read_external_mem(std::stringstream& execute_kernel,
143  std::string& indent);
144  void execute_write_external_mem(std::stringstream& execute_kernel,
145  std::string& indent);
146  void execute_external_mem_before_input(std::stringstream& execute_kernel,
147  std::string& indent);
148  void execute_external_mem_after_output(std::stringstream& execute_kernel,
149  std::string& indent);
150  void execute_external_mem_return(std::stringstream& execute_kernel,
151  std::string& indent);
152  void execute_read_input(std::stringstream& execute_kernel,
153  std::string& indent);
154  void execute_write_output(std::stringstream& execute_kernel,
155  std::string& indent);
156  void execute_kernel_export(std::stringstream& execute_kernel);
157  void execute_kernel_mk_file();
158  void execute_kernel_header();
159 
160  void dfs_store_op(const ExprPtr& expr);
161  void dfs_load_from_store(const ExprPtr& expr);
162  void dfs_int_var_width(const ExprPtr& expr);
163  void dfs_external_mem_load(const ExprPtr& expr);
164  void dfs_kernel(std::stringstream& dfs_simulator, std::string& indent,
165  const ExprPtr& expr);
166  void dfs_uninterpreted_func_decl(const FuncPtr& func);
167  void dfs_const_node(std::stringstream& dfs_simulator, std::string& indent,
168  const ExprPtr& expr);
169  void dfs_unary_op(std::stringstream& dfs_simulator, std::string& indent,
170  const ExprPtr& expr);
171  void dfs_unary_op_check(const ExprPtr& expr);
172  void dfs_binary_op_bool_out(std::stringstream& dfs_simulator,
173  std::string& indent, const ExprPtr& expr);
174  void dfs_binary_op_bool_out_check(const ExprPtr& expr);
175  void dfs_binary_op_non_mem(std::stringstream& dfs_simulator,
176  std::string& indent, const ExprPtr& expr);
177  void dfs_binary_op_non_mem_check(const ExprPtr& expr);
178  void dfs_binary_op_mem(std::stringstream& dfs_simulator, std::string& indent,
179  const ExprPtr& expr);
180  void dfs_extract_op(std::stringstream& dfs_simulator, std::string& indent,
181  const ExprPtr& expr);
182  void dfs_ext_op(std::stringstream& dfs_simulator, std::string& indent,
183  const ExprPtr& expr);
184  void dfs_func_op(std::stringstream& dfs_simulator, std::string& indent,
185  const ExprPtr& expr);
186  void dfs_func_op_check(const ExprPtr& expr);
187  void dfs_ite_op(std::stringstream& dfs_simulator, std::string& indent,
188  const ExprPtr& expr);
189  std::string get_type_str(const ExprPtr& expr);
190 
191  std::string get_arg_str(const ExprPtr& arg);
192  void increase_indent(std::string& indent);
193  void decrease_indent(std::string& indent);
194  int get_update_state_num(const InstrPtr& instr_expr);
195  bool load_from_store_analysis(const ExprPtr& expr);
196  void declare_variable_with_id(size_t id, const std::string& v_type,
197  const std::string& v_name);
198  void int_var_width_scan();
199 
201  void generate_cmake_support();
202 
203  std::string export_dir_;
204  std::string systemc_path_;
205 
206  std::stringstream header_;
207  std::stringstream mk_script_;
208  std::stringstream obj_list_;
209  std::string header_indent_;
210 
211  bool cmake_support_ = false;
212  std::vector<std::string> source_file_list_;
213  std::vector<std::string> header_file_list_;
214 
215  std::set<size_t> searched_id_set_;
216  std::set<size_t> store_ite_set_;
217  std::set<size_t> const_mem_set_;
218  std::set<size_t> declared_id_set_;
219  std::set<std::string> func_set_;
220  std::set<size_t> defined_store_ite_set_;
221  std::set<size_t> defined_state_set_;
222  std::set<int> dfs_ld_search_set_;
223  std::vector<ld_info> external_ld_set_;
224  std::vector<st_info> external_st_set_;
225  int ld_st_counter_ = 0;
226  bool EXTERNAL_MEM_ = false;
227  const int MEM_MAP_ARRAY_DIV = 16;
228  std::set<int> int_var_width_set_;
229 
230  // Readable_ is used to control whether the generated function name is
231  // huname-readable. When being set true, function will be named based on the
232  // instruction name and the updated state name. However, there is a potential
233  // same-name bug if setting true.
234  bool readable_ = true;
235  bool qemu_device_ = false;
236 
237  InstrLvlAbsPtr model_ptr_;
238 };
239 
240 }; // namespace ilang
241 
242 #endif // ILANG_TARGET_SC_ILA_SIM_H__
void enable_cmake_support()
Set to CMake build mode.
Expr::ExprPtr ExprPtr
Pointer type for normal use of Expr.
Definition: expr.h:138
TODO.
Definition: ila_sim.h:37
A class to generate SystemC simulator model from ILA model Example Use:
Definition: ila_sim.h:27
void set_systemc_path(std::string systemc_path)
(To be deprecated) set the path to SystemC library.
Instr::InstrPtr InstrPtr
Pointer type for normal use of Instr.
Definition: instr.h:132
void sim_gen(std::string export_dir, bool external_mem=false, bool readable=false, bool qemu_device=false)
Generate the simulator.
Func::FuncPtr FuncPtr
Pointer type for normal use of Func.
Definition: func.h:83
TODO.
Definition: ila_sim.h:30
InstrLvlAbs::InstrLvlAbsPtr InstrLvlAbsPtr
Pointer type for normal use of InstrLvlAbs.
Definition: instr_lvl_abs.h:326
void set_instr_lvl_abs(const InstrLvlAbsPtr &model_ptr)
Set the target ILA model.
IlaSim()
Default constructor.