To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 12687661 authored by Pavel Zakopaylo's avatar Pavel Zakopaylo
Browse files

Spec compliance; Made enums (e.g. compare ops) have correct values

parent 695e2d2d
......@@ -14,6 +14,7 @@
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Mu.AST (
HasName (..)
......@@ -56,6 +57,8 @@ module Mu.AST (
, CommInst (..)
) where
import Prelude hiding (EQ)
import Data.Monoid ((<>))
import Data.Binary (Binary)
import Data.ByteString.Char8 (ByteString)
......@@ -273,7 +276,7 @@ newtype Flag = Flag
instance Binary Flag
-- | Binary Ops as defined by the Mu Spec
-- | Binary Ops all use the same arguments, so these flags represent precisly which binary operation to display
-- | Binary Ops all use the same arguments, so these flags represent precisely which binary operation to display
data BinaryOp
= Add
| Sub
......@@ -293,9 +296,52 @@ data BinaryOp
| FMul
| FDiv
| FRem
deriving (Eq, Ord, Enum, Show, Generic)
deriving (Eq, Ord, Show, Generic)
instance Binary BinaryOp
instance Enum BinaryOp where
fromEnum op = case op of
Add -> 0x01
Sub -> 0x02
Mul -> 0x03
SDiv -> 0x04
SRem -> 0x05
UDiv -> 0x06
URem -> 0x07
Shl -> 0x08
LShr -> 0x09
AShr -> 0x0a
And -> 0x0b
Or -> 0x0c
Xor -> 0x0d
FAdd -> 0xb0
FSub -> 0xb1
FMul -> 0xb2
FDiv -> 0xb3
FRem -> 0xb4
toEnum val = case val of
0x01 -> And
0x02 -> Sub
0x03 -> Mul
0x04 -> SDiv
0x05 -> SRem
0x06 -> UDiv
0x07 -> URem
0x08 -> Shl
0x09 -> LShr
0x0a -> AShr
0x0b -> And
0x0c -> Or
0x0d -> Xor
0xb0 -> FAdd
0xb1 -> FSub
0xb2 -> FMul
0xb3 -> FDiv
0xb4 -> FRem
_ -> error $ (show val) ++ " is not a valid BinaryOp"
-- | Compare Ops as defined by the Mu Spec
-- | See Binary Ops for more detail
data CompareOp
......@@ -325,10 +371,67 @@ data CompareOp
| FULE
| FUNE
| FUNO
deriving (Eq, Ord, Enum, Show, Generic)
deriving (Eq, Ord, Show, Generic)
instance Binary CompareOp
instance Enum CompareOp where
fromEnum op = case op of
EQ -> 0x20
NE -> 0x21
SGE -> 0x22
SGT -> 0x23
SLE -> 0x24
SLT -> 0x25
UGE -> 0x26
UGT -> 0x27
ULE -> 0x28
ULT -> 0x29
FFALSE -> 0xC0
FTRUE -> 0xC1
FUNO -> 0xC2
FUEQ -> 0xC3
FUNE -> 0xC4
FUGT -> 0xC5
FUGE -> 0xC6
FULT -> 0xC7
FULE -> 0xC8
FORD -> 0xC9
FOEQ -> 0xCA
FONE -> 0xCB
FOGT -> 0xCC
FOGE -> 0xCD
FOLT -> 0xCE
FOLE -> 0xCF
toEnum val = case val of
0x20 -> EQ
0x21 -> NE
0x22 -> SGE
0x23 -> SGT
0x24 -> SLE
0x25 -> SLT
0x26 -> UGE
0x27 -> UGT
0x28 -> ULE
0x29 -> ULT
0xC0 -> FFALSE
0xC1 -> FTRUE
0xC2 -> FUNO
0xC3 -> FUEQ
0xC4 -> FUNE
0xC5 -> FUGT
0xC6 -> FUGE
0xC7 -> FULT
0xC8 -> FULE
0xC9 -> FORD
0xCA -> FOEQ
0xCB -> FONE
0xCC -> FOGT
0xCD -> FOGE
0xCE -> FOLT
0xCF -> FOLE
_ -> error $ (show val) ++ " is not a valid CompareOp"
-- | Convert Ops as defined by the Mu Spec
-- | See Binary Ops for more detail
data ConvertOp
......@@ -344,10 +447,39 @@ data ConvertOp
| BITCAST
| REFCAST
| PTRCAST
deriving (Eq, Ord, Enum, Show, Generic)
deriving (Eq, Ord, Show, Generic)
instance Binary ConvertOp
instance Enum ConvertOp where
fromEnum op = case op of
TRUNC -> 0x30
ZEXT -> 0x31
SEXT -> 0x32
FPTRUNC -> 0x33
FPEXT -> 0x34
FPTOUI -> 0x35
FPTOSI -> 0x36
UITOFP -> 0x37
SITOFP -> 0x38
BITCAST -> 0x39
REFCAST -> 0x3A
PTRCAST -> 0x3B
toEnum val = case val of
0x30 -> TRUNC
0x31 -> ZEXT
0x32 -> SEXT
0x33 -> FPTRUNC
0x34 -> FPEXT
0x35 -> FPTOUI
0x36 -> FPTOSI
0x37 -> UITOFP
0x38 -> SITOFP
0x39 -> BITCAST
0x3a -> REFCAST
0x3b -> PTRCAST
_ -> error $ (show val) ++ " is not a valid ConvertOp"
-- | Atomic RMW Ops as defined by the mu spec
-- | See Binary Ops for more detail
data AtomicRMWOp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment