Tower.hs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module Gidl.Backend.Tower where
  2. import Data.List (intercalate)
  3. import Ivory.Artifact
  4. import Ivory.Artifact.Template
  5. import qualified Paths_gidl as P
  6. import Gidl.Types
  7. import Gidl.Interface
  8. import Gidl.Schema
  9. import Gidl.Backend.Cabal
  10. import Gidl.Backend.Ivory (dotwords, ivorySources)
  11. import Gidl.Backend.Tower.Interface
  12. towerBackend :: TypeEnv -> InterfaceEnv -> String -> String -> [Artifact]
  13. towerBackend te ie pkgname namespace_raw =
  14. [ cabalFileArtifact cf
  15. , makefile
  16. , defaultconf
  17. , artifactPath "tests" (codegenTest namespace)
  18. ] ++ map (artifactPath "src") sources
  19. where
  20. namespace = dotwords namespace_raw
  21. sources = isources ++ tsources
  22. tsources = towerSources ie (namespace ++ ["Tower"])
  23. isources = ivorySources te ie (namespace ++ ["Ivory"])
  24. cf = (defaultCabalFile pkgname cabalmods deps) { executables = [ cg_exe ] }
  25. cabalmods = map (filePathToPackage . artifactFileName) sources
  26. deps = words "ivory ivory-stdlib ivory-serialize tower"
  27. cg_exe = defaultCabalExe (pkgname ++ "-gen") "CodeGen.hs"
  28. (deps ++ (words "tower-config tower-freertos-stm32") ++ [pkgname])
  29. towerSources :: InterfaceEnv -> [String] -> [Artifact]
  30. towerSources (InterfaceEnv ie) namespace = towerInterfaces
  31. where
  32. towerInterfaces = concat
  33. [ [ interfaceModule (namespace ++ ["Tower", "Interface"]) i (producerSchema i)
  34. , interfaceModule (namespace ++ ["Tower", "Interface"]) i (consumerSchema i) ]
  35. | (_iname, i) <- ie ]
  36. makefile :: Artifact
  37. makefile = artifactCabalFile P.getDataDir "support/tower/Makefile"
  38. defaultconf :: Artifact
  39. defaultconf = artifactCabalFile P.getDataDir "support/tower/default.conf"
  40. codegenTest :: [String] -> Artifact
  41. codegenTest modulepath =
  42. artifactCabalFileTemplate P.getDataDir fname
  43. [("module_path", intercalate "." modulepath )]
  44. where
  45. fname = "support/tower/CodeGen.hs.template"