]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Added LFSR creation v1:
authorMariam Arutunian <mariamarutunian@gmail.com>
Fri, 9 Dec 2022 08:48:39 +0000 (12:48 +0400)
committerJeff Law <jlaw@ventanamicro>
Tue, 21 Mar 2023 15:03:19 +0000 (09:03 -0600)
  - Calculate value of the LFSR state.

Changes in Sym_exec v6:

  - Changed all const memeber functions to static.

Changes in Extract polynomial v2:

  - Changed extract_polynomial to extract_poly_and_create_lfsr, which calculates polynomial and creates LFSR.
  - Moved some instructions from extract_polynomial to execute_crc_loop.

Changes in CRC detection v5:

  - Instead extract_polynomial, Call extract_poly_and_create_lfsr, check return value and print the LFSR.

gcc/gimple-crc-optimization.cc
gcc/sym-exec/state.cc
gcc/sym-exec/state.h
gcc/symb-execute-all-paths.cc
gcc/symb-execute-all-paths.h

index f810dc40367ef2bc21004bf21465c7d5647ed124..dd1595ad261057d279dc06a940d8390c54b76315 100644 (file)
@@ -939,20 +939,25 @@ crc_optimization::execute (function *fun)
       }
 
       crc_symb_execution execute_loop;
-      vec<value*> * polynomial
-      = execute_loop.extract_polynomial (crc_loop, first_phi_for_crc,
-                                        data, is_left_shift);
+      vec<value*> * lfsr
+      = execute_loop.extract_poly_and_create_lfsr (crc_loop, first_phi_for_crc,
+                                                  data, is_left_shift);
 
-    if (!polynomial)
-      {
+      if (!lfsr)
+       {
        if (dump_file)
-         fprintf (dump_file, "\nCouldn't determine the polynomial!\n");
+         fprintf (dump_file, "Couldn't create LFSR!\n");
        return 0;
-      }
-
-    /* TODO: Create LFSR state.  */
-
-    /* TODO: Match LFSR.  */
+       }
+      else
+       {
+         if (dump_file && (dump_flags & TDF_DETAILS))
+           {
+             fprintf (dump_file, "\nLFSR value is \n");
+             state::print_bits (lfsr);
+           }
+       }
+       /* TODO: Match LFSR.  */
   }
   return 0;
 }
index 809e0a91b5d133a9d2183b0707be81b10e9449f7..abf284d4a5caa7f8754877e7a733b74e477bb429 100644 (file)
@@ -90,7 +90,7 @@ state::check_args_compatibility (tree arg1, tree arg2, tree dest)
 /* Creates bit sequence of given constant tree.  */
 
 vec<value*>
