diff options
author | Yann Herklotz <git@ymhg.org> | 2019-05-10 17:41:44 +0100 |
---|---|---|
committer | Yann Herklotz <git@ymhg.org> | 2019-05-10 17:41:44 +0100 |
commit | 1bf5b56da8df267fd33e738b53e29e832854856b (patch) | |
tree | 83b451ca816e9fffc3faadef3ed37054549820f6 /src/VeriFuzz/Verilog/AST.hs | |
parent | 8241ebad9374187b20ee0fdd43029a2a5ddfbb4e (diff) | |
download | verismith-1bf5b56da8df267fd33e738b53e29e832854856b.tar.gz verismith-1bf5b56da8df267fd33e738b53e29e832854856b.zip |
Add constant expression to expression conversion and vice versa
Diffstat (limited to 'src/VeriFuzz/Verilog/AST.hs')
-rw-r--r-- | src/VeriFuzz/Verilog/AST.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/VeriFuzz/Verilog/AST.hs b/src/VeriFuzz/Verilog/AST.hs index c4d889b..30634c0 100644 --- a/src/VeriFuzz/Verilog/AST.hs +++ b/src/VeriFuzz/Verilog/AST.hs @@ -59,6 +59,8 @@ module VeriFuzz.Verilog.AST , Expr(..) , ConstExpr(..) , ConstExprF(..) + , constToExpr + , exprToConst , Range(..) , constNum , constParamId @@ -265,6 +267,25 @@ data ConstExpr = ConstNum { _constNum :: {-# UNPACK #-} !BitVec } | ConstStr { _constStr :: {-# UNPACK #-} !Text } deriving (Eq, Show, Ord, Data) +constToExpr :: ConstExpr -> Expr +constToExpr (ConstNum a) = Number a +constToExpr (ParamId a) = Id a +constToExpr (ConstConcat a) = Concat $ fmap constToExpr a +constToExpr (ConstUnOp a b) = UnOp a $ constToExpr b +constToExpr (ConstBinOp a b c) = BinOp (constToExpr a) b $ constToExpr c +constToExpr (ConstCond a b c) = Cond (constToExpr a) (constToExpr b) $ constToExpr c +constToExpr (ConstStr a) = Str a + +exprToConst :: Expr -> ConstExpr +exprToConst (Number a) = ConstNum a +exprToConst (Id a) = ParamId a +exprToConst (Concat a) = ConstConcat $ fmap exprToConst a +exprToConst (UnOp a b) = ConstUnOp a $ exprToConst b +exprToConst (BinOp a b c) = ConstBinOp (exprToConst a) b $ exprToConst c +exprToConst (Cond a b c) = ConstCond (exprToConst a) (exprToConst b) $ exprToConst c +exprToConst (Str a) = ConstStr a +exprToConst _ = error "Not a constant expression" + instance Num ConstExpr where a + b = ConstBinOp a BinPlus b a - b = ConstBinOp a BinMinus b |