00001
00002
00003
00004
00005
00006
00007
00008 #ifndef FUNCTION_H_
00009 #define FUNCTION_H_
00010 #include<vector>
00011 #include<string>
00012 #include<map>
00013 #include "SummaryUnit.h"
00014 #include "Serializable.h"
00015
00016
00017
00018
00023 #define ALLOW_OFFSETS true
00024
00025
00030 #define ADD_DROP_TEMP_INSTRUCTIONS false
00031
00032
00033 using namespace std;
00034
00035 namespace il{
00036 class function_declaration;
00037 class expression;
00038 class statement;
00039 class label;
00040 class case_label;
00041 class unop_expression;
00042
00043 class type;
00044 class initializer_list_expression;
00045 class file;
00046 class function_type;
00047 class node;
00048 class variable_declaration;
00049 class binop_expression;
00050 }
00051
00052 namespace sail {
00053 class Instruction;
00054 class Symbol;
00055 class Variable;
00056 class Label;
00057 class Cfg;
00058 class TranslationUnit;
00059
00065 class Function: public Serializable, public SummaryUnit{
00066
00067 friend class boost::serialization::access;
00068
00069 template<class Archive>
00070 void serialize(Archive & ar, const unsigned int version)
00071 {
00072 ar & boost::serialization::base_object<Serializable>(*this);
00073 ar & boost::serialization::base_object<sail::SummaryUnit>(*this);
00074
00075 ar & body;
00076 ar & original;
00077 ar & id;
00078 ar & has_return;
00079 ar & cfg;
00080 ar & first_line;
00081 ar & cpp;
00082 }
00083 private:
00084 vector<Instruction*>* body;
00085 il::function_declaration* original;
00086
00087 Identifier id;
00088
00089 map<il::label*, Label*> label_map;
00090 map<il::case_label*, Label*> case_label_map;
00091
00092 map<Label*, Label*> label_eqv_map;
00093 int label_counter;
00094 int default_counter;
00095 Label* return_label;
00096 bool has_return;
00097 Cfg* cfg;
00098 int cur_line;
00099 int first_line;
00100 bool cpp;
00101
00102
00103
00104
00105
00106
00107
00108
00109 map<string, Variable*> cxx_zgv_vars;
00110
00111
00112
00113
00114
00115
00116
00117
00118 public:
00119
00120
00121
00122
00123 Function(il::function_declaration* original, il::file* f, bool cpp);
00124
00125
00126
00127
00128 Function(vector<il::variable_declaration*>& global_decls, string file,
00129 bool cpp, vector<Variable*> & zvg_vars);
00130
00131
00132
00133 Function()
00134 {
00135 body = NULL;
00136 original = NULL;
00137 has_return = false;
00138 cfg = NULL;
00139 cur_line = -1;
00140 first_line = -1;
00141 };
00142 virtual ~Function();
00143 virtual string to_string() const;
00144 virtual string to_string(bool pretty_print) const;
00145
00151 il::function_declaration* get_original_declaration();
00152
00153
00158 vector<Instruction*>* get_body();
00159
00164 Cfg* get_cfg();
00165 il::function_type* get_signature();
00166
00172 void get_instructions(vector<Instruction*>& instructions);
00173
00177 virtual Identifier get_identifier();
00178
00182 il::namespace_context get_namespace();
00183
00184
00188 bool is_method();
00189
00194 il::record_type* get_defining_class();
00195
00199 bool is_virtual_method();
00200
00201
00205 bool is_abstract_virtual_method();
00206
00210 bool is_constructor();
00211
00215 bool is_destructor();
00216
00217
00218 map<string, Variable*>& get_cxx_zvg_vars();
00219
00220
00221
00222
00223
00224
00225
00229 virtual bool is_function();
00230
00234 virtual bool is_superblock();
00235
00236
00237
00242 virtual BasicBlock* get_entry_block();
00243
00247 virtual BasicBlock* get_exit_block();
00248
00253 virtual BasicBlock* get_exception_block();
00254
00258 int get_first_line();
00259
00260
00264 bool is_init_function();
00265
00269 il::type* get_return_type();
00270
00271
00272
00273 string get_file();
00274
00275 private:
00276 void make_function_body();
00277 Symbol* process_expression(il::expression* exp);
00278 Symbol* process_statement(il::statement* stmt, bool return_needed);
00279 Label* find_or_create_label(il::label* l);
00280 Label* find_or_create_label(il::case_label* l);
00281 Label* create_default_label();
00282 bool case_label_exists(il::case_label* l);
00283 Label* get_fresh_label();
00284 Label* get_return_label();
00285 void process_if_statement(il::statement* stmt);
00286 void process_return_statement(il::statement* stmt);
00287 Symbol* process_set_instruction(il::statement* stmt, bool return_needed,
00288 il::node* original = NULL);
00289 void process_switch_statement(il::statement* stmt);
00290 Symbol* process_conditional_expression(il::expression* exp);
00291 Symbol* process_unop_side_effect(il::unop_expression* unop);
00292 Symbol* process_pre_unop(il::unop_expression* unop);
00293 Symbol* process_post_unop(il::unop_expression* unop);
00294 Symbol* generate_condition_from_ranges(vector<pair<long, long> >* ranges,
00295 Symbol *switch_var, il::type* t );
00296 Variable* process_function_call(il::expression* exp);
00297 Variable* process_function_pointer_call(il::expression* exp);
00298 Variable* process_initializer_list(il::expression* exp);
00299 Variable* process_record_initializer_list(il::initializer_list_expression*
00300 init_exp);
00301 Variable* process_array_initializer_list(il::initializer_list_expression*
00302 init_exp);
00303 void remove_redundant_temporaries();
00304 void remove_redundant_labels();
00305 void compute_label_equivalences();
00306 void remove_null_instructions();
00307 il::expression* strip_casts(il::expression* e);
00308 void add_drop_temp(Symbol* s);
00309 void add_drop_ref(Symbol* s);
00310 Symbol* process_complex_store(il::expression* lhs_exp, Symbol* rhs,
00311 il::statement* original, bool return_needed);
00312 Symbol* calculate_complex_address(il::expression* lhs_exp,
00313 il::node* stmt);
00314 Variable* make_multiply_binop(Symbol* s1, Symbol* s2);
00315 Variable* make_add_binop(Symbol* s1, Symbol* s2);
00316
00317
00318
00319
00320
00321
00322
00323 Symbol* convert_to_mod_expression(il::binop_expression* exp);
00324
00325
00326
00327
00328
00329 void make_first_op_constant(il::binop_expression* exp);
00330
00331 };
00332
00333 }
00334
00335 #endif