2019-09-27 20:18:30 +03:00
|
|
|
{-# LANGUAGE DataKinds, FlexibleContexts, PackageImports, PartialTypeSignatures, TypeApplications, TypeFamilies #-}
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2018-03-08 03:34:20 +03:00
|
|
|
module Main where
|
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
import Algebra.Graph
|
2018-07-18 18:38:28 +03:00
|
|
|
import Control.Monad
|
2019-09-27 20:18:30 +03:00
|
|
|
import Data.Abstract.Evaluatable
|
|
|
|
import Data.Abstract.FreeVariables
|
|
|
|
import Data.Blob
|
|
|
|
import Data.Blob.IO (readBlobFromFile')
|
|
|
|
import Data.Bifunctor
|
|
|
|
import Data.Functor.Classes
|
|
|
|
import "semantic" Data.Graph (Graph (..), topologicalSort)
|
|
|
|
import Data.Graph.ControlFlowVertex
|
2018-07-18 18:38:28 +03:00
|
|
|
import qualified Data.Language as Language
|
2019-09-27 20:18:30 +03:00
|
|
|
import Data.Project
|
2018-07-18 18:38:28 +03:00
|
|
|
import Data.Proxy
|
2019-09-27 20:18:30 +03:00
|
|
|
import Data.Term
|
|
|
|
import Gauge.Main
|
2018-07-18 18:38:28 +03:00
|
|
|
import Parsing.Parser
|
|
|
|
import Semantic.Config (defaultOptions)
|
2019-09-27 20:18:30 +03:00
|
|
|
import Semantic.Graph
|
|
|
|
import Semantic.Task (SomeException, TaskSession (..), runTask, withOptions)
|
|
|
|
import Semantic.Util hiding (evalPythonProject, evalRubyProject, evaluateProject)
|
|
|
|
import Source.Loc
|
|
|
|
import qualified System.Path as Path
|
|
|
|
import System.Path ((</>))
|
2018-07-18 18:38:28 +03:00
|
|
|
|
|
|
|
-- Duplicating this stuff from Util to shut off the logging
|
2019-09-27 20:18:30 +03:00
|
|
|
|
|
|
|
callGraphProject' :: ( Language.SLanguage lang
|
|
|
|
, Ord1 syntax
|
|
|
|
, Declarations1 syntax
|
|
|
|
, Evaluatable syntax
|
|
|
|
, FreeVariables1 syntax
|
|
|
|
, AccessControls1 syntax
|
|
|
|
, HasPrelude lang
|
|
|
|
, Functor syntax
|
|
|
|
, VertexDeclarationWithStrategy (VertexDeclarationStrategy syntax) syntax syntax
|
|
|
|
)
|
|
|
|
=> TaskSession
|
|
|
|
-> Proxy lang
|
|
|
|
-> Parser (Term syntax Loc)
|
|
|
|
-> Path.RelFile
|
|
|
|
-> IO (Either String (Data.Graph.Graph ControlFlowVertex))
|
|
|
|
callGraphProject' session proxy parser path = fmap (first show) . runTask session $ do
|
|
|
|
blob <- readBlobFromFile' (fileForRelPath path)
|
|
|
|
package <- fmap snd <$> parsePackage parser (Project (Path.toString (Path.takeDirectory path)) [blob] (Language.reflect proxy) [])
|
|
|
|
modules <- topologicalSort <$> runImportGraphToModules proxy package
|
|
|
|
runCallGraph proxy False modules package
|
|
|
|
|
|
|
|
callGraphProject proxy parser paths = withOptions defaultOptions $ \ config logger statter ->
|
|
|
|
callGraphProject' (TaskSession config "" False logger statter) proxy parser paths
|
|
|
|
|
2018-08-14 01:42:42 +03:00
|
|
|
evalRubyProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.Ruby) rubyParser
|
|
|
|
evalPythonProject = justEvaluating <=< evaluateProject (Proxy :: Proxy 'Language.Python) pythonParser
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
evaluateProject proxy parser path = withOptions defaultOptions $ \ config logger statter ->
|
|
|
|
evaluateProject' (TaskSession config "" False logger statter) proxy parser [Path.toString path]
|
2018-03-08 03:34:20 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
pyEval :: Path.RelFile -> Benchmarkable
|
|
|
|
pyEval p = nfIO $ evalPythonProject (Path.relDir "bench/bench-fixtures/python" </> p)
|
2018-03-08 03:34:20 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
rbEval :: Path.RelFile -> Benchmarkable
|
|
|
|
rbEval p = nfIO $ evalRubyProject (Path.relDir "bench/bench-fixtures/python" </> p)
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
pyCall :: Path.RelFile -> Benchmarkable
|
|
|
|
pyCall p = nfIO $ callGraphProject (Proxy @'Language.Python) pythonParser (Path.relDir "bench/bench-fixtures/python/" </> p)
|
2018-07-18 18:38:28 +03:00
|
|
|
|
2019-09-27 20:18:30 +03:00
|
|
|
rbCall :: Path.RelFile -> Benchmarkable
|
|
|
|
rbCall p = nfIO $ callGraphProject (Proxy @'Language.Ruby) rubyParser $ (Path.relDir "bench/bench-fixtures/ruby" </> p)
|
2018-03-08 03:34:20 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2018-03-08 03:47:23 +03:00
|
|
|
main = defaultMain
|
2019-09-27 20:18:30 +03:00
|
|
|
[ bgroup "python" [ bench "assignment" . pyEval $ Path.relFile "simple-assignment.py"
|
|
|
|
, bench "function def" . pyEval $ Path.relFile "function-definition.py"
|
|
|
|
, bench "if + function calls" . pyCall . Path.relFile $ "if-statement-functions.py"
|
|
|
|
, bench "call graph" $ pyCall . Path.relFile $ "if-statement-functions.py"
|
2018-03-12 17:51:07 +03:00
|
|
|
]
|
2019-09-27 20:18:30 +03:00
|
|
|
, bgroup "ruby" [ bench "assignment" . rbEval $ Path.relFile "simple-assignment.rb"
|
|
|
|
, bench "function def" . rbEval . Path.relFile $ "function-definition.rb"
|
|
|
|
, bench "if + function calls" . rbCall $ Path.relFile "if-statement-functions.rb"
|
|
|
|
, bench "call graph" $ rbCall $ Path.relFile "if-statement-functions.rb"
|
2018-03-08 03:47:23 +03:00
|
|
|
]
|
2018-03-08 03:34:20 +03:00
|
|
|
]
|