diff options
author | matevos <matevosmehrabyan@gmail.com> | 2022-11-25 17:29:36 +0400 |
---|---|---|
committer | Jeff Law <jlaw@ventanamicro> | 2023-03-21 09:03:18 -0600 |
commit | 7770713ea086e24c31689d70199ddca8d44f65aa (patch) | |
tree | d15e1222f7b9b437006ec8acbd495d50d5411476 /gcc/sym-exec/state.h | |
parent | 043a3ec9dc232a5142972ba5fa2fd42a5deec3e9 (diff) | |
download | gcc-7770713ea086e24c31689d70199ddca8d44f65aa.zip gcc-7770713ea086e24c31689d70199ddca8d44f65aa.tar.gz gcc-7770713ea086e24c31689d70199ddca8d44f65aa.tar.bz2 |
sym-exec v4: - Fixed condition adding - Returning expression doing and condition adding status - Handled global variables - Added Multiplication expression support - Updated addition and subtraction expression based of full adder - Added pointers basic addition, subtraction and dereferencing support - Some code refactored
Diffstat (limited to 'gcc/sym-exec/state.h')
-rw-r--r-- | gcc/sym-exec/state.h | 125 |
1 files changed, 97 insertions, 28 deletions
diff --git a/gcc/sym-exec/state.h b/gcc/sym-exec/state.h index 3a9808c..f074a9a 100644 --- a/gcc/sym-exec/state.h +++ b/gcc/sym-exec/state.h @@ -36,19 +36,50 @@ class state { typedef void (state::*binary_func) (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest); + typedef void (state::*binary_cond_func) (vec<value*> * arg1_bits, + vec<value*> * arg2_bits); + private: /* Here is stored values of bit of each variable. */ hash_map<tree, vec < value * >> var_states; hash_set<bit_expression *> conditions; + /* Performs AND operation on two bits. */ + value * and_two_bits (value *var1, value* var2) const; + vec<value*> create_bits_for_const (tree var, size_t size) const; void free_bits (vec<value*> * bits) const; - void check_args_compatibility (tree arg1, tree arg2, tree dest); + bool check_args_compatibility (tree arg1, tree arg2, tree dest); + + void add_equal_cond (vec<value*> * arg1_bits, vec<value*> * arg2_bits); + + void add_not_equal_cond (vec<value*> * arg1_bits, vec<value*> * arg2_bits); + + void add_greater_than_cond (vec<value*> * arg1_bits, vec<value*> * arg2_bits); + + void add_less_than_cond (vec<value*> * arg1_bits, vec<value*> * arg2_bits); + + void add_greater_or_equal_cond (vec<value*> * arg1_bits, + vec<value*> * arg2_bits); + + void add_less_or_equal_cond (vec<value*> * arg1_bits, + vec<value*> * arg2_bits); + + bool add_binary_cond (tree arg1, tree arg2, binary_cond_func cond_func); - void do_binary_operation (tree arg1, tree arg2, tree dest, + bit_expression* construct_great_than_cond (vec<value*> * arg1_bits, + vec<value*> * arg2_bits); + + bit_expression* construct_less_than_cond (vec<value*> * arg1_bits, + vec<value*> * arg2_bits); + + bit_expression* construct_equal_cond (vec<value*> * arg1_bits, + vec<value*> * arg2_bits); + + bool do_binary_operation (tree arg1, tree arg2, tree dest, binary_func bin_func); void do_and (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest); @@ -67,6 +98,8 @@ class state { void do_sub (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest); + void do_mul (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest); + /* Performs AND operation for 2 symbolic_bit operands. */ value *and_sym_bits (const value * var1, const value * var2) const; @@ -76,6 +109,9 @@ class state { /* Performs AND operation for 2 constant bit operands. */ bit *and_const_bits (const bit * const_bit1, const bit * const_bit2) const; + /* Performs OR operation on two bits. */ + value * or_two_bits (value *var1, value* var2) const; + /* Performs OR operation for 2 symbolic_bit operands. */ value *or_sym_bits (const value * var1, const value * var2) const; @@ -85,12 +121,18 @@ class state { /* Performs OR operation for 2 constant bit operands. */ bit *or_const_bits (const bit * const_bit1, const bit * const_bit2) const; + /* Performs complement operation on a bit. */ + value * complement_a_bit (value *var) const; + /* Performs NOT operation for constant bit. */ bit *complement_const_bit (const bit * const_bit) const; /* Performs NOT operation for symbolic_bit. */ value *complement_sym_bit (const value * var) const; + /* Performs XOR operation on two bits. */ + value * xor_two_bits (value *var1, value* var2) const; + /* Performs XOR operation for 2 symbolic_bit operands. */ value *xor_sym_bits (const value * var1, const value * var2) const; @@ -123,6 +165,31 @@ class state { exists or not. */ bool is_declared (tree var); + void declare_if_needed (tree var, size_t size); + + /* Shifts value_vector left by shift_value bits. */ + vec <value *> *shift_left_by_const (const vec <value *> *arg_vector, + size_t shift_value); + + /* Checks if all vector elements are const_bit_expressions. */ + bool is_bit_vector (const vec <value *> *value_vector); + + /* returns the value of the number represented as a bit vector. */ + size_t get_value (const vec <value *> *bit_vector); + + /* Adds two bits and carry value. + Resturn result and stores new carry bit in "carry". */ + value* full_adder (value* var1, value* var2, value*& carry); + + /* Returns the additive inverse of the number stored in number verctor. */ + vec <value *> * additive_inverse (const vec <value *> *number); + + /* ANDs every bit of the vector with var_bit, stroes the result in var1. */ + void and_number_bit (vec<value *> *var1, value *var_bit); + + /* Adds two vectors, stores the result in the first one. */ + void add_numbers (vec< value * > *var1, const vec< value * > *var2); + public: state (); @@ -155,54 +222,56 @@ class state { unsigned get_var_size (tree var); /* Does bit-level XOR operation for given variables. */ - void do_xor (tree arg1, tree arg2, tree dest); + bool do_xor (tree arg1, tree arg2, tree dest); /* Does bit-level AND operation for given variables. */ - void do_and (tree arg1, tree arg2, tree dest); + bool do_and (tree arg1, tree arg2, tree dest); /* Does bit-level OR operation for given variables. */ - void do_or (tree arg1, tree arg2, tree dest); + bool do_or (tree arg1, tree arg2, tree dest); - void do_assign (tree arg, tree dest); - - /* Shifts value_vector left by shift_value bits. */ - vec <value *> shift_left_by_const (const vec <value *> * value_vector, - size_t shift_value); - - /* Checks if all vector elements are const_bit_expressions. */ - bool is_bit_vector (vec <value *> * value_vector); - - /* Returns the value of the number represented as a bit vector. */ - size_t get_value (vec <value *> * bit_vector); + bool do_assign (tree arg, tree dest); /* Does shift_left operation for given variables. */ - void do_shift_left (tree arg1, tree arg2, tree dest); + bool do_shift_left (tree arg1, tree arg2, tree dest); /* Does shift_right operation for given variables. */ - void do_shift_right (tree arg1, tree arg2, tree dest); + bool do_shift_right (tree arg1, tree arg2, tree dest); /* Adds two variables. */ - void do_add (tree arg1, tree arg2, tree dest); + bool do_add (tree arg1, tree arg2, tree dest); /* Does subtraction. */ - void do_sub (tree arg1, tree arg2, tree dest); + bool do_sub (tree arg1, tree arg2, tree dest); + + /* Multiplies two variables, stores result in dest. */ + bool do_mul (tree arg1, tree arg2, tree dest); /* Negates given variable. */ - void do_complement (tree arg, tree dest); + bool do_complement (tree arg, tree dest); + + bool add_equal_cond (tree arg1, tree arg2); + + /* Gets the value of *arg1 and stores it in dest. */ + bool do_mem_ref (tree arg1, tree dest); + + /* Performs addition on arg1 pointer. */ + bool do_pointer_plus (tree arg1, tree arg2, tree dest); - void add_equal_cond (tree arg1, tree arg2); + /* Perform subtractions on arg1 pointer. */ + bool do_pointer_diff (tree arg1, tree arg2, tree dest); - void add_not_equal_cond (tree arg1, tree arg2); + bool add_not_equal_cond (tree arg1, tree arg2); - void add_greater_than_cond (tree arg1, tree arg2); + bool add_greater_than_cond (tree arg1, tree arg2); - void add_less_than_cond (tree arg1, tree arg2); + bool add_less_than_cond (tree arg1, tree arg2); - void add_greater_or_equal_cond (tree arg1, tree arg2); + bool add_greater_or_equal_cond (tree arg1, tree arg2); - void add_less_or_equal_cond (tree arg1, tree arg2); + bool add_less_or_equal_cond (tree arg1, tree arg2); - void add_bool_cond (tree arg); + bool add_bool_cond (tree arg); bool check_const_bit_equality (vec<value *> * arg1_bits, vec<value *> * arg2_bits) const; |