aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriFuzz/Verilog/AST.hs
diff options
context:
space:
mode:
authorYann Herklotz <git@ymhg.org>2019-05-13 14:58:34 +0100
committerYann Herklotz <git@ymhg.org>2019-05-13 14:58:34 +0100
commit4ecf423075f146ee0a1a452a5658e7a13f99aa9b (patch)
tree36ba41829cee08d217e419eeff4ce65583d89854 /src/VeriFuzz/Verilog/AST.hs
parent426f0d71eca2dc578e4258df05be296003c3e4cb (diff)
downloadverismith-4ecf423075f146ee0a1a452a5658e7a13f99aa9b.tar.gz
verismith-4ecf423075f146ee0a1a452a5658e7a13f99aa9b.zip
Use NonEmpty to represent concatenation
Diffstat (limited to 'src/VeriFuzz/Verilog/AST.hs')
-rw-r--r--src/VeriFuzz/Verilog/AST.hs24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/VeriFuzz/Verilog/AST.hs b/src/VeriFuzz/Verilog/AST.hs
index 8adf58e..1957cb5 100644
--- a/src/VeriFuzz/Verilog/AST.hs
+++ b/src/VeriFuzz/Verilog/AST.hs
@@ -138,11 +138,11 @@ module VeriFuzz.Verilog.AST
)
where
-import Control.Lens
+import Control.Lens hiding ((<|))
import Data.Data
import Data.Data.Lens
import Data.Functor.Foldable.TH (makeBaseFunctor)
-import Data.List.NonEmpty (NonEmpty)
+import Data.List.NonEmpty (NonEmpty (..), (<|))
import Data.String (IsString, fromString)
import Data.Text (Text)
import Data.Traversable (sequenceA)
@@ -218,7 +218,7 @@ data Expr = Number {-# UNPACK #-} !BitVec
| VecSelect {-# UNPACK #-} !Identifier !Expr
| RangeSelect {-# UNPACK #-} !Identifier !Range
-- ^ Symbols
- | Concat ![Expr]
+ | Concat !(NonEmpty Expr)
-- ^ Bit-wise concatenation of expressions represented by braces.
| UnOp !UnaryOperator !Expr
| BinOp !Expr !BinaryOperator !Expr
@@ -238,12 +238,12 @@ instance Num Expr where
instance Semigroup Expr where
(Concat a) <> (Concat b) = Concat $ a <> b
- (Concat a) <> b = Concat $ a <> [b]
- a <> (Concat b) = Concat $ a : b
- a <> b = Concat [a, b]
+ (Concat a) <> b = Concat $ a <> (b :| [])
+ a <> (Concat b) = Concat $ a <| b
+ a <> b = Concat $ a <| b :| []
instance Monoid Expr where
- mempty = Concat []
+ mempty = Number 0
instance IsString Expr where
fromString = Str . fromString
@@ -254,7 +254,7 @@ instance Plated Expr where
-- | Constant expression, which are known before simulation at compile time.
data ConstExpr = ConstNum { _constNum :: {-# UNPACK #-} !BitVec }
| ParamId { _constParamId :: {-# UNPACK #-} !Identifier }
- | ConstConcat { _constConcat :: ![ConstExpr] }
+ | ConstConcat { _constConcat :: !(NonEmpty ConstExpr) }
| ConstUnOp { _constUnOp :: !UnaryOperator
, _constPrim :: !ConstExpr
}
@@ -299,12 +299,12 @@ instance Num ConstExpr where
instance Semigroup ConstExpr where
(ConstConcat a) <> (ConstConcat b) = ConstConcat $ a <> b
- (ConstConcat a) <> b = ConstConcat $ a <> [b]
- a <> (ConstConcat b) = ConstConcat $ a : b
- a <> b = ConstConcat [a, b]
+ (ConstConcat a) <> b = ConstConcat $ a <> (b :| [])
+ a <> (ConstConcat b) = ConstConcat $ a <| b
+ a <> b = ConstConcat $ a <| b :| []
instance Monoid ConstExpr where
- mempty = ConstConcat []
+ mempty = ConstNum 0
instance IsString ConstExpr where
fromString = ConstStr . fromString