1 // -*- mode: C++ -*- 2 // 3 // Copyright (c) 2007, 2008, 2010, 2011, 2013, 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 // 31 // This file was derived from a random program generator written by Bryan 32 // Turner. The attributions in that file was: 33 // 34 // Random Program Generator 35 // Bryan Turner (bryan.turner@pobox.com) 36 // July, 2005 37 // 38 39 #ifndef BLOCK_H 40 #define BLOCK_H 41 42 /////////////////////////////////////////////////////////////////////////////// 43 44 #include <ostream> 45 #include <vector> 46 #include <map> 47 48 #include "Statement.h" 49 #include "Type.h" 50 51 class CGContext; 52 class Statement; 53 class Variable; 54 class Fact; 55 class FactMgr; 56 class Effect; 57 58 /* 59 * 60 */ 61 class Block : public Statement 62 { 63 public: 64 // Factory method. 65 static Block *make_random(CGContext &cg_context, bool looping = false); 66 67 static Block *make_dummy_block(CGContext &cg_context); 68 69 Block(Block* b, int block_size); 70 virtual ~Block(void); 71 72 // set_depth_protect(bool b)73 virtual bool set_depth_protect(bool b) { depth_protect = b; return b; } get_depth_protect(void)74 virtual bool get_depth_protect(void) { return depth_protect; } 75 76 virtual void Output(std::ostream &out, FactMgr* fm, int indent=0) const; 77 78 void OutputTmpVariableList(std::ostream &out, int indent) const; 79 80 Block* random_parent_block(void); 81 block_size()82 int block_size() { return block_size_; } 83 // These are currently accessed directly. 84 std::vector<Statement *> stms; 85 std::vector<Statement *> deleted_stms; 86 std::vector<Variable *> local_vars; 87 mutable std::map<std::string, enum eSimpleType> macro_tmp_vars; 88 89 std::string create_new_tmp_var(enum eSimpleType type) const; 90 get_blocks(std::vector<const Block * > & blks)91 virtual void get_blocks(std::vector<const Block*>& blks) const { blks.push_back(this);} get_exprs(std::vector<const Expression * > &)92 virtual void get_exprs(std::vector<const Expression*>& /* exps */) const {}; 93 const Statement* get_last_stm(void) const; 94 bool is_var_on_stack(const Variable* v) const; 95 std::vector<const ExpressionVariable*> get_dereferenced_ptrs(void) const; 96 97 Statement* append_return_stmt(CGContext& cg_context); 98 virtual bool must_return(void) const; 99 bool must_break_or_return(void) const; 100 virtual bool must_jump(void) const; 101 bool from_tail_to_head(void) const; 102 bool need_nested_loop(const CGContext& cg_context); 103 Statement* append_nested_loop(CGContext& cg_context); 104 105 virtual bool visit_facts(vector<const Fact*>& inputs, CGContext& cg_context) const; 106 107 bool contains_back_edge(void) const; 108 109 bool find_fixed_point(vector<const Fact*> inputs, vector<const Fact*>& post_facts, CGContext& cg_context, int& fail_index, bool visit_once) const; 110 111 void post_creation_analysis(CGContext& cg_context, const Effect& pre_effect); 112 113 size_t remove_stmt(const Statement* s); 114 115 bool looping; 116 117 bool in_array_loop; 118 119 bool need_revisit; 120 121 std::vector<const Statement*> break_stms; 122 123 private: 124 125 bool depth_protect; 126 127 // maximum block size 128 const int block_size_; 129 130 void set_accumulated_effect(CGContext& cg_context) const; 131 132 ////////////////////////////////////////////////////////////// 133 Block(const Block &b); // unimplemented 134 135 Block &operator=(const Block &b); // unimplemented 136 }; 137 138 Block* find_block_by_id(int blk_id); 139 /////////////////////////////////////////////////////////////////////////////// 140 141 #endif // BLOCK_H 142 143 // Local Variables: 144 // c-basic-offset: 4 145 // tab-width: 4 146 // End: 147 148 // End of file. 149