2
2
Copyright : (C) 2013-2016, University of Twente,
3
3
2016-2017, Myrtle Software Ltd,
4
4
2017-2022, Google Inc.,
5
- 2017-2022, QBayLogic B.V.
5
+ 2017-2023, QBayLogic B.V.
6
+ 2023, LumiGuide Fietsdetectie B.V.
6
7
License : BSD2 (see the file LICENSE)
7
8
Maintainer : QBayLogic B.V. <[email protected] >
8
9
-}
@@ -2202,6 +2203,136 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2202
2203
-> reduce (boolToBoolLiteral tcm ty (s1 == s2))
2203
2204
| otherwise -> error (show args)
2204
2205
2206
+ " Clash.Class.BitPack.Internal.packInt8#" -- :: Int8 -> BitVector 8
2207
+ | [DC _ [Left arg]] <- args
2208
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2209
+ #if MIN_VERSION_base(4,16,0)
2210
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int8Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2211
+ #else
2212
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2213
+ #endif
2214
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2215
+ in Just $ mach2
2216
+ { mStack = mStack mach
2217
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2218
+ }
2219
+ | otherwise -> error (show args)
2220
+
2221
+ " Clash.Class.BitPack.Internal.packInt16#" -- :: Int16 -> BitVector 16
2222
+ | [DC _ [Left arg]] <- args
2223
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2224
+ #if MIN_VERSION_base(4,16,0)
2225
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2226
+ #else
2227
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2228
+ #endif
2229
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2230
+ in Just $ mach2
2231
+ { mStack = mStack mach
2232
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2233
+ }
2234
+ | otherwise -> error (show args)
2235
+
2236
+ " Clash.Class.BitPack.Internal.packInt32#" -- :: Int32 -> BitVector 32
2237
+ | [DC _ [Left arg]] <- args
2238
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2239
+ #if MIN_VERSION_base(4,16,0)
2240
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int32Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2241
+ #else
2242
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2243
+ #endif
2244
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2245
+ in Just $ mach2
2246
+ { mStack = mStack mach
2247
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2248
+ }
2249
+ | otherwise -> error (show args)
2250
+
2251
+ " Clash.Class.BitPack.Internal.packInt64#" -- :: Int64 -> BitVector 64
2252
+ | [DC _ [Left arg]] <- args
2253
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2254
+ #if MIN_VERSION_base(4,16,0)
2255
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Int64Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2256
+ #else
2257
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (IntLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2258
+ #endif
2259
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2260
+ in Just $ mach2
2261
+ { mStack = mStack mach
2262
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2263
+ }
2264
+ | otherwise -> error (show args)
2265
+
2266
+ " Clash.Class.BitPack.Internal.packWord#" -- :: Word -> BitVector WORD_SIZE_IN_BITS
2267
+ | [DC _ [Left arg]] <- args
2268
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2269
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2270
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2271
+ in Just $ mach2
2272
+ { mStack = mStack mach
2273
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2274
+ }
2275
+ | otherwise -> error (show args)
2276
+
2277
+ " Clash.Class.BitPack.Internal.packWord8#" -- :: Word8 -> BitVector 8
2278
+ | [DC _ [Left arg]] <- args
2279
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2280
+ #if MIN_VERSION_base(4,16,0)
2281
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word8Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2282
+ #else
2283
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2284
+ #endif
2285
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2286
+ in Just $ mach2
2287
+ { mStack = mStack mach
2288
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2289
+ }
2290
+ | otherwise -> error (show args)
2291
+
2292
+ " Clash.Class.BitPack.Internal.packWord16#" -- :: Word16 -> BitVector 16
2293
+ | [DC _ [Left arg]] <- args
2294
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2295
+ #if MIN_VERSION_base(4,16,0)
2296
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2297
+ #else
2298
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2299
+ #endif
2300
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2301
+ in Just $ mach2
2302
+ { mStack = mStack mach
2303
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2304
+ }
2305
+ | otherwise -> error (show args)
2306
+
2307
+ " Clash.Class.BitPack.Internal.packWord32#" -- :: Word32 -> BitVector 32
2308
+ | [DC _ [Left arg]] <- args
2309
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2310
+ #if MIN_VERSION_base(4,16,0)
2311
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word32Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2312
+ #else
2313
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2314
+ #endif
2315
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2316
+ in Just $ mach2
2317
+ { mStack = mStack mach
2318
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2319
+ }
2320
+ | otherwise -> error (show args)
2321
+
2322
+ " Clash.Class.BitPack.Internal.packWord64#" -- :: Word64 -> BitVector 64
2323
+ | [DC _ [Left arg]] <- args
2324
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2325
+ #if MIN_VERSION_base(4,16,0)
2326
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word64Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2327
+ #else
2328
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2329
+ #endif
2330
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2331
+ in Just $ mach2
2332
+ { mStack = mStack mach
2333
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2334
+ }
2335
+ | otherwise -> error (show args)
2205
2336
2206
2337
" Clash.Class.BitPack.Internal.packDouble#" -- :: Double -> BitVector 64
2207
2338
| [DC _ [Left arg]] <- args
@@ -2223,6 +2354,124 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2223
2354
, mTerm = mkBitVectorLit' resTyInfo 0 (toInteger $ (pack :: Word32 -> BitVector 32 ) i)
2224
2355
}
2225
2356
2357
+ " Clash.Class.BitPack.Internal.packCUShort#" -- :: CUShort -> BitVector 16
2358
+ | [DC _ [Left arg]] <- args
2359
+ , eval <- Evaluator ghcStep ghcUnwind ghcPrimStep ghcPrimUnwind
2360
+ #if MIN_VERSION_base(4,16,0)
2361
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (Word16Literal i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2362
+ #else
2363
+ , mach2@ Machine {mStack= [] ,mTerm= Literal (WordLiteral i)} <- whnf eval tcm True (setTerm arg $ stackClear mach)
2364
+ #endif
2365
+ -> let resTyInfo = extractTySizeInfo tcm ty tys
2366
+ in Just $ mach2
2367
+ { mStack = mStack mach
2368
+ , mTerm = mkBitVectorLit' resTyInfo 0 i
2369
+ }
2370
+ | otherwise -> error (show args)
2371
+
2372
+ " Clash.Class.BitPack.Internal.unpackInt8#" -- BitVector 8 -> Int8
2373
+ | [i] <- bitVectorLiterals' args
2374
+ -> let resTy = getResultTy tcm ty tys
2375
+ val = toInteger (unpack (toBV i) :: Signed 8 )
2376
+ #if MIN_VERSION_base(4,16,0)
2377
+ proj = Int8Literal
2378
+ #else
2379
+ proj = IntLiteral
2380
+ #endif
2381
+ in reduce (mkIntCLit tcm proj val resTy)
2382
+ | otherwise -> error (show args)
2383
+
2384
+ " Clash.Class.BitPack.Internal.unpackInt16#" -- BitVector 16 -> Int16
2385
+ | [i] <- bitVectorLiterals' args
2386
+ -> let resTy = getResultTy tcm ty tys
2387
+ val = toInteger (unpack (toBV i) :: Signed 16 )
2388
+ #if MIN_VERSION_base(4,16,0)
2389
+ proj = Int16Literal
2390
+ #else
2391
+ proj = IntLiteral
2392
+ #endif
2393
+ in reduce (mkIntCLit tcm proj val resTy)
2394
+ | otherwise -> error (show args)
2395
+
2396
+ " Clash.Class.BitPack.Internal.unpackInt32#" -- BitVector 32 -> Int32
2397
+ | [i] <- bitVectorLiterals' args
2398
+ -> let resTy = getResultTy tcm ty tys
2399
+ val = toInteger (unpack (toBV i) :: Signed 32 )
2400
+ #if MIN_VERSION_base(4,16,0)
2401
+ proj = Int32Literal
2402
+ #else
2403
+ proj = IntLiteral
2404
+ #endif
2405
+ in reduce (mkIntCLit tcm proj val resTy)
2406
+ | otherwise -> error (show args)
2407
+
2408
+ " Clash.Class.BitPack.Internal.unpackInt64#" -- BitVector 64 -> Int64
2409
+ | [i] <- bitVectorLiterals' args
2410
+ -> let resTy = getResultTy tcm ty tys
2411
+ val = toInteger (unpack (toBV i) :: Signed 64 )
2412
+ #if MIN_VERSION_base(4,16,0)
2413
+ proj = Int64Literal
2414
+ #else
2415
+ proj = IntLiteral
2416
+ #endif
2417
+ in reduce (mkIntCLit tcm proj val resTy)
2418
+ | otherwise -> error (show args)
2419
+
2420
+ " Clash.Class.BitPack.Internal.unpackWord#" -- BitVector WORD_SIZE_IN_BITS -> Word
2421
+ | [i] <- bitVectorLiterals' args
2422
+ -> let resTy = getResultTy tcm ty tys
2423
+ val = toInteger (unpack (toBV i) :: Unsigned 64 )
2424
+ in reduce (mkIntCLit tcm WordLiteral val resTy)
2425
+ | otherwise -> error (show args)
2426
+
2427
+ " Clash.Class.BitPack.Internal.unpackWord8#" -- BitVector 8 -> Word8
2428
+ | [i] <- bitVectorLiterals' args
2429
+ -> let resTy = getResultTy tcm ty tys
2430
+ val = toInteger (unpack (toBV i) :: Unsigned 8 )
2431
+ #if MIN_VERSION_base(4,16,0)
2432
+ proj = Word8Literal
2433
+ #else
2434
+ proj = WordLiteral
2435
+ #endif
2436
+ in reduce (mkIntCLit tcm proj val resTy)
2437
+ | otherwise -> error (show args)
2438
+
2439
+ " Clash.Class.BitPack.Internal.unpackWord16#" -- BitVector 16 -> Word16
2440
+ | [i] <- bitVectorLiterals' args
2441
+ -> let resTy = getResultTy tcm ty tys
2442
+ val = toInteger (unpack (toBV i) :: Unsigned 16 )
2443
+ #if MIN_VERSION_base(4,16,0)
2444
+ proj = Word16Literal
2445
+ #else
2446
+ proj = WordLiteral
2447
+ #endif
2448
+ in reduce (mkIntCLit tcm proj val resTy)
2449
+ | otherwise -> error (show args)
2450
+
2451
+ " Clash.Class.BitPack.Internal.unpackWord32#" -- BitVector 32 -> Word32
2452
+ | [i] <- bitVectorLiterals' args
2453
+ -> let resTy = getResultTy tcm ty tys
2454
+ val = toInteger (unpack (toBV i) :: Unsigned 32 )
2455
+ #if MIN_VERSION_base(4,16,0)
2456
+ proj = Word32Literal
2457
+ #else
2458
+ proj = WordLiteral
2459
+ #endif
2460
+ in reduce (mkIntCLit tcm proj val resTy)
2461
+ | otherwise -> error (show args)
2462
+
2463
+ " Clash.Class.BitPack.Internal.unpackWord64#" -- BitVector 64 -> Word64
2464
+ | [i] <- bitVectorLiterals' args
2465
+ -> let resTy = getResultTy tcm ty tys
2466
+ val = toInteger (unpack (toBV i) :: Unsigned 64 )
2467
+ #if MIN_VERSION_base(4,16,0)
2468
+ proj = Word64Literal
2469
+ #else
2470
+ proj = WordLiteral
2471
+ #endif
2472
+ in reduce (mkIntCLit tcm proj val resTy)
2473
+ | otherwise -> error (show args)
2474
+
2226
2475
" Clash.Class.BitPack.Internal.unpackFloat#"
2227
2476
| [i] <- bitVectorLiterals' args
2228
2477
-> let resTy = getResultTy tcm ty tys
@@ -2235,6 +2484,18 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2235
2484
val = unpack (toBV i :: BitVector 64 )
2236
2485
in reduce (mkDoubleCLit tcm val resTy)
2237
2486
2487
+ " Clash.Class.BitPack.Internal.unpackCUShort#"
2488
+ | [i] <- bitVectorLiterals' args
2489
+ -> let resTy = getResultTy tcm ty tys
2490
+ val = toInteger (unpack (toBV i) :: Unsigned 16 )
2491
+ #if MIN_VERSION_base(4,16,0)
2492
+ proj = Word16Literal
2493
+ #else
2494
+ proj = WordLiteral
2495
+ #endif
2496
+ in reduce (mkIntCLit tcm proj val resTy)
2497
+ | otherwise -> error (show args)
2498
+
2238
2499
" Clash.Class.BitPack.Internal.xToBV"
2239
2500
| isSubj
2240
2501
, Just (nTy, kn) <- extractKnownNat tcm tys
@@ -2793,7 +3054,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2793
3054
" Clash.Sized.Internal.Index.fromEnum#"
2794
3055
| [i] <- indexLiterals' args
2795
3056
-> let resTy = getResultTy tcm ty tys
2796
- in reduce (mkIntCLit tcm i resTy)
3057
+ in reduce (mkIntCLit tcm IntLiteral i resTy)
2797
3058
2798
3059
-- Bounded
2799
3060
" Clash.Sized.Internal.Index.maxBound#"
@@ -2910,7 +3171,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
2910
3171
" Clash.Sized.Internal.Signed.fromEnum#"
2911
3172
| [i] <- signedLiterals' args
2912
3173
-> let resTy = getResultTy tcm ty tys
2913
- in reduce (mkIntCLit tcm i resTy)
3174
+ in reduce (mkIntCLit tcm IntLiteral i resTy)
2914
3175
2915
3176
-- Bounded
2916
3177
" Clash.Sized.Internal.Signed.minBound#"
@@ -3128,7 +3389,7 @@ ghcPrimStep tcm isSubj pInfo tys args mach = case primName pInfo of
3128
3389
" Clash.Sized.Internal.Unsigned.fromEnum#"
3129
3390
| [i] <- unsignedLiterals' args
3130
3391
-> let resTy = getResultTy tcm ty tys
3131
- in reduce (mkIntCLit tcm i resTy)
3392
+ in reduce (mkIntCLit tcm IntLiteral i resTy)
3132
3393
3133
3394
-- Bounded
3134
3395
" Clash.Sized.Internal.Unsigned.minBound#"
@@ -4709,9 +4970,9 @@ bitVectorLitIntLit tcm tys args
4709
4970
| otherwise
4710
4971
= Nothing
4711
4972
4712
- mkIntCLit :: TyConMap -> Integer -> Type -> Term
4713
- mkIntCLit tcm lit resTy =
4714
- App (Data intDc) (Literal (IntLiteral lit))
4973
+ mkIntCLit :: TyConMap -> ( Integer -> Literal ) -> Integer -> Type -> Term
4974
+ mkIntCLit tcm proj lit resTy =
4975
+ App (Data intDc) (Literal (proj lit))
4715
4976
where
4716
4977
(_, tyView -> TyConApp intTcNm [] ) = splitFunForallTy resTy
4717
4978
Just intTc = UniqMap. lookup intTcNm tcm
@@ -5045,7 +5306,7 @@ liftBitVector2CInt
5045
5306
liftBitVector2CInt tcm resTy f args _p
5046
5307
| [i] <- bitVectorLiterals' args
5047
5308
= let val = f (toBV i)
5048
- in Just $ mkIntCLit tcm val resTy
5309
+ in Just $ mkIntCLit tcm IntLiteral val resTy
5049
5310
| otherwise
5050
5311
= Nothing
5051
5312
0 commit comments