2024-10-02 22:56:15 +02:00
|
|
|
module Language.Elna.Backend.Intermediate
|
2024-11-10 21:57:30 +01:00
|
|
|
( ProcedureQuadruples(..)
|
|
|
|
, Operand(..)
|
2024-10-02 22:56:15 +02:00
|
|
|
, Quadruple(..)
|
2024-10-11 16:14:01 +02:00
|
|
|
, Label(..)
|
2024-10-02 22:56:15 +02:00
|
|
|
, Variable(..)
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Data.Int (Int32)
|
2024-11-10 21:57:30 +01:00
|
|
|
import Data.HashMap.Strict (HashMap)
|
|
|
|
import Data.Vector (Vector)
|
2024-10-02 22:56:15 +02:00
|
|
|
import Data.Word (Word32)
|
|
|
|
import Data.Text (Text)
|
2024-10-11 16:14:01 +02:00
|
|
|
import qualified Data.Text as Text
|
2024-11-10 21:57:30 +01:00
|
|
|
import Language.Elna.Location (Identifier(..))
|
2024-10-11 16:14:01 +02:00
|
|
|
|
|
|
|
newtype Label = Label { unLabel :: Text }
|
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
instance Show Label
|
|
|
|
where
|
|
|
|
show (Label label) = '.' : Text.unpack label
|
2024-10-02 22:56:15 +02:00
|
|
|
|
2024-11-06 22:23:49 +01:00
|
|
|
data Variable = TempVariable Word32 | LocalVariable Word32
|
2024-10-02 22:56:15 +02:00
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
instance Show Variable
|
|
|
|
where
|
2024-11-06 22:23:49 +01:00
|
|
|
show (LocalVariable variable) = '@' : show variable
|
2024-10-02 22:56:15 +02:00
|
|
|
show (TempVariable variable) = '$' : show variable
|
|
|
|
|
|
|
|
data Operand v
|
|
|
|
= IntOperand Int32
|
|
|
|
| VariableOperand v
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2024-11-10 21:57:30 +01:00
|
|
|
newtype ProcedureQuadruples v =
|
|
|
|
ProcedureQuadruples (HashMap Identifier (Vector (Quadruple v)))
|
|
|
|
deriving (Eq, Show)
|
|
|
|
|
2024-10-02 22:56:15 +02:00
|
|
|
data Quadruple v
|
|
|
|
= StartQuadruple
|
|
|
|
| StopQuadruple
|
|
|
|
| ParameterQuadruple (Operand v)
|
|
|
|
| CallQuadruple Text Word32
|
|
|
|
| AddQuadruple (Operand v) (Operand v) v
|
|
|
|
| SubtractionQuadruple (Operand v) (Operand v) v
|
|
|
|
| NegationQuadruple (Operand v) v
|
2024-10-04 18:26:10 +02:00
|
|
|
| ProductQuadruple (Operand v) (Operand v) v
|
2024-10-06 18:07:57 +02:00
|
|
|
| DivisionQuadruple (Operand v) (Operand v) v
|
2024-10-11 16:14:01 +02:00
|
|
|
| GoToQuadruple Label
|
2024-11-06 22:23:49 +01:00
|
|
|
| AssignQuadruple (Operand v) v
|
|
|
|
{-| ArrayQuadruple Variable Operand Variable
|
2024-10-13 12:59:47 +02:00
|
|
|
| ArrayAssignQuadruple Operand Operand Variable -}
|
|
|
|
| LessOrEqualQuadruple (Operand v) (Operand v) Label
|
|
|
|
| GreaterOrEqualQuadruple (Operand v) (Operand v) Label
|
|
|
|
| GreaterQuadruple (Operand v) (Operand v) Label
|
|
|
|
| LessQuadruple (Operand v) (Operand v) Label
|
|
|
|
| NonEqualQuadruple (Operand v) (Operand v) Label
|
2024-10-11 16:14:01 +02:00
|
|
|
| EqualQuadruple (Operand v) (Operand v) Label
|
|
|
|
| LabelQuadruple Label
|
2024-10-02 22:56:15 +02:00
|
|
|
deriving (Eq, Show)
|