2022-05-30 18:46:17 +03:00
|
|
|
module Commands.Compile where
|
|
|
|
|
2022-09-14 17:16:15 +03:00
|
|
|
import Commands.Base
|
|
|
|
import Commands.Compile.Options
|
2023-03-14 18:24:07 +03:00
|
|
|
import Commands.Dev.Core.Compile.Base qualified as Compile
|
|
|
|
import Commands.Extra.Compile qualified as Compile
|
2022-05-30 18:46:17 +03:00
|
|
|
import Data.Text.IO qualified as TIO
|
2023-03-14 18:24:07 +03:00
|
|
|
import Juvix.Compiler.Core qualified as Core
|
|
|
|
import Juvix.Compiler.Core.Pretty qualified as Core
|
2023-03-15 18:41:39 +03:00
|
|
|
import Juvix.Compiler.Core.Transformation.DisambiguateNames qualified as Core
|
2022-05-30 18:46:17 +03:00
|
|
|
|
2023-12-06 20:24:59 +03:00
|
|
|
runCommand :: (Members '[Embed IO, App, TaggedLock] r) => CompileOptions -> Sem r ()
|
2022-09-14 17:16:15 +03:00
|
|
|
runCommand opts@CompileOptions {..} = do
|
2023-05-24 16:42:20 +03:00
|
|
|
inputFile <- getMainFile _compileInputFile
|
|
|
|
Core.CoreResult {..} <- runPipeline (AppPath (preFileFromAbs inputFile) True) upToCore
|
2023-03-14 18:24:07 +03:00
|
|
|
let arg =
|
|
|
|
Compile.PipelineArg
|
|
|
|
{ _pipelineArgFile = inputFile,
|
|
|
|
_pipelineArgOptions = opts,
|
2023-12-30 22:15:35 +03:00
|
|
|
_pipelineArgModule = _coreResultModule
|
2023-03-14 18:24:07 +03:00
|
|
|
}
|
|
|
|
case _compileTarget of
|
|
|
|
TargetNative64 -> Compile.runCPipeline arg
|
|
|
|
TargetWasm32Wasi -> Compile.runCPipeline arg
|
|
|
|
TargetGeb -> Compile.runGebPipeline arg
|
2023-05-19 15:43:45 +03:00
|
|
|
TargetVampIR -> Compile.runVampIRPipeline arg
|
2023-03-14 18:24:07 +03:00
|
|
|
TargetCore -> writeCoreFile arg
|
|
|
|
TargetAsm -> Compile.runAsmPipeline arg
|
|
|
|
|
2023-12-06 20:24:59 +03:00
|
|
|
writeCoreFile :: (Members '[Embed IO, App, TaggedLock] r) => Compile.PipelineArg -> Sem r ()
|
2023-03-27 11:42:27 +03:00
|
|
|
writeCoreFile pa@Compile.PipelineArg {..} = do
|
|
|
|
entryPoint <- Compile.getEntry pa
|
2023-03-14 18:24:07 +03:00
|
|
|
coreFile <- Compile.outputFile _pipelineArgOptions _pipelineArgFile
|
2023-12-30 22:15:35 +03:00
|
|
|
r <- runReader entryPoint $ runError @JuvixError $ Core.toStored _pipelineArgModule
|
2023-03-20 12:13:07 +03:00
|
|
|
case r of
|
|
|
|
Left e -> exitJuvixError e
|
2023-12-30 22:15:35 +03:00
|
|
|
Right md ->
|
|
|
|
embed $ TIO.writeFile (toFilePath coreFile) (show $ Core.ppOutDefault (Core.disambiguateNames md ^. Core.moduleInfoTable))
|