|
1 | 1 | {-# LANGUAGE CPP #-} |
2 | 2 | -- editorconfig-checker-disable-file |
| 3 | +{-# LANGUAGE CPP #-} |
3 | 4 | {-# LANGUAGE GADTs #-} |
4 | 5 | {-# LANGUAGE LambdaCase #-} |
5 | 6 | {-# LANGUAGE OverloadedStrings #-} |
|
11 | 12 |
|
12 | 13 | module PlutusTx.Options where |
13 | 14 |
|
| 15 | +{- ORMOLU_DISABLE -} |
14 | 16 | import PlutusCore.Error as PLC |
15 | 17 | import PlutusCore.Parser as PLC |
16 | 18 | import PlutusCore.Quote as PLC |
@@ -44,6 +46,11 @@ import Prettyprinter |
44 | 46 | import Text.Read (readMaybe) |
45 | 47 | import Type.Reflection |
46 | 48 |
|
| 49 | +#ifdef CERTIFY |
| 50 | +import Text.Megaparsec.Char (alphaNumChar, char, upperChar) |
| 51 | +import Control.Applicative (many, optional, (<|>)) |
| 52 | +#endif |
| 53 | + |
47 | 54 | data PluginOptions = PluginOptions |
48 | 55 | { _posPlcTargetVersion :: PLC.Version |
49 | 56 | , _posDoTypecheck :: Bool |
@@ -82,6 +89,9 @@ data PluginOptions = PluginOptions |
82 | 89 | -- Which effectively ignores the trace text. |
83 | 90 | _posRemoveTrace :: Bool |
84 | 91 | , _posDumpCompilationTrace :: Bool |
| 92 | +#ifdef CERTIFY |
| 93 | + , _posCertify :: Maybe String |
| 94 | +#endif |
85 | 95 | } |
86 | 96 |
|
87 | 97 | makeLenses ''PluginOptions |
@@ -314,6 +324,20 @@ pluginOptions = |
314 | 324 | , let k = "dump-compilation-trace" |
315 | 325 | desc = "Dump compilation trace for debugging" |
316 | 326 | in (k, PluginOption typeRep (setTrue k) posDumpCompilationTrace desc []) |
| 327 | +#ifdef CERTIFY |
| 328 | + , let k = "certify" |
| 329 | + desc = |
| 330 | + "Produce a certificate for the compiled program, with the given name. " |
| 331 | + <> "This certificate provides evidence that the compiler optimizations have " |
| 332 | + <> "preserved the functional behavior of the original program. " |
| 333 | + <> "Currently, this is only supported for the UPLC compilation pipeline." |
| 334 | + p = |
| 335 | + optional $ do |
| 336 | + firstC <- upperChar |
| 337 | + rest <- many (alphaNumChar <|> char '_' <|> char '\\') |
| 338 | + pure (firstC : rest) |
| 339 | + in (k, PluginOption typeRep (plcParserOption p k) posCertify desc []) |
| 340 | +#endif |
317 | 341 | ] |
318 | 342 |
|
319 | 343 | flag :: (a -> a) -> OptionKey -> Maybe OptionValue -> Validation ParseError (a -> a) |
@@ -387,6 +411,9 @@ defaultPluginOptions = |
387 | 411 | , _posPreserveLogging = True |
388 | 412 | , _posRemoveTrace = False |
389 | 413 | , _posDumpCompilationTrace = False |
| 414 | +#ifdef CERTIFY |
| 415 | + , _posCertify = Nothing |
| 416 | +#endif |
390 | 417 | } |
391 | 418 |
|
392 | 419 | processOne |
|
0 commit comments