From 645ea9ac09039d3c695c25018b2f089df7e09828 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 28 Oct 2021 23:33:06 +0100 Subject: Add GSA Types --- .envrc | 1 + .gitignore | 2 ++ app/Main.hs | 2 +- bench/Main.hs | 2 +- gsa-parser.cabal | 7 +++- src/GSA.hs | 7 ++++ src/GSA/Common.hs | 1 + src/GSA/Types.hs | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Lib.hs | 7 ---- 9 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 .envrc create mode 100644 src/GSA.hs create mode 100644 src/GSA/Common.hs create mode 100644 src/GSA/Types.hs delete mode 100644 src/Lib.hs 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/GSA.hs b/src/GSA.hs new file mode 100644 index 0000000..3262c33 --- /dev/null +++ b/src/GSA.hs @@ -0,0 +1,7 @@ +module GSA + ( someFunc, + ) +where + +someFunc :: IO () +someFunc = putStrLn "hey" 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) diff --git a/src/Lib.hs b/src/Lib.hs deleted file mode 100644 index 1055c22..0000000 --- a/src/Lib.hs +++ /dev/null @@ -1,7 +0,0 @@ -module Lib - ( someFunc, - ) -where - -someFunc :: IO () -someFunc = putStrLn "hey" -- cgit