-
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.
This PR implements generic support for Cairo VM builtins. The calling convention in the generated CASM code is changed to allow for passing around the builtin pointers. Appropriate builtin initialization and finalization code is added. Support for specific builtins (e.g. Poseidon hash, range check, Elliptic Curve operation) still needs to be implemented in separate PRs. * Closes #2683
- Loading branch information
Showing
15 changed files
with
201 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Juvix.Compiler.Casm.Data.Builtins where | ||
|
||
import Juvix.Extra.Strings qualified as Str | ||
import Juvix.Prelude | ||
|
||
-- The order of the builtins must correspond to the "standard" builtin order in | ||
-- the Cairo VM implementation. See: | ||
-- https://github.com/lambdaclass/cairo-vm/blob/main/vm/src/vm/runners/cairo_runner.rs#L257 | ||
data Builtin | ||
= BuiltinRangeCheck | ||
| BuiltinEcOp | ||
| BuiltinPoseidon | ||
deriving stock (Show, Eq, Generic, Enum, Bounded) | ||
|
||
instance Hashable Builtin | ||
|
||
builtinsNum :: Int | ||
builtinsNum = length (allElements @Builtin) | ||
|
||
builtinName :: Builtin -> Text | ||
builtinName = \case | ||
BuiltinRangeCheck -> Str.cairoRangeCheck | ||
BuiltinEcOp -> Str.cairoEcOp | ||
BuiltinPoseidon -> Str.cairoPoseidon | ||
|
||
builtinNames :: [Text] | ||
builtinNames = map builtinName allElements |
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 Juvix.Compiler.Casm.Data.Result where | ||
|
||
import Juvix.Compiler.Casm.Data.Builtins | ||
import Juvix.Compiler.Casm.Data.LabelInfo | ||
import Juvix.Compiler.Casm.Language | ||
|
||
data Result = Result | ||
{ _resultLabelInfo :: LabelInfo, | ||
_resultCode :: [Instruction] | ||
_resultCode :: [Instruction], | ||
_resultBuiltins :: [Builtin] | ||
} | ||
|
||
makeLenses ''Result |
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.