Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended syntax: pipeline #116

Merged
merged 11 commits into from
Nov 14, 2020
6 changes: 6 additions & 0 deletions grin/grin.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ library
Grin.ExtendedSyntax.TypeEnv
Grin.ExtendedSyntax.TypeEnvDefs
Grin.ExtendedSyntax.GADT
Pipeline.ExtendedSyntax.Eval
Pipeline.ExtendedSyntax.Optimizations
Pipeline.ExtendedSyntax.Pipeline
Pipeline.Eval
Pipeline.Optimizations
Pipeline.Pipeline
Expand Down Expand Up @@ -321,9 +324,11 @@ test-suite grin-test
ExtendedSyntax.LintSpec
ExtendedSyntax.NametableSpec
ExtendedSyntax.ParserSpec
ExtendedSyntax.PipelineSpec
ExtendedSyntax.PrimOpsSpec
ExtendedSyntax.TestSpec
Transformations.ExtendedSyntax.BindNormalisationSpec
Transformations.ExtendedSyntax.ConfluenceSpec
Transformations.ExtendedSyntax.ConversionSpec
Transformations.ExtendedSyntax.MangleNamesSpec
Transformations.ExtendedSyntax.StaticSingleAssignmentSpec
Expand Down Expand Up @@ -377,6 +382,7 @@ test-suite grin-test
Transformations.BindNormalisationSpec
Transformations.ConfluenceSpec
Transformations.MangleNamesSpec
Samples.ExtendedSyntax.SumListSpec
Samples.SumListSpec
Samples.ArityFullRemoveSpec
LintSpec
Expand Down
46 changes: 46 additions & 0 deletions grin/src/Pipeline/ExtendedSyntax/Eval.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{-# LANGUAGE OverloadedStrings #-}
module Pipeline.ExtendedSyntax.Eval where

import qualified Data.Text.IO as Text
import Text.Megaparsec

import Grin.ExtendedSyntax.Grin
import Grin.ExtendedSyntax.TypeCheck
import Grin.ExtendedSyntax.Parse
import Reducer.ExtendedSyntax.Base (RTVal)
import qualified Reducer.ExtendedSyntax.IO as ReducerIO
import qualified Reducer.ExtendedSyntax.Pure as ReducerPure
import qualified Reducer.ExtendedSyntax.LLVM.JIT as LLVM
import qualified Reducer.ExtendedSyntax.LLVM.CodeGen as LLVM
import qualified AbstractInterpretation.ExtendedSyntax.HeapPointsTo.CodeGen as HPT
import qualified AbstractInterpretation.ExtendedSyntax.HeapPointsTo.Result as HPT
import AbstractInterpretation.ExtendedSyntax.Reduce (AbstractInterpretationResult(..), evalAbstractProgram)



data Reducer
= PureReducer
| IOReducer
| LLVMReducer
deriving (Eq, Show)

-- TODO: Add Mode as a parameter?
eval' :: Reducer -> String -> IO RTVal
eval' reducer fname = do
content <- Text.readFile fname
case parseGrin fname content of
Left err -> error $ parseErrorPretty' content err
Right program ->
case reducer of
PureReducer -> ReducerPure.reduceFun program "grinMain"
IOReducer -> ReducerIO.reduceFun program "grinMain"
LLVMReducer -> LLVM.eagerJit (LLVM.codeGen typeEnv program) "grinMain" where
typeEnv = either error id $ typeEnvFromHPTResult hptResult
hptResult = HPT.toHPTResult hptMapping ((_airComp . evalAbstractProgram) $ hptProgram)
(hptProgram, hptMapping) = HPT.codeGen program

evalProgram :: Reducer -> Program -> IO RTVal
evalProgram reducer program =
case reducer of
PureReducer -> ReducerPure.reduceFun program "grinMain"
IOReducer -> ReducerIO.reduceFun program "grinMain"
39 changes: 39 additions & 0 deletions grin/src/Pipeline/ExtendedSyntax/Optimizations.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Pipeline.ExtendedSyntax.Optimizations
( evaluatedCaseElimination
, trivialCaseElimination
, sparseCaseOptimisation
, copyPropagation
, constantPropagation
, interproceduralDeadDataElimination
, interproceduralDeadFunctionElimination
, interproceduralDeadParameterElimination
, deadFunctionElimination
, deadVariableElimination
, deadParameterElimination
, commonSubExpressionElimination
, caseCopyPropagation
, generalizedUnboxing
, arityRaising
, caseHoisting
, lateInlining
, nonSharedElimination
) where

import Transformations.ExtendedSyntax.Optimising.EvaluatedCaseElimination (evaluatedCaseElimination)
import Transformations.ExtendedSyntax.Optimising.TrivialCaseElimination (trivialCaseElimination)
import Transformations.ExtendedSyntax.Optimising.SparseCaseOptimisation (sparseCaseOptimisation)
import Transformations.ExtendedSyntax.Optimising.CopyPropagation (copyPropagation)
import Transformations.ExtendedSyntax.Optimising.ConstantPropagation (constantPropagation)
import Transformations.ExtendedSyntax.Optimising.InterproceduralDeadDataElimination (interproceduralDeadDataElimination)
import Transformations.ExtendedSyntax.Optimising.InterproceduralDeadFunctionElimination (interproceduralDeadFunctionElimination)
import Transformations.ExtendedSyntax.Optimising.InterproceduralDeadParameterElimination (interproceduralDeadParameterElimination)
import Transformations.ExtendedSyntax.Optimising.DeadFunctionElimination (deadFunctionElimination)
import Transformations.ExtendedSyntax.Optimising.DeadVariableElimination (deadVariableElimination)
import Transformations.ExtendedSyntax.Optimising.DeadParameterElimination (deadParameterElimination)
import Transformations.ExtendedSyntax.Optimising.CSE (commonSubExpressionElimination)
import Transformations.ExtendedSyntax.Optimising.CaseCopyPropagation (caseCopyPropagation)
import Transformations.ExtendedSyntax.Optimising.GeneralizedUnboxing (generalizedUnboxing)
import Transformations.ExtendedSyntax.Optimising.ArityRaising (arityRaising)
import Transformations.ExtendedSyntax.Optimising.CaseHoisting (caseHoisting)
import Transformations.ExtendedSyntax.Optimising.Inlining (lateInlining)
import Transformations.ExtendedSyntax.Optimising.NonSharedElimination (nonSharedElimination)
Loading