aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2021-10-28 23:33:06 +0100
committerYann Herklotz <git@yannherklotz.com>2021-10-28 23:33:06 +0100
commit645ea9ac09039d3c695c25018b2f089df7e09828 (patch)
treea44d4a97ed59f5881ee5c1b1563aa65b8938df16
parentd04cc0b59c49511b3ebae20b0b2ce98d61f04c64 (diff)
downloadgsa-parser-645ea9ac09039d3c695c25018b2f089df7e09828.tar.gz
gsa-parser-645ea9ac09039d3c695c25018b2f089df7e09828.zip
Add GSA Types
-rw-r--r--.envrc1
-rw-r--r--.gitignore2
-rw-r--r--app/Main.hs2
-rw-r--r--bench/Main.hs2
-rw-r--r--gsa-parser.cabal7
-rw-r--r--src/GSA.hs (renamed from src/Lib.hs)2
-rw-r--r--src/GSA/Common.hs1
-rw-r--r--src/GSA/Types.hs99
8 files changed, 112 insertions, 4 deletions
diff --git a/.envrc b/.envrc
new file mode 100644
index 0000000..3550a30
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/.gitignore b/.gitignore
index edb8907..66da175 100644
--- a/.gitignore
+++ b/.gitignore
@@ -25,3 +25,5 @@ cabal.project.local
cabal.project.local~
.HTF/
.ghc.environment.*
+
+.direnv
diff --git a/app/Main.hs b/app/Main.hs
index 2ca1f1d..dc849e7 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,4 +1,4 @@
-import Lib
+import GSA
main :: IO ()
main = putStrLn "heyyyyyy"
diff --git a/bench/Main.hs b/bench/Main.hs
index 04c2719..c619f4f 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -1,4 +1,4 @@
-import Lib
+import GSA
main :: IO ()
main = putStrLn "heyyyyyyyyyyyyyyyyyyyy"
diff --git a/gsa-parser.cabal b/gsa-parser.cabal
index b360072..a171840 100644
--- a/gsa-parser.cabal
+++ b/gsa-parser.cabal
@@ -27,14 +27,19 @@ common common-options
-Wall -Wcompat -Widentities -Wincomplete-uni-patterns
-Wincomplete-record-updates -Wredundant-constraints
-fhide-source-paths -Wpartial-fields
+ default-extensions: OverloadedStrings
library
import: common-options
hs-source-dirs: src
- exposed-modules: Lib
+ exposed-modules: GSA
+ , GSA.Common
+ , GSA.Types
build-depends:
, containers
, mtl
+ , megaparsec
+ , text
executable gsa-parser-exe
import: common-options
diff --git a/src/Lib.hs b/src/GSA.hs
index 1055c22..3262c33 100644
--- a/src/Lib.hs
+++ b/src/GSA.hs
@@ -1,4 +1,4 @@
-module Lib
+module GSA
( someFunc,
)
where
diff --git a/src/GSA/Common.hs b/src/GSA/Common.hs
new file mode 100644
index 0000000..7c50630
--- /dev/null
+++ b/src/GSA/Common.hs
@@ -0,0 +1 @@
+module GSA.Common where
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)