ソースを参照

beginning of tower backend

Pat Hickey 9 年 前
コミット
98c7179538

+ 13 - 3
.travis.yml

@@ -2,14 +2,24 @@ language: haskell
 
 
 before_install:
+  - sudo add-apt-repository -y ppa:terry.guo/gcc-arm-embedded
+  - sudo apt-get update -qq
+  - sudo apt-get install -y gcc-arm-none-eabi
   - git clone https://github.com/galoisinc/ivory
   - export IVORY_REPO=$PWD/ivory
+  - git clone https://github.com/galoisinc/tower
+  - export TOWER_REPO=$PWD/tower
+  - git clone https://github.com/galoisinc/ivory-tower-stm32
+  - export BSP_REPO=$PWD/ivory-tower-stm32
 install:
   - cabal install alex
   - cabal install happy
 script:
-  - IVORY_REPO=$IVORY_REPO make create-sandbox
-  - IVORY_REPO=$IVORY_REPO make
-  - IVORY_REPO=$IVORY_REPO make test
+  - ghc --version
+  - cabal --version
+  - arm-none-eabi-gcc --version
+  - IVORY_REPO=$IVORY_REPO TOWER_REPO=$TOWER_REPO BSP_REPO=$BSP_REPO make create-sandbox
+  - IVORY_REPO=$IVORY_REPO TOWER_REPO=$TOWER_REPO BSP_REPO=$BSP_REPO make
+  - IVORY_REPO=$IVORY_REPO TOWER_REPO=$TOWER_REPO BSP_REPO=$BSP_REPO make test
 ghc:
   - 7.8

+ 16 - 0
Makefile

@@ -11,6 +11,7 @@ create-sandbox:
 
 test: haskell-backend-test
 test: ivory-backend-test
+test: tower-backend-test
 
 haskell-backend-test:
 	cabal run gidl -- -b haskell \
@@ -39,8 +40,23 @@ ivory-backend-test:
 ivory-backend-test-clean:
 	-rm -rf tests/gidl-ivory-backend-test
 
+tower-backend-test:
+	cabal run gidl -- -b tower \
+		--debug \
+		-i tests/example.idl \
+		-o tests/gidl-tower-backend-test \
+		-p gidl-tower-backend-test \
+		-n Gidl.Test
+	make -C tests/gidl-tower-backend-test create-sandbox
+	make -C tests/gidl-tower-backend-test
+	make -C tests/gidl-tower-backend-test test
+
+tower-backend-test-clean:
+	-rm -rf tests/gidl-tower-backend-test
+
 
 clean: ivory-backend-test-clean
+clean: tower-backend-test-clean
 clean: haskell-backend-test-clean
 
 distclean: clean

+ 6 - 2
gidl.cabal

@@ -8,7 +8,10 @@ copyright:           2015 Galois Inc
 build-type:          Simple
 cabal-version:       >=1.10
 
-data-files: support/ivory/Unpack.hs.template
+data-files: support/ivory/Unpack.hs.template,
+            support/ivory/CodeGen.hs.template,
+            support/ivory/Makefile,
+            support/tower/Makefile
 
 library
   exposed-modules:     Gidl,
@@ -28,7 +31,8 @@ library
                        Gidl.Backend.Ivory.Interface,
                        Gidl.Backend.Ivory.Test,
                        Gidl.Backend.Ivory.Types,
-                       Gidl.Backend.Ivory.Unpack
+                       Gidl.Backend.Ivory.Unpack,
+                       Gidl.Backend.Tower
 
   other-modules:       Paths_gidl
 

+ 6 - 1
src/Gidl.hs

@@ -15,6 +15,7 @@ import Ivory.Artifact
 import Gidl.Parse
 import Gidl.Backend.Haskell
 import Gidl.Backend.Ivory
+import Gidl.Backend.Tower
 
 data OptParser opt = OptParser [String] (opt -> opt)
 instance Monoid (OptParser opt) where
@@ -38,6 +39,7 @@ parseOptions opts args = case getOpt Permute opts args of
 data Backend
   = HaskellBackend
   | IvoryBackend
+  | TowerBackend
   deriving (Eq, Show)
 
 data Opts = Opts
