diff options
author | Cheng Shao <astrohavoc@gmail.com> | 2022-10-24 14:20:31 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-11-11 00:26:55 -0500 |
commit | 36340328a6a26529b1eb4ca0413dc87eb91fe700 (patch) | |
tree | 7cdb9320d2720ed67a84b80908a55e76939027ce /compiler/GHC/CmmToAsm/Wasm/Utils.hs | |
parent | a8adc71e80734c6dc2e119596368f84e39fd1172 (diff) | |
download | haskell-36340328a6a26529b1eb4ca0413dc87eb91fe700.tar.gz |
compiler: wasm32 NCG
This patch adds the wasm32 NCG.
Diffstat (limited to 'compiler/GHC/CmmToAsm/Wasm/Utils.hs')
-rw-r--r-- | compiler/GHC/CmmToAsm/Wasm/Utils.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/compiler/GHC/CmmToAsm/Wasm/Utils.hs b/compiler/GHC/CmmToAsm/Wasm/Utils.hs new file mode 100644 index 0000000000..b794c7f5b7 --- /dev/null +++ b/compiler/GHC/CmmToAsm/Wasm/Utils.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE Strict #-} + +module GHC.CmmToAsm.Wasm.Utils + ( naturalNarrowing, + widthMax, + detEltsUFM, + detEltsUniqMap, + builderCommas, + ) +where + +import Data.ByteString.Builder +import Data.List (intersperse, sortOn) +import GHC.Cmm +import GHC.Prelude +import GHC.Types.Unique.FM +import GHC.Types.Unique.Map + +naturalNarrowing :: Width -> Integer -> Integer +naturalNarrowing w i + | i < 0 = narrowS w i + | otherwise = narrowU w i + +widthMax :: Width -> Integer +widthMax w = (1 `shiftL` widthInBits w) - 1 + +detEltsUFM :: Ord k => UniqFM k0 (k, a) -> [(k, a)] +detEltsUFM = sortOn fst . nonDetEltsUFM + +detEltsUniqMap :: Ord k => UniqMap k a -> [(k, a)] +detEltsUniqMap = sortOn fst . nonDetEltsUniqMap + +builderCommas :: (a -> Builder) -> [a] -> Builder +builderCommas f xs = mconcat (intersperse ", " (map f xs)) |