[Git][ghc/ghc][wip/nr/wasm-translation-prototypes] added a unary operator
Norman Ramsey (@nrnrnr)
gitlab at gitlab.haskell.org
Thu Sep 29 16:38:23 UTC 2022
Norman Ramsey pushed to branch wip/nr/wasm-translation-prototypes at Glasgow Haskell Compiler / GHC
Commits:
a0648016 by Norman Ramsey at 2022-09-29T12:38:07-04:00
added a unary operator
- - - - -
2 changed files:
- compiler/GHC/Wasm/IR.hs
- compiler/GHC/Wasm/Tx.hs
Changes:
=====================================
compiler/GHC/Wasm/IR.hs
=====================================
@@ -125,6 +125,10 @@ data WasmIR :: WasmType -> [WasmType] -> [WasmType] -> Type where
WasmSub :: WasmTypeTag t -> WasmIR bool (t : t : stack) (t : stack)
WasmS_Ge :: WasmTypeTag t -> WasmIR bool (t : t : stack) (bool : stack) -- signed >=
+ WasmNot :: WasmTypeTag t -> WasmIR bool (t : stack) (t : stack) -- bitwise
+
+ -----
+
WasmCCall :: SymName -> WasmIR bool pre post -- completely untyped
WasmGlobalSet :: WasmTypeTag t -> SymName -> WasmIR bool (t : pre) pre
WasmLocalGet :: WasmTypeTag t -> Int -> WasmIR bool pre (t : pre)
=====================================
compiler/GHC/Wasm/Tx.hs
=====================================
@@ -45,6 +45,8 @@ tx expr k =
CmmMachOp (MO_S_Ge w) es -> wasmCompare w es WasmS_Ge k
+ CmmMachOp (MO_Not w) es -> wasmUnary w es WasmNot k
+
_ -> panic "unimplemented"
wasmBinary :: CG bool codegen
@@ -61,6 +63,15 @@ wasmCompare :: forall bool codegen r . CG bool codegen
-> ( WasmTypeTag bool -> WasmIR bool '[] (bool : '[]) -> codegen bool r)
-> codegen bool r
+wasmUnary :: CG bool codegen
+ => CT.Width
+ -> [CmmExpr]
+ -> (forall t . WasmTypeTag t -> WasmIR bool (t : '[]) (t : '[]))
+ -> (forall t . WasmTypeTag t -> WasmIR bool '[] (t : '[]) -> codegen bool r)
+ -> codegen bool r
+
+
+
wasmBinary w es operator k =
binaryCPS es $ \tag code1 code2 ->
@@ -88,7 +99,11 @@ binaryCPS [e1, e2] k = -- would dearly love to use do notation here
case tag1 `testEquality` tag2 of -- mandatory check
Just Refl -> k tag1 code1 code2
Nothing -> panic "ill-typed Cmm"
-binaryCPS _ _ = panic "wrong number of operands to machine operator in Cmm"
+binaryCPS _ _ = panic "wrong number of operands to binary operator in Cmm"
+
+wasmUnary w [e] operator k =
+ tx e $ \tag code -> checkTagWidth tag w $ k tag (code <> operator tag)
+wasmUnary _ _ _ _ = panic "wrong number of operands to unary operator in Cmm"
--whenEqual :: WasmTypeTag t -> WasmTypeTag t' -> (forall t . WasmTypeTag t -> a) -> a
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a06480168b15d7bcf115977279d47a45f2e350d6
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a06480168b15d7bcf115977279d47a45f2e350d6
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20220929/290f4a5f/attachment-0001.html>
More information about the ghc-commits
mailing list