@@ -65,8 +67,9 @@ setBackend :: String -> OptParser Opts
 setBackend b = case map toUpper b of
   "HASKELL" -> success (\o -> o { backend = HaskellBackend })
   "IVORY"   -> success (\o -> o { backend = IvoryBackend })
+  "TOWER"   -> success (\o -> o { backend = TowerBackend })
   _         -> invalid ("\"" ++ b ++ "\" is not a valid backend.\n"
-                          ++ "Supported backends: haskell, ivory")
+                          ++ "Supported backends: haskell, ivory, tower")
 
 setIdlPath :: String -> OptParser Opts
 setIdlPath p = success (\o -> o { idlpath = p })
@@ -133,6 +136,8 @@ run = do
           haskellBackend te ie (packagename opts) (namespace opts)
         IvoryBackend -> artifactBackend opts $
           ivoryBackend te ie (packagename opts) (namespace opts)
+        TowerBackend -> artifactBackend opts $
+          towerBackend te ie (packagename opts) (namespace opts)
 
   where
   artifactBackend :: Opts -> [Artifact] -> IO ()

+ 39 - 59
src/Gidl/Backend/Ivory.hs

@@ -1,5 +1,13 @@
 module Gidl.Backend.Ivory where
 
+import Ivory.Artifact
+import Ivory.Artifact.Template
+
+import Data.Char (isSpace)
+import Data.List (intercalate)
+
+import qualified Paths_gidl as P
+
 import Gidl.Types
 import Gidl.Interface
 import Gidl.Schema
@@ -8,80 +16,52 @@ import Gidl.Backend.Ivory.Types
 import Gidl.Backend.Ivory.Interface
 import Gidl.Backend.Ivory.Unpack
 
-import Ivory.Artifact
-
-import Data.Char (isSpace)
-import Text.PrettyPrint.Mainland
-
 ivoryBackend :: TypeEnv -> InterfaceEnv -> String -> String -> [Artifact]
-ivoryBackend (TypeEnv te) (InterfaceEnv ie) pkgname namespace_raw =
+ivoryBackend te ie pkgname namespace_raw =
   [ cabalFileArtifact cf
   , artifactPath "tests" $ codegenTest namespace
   , makefile
-  ] ++
-  [ artifactPath "src" m | m <- sourceMods
-  ]
+  ] ++ map (artifactPath "src") sources
   where
-  userDefinedTypes = [ t | (_,t) <- te, isUserDefined t ]
-  tmods = [ typeModule (namespace ++ ["Types"]) t
-          | t <- userDefinedTypes ]
-  imods =[ [ interfaceModule (namespace ++ ["Interface"]) i (producerSchema i)
-           , interfaceModule (namespace ++ ["Interface"]) i (consumerSchema i)
-           ]
-         | (_iname, i) <- ie
-         ]
-  sourceMods = tmods
-            ++ concat imods
-            ++ [ typeUmbrella namespace userDefinedTypes
-               , unpackModule namespace
-               ]
+  sources = ivorySources te ie namespace
+  namespace = dotwords namespace_raw
+
   cf = (defaultCabalFile pkgname cabalmods deps) { executables = [ cg_exe ] }
   cg_exe = defaultCabalExe (pkgname ++ "-gen") "CodeGen.hs"
               (deps ++ (words "ivory-backend-c") ++ [pkgname])
-  cabalmods = [ filePathToPackage (artifactFileName m) | m <- sourceMods ]
+  cabalmods = map (filePathToPackage . artifactFileName) sources
   deps = words "ivory ivory-stdlib ivory-serialize"
 
-  namespace = dotwords namespace_raw
 
 
-  dotwords :: String -> [String]
-  dotwords s = case dropWhile isDot s of
-    "" -> []
-    s' -> let  (w, s'') = break isDot s' in w : dotwords s''
+ivorySources :: TypeEnv -> InterfaceEnv -> [String] -> [Artifact]
+ivorySources (TypeEnv te) (InterfaceEnv ie) namespace =
+  tmods ++ concat imods ++ [ typeUmbrella namespace userDefinedTypes
+                           , unpackModule namespace
+                           ]
+  where
+  userDefinedTypes = [ t | (_,t) <- te, isUserDefined t ]
+  tmods = [ typeModule (namespace ++ ["Types"]) t
+          | t <- userDefinedTypes ]
+  imods = [ [ interfaceModule (namespace ++ ["Interface"]) i (producerSchema i)
+            , interfaceModule (namespace ++ ["Interface"]) i (consumerSchema i) ]
+          | (_iname, i) <- ie ]
+
+dotwords :: String -> [String]
+dotwords s = case dropWhile isDot s of
+  "" -> []
+  s' -> let  (w, s'') = break isDot s' in w : dotwords s''
+  where
   isDot c = (c == '.') || isSpace c
 
 makefile :: Artifact