-state::create_bits_for_const (tree var, size_t size) const
+state::create_bits_for_const (tree var, size_t size)
 {
   HOST_WIDE_INT val = tree_to_shwi (var);
   vec<value *> bits;
@@ -109,7 +109,7 @@ state::create_bits_for_const (tree var, size_t size) const
 /* Removes given sequence of bits.  */
 
 void
-state::free_bits (vec<value*> * bits) const
+state::free_bits (vec<value*> * bits)
 {
   if (bits == nullptr || !bits->exists ())
     return;
@@ -179,7 +179,7 @@ state::clear_conditions ()
 /* performs AND operation for 2 symbolic_bit operands.  */
 
 value *
-state::and_sym_bits (const value * var1, const value * var2) const
+state::and_sym_bits (const value * var1, const value * var2)
 {
   return new bit_and_expression (var1->copy (), var2->copy ());
 }
@@ -188,7 +188,7 @@ state::and_sym_bits (const value * var1, const value * var2) const
 /* performs AND operation for a symbolic_bit and const_bit operands.  */
 
 value *
-state::and_var_const (const value * var1, const bit * const_bit) const
+state::and_var_const (const value * var1, const bit * const_bit)
 {
   if (const_bit->get_val () == 1)
     return var1->copy ();
@@ -200,7 +200,7 @@ state::and_var_const (const value * var1, const bit * const_bit) const
 /* performs AND operation for 2 constant bit operands.  */
 
 bit *
-state::and_const_bits (const bit * const_bit1, const bit * const_bit2) const
+state::and_const_bits (const bit * const_bit1, const bit * const_bit2)
 {
   if (const_bit1->get_val () == const_bit2->get_val ())
     return new bit (*const_bit1);
@@ -212,7 +212,7 @@ state::and_const_bits (const bit * const_bit1, const bit * const_bit2) const
 /* performs OR operation for 2 symbolic_bit operands.  */
 
 value *
-state::or_sym_bits (const value * var1, const value * var2) const
+state::or_sym_bits (const value * var1, const value * var2)
 {
   return new bit_or_expression (var1->copy (), var2->copy ());
 }
@@ -221,7 +221,7 @@ state::or_sym_bits (const value * var1, const value * var2) const
 /* performs OR operation for a symbolic_bit and a constant bit operands.  */
 
 value *
-state::or_var_const (const value * var1, const bit * const_bit) const
+state::or_var_const (const value * var1, const bit * const_bit)
 {
   if (const_bit->get_val () == 0)
     return var1->copy ();
@@ -233,7 +233,7 @@ state::or_var_const (const value * var1, const bit * const_bit) const
 /* performs OR operation for 2 constant bit operands.  */
 
 bit *
-state::or_const_bits (const bit * const_bit1, const bit * const_bit2) const
+state::or_const_bits (const bit * const_bit1, const bit * const_bit2)
 {
   if (const_bit1->get_val () == const_bit2->get_val ())
     return new bit (*const_bit1);
@@ -295,7 +295,7 @@ state::make_symbolic (tree var, unsigned size)
 /* Performs AND operation on two bits.  */
 
 value *
-state::and_two_bits (value *arg1_bit, value* arg2_bit) const
+state::and_two_bits (value *arg1_bit, value* arg2_bit)
 {
   value *result = nullptr;
 
@@ -387,7 +387,7 @@ state::do_and (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest)
 /* Performs OR operation on two bits.  */
 
 value *
-state::or_two_bits (value *arg1_bit, value* arg2_bit) const
+state::or_two_bits (value *arg1_bit, value* arg2_bit)
 {
   value *result = nullptr;
 
@@ -436,7 +436,7 @@ state::do_or (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest)
 /* Performs XOR operation on two bits.  */
 
 value *
-state::xor_two_bits (value *arg1_bit, value* arg2_bit) const
+state::xor_two_bits (value *arg1_bit, value* arg2_bit)
 {
   value *result = nullptr;
 
@@ -716,7 +716,7 @@ state::do_sub (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest)
 /* Performs complement operation on a bit.  */
 
 value *
-state::complement_a_bit (value *var) const
+state::complement_a_bit (value *var)
 {
   value *result = nullptr;
   bit* const_bit = dyn_cast<bit *> (var);
@@ -847,7 +847,7 @@ state::do_assign_pow2 (tree dest, unsigned pow)
 /* Performs NOT operation for constant bit.  */
 
 bit *
-state::complement_const_bit (const bit * const_bit) const
+state::complement_const_bit (const bit * const_bit)
 {
   return new bit (1u ^ const_bit->get_val ());
 }
@@ -856,7 +856,7 @@ state::complement_const_bit (const bit * const_bit) const
 /* Performs NOT operation for symbolic_bit.  */
 
 value *
-state::complement_sym_bit (const value * var) const
+state::complement_sym_bit (const value * var)
 {
   return new bit_complement_expression (var->copy ());
 }
@@ -865,7 +865,7 @@ state::complement_sym_bit (const value * var) const
 /* Performs XOR operation for 2 symbolic_bit operands.  */
 
 value *
-state::xor_sym_bits (const value * var1, const value * var2) const
+state::xor_sym_bits (const value * var1, const value * var2)
 {
   value * var2_copy = var2->copy ();
   bit_expression * var2_node_with_const_child
@@ -950,7 +950,7 @@ state::xor_sym_bits (const value * var1, const value * var2) const
 /* Performs XOR operation for 2 constant bit operands.  */
 
 bit *
-state::xor_const_bits (const bit * const_bit1, const bit * const_bit2) const
+state::xor_const_bits (const bit * const_bit1, const bit * const_bit2)
 {
   return new bit (const_bit1->get_val () ^ const_bit2->get_val ());
 }
@@ -959,7 +959,7 @@ state::xor_const_bits (const bit * const_bit1, const bit * const_bit2) const
 /* Performs XOR operation for a symbolic_bit and const_bit operands.  */
 
 value *
-state::xor_var_const (const value * var, const bit * const_bit) const
+state::xor_var_const (const value * var, const bit * const_bit)
 {
   value *var_copy = var->copy ();
   bit_expression *node_with_const_child
@@ -992,7 +992,7 @@ state::xor_var_const (const value * var, const bit * const_bit) const
    on safe branching.  */
 
 bit_expression *
-state::get_parent_with_const_child (value* root) const
+state::get_parent_with_const_child (value* root)
 {
   if (! is_a<bit_expression *> (root))
     return nullptr;
@@ -1028,7 +1028,7 @@ state::get_parent_with_const_child (value* root) const
 /* Checks if node is AND, OR or XOR expression as they are comutative.  */
 
 bool
-state::is_safe_branching (value* node) const
+state::is_safe_branching (value* node)
 {
   return is_a<bit_and_expression *> (node) || is_a<bit_or_expression *> (node)
         || is_a<bit_xor_expression *> (node);
@@ -1151,7 +1151,7 @@ state::do_mul (vec<value*> * arg1_bits, vec<value*> * arg2_bits, tree dest)
 
 bool
 state::check_const_bit_equality (vec<value *> * arg1_bits,
-                                vec<value *> * arg2_bits) const
+                                vec<value *> * arg2_bits)
 {
   for (size_t i = 1; i < arg1_bits->length (); i++)
     if (as_a<bit *>((*arg1_bits)[i])->get_val ()
@@ -1192,7 +1192,7 @@ state::add_equal_cond (vec<value*> * arg1_bits, vec<value*> * arg2_bits)
 
 bool
 state::check_const_bit_are_not_equal (vec<value *> * arg1_bits,
-                                     vec<value *> * arg2_bits) const
+                                     vec<value *> * arg2_bits)
 {
   for (size_t i = 0; i < arg1_bits->length (); i++)
     if (as_a<bit *>((*arg1_bits)[i])->get_val ()
@@ -1241,7 +1241,7 @@ state::add_not_equal_cond (vec<value*> * arg1_bits, vec<value*> * arg2_bits)
 
 bool
 state::check_const_bit_is_greater_than (vec<value *> * arg1_bits,
-                                       vec<value *> * arg2_bits) const
+                                       vec<value *> * arg2_bits)
 {
   for (int i = arg1_bits->length () - 1; i >= 0; i--)
     {
@@ -1315,7 +1315,7 @@ state::construct_great_than_cond (vec<value*> * arg1_bits,
 
 bool
 state::check_const_bit_is_less_than (vec<value *> * arg1_bits,
-                                    vec<value *> * arg2_bits) const
+                                    vec<value *> * arg2_bits)
 {
   for (int i = arg1_bits->length () - 1; i >= 0; i--)
     {
@@ -1636,7 +1636,7 @@ state::do_pointer_diff (tree arg1, tree arg2, tree dest)
 
 
 vec<value *> *
-state::make_copy (vec<value *> *bits) const
+state::make_copy (vec<value *> *bits)
 {
   vec<value *> * copied_bits = new vec<value*> ();
   copied_bits->create (bits->length ());
@@ -1718,3 +1718,89 @@ state::do_cast (tree var, tree dest, size_t cast_size)
     }
   return true;
 }
+
+/* Create LFSR value for the reversed CRC.  */
+void
+state::create_reversed_lfsr (vec<value *> &lfsr, const vec<value *> &crc,
+                            const vec<value *> &polynomial)
+{
+  size_t size = crc.length ();
+
+  /* Determine values of all bits, except MSB.  */
+  for (size_t i = 0; i < size - 1; i++)
+    {
+      if (as_a<bit *> (polynomial[i])->get_val ())
+       lfsr.quick_push (state::xor_two_bits (crc[i + 1], crc[0]));
+      else
+       lfsr.quick_push (crc[i+1]->copy ());
+    }
+
+    /* Determine value of MSB.  */
+  if (as_a<bit *> (polynomial[size-1])->get_val ())
+    lfsr.quick_push (crc[0]->copy ());
+  else
+    lfsr.quick_push (new bit (0));
+}
+
+/* Create LFSR value for the forward CRC.  */
+void
+state::create_forward_lfsr (vec<value *> &lfsr, const vec<value *> &crc,
+                           const vec<value *> &polynomial)
+{
+  size_t size = crc.length ();
+
+  /* Determine value of LSB.  */
+  if (as_a<bit *> (polynomial[0])->get_val ())
+    lfsr.quick_push (crc[size - 1]->copy ());
+  else
+    lfsr.quick_push (new bit (0));
+
+  /* Determine values of remaining bits.  */
+  for (size_t i = 1; i < size; i++)
+    {
+      if (as_a<bit *> (polynomial[i])->get_val ())
+       lfsr.quick_push (state::xor_two_bits (crc[i - 1], crc[size - 1]));
+      else
+       lfsr.quick_push (crc[i - 1]->copy ());
+    }
+}
+
+/* Create LFSR value.  */
+vec<value *> *
+state::create_lfsr (tree crc, vec<value *> *polynomial, bool is_bit_forward)
+{
+  /* Check size compatibility․  */
+  unsigned HOST_WIDE_INT size = polynomial->length ();
+  unsigned HOST_WIDE_INT crc_size = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (crc)));
+  if (crc_size < size)
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+       fprintf (dump_file, "LFSR state creation: "
+                           "Polynomial doesn't fit into the crc.\n");
+
+      return nullptr;
+    }
+
+  /* Create vector of symbolic bits for crc.  */
+  vec<value *> *crc_value = new vec<value *> ();
+  crc_value->create (size);
+
+  for (unsigned HOST_WIDE_INT i = 0; i < size; i++)
+    crc_value->quick_push (new symbolic_bit (i, crc));
+
+  /* create LFSR vector.  */
+  vec<value *> *lfsr = new vec<value *> ();
+  lfsr->create (size);
+
+  /* Calculate values for LFSR.  */
+  if (is_bit_forward)
+    create_forward_lfsr (*lfsr, *crc_value, *polynomial);
+  else
+    create_reversed_lfsr (*lfsr, *crc_value, *polynomial);
+
+  /* crc_value is no more needed, delete.  */
+  free_bits (crc_value);
+  delete crc_value;
+
+  return lfsr;
+}
\ No newline at end of file
index c2f53ce907772c90347d719a2cedafc7f81ce480..2c1e20b2083efe68a09c457da2c82a4414c5171b 100644 (file)
@@ -29,10 +29,10 @@ class state {
   condition_status last_cond_status = condition_status::CS_NO_COND;
 
   /* Creates bit sequence of given constant tree.  */
-  vec<value*> create_bits_for_const (tree var, size_t size) const;
+  vec<value*> create_bits_for_const (tree var, size_t size);
 
   /* Removes given sequence of bits.  */
-  void free_bits (vec<value*> * bits) const;
+  static void free_bits (vec<value*> * bits);
 
   /* Checks if sizes of arguments and destination are compatible.  */
   bool check_args_compatibility (tree arg1, tree arg2, tree dest);
@@ -103,7 +103,7 @@ class state {
   bool do_cast (tree arg, tree dest, size_t cast_size);
 
   /* Performs AND operation on two bits.  */
-  value *and_two_bits (value *arg1_bit, value* arg2_bit) const;
+  static value *and_two_bits (value *arg1_bit, value* arg2_bit);
 
   /* ANDs every bit of the vector with var_bit, stroes the result in var1.  */
   void and_number_bit (vec<value *> *var1, value *var_bit);
@@ -111,46 +111,46 @@ class state {
   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;
+  static value *and_sym_bits (const value * var1, const value * var2);
 
   /* Performs AND operation for a symbolic_bit and const_bit operands.  */
-  value *and_var_const (const value * var1, const bit * const_bit) const;
+  static value *and_var_const (const value * var1, const bit * const_bit);
 
   /* Performs AND operation for 2 constant bit operands.  */
-  bit *and_const_bits (const bit * const_bit1, const bit * const_bit2) const;
+  static bit *and_const_bits (const bit * const_bit1, const bit * const_bit2);
 
   /* Performs OR operation on two bits.  */
-  value *or_two_bits (value *arg1_bit, value* arg2_bit) const;
+  static value *or_two_bits (value *arg1_bit, value* arg2_bit);
 
   /* Performs OR operation for 2 symbolic_bit operands.  */
-  value *or_sym_bits (const value * var1, const value * var2) const;
+  static value *or_sym_bits (const value * var1, const value * var2);
 
   /* Performs OR operation for a symbolic_bit and a constant bit operands.  */
-  value *or_var_const (const value * var1, const bit * const_bit) const;
+  static value *or_var_const (const value * var1, const bit * const_bit);
 
   /* Performs OR operation for 2 constant bit operands.  */
-  bit *or_const_bits (const bit * const_bit1, const bit * const_bit2) const;
+  static bit *or_const_bits (const bit * const_bit1, const bit * const_bit2);
 
   /* Performs complement operation on a bit.  */
-  value * complement_a_bit (value *var) const;
+  static value * complement_a_bit (value *var);
 
   /* Performs NOT operation for constant bit.  */
-  bit *complement_const_bit (const bit * const_bit) const;
+  static bit *complement_const_bit (const bit * const_bit);
 
   /* Performs NOT operation for symbolic_bit.  */
-  value *complement_sym_bit (const value * var) const;
+  static value *complement_sym_bit (const value * var);
 
   /* Performs XOR operation on two bits.  */
-  value * xor_two_bits (value *var1, value* var2) const;
+  static value * xor_two_bits (value *var1, value* var2);
 
   /* Performs XOR operation for 2 symbolic_bit operands.  */
-  value *xor_sym_bits (const value * var1, const value * var2) const;
+  static value *xor_sym_bits (const value * var1, const value * var2);
 
   /* Performs XOR operation for 2 constant bit operands.  */
-  bit *xor_const_bits (const bit * const_bit1, const bit * const_bit2) const;
+  static bit *xor_const_bits (const bit * const_bit1, const bit * const_bit2);
 
   /* Performs XOR operation for a symbolic_bit and const_bit operands.  */
-  value *xor_var_const (const value * var, const bit * const_bit) const;
+  static value *xor_var_const (const value * var, const bit * const_bit);
 
   /* shift_right operation.  Case: var2 is a sym_bit.  */
   void shift_right_sym_bits (vec<value*> * arg1_bits, vec<value*> * arg2_bits,
@@ -166,10 +166,10 @@ class state {
 
   /* Return node which has a const bit child.  Traversal is done based
      on safe branching.  */
-  bit_expression* get_parent_with_const_child (value* root) const;
+  static bit_expression* get_parent_with_const_child (value* root);
 
   /* Checks if node is AND, OR or XOR expression.  */
-  bool is_safe_branching (value* node) const;
+  static bool is_safe_branching (value* node);
 
   /* Checks whether state for variable with specified name already
      exists or not.  */
@@ -194,7 +194,18 @@ class state {
   /* Adds two vectors, stores the result in the first one.  */
   void add_numbers (vec<value *> *var1, const vec<value *> *var2);
 
-  vec<value *> * make_copy (vec<value *> *bits) const;
+  static vec<value *> * make_copy (vec<value *> *bits);
+
+
+  /* Create LFSR value for the reversed CRC.  */
+  static void
+  create_reversed_lfsr (vec<value *> &lfsr, const vec<value *> &crc,
+                       const vec<value *> &polynomial);
+
+  /* Create LFSR value for the forward CRC.  */
+  static void
+  create_forward_lfsr (vec<value *> &lfsr, const vec<value *> &crc,
+                      const vec<value *> &polynomial);
 
  public:
    state ();
@@ -287,20 +298,24 @@ class state {
 
   bool add_bool_cond (tree arg);
 
-  bool check_const_bit_equality (vec<value *> * arg1_bits,
-                                vec<value *> * arg2_bits) const;
+  static bool check_const_bit_equality (vec<value *> * arg1_bits,
+                                       vec<value *> * arg2_bits);
 
-  bool check_const_bit_are_not_equal (vec<value *> * arg1_bits,
-                                     vec<value *> * arg2_bits) const;
+  static bool check_const_bit_are_not_equal (vec<value *> * arg1_bits,
+                                            vec<value *> * arg2_bits);
 
-  bool check_const_bit_is_greater_than (vec<value *> * arg1_bits,
-                                       vec<value *> * arg2_bits) const;
+  static bool check_const_bit_is_greater_than (vec<value *> * arg1_bits,
+                                              vec<value *> * arg2_bits);
 
-  bool check_const_bit_is_less_than (vec<value *> * arg1_bits,
-                                    vec<value *> * arg2_bits) const;
+  static bool check_const_bit_is_less_than (vec<value *> * arg1_bits,
+                                           vec<value *> * arg2_bits);
 
   /* Returns status of last added condition.  */
   condition_status get_last_cond_status ();
+
+  /* Create LFSR value.  */
+  static vec<value *> * create_lfsr (tree crc, vec<value *> *polynomial,
+                                    bool is_bit_forward);
 };
 
 #endif /* SYM_EXEC_STATE_H.  */
index 1a20a538ed7cadde8e70eb33107b1480da1acbf7..07b4b7238c802512f8a7d8adc9c8228a5150d75a 100644 (file)
@@ -682,6 +682,11 @@ bool
 crc_symb_execution::execute_crc_loop (loop *crc_loop, gphi *crc, gphi *data,
                                      bool is_shift_left)
 {
+  if (dump_file)
+    fprintf (dump_file, "\n\nTrying to calculate the polynomial.\n\n");
+
+  states.quick_push (new state);
+
   basic_block bb = crc_loop->header;
   assign_vals_to_header_phis (states.last (), bb, crc, data, is_shift_left);
 
@@ -709,31 +714,38 @@ crc_symb_execution::execute_crc_loop (loop *crc_loop, gphi *crc, gphi *data,
       if (!execute_bb_statements (bb, e, stack))
        return false;
     }
+
+  if (states.length () != 1)
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+       fprintf (dump_file, "The number of states is not one.\n");
+      return false;
+    }
   return true;
 }
 
-
+/* Return true if all bits of the polynomial are constants (0 or 1).
+   Otherwise return false.  */
+bool polynomial_is_known (const vec<value*> &polynomial)
+{
+  for (size_t i=0; i<polynomial.length (); i++)
+    {
+      if (!is_a <bit *> (polynomial[i]))
+      return false;
+    }
+    return true;
+}
 /* Execute the loop, which is expected to calculate CRC,
    to extract polynomial, assigning real numbers to crc and data.  */
 vec<value*> *
-crc_symb_execution::extract_polynomial (loop *crc_loop,
-                                       gphi *crc, gphi *data,
-                                       bool is_shift_left)
+crc_symb_execution::extract_poly_and_create_lfsr (loop *crc_loop,
+                                                 gphi *crc, gphi *data,
+                                                 bool is_shift_left)
 {
-  if (dump_file)
-    fprintf (dump_file, "\n\nTrying to calculate the polynomial.\n\n");
-
-  state * polynomial_state = new state;
-  states.quick_push (polynomial_state);
-
-  execute_crc_loop (crc_loop, crc, data, is_shift_left);
+  if (!execute_crc_loop (crc_loop, crc, data, is_shift_left))
+    return nullptr;
 
-  if (states.length () != 1)
-    {
-      if (dump_file && (dump_flags & TDF_DETAILS))
-       fprintf (dump_file, "The number of states is not one.\n");
-      return nullptr;
-    }
+  state *polynomial_state = states.last ();
 
   /* Get the tree which will contain the value of the polynomial
      at the end of the loop.  */
@@ -746,23 +758,32 @@ crc_symb_execution::extract_polynomial (loop *crc_loop,
       fprintf (dump_file, " variable.\n");
     }
 
-
   /* Get the value of the tree.  */
   vec<value*> * polynomial = polynomial_state->get_bits (calculated_crc);
-  if (polynomial == nullptr)
-   {
-    if (dump_file && (dump_flags & TDF_DETAILS))
-       fprintf (dump_file, "Polynomial's value is null");
-    return nullptr;
-   }
-
-   if (dump_file && (dump_flags & TDF_DETAILS))
-     {
-       /* Note: It may not be the real polynomial.
-          If it's a bit reflected crc, then to get a real polynomial,
-          it must be reflected and 1 bit added.  */
-       fprintf (dump_file, "Polynomial's value is ");
-       state::print_bits (polynomial);
-     }
-  return polynomial;
+  if (!polynomial)
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+       fprintf (dump_file, "Polynomial's value is null");
+      return nullptr;
+    }
+
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    {
+      /* Note: It may not be the real polynomial.  If it's a bit reflected crc,
+        then to get a real polynomial,
+        it must be reflected and 1 bit added.  */
+      fprintf (dump_file, "Polynomial's value is ");
+      state::print_bits (polynomial);
+    }
+
+  if (!polynomial_is_known (*polynomial))
+    {
+      if (dump_file && (dump_flags & TDF_DETAILS))
+       {
+         fprintf (dump_file, "Polynomial's value is not constant.\n");
+       }
+      return nullptr;
+    }
+
+  return state::create_lfsr (calculated_crc, polynomial, is_shift_left);
 }
\ No newline at end of file
index 3f664f8404e6837e4320ee0451c9ee7c8acb201b..7177a3fc22215157505b9976c29a5d342eeea97d 100644 (file)
@@ -100,7 +100,7 @@ class crc_symb_execution {
 
   /* Returns calculated polynomial by executing the loop
      with concrete values.  */
-  vec<value*> * extract_polynomial (loop *, gphi *, gphi *, bool);
+  vec<value*> * extract_poly_and_create_lfsr (loop *, gphi *, gphi *, bool);
 
   crc_symb_execution ()
   {