aboutsummaryrefslogtreecommitdiffstats
path: root/src/GSA/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GSA/Types.hs')
-rw-r--r--src/GSA/Types.hs99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/GSA/Types.hs b/src/GSA/Types.hs
new file mode 100644
index 0000000..a99cac7
--- /dev/null
+++ b/src/GSA/Types.hs
@@ -0,0 +1,99 @@
+module GSA.Types where
+
+import Data.IntMap.Strict (IntMap)
+import Data.Text (Text)
+
+data Typ
+ = Tint
+ | Tfloat
+ | Tlong
+ | Tsingle
+ | Tany32
+ | Tany64
+ deriving (Eq, Show)
+
+data RetTyp
+ = Tret Typ
+ | Tint8signed
+ | Tint8unsigned
+ | Tint16signed
+ | Tint16unsigned
+ | Tvoid
+ deriving (Eq, Show)
+
+data Signature = Signature
+ { sigArgs :: [Typ],
+ sigRes :: RetTyp
+ }
+ deriving (Eq, Show)
+
+data Chunk
+ = Mint8signed
+ | Mint8unsigned
+ | Mint16signed
+ | Mint16unsigned
+ | Mint32
+ | Mint64
+ | Mfloat32
+ | Mfloat64
+ | Many32
+ | Many64
+
+signatureMain :: Signature
+signatureMain = Signature {sigArgs = [], sigRes = Tret Tint}
+
+newtype Node = Node {getNode :: Int} deriving (Eq, Show)
+
+newtype Reg = Reg {getReg :: Int} deriving (Eq, Show)
+
+newtype Ident = Ident {getIdent :: Int} deriving (Eq, Show)
+
+newtype Addressing = Addressing {getAddressing :: Int} deriving (Eq, Show)
+
+newtype Operation = Operation {getOperation :: Int} deriving (Eq, Show)
+
+type Condition = Int
+
+data Pred a
+ = Ptrue
+ | Pfalse
+ | Plit (Bool, a)
+ | Pand (Pred a) (Pred a)
+ | Por (Pred a) (Pred a)
+ deriving (Eq, Show)
+
+type Predicate = Pred Condition
+
+data MergeInstruction
+ = Imu Reg Reg Reg
+ | Igamma [(Predicate, Reg)] Reg
+ | Ieta Predicate Reg Reg
+ deriving (Eq, Show)
+
+data Instruction
+ = Inop Node
+ | Iop Operation [Reg] Reg Node
+ | Iload Chunk Addressing [Reg] Reg Node
+ | Istore Chunk Addressing [Reg] Reg Node
+ | Icall Signature (Either Reg Ident)
+ | Icond Condition [Reg] Node Node
+ | Ijumptable Reg [Node]
+ | Ireturn (Maybe Reg)
+ | Imfunc [MergeInstruction]
+ deriving (Eq, Show)
+
+newtype MergeBlock = MergeBlock {getMergeBlock :: [MergeInstruction]} deriving (Eq, Show)
+
+newtype Code = Code {getCode :: IntMap Instruction} deriving (Eq, Show)
+
+data Function = Function
+ { fnSig :: Signature,
+ fnParams :: [Reg],
+ fnStackSize :: Int,
+ fnCode :: Code,
+ fnEntrypoint :: Node,
+ fnExtParams :: [Reg]
+ }
+ deriving (Eq, Show)
+
+newtype Program = Program {getProgram :: [Function]} deriving (Eq, Show)