-makefile = artifactText "Makefile" $
-  prettyLazyText 80 $ stack
-    [ text "IVORY_REPO ?= ../../../ivory"
-    , empty
-    , text "default:"
-    , text "\tcabal build"
-    , empty
-    , text "create-sandbox:"
-    , text "\tcabal sandbox init"
-    , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory"
-    , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-artifact"
-    , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-serialize"
-    , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-stdlib"
-    , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-opts"
-    , text "\tcabal sandbox add-source $(IVORY_REPO)/ivory-backend-c"
-    , text "\tcabal install --enable-tests --dependencies-only"
-    , empty
-    , text "test:"
-    , text "\tcabal run -- --src-dir=codegen-out"
-    , empty
-    ]
+makefile = artifactCabalFile P.getDataDir "support/ivory/Makefile"
 
 codegenTest :: [String] -> Artifact
-codegenTest modulepath = artifactText "CodeGen.hs" $
-  prettyLazyText 80 $ stack
-    [ text "module Main where"
-    , text "import Ivory.Compile.C.CmdlineFrontend"
-    , text "import Ivory.Serialize"
-    , text "import" <+> cat (punctuate dot (map text modulepath)) <> text ".Types"
-    , text "main :: IO ()"
-    , text "main = compile (serializeModule:typeModules) serializeArtifacts"
-    ]
-
+codegenTest modulepath =
+  artifactPath (intercalate "/" modulepath) $
+  artifactCabalFileTemplate P.getDataDir fname
+    [("module_path", intercalate "." modulepath )]
+  where
+  fname = "support/ivory/CodeGen.hs.template"
 

+ 1 - 1
src/Gidl/Backend/Ivory/Unpack.hs

@@ -12,4 +12,4 @@ unpackModule modulepath =
   artifactCabalFileTemplate P.getDataDir fname
     [("module_path", intercalate "." modulepath )]
   where
-  name = "support/ivory/Unpack.hs.template"
+  fname = "support/ivory/Unpack.hs.template"

+ 47 - 0
src/Gidl/Backend/Tower.hs

@@ -0,0 +1,47 @@
+module Gidl.Backend.Tower where
+
+import Data.List (intercalate)
+
+import Ivory.Artifact
+import Ivory.Artifact.Template
+
+import qualified Paths_gidl as P
+
+import Gidl.Types
+import Gidl.Interface
+import Gidl.Schema
+import Gidl.Backend.Cabal
+import Gidl.Backend.Ivory (dotwords, ivorySources)
+
+towerBackend :: TypeEnv -> InterfaceEnv -> String -> String -> [Artifact]
+towerBackend te ie pkgname namespace_raw =
+  [ cabalFileArtifact cf
+  , makefile
+  , defaultconf
+  , artifactPath "tests" (codegenTest namespace)
+  ] ++ map (artifactPath "src") sources
+  where
+  sources = isources ++ []
+
+  namespace = dotwords namespace_raw
+  isources = ivorySources te ie (namespace ++ ["Ivory"])
+
+  cf = (defaultCabalFile pkgname cabalmods deps) { executables = [ cg_exe ] }
+  cabalmods = map (filePathToPackage . artifactFileName) sources
+  deps = words "ivory ivory-stdlib ivory-serialize tower"
+  cg_exe = defaultCabalExe (pkgname ++ "-gen") "CodeGen.hs"
+            (deps ++ (words "tower-config tower-freertos-stm32") ++ [pkgname])
+
+makefile :: Artifact
+makefile = artifactCabalFile P.getDataDir "support/tower/Makefile"
+
+defaultconf :: Artifact
+defaultconf = artifactCabalFile P.getDataDir "support/tower/default.conf"
+
+codegenTest :: [String] -> Artifact
+codegenTest modulepath =
+  artifactCabalFileTemplate P.getDataDir fname
+    [("module_path", intercalate "." modulepath )]
+  where
+  fname = "support/tower/CodeGen.hs.template"
+

