;;; Unit tests to ensure that impure functions are not optimized out

(extfun impure ((arg (bits 5))) (bits 5))

(module taint_analysis
  (register v 5'b0)

  (cpp-preamble "
class extfuns {
  bits<5> state{0u};
public:
  bits<5> impure(const bits<5>& arg) {
    std::cerr << arg << std::endl;
    return (state = state + arg);
  }
};")

  (rule keep_impure_exprs
    (ignore (+ (impure 5'b0) (impure 5'b1)))
    (write.0 v (impure 5'2)))

  (rule keep_impure_branches
    (if true
        (write.1 v 5'b0)
      (write.1 v 5'b0)))

  (scheduler s (sequence keep_impure_exprs keep_impure_branches)))
