1 // -*- mode: C++ -*- 2 // 3 // Copyright (c) 2007, 2008, 2010, 2011, 2015 The University of Utah 4 // All rights reserved. 5 // 6 // This file is part of `csmith', a random generator of C programs. 7 // 8 // Redistribution and use in source and binary forms, with or without 9 // modification, are permitted provided that the following conditions are met: 10 // 11 // * Redistributions of source code must retain the above copyright notice, 12 // this list of conditions and the following disclaimer. 13 // 14 // * Redistributions in binary form must reproduce the above copyright 15 // notice, this list of conditions and the following disclaimer in the 16 // documentation and/or other materials provided with the distribution. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 // POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef BOOKKEEPER_H 31 #define BOOKKEEPER_H 32 33 /////////////////////////////////////////////////////////////////////////////// 34 #include <string> 35 #include <vector> 36 using namespace std; 37 38 class Variable; 39 class Expression; 40 class Statement; 41 class Fact; 42 class Type; 43 44 class Bookkeeper 45 { 46 public: 47 Bookkeeper(void); 48 ~Bookkeeper(void); 49 50 static void doFinalization(); 51 52 static void output_statistics(std::ostream &out); 53 54 static void output_struct_union_statistics(std::ostream &out); 55 56 static void output_expr_statistics(std::ostream &out); 57 58 static void output_pointer_statistics(std::ostream &out); 59 60 static void output_jump_statistics(std::ostream &out); 61 62 static void output_stmts_statistics(std::ostream &out); 63 64 static void output_volatile_access_statistics(std::ostream &out); 65 66 static void output_counters(std::ostream &out, const char* prefix_msg, 67 const char* breakdown_msg, const std::vector<int> &counters, int starting_pos = 0); 68 69 static void update_ptr_aliases(const vector<Fact*>& facts, vector<const Variable*>& ptrs, vector<vector<const Variable*> >& aliases); 70 71 static void record_address_taken(const Variable *var); 72 73 static void record_pointer_comparisons(const Expression* lhs, const Expression* rhs); 74 75 static void record_volatile_access(const Variable* var, int deref_level, bool write); 76 77 static void record_type_with_bitfields(const Type* typ); 78 79 static void record_vars_with_bitfields(const Type *type); 80 81 static void record_bitfields_writes(const Variable *var); 82 83 static void record_bitfields_reads(const Variable *var); 84 85 static void output_bitfields(std::ostream &out); 86 87 static void output_var_freshness(std::ostream &out); 88 89 static void stat_expr_depths_for_stmt(const Statement* s); 90 static void stat_expr_depths(void); 91 92 static int stat_blk_depths_for_stmt(const Statement* s); 93 static int stat_blk_depths(void); 94 95 static std::vector<int> struct_depth_cnts; 96 97 static int union_var_cnt; 98 99 static std::vector<int> expr_depth_cnts; 100 101 static std::vector<int> blk_depth_cnts; 102 103 static std::vector<int> dereference_level_cnts; 104 105 static int address_taken_cnt; 106 107 static std::vector<int> write_dereference_cnts; 108 109 static std::vector<int> read_dereference_cnts; 110 111 static int cmp_ptr_to_null; 112 static int cmp_ptr_to_ptr; 113 static int cmp_ptr_to_addr; 114 115 static int read_volatile_cnt; 116 static int read_volatile_thru_ptr_cnt; 117 static int write_volatile_cnt; 118 static int write_volatile_thru_ptr_cnt; 119 static int read_non_volatile_cnt; 120 static int write_non_volatile_cnt; 121 122 static int pointer_avail_for_dereference; 123 static int volatile_avail; 124 125 static int structs_with_bitfields; 126 static std::vector<int> vars_with_bitfields; 127 static std::vector<int> vars_with_full_bitfields; 128 static int vars_with_bitfields_address_taken_cnt; 129 static int bitfields_in_total; 130 static int unamed_bitfields_in_total; 131 static int const_bitfields_in_total; 132 static int volatile_bitfields_in_total; 133 static int lhs_bitfields_structs_vars_cnt; 134 static int rhs_bitfields_structs_vars_cnt; 135 static int lhs_bitfield_cnt; 136 static int rhs_bitfield_cnt; 137 138 static int forward_jump_cnt; 139 static int backward_jump_cnt; 140 141 static int use_new_var_cnt; 142 static int use_old_var_cnt; 143 144 static bool rely_on_int_size; 145 static bool rely_on_ptr_size; 146 }; 147 148 void incr_counter(std::vector<int>& counters, int index); 149 int calc_total(const std::vector<int>& counters); 150 151 /////////////////////////////////////////////////////////////////////////////// 152 153 #endif // BOOKKEEPER_H 154 155 // Local Bookkeepers: 156 // c-basic-offset: 4 157 // tab-width: 4 158 // End: 159 160 // End of file. 161