+ 9 - 0
support/ivory/CodeGen.hs.template

@@ -0,0 +1,9 @@
+module Main where
+
+import Ivory.Compile.C.CmdlineFrontend
+import Ivory.Serialize
+
+import $module_path$.Types
+
+main :: IO ()
+main = compile (serializeModule:typeModules) serializeArtifacts

+ 17 - 0
support/ivory/Makefile

@@ -0,0 +1,17 @@
+IVORY_REPO ?= ../../../ivory
+
+default:
+	cabal build
+
+create-sandbox:
+	cabal sandbox init
+	cabal sandbox add-source $(IVORY_REPO)/ivory
+	cabal sandbox add-source $(IVORY_REPO)/ivory-artifact
+	cabal sandbox add-source $(IVORY_REPO)/ivory-serialize
+	cabal sandbox add-source $(IVORY_REPO)/ivory-stdlib
+	cabal sandbox add-source $(IVORY_REPO)/ivory-opts
+	cabal sandbox add-source $(IVORY_REPO)/ivory-backend-c
+	cabal install --enable-tests --dependencies-only
+
+test:
+	cabal run -- --src-dir=codegen-out

+ 0 - 1
support/ivory/Unpack.hs.template

@@ -1,4 +1,3 @@
-
 {-# LANGUAGE DataKinds #-}
 {-# LANGUAGE RankNTypes #-}
 {-# LANGUAGE ScopedTypeVariables #-}

+ 23 - 0
support/tower/CodeGen.hs.template

@@ -0,0 +1,23 @@
+module Main where
+
+import Ivory.Tower
+import Ivory.Tower.Config
+import Ivory.Tower.Compile
+import Ivory.OS.FreeRTOS.Tower.STM32
+
+import Ivory.Serialize
+import $module_path$.Ivory.Types (typeModules)
+
+main :: IO ()
+main = towerCompile p app
+  where p topts = do
+            cfg <- getConfig topts (stm32ConfigParser (stm32f405Defaults 24))
+            return (stm32FreeRTOS id cfg)
+
+app :: Tower e ()
+app = do
+  towerModule serializeModule
+  mapM_ towerArtifact serializeArtifacts
+  mapM_ towerModule typeModules
+  mapM_ towerDepends typeModules
+

+ 27 - 0
support/tower/Makefile

@@ -0,0 +1,27 @@
+IVORY_REPO ?= ../../../ivory
+TOWER_REPO ?= ../../../tower
+BSP_REPO ?= ../../../ivory-tower-stm32
+
+default:
+	cabal build
+
+create-sandbox:
+	cabal sandbox init
+	cabal sandbox add-source $(IVORY_REPO)/ivory
+	cabal sandbox add-source $(IVORY_REPO)/ivory-artifact
+	cabal sandbox add-source $(IVORY_REPO)/ivory-serialize
+	cabal sandbox add-source $(IVORY_REPO)/ivory-stdlib
+	cabal sandbox add-source $(IVORY_REPO)/ivory-opts
+	cabal sandbox add-source $(IVORY_REPO)/ivory-hw
+	cabal sandbox add-source $(IVORY_REPO)/ivory-backend-c
+	cabal sandbox add-source $(TOWER_REPO)/tower-config
+	cabal sandbox add-source $(TOWER_REPO)/tower
+	cabal sandbox add-source $(BSP_REPO)/ivory-freertos-bindings
+	cabal sandbox add-source $(BSP_REPO)/tower-freertos-stm32
+	cabal sandbox add-source $(BSP_REPO)/ivory-bsp-stm32
+	cabal sandbox add-source $(BSP_REPO)/ivory-bsp-tests
+	cabal install --enable-tests --dependencies-only
+
+test:
+	cabal run -- --src-dir=codegen-out
+	make -C codegen-out

+ 5 - 0
support/tower/default.conf

@@ -0,0 +1,5 @@
+[stm32]
+bootloader = "none"
+processor = "stm32f405"
+xtalMHz = 24
+sysclkMHz = 168

+ 1 - 0
tests/.gitignore

@@ -1,2 +1,3 @@
 gidl-haskell-backend-test
 gidl-ivory-backend-test
+gidl-tower-backend-test