1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 10:03:22 +03:00
juvix/app/Commands/Dev/Asm/Validate.hs

29 lines
1.0 KiB
Haskell
Raw Normal View History

2022-09-29 18:44:55 +03:00
module Commands.Dev.Asm.Validate where
import Commands.Base
import Commands.Dev.Asm.Validate.Options
import Juvix.Compiler.Asm.Pretty qualified as Asm
import Juvix.Compiler.Asm.Transformation.Validate qualified as Asm
2022-09-29 18:44:55 +03:00
import Juvix.Compiler.Asm.Translation.FromSource qualified as Asm
runCommand :: forall r. (Members '[Embed IO, App] r) => AsmValidateOptions -> Sem r ()
2022-09-29 18:44:55 +03:00
runCommand opts = do
2022-12-20 15:05:40 +03:00
afile :: Path Abs File <- someBaseToAbs' file
s <- embed (readFile (toFilePath afile))
case Asm.runParser (toFilePath afile) s of
2022-09-29 18:44:55 +03:00
Left err -> exitJuvixError (JuvixError err)
Right tab -> do
case Asm.validate' tab of
2022-09-29 18:44:55 +03:00
Just err ->
exitJuvixError (JuvixError err)
Nothing ->
if
| opts ^. asmValidateNoPrint ->
exitMsg ExitSuccess "validation succeeded"
| otherwise -> do
renderStdOut (Asm.ppOutDefault tab tab)
exitMsg ExitSuccess ""
2022-09-29 18:44:55 +03:00
where
2022-12-20 15:05:40 +03:00
file :: SomeBase File
2022-09-29 18:44:55 +03:00
file = opts ^. asmValidateInputFile . pathPath