2022-12-06 13:33:20 +03:00
|
|
|
module Commands.Dev.Asm.Compile where
|
|
|
|
|
|
|
|
import Commands.Base
|
|
|
|
import Commands.Dev.Asm.Compile.Options
|
|
|
|
import Commands.Extra.Compile qualified as Compile
|
|
|
|
import Data.Text.IO qualified as TIO
|
|
|
|
import Juvix.Compiler.Asm.Translation.FromSource qualified as Asm
|
|
|
|
import Juvix.Compiler.Backend qualified as Backend
|
|
|
|
import Juvix.Compiler.Backend.C qualified as C
|
|
|
|
|
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
|
|
|
runCommand :: forall r. (Members '[Embed IO, App] r) => AsmCompileOptions -> Sem r ()
|
2022-12-06 13:33:20 +03:00
|
|
|
runCommand opts = do
|
2022-12-20 15:05:40 +03:00
|
|
|
file <- getFile
|
2023-04-19 17:56:48 +03:00
|
|
|
ep <- getEntryPoint (AppPath (preFileFromAbs file) True)
|
2023-03-27 11:42:27 +03:00
|
|
|
tgt <- getTarget (opts ^. compileTarget)
|
|
|
|
let entryPoint :: EntryPoint
|
|
|
|
entryPoint =
|
|
|
|
ep
|
|
|
|
{ _entryPointTarget = tgt,
|
|
|
|
_entryPointDebug = opts ^. compileDebug
|
|
|
|
}
|
2022-12-20 15:05:40 +03:00
|
|
|
s <- embed (readFile (toFilePath file))
|
|
|
|
case Asm.runParser (toFilePath file) s of
|
2022-12-06 13:33:20 +03:00
|
|
|
Left err -> exitJuvixError (JuvixError err)
|
2023-03-14 18:24:07 +03:00
|
|
|
Right tab -> do
|
2023-03-27 11:42:27 +03:00
|
|
|
case run $ runReader entryPoint $ runError $ asmToMiniC tab of
|
2023-03-14 18:24:07 +03:00
|
|
|
Left err -> exitJuvixError err
|
|
|
|
Right C.MiniCResult {..} -> do
|
|
|
|
buildDir <- askBuildDir
|
|
|
|
ensureDir buildDir
|
|
|
|
cFile <- inputCFile file
|
|
|
|
embed $ TIO.writeFile (toFilePath cFile) _resultCCode
|
2023-05-24 16:42:20 +03:00
|
|
|
Compile.runCommand opts {_compileInputFile = Just (AppPath (preFileFromAbs cFile) False)}
|
2022-12-06 13:33:20 +03:00
|
|
|
where
|
2022-12-20 15:05:40 +03:00
|
|
|
getFile :: Sem r (Path Abs File)
|
2023-05-24 16:42:20 +03:00
|
|
|
getFile = getMainFile (opts ^. compileInputFile)
|
2022-12-06 13:33:20 +03:00
|
|
|
|
2023-03-27 11:42:27 +03:00
|
|
|
getTarget :: CompileTarget -> Sem r Backend.Target
|
|
|
|
getTarget = \case
|
2023-03-14 18:24:07 +03:00
|
|
|
TargetWasm32Wasi -> return Backend.TargetCWasm32Wasi
|
|
|
|
TargetNative64 -> return Backend.TargetCNative64
|
|
|
|
TargetGeb -> exitMsg (ExitFailure 1) "error: GEB target not supported for JuvixAsm"
|
2023-05-19 15:43:45 +03:00
|
|
|
TargetVampIR -> exitMsg (ExitFailure 1) "error: VampIR target not supported for JuvixAsm"
|
2023-03-14 18:24:07 +03:00
|
|
|
TargetCore -> exitMsg (ExitFailure 1) "error: JuvixCore target not supported for JuvixAsm"
|
|
|
|
TargetAsm -> exitMsg (ExitFailure 1) "error: JuvixAsm target not supported for JuvixAsm"
|
2022-12-06 13:33:20 +03:00
|
|
|
|
Update CI to install Smoke, Github actions, and Makefile fixes (#1735)
This PR adds some maintenance at different levels to the CI config, the
Make file, and formatting.
- Most of the actions used by the CI related to haskell, ormolu, hlint
and pre-commit have been updated because Github requires NodeJS 16. This
change removes all the old warnings related to nodeJs.
In the case of ormolu, the new version makes us format some files that
were not formatted before, similarly with hlint.
- The CI has been updated to use the latest version of the Smoke testing
framework, which introduced installation of the dependencies for Linux
(libicu66) and macOS (icu4c) in the CI. In the case of macOS, the CI
uses a binary for smoke. For Linux, we use stack to build smoke from the
source. The source here is in a fork of [the official Smoke
repo](https://github.com/SamirTalwar/smoke). Such includes some
features/changes that are not yet in the official repo.
- The Makefile runs the ormolu and hlint targets using as a path for the
binaries the environment variables ORMOLU and HLINT. Thus, export those
variables in your environment before running `make check,` `make format`
or `make hlint`. Otherwise, the Makefile will use the binaries provided
by `stack`.
Co-authored-by: Paul Cadman <git@paulcadman.dev>
2023-01-24 13:50:23 +03:00
|
|
|
inputCFile :: (Members '[App] r) => Path Abs File -> Sem r (Path Abs File)
|
2022-12-20 15:05:40 +03:00
|
|
|
inputCFile inputFileCompile = do
|
2023-01-06 19:54:13 +03:00
|
|
|
buildDir <- askBuildDir
|
|
|
|
return (buildDir <//> outputMiniCFile)
|
2022-12-06 13:33:20 +03:00
|
|
|
where
|
2022-12-20 15:05:40 +03:00
|
|
|
outputMiniCFile :: Path Rel File
|
|
|
|
outputMiniCFile = replaceExtension' ".c" (filename inputFileCompile)
|