-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JuvixReg to CASM translation (#2671)
* Closes #2562 Checklist --------- - [x] Translation from JuvixReg to CASM - [x] CASM runtime - [x] Juvix to CASM pipeline: combine the right transformations and check prerequisites - [x] CLI commands: add target `casm` to the `compile` commands - [x] Tests: - [x] Test the translation from JuvixReg to CASM - [x] Test the entire pipeline from Juvix to CASM
- Loading branch information
Showing
254 changed files
with
6,140 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
module Commands.Dev.Reg where | ||
|
||
import Commands.Base | ||
import Commands.Dev.Reg.Compile as Compile | ||
import Commands.Dev.Reg.Options | ||
import Commands.Dev.Reg.Read as Read | ||
import Commands.Dev.Reg.Run as Run | ||
|
||
runCommand :: forall r. (Members '[EmbedIO, App, TaggedLock] r) => RegCommand -> Sem r () | ||
runCommand = \case | ||
Compile opts -> Compile.runCommand opts | ||
Run opts -> Run.runCommand opts | ||
Read opts -> Read.runCommand opts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
module Commands.Dev.Reg.Compile where | ||
|
||
import Commands.Base | ||
import Commands.Dev.Reg.Compile.Options | ||
import Commands.Extra.Compile qualified as Compile | ||
import Juvix.Compiler.Backend qualified as Backend | ||
import Juvix.Compiler.Backend.C qualified as C | ||
import Juvix.Compiler.Casm.Data.Result qualified as Casm | ||
import Juvix.Compiler.Casm.Pretty qualified as Casm | ||
import Juvix.Compiler.Reg.Translation.FromSource qualified as Reg | ||
import Juvix.Prelude.Pretty | ||
|
||
runCommand :: forall r. (Members '[EmbedIO, App, TaggedLock] r) => CompileOptions -> Sem r () | ||
runCommand opts = do | ||
file <- getFile | ||
s <- readFile file | ||
case Reg.runParser file s of | ||
Left err -> exitJuvixError (JuvixError err) | ||
Right tab -> do | ||
ep <- getEntryPoint (AppPath (preFileFromAbs file) True) | ||
tgt <- getTarget (opts ^. compileTarget) | ||
let entryPoint :: EntryPoint | ||
entryPoint = | ||
ep | ||
{ _entryPointTarget = tgt, | ||
_entryPointDebug = opts ^. compileDebug | ||
} | ||
case opts ^. compileTarget of | ||
TargetCasm -> do | ||
casmFile <- Compile.outputFile opts file | ||
r <- | ||
runReader entryPoint | ||
. runError @JuvixError | ||
. regToCasm | ||
$ tab | ||
Casm.Result {..} <- getRight r | ||
writeFileEnsureLn casmFile (toPlainText $ Casm.ppProgram _resultCode) | ||
_ -> | ||
case run $ runReader entryPoint $ runError $ regToMiniC tab of | ||
Left err -> exitJuvixError err | ||
Right C.MiniCResult {..} -> do | ||
buildDir <- askBuildDir | ||
ensureDir buildDir | ||
cFile <- inputCFile file | ||
writeFileEnsureLn cFile _resultCCode | ||
outfile <- Compile.outputFile opts file | ||
Compile.runCommand | ||
opts | ||
{ _compileInputFile = Just (AppPath (preFileFromAbs cFile) False), | ||
_compileOutputFile = Just (AppPath (preFileFromAbs outfile) False) | ||
} | ||
where | ||
getFile :: Sem r (Path Abs File) | ||
getFile = getMainFile (opts ^. compileInputFile) | ||
|
||
getTarget :: CompileTarget -> Sem r Backend.Target | ||
getTarget = \case | ||
TargetWasm32Wasi -> return Backend.TargetCWasm32Wasi | ||
TargetNative64 -> return Backend.TargetCNative64 | ||
TargetCasm -> return Backend.TargetCairo | ||
TargetReg -> err "JuvixReg" | ||
TargetNockma -> err "Nockma" | ||
TargetAnoma -> err "Anoma" | ||
TargetTree -> err "JuvixTree" | ||
TargetGeb -> err "GEB" | ||
TargetVampIR -> err "VampIR" | ||
TargetCore -> err "JuvixCore" | ||
TargetAsm -> err "JuvixAsm" | ||
where | ||
err :: Text -> Sem r a | ||
err tgt = exitMsg (ExitFailure 1) ("error: " <> tgt <> " target not supported for JuvixReg") | ||
|
||
inputCFile :: (Members '[App] r) => Path Abs File -> Sem r (Path Abs File) | ||
inputCFile inputFileCompile = do | ||
buildDir <- askBuildDir | ||
return (buildDir <//> outputMiniCFile) | ||
where | ||
outputMiniCFile :: Path Rel File | ||
outputMiniCFile = replaceExtension' ".c" (filename inputFileCompile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Commands.Dev.Reg.Compile.Options | ||
( module Commands.Dev.Reg.Compile.Options, | ||
module Commands.Extra.Compile.Options, | ||
) | ||
where | ||
|
||
import Commands.Extra.Compile.Options | ||
import CommonOptions | ||
import Data.List.NonEmpty qualified as NonEmpty | ||
|
||
regSupportedTargets :: NonEmpty CompileTarget | ||
regSupportedTargets = | ||
NonEmpty.fromList | ||
[ TargetWasm32Wasi, | ||
TargetNative64, | ||
TargetCasm | ||
] | ||
|
||
parseRegCompileOptions :: Parser CompileOptions | ||
parseRegCompileOptions = | ||
parseCompileOptions | ||
regSupportedTargets | ||
(parseInputFile FileExtJuvixReg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.