{-# LANGUAGE NoImplicitPrelude #-}

-- | This will fail to verify since the verification does not assume the
-- @lessThanBitWidth@ property, which is needed to prevent shifting by too
-- large of a value.
module Copilot.Verifier.Examples.ShouldFail.Partial.ShiftRTooLarge where

import Language.Copilot
import Copilot.Compile.C99
import Copilot.Verifier ( Verbosity, VerifierOptions(..)
                        , defaultVerifierOptions, verifyWithOptions )

spec :: Spec
spec :: Spec
spec = do
  let stream1 :: Stream Int32
      stream1 :: Stream Int32
stream1 = String -> Maybe [Int32] -> Stream Int32
forall a. Typed a => String -> Maybe [a] -> Stream a
extern String
"stream1" Maybe [Int32]
forall a. Maybe a
Nothing

      stream2 :: Stream Int64
      stream2 :: Stream Int64
stream2 = String -> Maybe [Int64] -> Stream Int64
forall a. Typed a => String -> Maybe [a] -> Stream a
extern String
"stream2" Maybe [Int64]
forall a. Maybe a
Nothing

  PropRef Universal
_ <- String -> Prop Universal -> Writer [SpecItem] (PropRef Universal)
forall a. String -> Prop a -> Writer [SpecItem] (PropRef a)
prop String
"lessThanBitWidth" (Stream Bool -> Prop Universal
forAll
         (Int64 -> Stream Int64
constI64 Int64
0 Stream Int64 -> Stream Int64 -> Stream Bool
forall a. (Ord a, Typed a) => Stream a -> Stream a -> Stream Bool
<= Stream Int64
stream2 Stream Bool -> Stream Bool -> Stream Bool
&& Stream Int64
stream2 Stream Int64 -> Stream Int64 -> Stream Bool
forall a. (Ord a, Typed a) => Stream a -> Stream a -> Stream Bool
< Int64 -> Stream Int64
constI64 Int64
32))
  String -> Stream Bool -> [Arg] -> Spec
trigger String
"streamShiftR" ((Stream Int32
stream1 Stream Int32 -> Stream Int64 -> Stream Int32
forall a b.
(Bits a, Typed a, Typed b, Integral b) =>
Stream a -> Stream b -> Stream a
.<<. Stream Int64
stream2) Stream Int32 -> Stream Int32 -> Stream Bool
forall a. (Eq a, Typed a) => Stream a -> Stream a -> Stream Bool
== Stream Int32
1) [Stream Int32 -> Arg
forall a. Typed a => Stream a -> Arg
arg Stream Int32
stream1, Stream Int64 -> Arg
forall a. Typed a => Stream a -> Arg
arg Stream Int64
stream2]

verifySpec :: Verbosity -> IO ()
verifySpec :: Verbosity -> IO ()
verifySpec Verbosity
verb = do
  Spec
spec' <- Spec -> IO Spec
forall a. Spec' a -> IO Spec
reify Spec
spec
  VerifierOptions -> CSettings -> [String] -> String -> Spec -> IO ()
verifyWithOptions VerifierOptions
defaultVerifierOptions{verbosity = verb}
    CSettings
mkDefaultCSettings
    -- ["lessThanBitWidth"]
    []
    String
"shiftRTooLargeFail" Spec
spec'