mirror of https://github.com/zachjs/sv2v.git
minor cleanup in AST and Parse.y
This commit is contained in:
parent
d34dc7dfeb
commit
d36e5bfe0b
|
|
@ -10,7 +10,6 @@ module Language.SystemVerilog.AST
|
||||||
, UniOp (..)
|
, UniOp (..)
|
||||||
, BinOp (..)
|
, BinOp (..)
|
||||||
, Sense (..)
|
, Sense (..)
|
||||||
, Call (..)
|
|
||||||
, BlockItemDeclaration (..)
|
, BlockItemDeclaration (..)
|
||||||
, Parameter (..)
|
, Parameter (..)
|
||||||
, Localparam (..)
|
, Localparam (..)
|
||||||
|
|
@ -22,7 +21,6 @@ module Language.SystemVerilog.AST
|
||||||
, GenCase
|
, GenCase
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Data.Bits
|
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
@ -66,7 +64,6 @@ instance Show Direction where
|
||||||
show Output = "output"
|
show Output = "output"
|
||||||
show Inout = "inout"
|
show Inout = "inout"
|
||||||
|
|
||||||
-- TODO: Support for arrays (multi-dimensional, too!)
|
|
||||||
data Type
|
data Type
|
||||||
= Reg (Maybe Range)
|
= Reg (Maybe Range)
|
||||||
| Wire (Maybe Range)
|
| Wire (Maybe Range)
|
||||||
|
|
@ -177,7 +174,7 @@ data Expr
|
||||||
| IdentBit Identifier Expr
|
| IdentBit Identifier Expr
|
||||||
| Repeat Expr [Expr]
|
| Repeat Expr [Expr]
|
||||||
| Concat [Expr]
|
| Concat [Expr]
|
||||||
| ExprCall Call
|
| Call Identifier [Expr]
|
||||||
| UniOp UniOp Expr
|
| UniOp UniOp Expr
|
||||||
| BinOp BinOp Expr Expr
|
| BinOp BinOp Expr Expr
|
||||||
| Mux Expr Expr Expr
|
| Mux Expr Expr Expr
|
||||||
|
|
@ -265,26 +262,12 @@ instance Show Expr where
|
||||||
IdentRange a (b, c) -> printf "%s[%s:%s]" a (show b) (show c)
|
IdentRange a (b, c) -> printf "%s[%s:%s]" a (show b) (show c)
|
||||||
Repeat a b -> printf "{%s {%s}}" (show a) (commas $ map show b)
|
Repeat a b -> printf "{%s {%s}}" (show a) (commas $ map show b)
|
||||||
Concat a -> printf "{%s}" (commas $ map show a)
|
Concat a -> printf "{%s}" (commas $ map show a)
|
||||||
ExprCall a -> show a
|
Call a b -> printf "%s(%s)" a (commas $ map show b)
|
||||||
UniOp a b -> printf "(%s %s)" (show a) (show b)
|
UniOp a b -> printf "(%s %s)" (show a) (show b)
|
||||||
BinOp a b c -> printf "(%s %s %s)" (show b) (show a) (show c)
|
BinOp a b c -> printf "(%s %s %s)" (show b) (show a) (show c)
|
||||||
Mux a b c -> printf "(%s ? %s : %s)" (show a) (show b) (show c)
|
Mux a b c -> printf "(%s ? %s : %s)" (show a) (show b) (show c)
|
||||||
Bit a b -> printf "(%s [%d])" (show a) b
|
Bit a b -> printf "(%s [%d])" (show a) b
|
||||||
|
|
||||||
instance Bits Expr where
|
|
||||||
(.&.) = BinOp BWAnd
|
|
||||||
(.|.) = BinOp BWOr
|
|
||||||
xor = BinOp BWXor
|
|
||||||
complement = UniOp BWNot
|
|
||||||
isSigned _ = False
|
|
||||||
shift = error "Not supported: shift"
|
|
||||||
rotate = error "Not supported: rotate"
|
|
||||||
bitSize = error "Not supported: bitSize"
|
|
||||||
bitSizeMaybe = error "Not supported: bitSizeMaybe"
|
|
||||||
testBit = error "Not supported: testBit"
|
|
||||||
bit = error "Not supported: bit"
|
|
||||||
popCount = error "Not supported: popCount"
|
|
||||||
|
|
||||||
data LHS
|
data LHS
|
||||||
= LHS Identifier
|
= LHS Identifier
|
||||||
| LHSBit Identifier Expr
|
| LHSBit Identifier Expr
|
||||||
|
|
@ -323,10 +306,6 @@ instance Show Stmt where
|
||||||
show (If a b c ) = printf "if (%s)\n%s\nelse\n%s" (show a) (indent $ show b) (indent $ show c)
|
show (If a b c ) = printf "if (%s)\n%s\nelse\n%s" (show a) (indent $ show b) (indent $ show c)
|
||||||
show (Null ) = ";"
|
show (Null ) = ";"
|
||||||
|
|
||||||
-- It's not obvious to me how this can be done in a top level
|
|
||||||
--show (StmtCall a ) = printf "%s;" (show a)
|
|
||||||
-- | StmtCall Call
|
|
||||||
|
|
||||||
data BlockItemDeclaration
|
data BlockItemDeclaration
|
||||||
= BIDReg (Maybe Range) Identifier [Range]
|
= BIDReg (Maybe Range) Identifier [Range]
|
||||||
| BIDParameter Parameter
|
| BIDParameter Parameter
|
||||||
|
|
@ -345,11 +324,6 @@ type Case = ([Expr], Stmt)
|
||||||
showCase :: (Show x, Show y) => ([x], y) -> String
|
showCase :: (Show x, Show y) => ([x], y) -> String
|
||||||
showCase (a, b) = printf "%s:\n%s" (commas $ map show a) (indent $ show b)
|
showCase (a, b) = printf "%s:\n%s" (commas $ map show a) (indent $ show b)
|
||||||
|
|
||||||
data Call = Call Identifier [Expr] deriving Eq
|
|
||||||
|
|
||||||
instance Show Call where
|
|
||||||
show (Call a b) = printf "%s(%s)" a (commas $ map show b)
|
|
||||||
|
|
||||||
data Sense
|
data Sense
|
||||||
= Sense LHS
|
= Sense LHS
|
||||||
| SenseOr Sense Sense
|
| SenseOr Sense Sense
|
||||||
|
|
|
||||||
|
|
@ -375,13 +375,9 @@ Number :: { String }
|
||||||
String :: { String }
|
String :: { String }
|
||||||
: string { toString $1 }
|
: string { toString $1 }
|
||||||
|
|
||||||
Call :: { Call }
|
|
||||||
: Identifier "(" CallArgs ")" { Call $1 $3 }
|
|
||||||
|
|
||||||
CallArgs :: { [Expr] }
|
CallArgs :: { [Expr] }
|
||||||
CallArgs
|
: Expr { [$1] }
|
||||||
: Expr { [$1] }
|
| CallArgs "," Expr { $1 ++ [$3] }
|
||||||
| CallArgs "," Expr { $1 ++ [$3] }
|
|
||||||
|
|
||||||
MaybeExpr :: { Maybe Expr }
|
MaybeExpr :: { Maybe Expr }
|
||||||
: { Nothing }
|
: { Nothing }
|
||||||
|
|
@ -395,7 +391,7 @@ Expr :: { Expr }
|
||||||
: "(" Expr ")" { $2 }
|
: "(" Expr ")" { $2 }
|
||||||
| String { String $1 }
|
| String { String $1 }
|
||||||
| Number { Number $1 }
|
| Number { Number $1 }
|
||||||
| Call { ExprCall $1 }
|
| Identifier "(" CallArgs ")" { Call $1 $3 }
|
||||||
| Identifier { Ident $1 }
|
| Identifier { Ident $1 }
|
||||||
| Identifier Range { IdentRange $1 $2 }
|
| Identifier Range { IdentRange $1 $2 }
|
||||||
| Identifier "[" Expr "]" { IdentBit $1 $3 }
|
| Identifier "[" Expr "]" { IdentBit $1 $3 }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue