rewire-backend-2.8: A Haskell-to-Verilog/VHDL compiler, the Hyle backend
Safe HaskellSafe
LanguageHaskell2010

ReWire.Cryptol.Syntax

Description

Abstract syntax for the fragment of Cryptol emitted by the Cryptol backend (ReWire.Hyle.ToCryptol). The generated file is a self-contained named module (Cryptol allows loading it under any file name): a few helper definitions implementing Hyle primitives, an optional parameter block declaring externs as uninterpreted functions, and one function per Hyle defn. Helper names contain a tick (rw'resize) so they can never collide with generated names (see cryptolName).

Synopsis

Documentation

type Name = Text Source #

type Size = Word Source #

cryptolName :: Text -> Name Source #

Maps a Hyle name to a valid Cryptol identifier body: any character outside [A-Za-z0-9_] becomes an underscore. Callers are expected to prepend a prefix (rw_), so the first character doesn't matter and the result can never collide with a Cryptol keyword, a Prelude name, or the tick-containing helper names. The one unprefixed use is the module name (ReWire.Hyle.ToCryptol via modName), where a keyword-named --top would emit an invalid module header.

data Module Source #

Constructors

Module 

Fields

Instances

Instances details
Show Module Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Eq Module Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Module -> Module -> Bool #

(/=) :: Module -> Module -> Bool #

Pretty Module Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

pretty :: Module -> Doc ann #

prettyList :: [Module] -> Doc ann

helpers :: Doc an Source #

Helper definitions emitted with every module, implementing Hyle primitives that don't map directly to a Cryptol operator. rw'resize truncates or zero-extends to the new width.

data Param Source #

An uninterpreted function declared in a parameter block: name, argument widths, result width.

Constructors

Param !Name ![Size] !Size 

Instances

Instances details
Show Param Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

showsPrec :: Int -> Param -> ShowS #

show :: Param -> String #

showList :: [Param] -> ShowS #

Eq Param Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Param -> Param -> Bool #

(/=) :: Param -> Param -> Bool #

data Len Source #

Sequence lengths in types: the device's quantified variable n, or 1 + n.

Constructors

LenVar 
LenSucc 

Instances

Instances details
Show Len Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

showsPrec :: Int -> Len -> ShowS #

show :: Len -> String #

showList :: [Len] -> ShowS #

Eq Len Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Len -> Len -> Bool #

(/=) :: Len -> Len -> Bool #

Pretty Len Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

pretty :: Len -> Doc ann #

prettyList :: [Len] -> Doc ann

data Ty Source #

Constructors

TBits !Size
[w]
TSeq !Len !Ty
[n]t

Instances

Instances details
Show Ty Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

showsPrec :: Int -> Ty -> ShowS #

show :: Ty -> String #

showList :: [Ty] -> ShowS #

Eq Ty Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Ty -> Ty -> Bool #

(/=) :: Ty -> Ty -> Bool #

Pretty Ty Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

pretty :: Ty -> Doc ann #

prettyList :: [Ty] -> Doc ann

ppFun :: [Ty] -> Ty -> Doc an Source #

data Defn Source #

Constructors

Defn 

Fields

Instances

Instances details
Show Defn Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

showsPrec :: Int -> Defn -> ShowS #

show :: Defn -> String #

showList :: [Defn] -> ShowS #

Eq Defn Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Defn -> Defn -> Bool #

(/=) :: Defn -> Defn -> Bool #

Pretty Defn Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

pretty :: Defn -> Doc ann #

prettyList :: [Defn] -> Doc ann

data Bind Source #

A where-binding with an explicit type annotation.

Constructors

Bind !Name !Ty !Exp 

Instances

Instances details
Show Bind Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

showsPrec :: Int -> Bind -> ShowS #

show :: Bind -> String #

showList :: [Bind] -> ShowS #

Eq Bind Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Bind -> Bind -> Bool #

(/=) :: Bind -> Bind -> Bool #

Pretty Bind Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

pretty :: Bind -> Doc ann #

prettyList :: [Bind] -> Doc ann

data Exp Source #

Constructors

Lit !BV

Sized hex/binary literal (or (zero : [0])).

Var !Name 
Call !Name ![Exp]

Prefix application: f e1 e2.

TCall !Name !Natural ![Exp]

Application with a type argument: f`{k} e1 e2.

BinOp !Name !Exp !Exp 
UnOp !Name !Exp 
Index !Exp !Natural
e @ k
If !Exp !Exp !Exp 
Sing !Exp

Bit to [1]: [e].

Comp !Exp ![(Name, Exp)]
[ e | x <- e1 | y <- e2 ]
SeqLit ![Exp]
[e1, e2]

Instances

Instances details
Show Exp Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

showsPrec :: Int -> Exp -> ShowS #

show :: Exp -> String #

showList :: [Exp] -> ShowS #

Eq Exp Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

(==) :: Exp -> Exp -> Bool #

(/=) :: Exp -> Exp -> Bool #

Pretty Exp Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

pretty :: Exp -> Doc ann #

prettyList :: [Exp] -> Doc ann

Parenless Exp Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

parenless :: Exp -> Bool Source #

class Parenless a where Source #

Methods

parenless :: a -> Bool Source #

Instances

Instances details
Parenless Exp Source # 
Instance details

Defined in ReWire.Cryptol.Syntax

Methods

parenless :: Exp -> Bool Source #

mparens :: (Pretty a, Parenless a) => a -> Doc an Source #

ppLit :: BV -> Doc an Source #

Hex when the width is a multiple of four (Cryptol hex literals have a width of exactly four bits per digit), binary otherwise.

slice :: Size -> Size -> Size -> Exp -> Exp Source #

Slicing, MSB-first (Cryptol's bit order): k bits starting at MSB offset off out of a w-bit expression. Skips take/drop when they would be the identity.

resize :: Size -> Exp -> Exp Source #

Truncate-or-zero-extend to the given width (the trunc and zext coercions), as implemented by the emitted rw'resize helper.

cat :: [Exp] -> Exp Source #

Concatenation, filtering zero-width parts.