Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sv2v
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
sv2v
Commits
59efba06
Commit
59efba06
authored
Mar 04, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LHSs are recursive (as they should have been)
parent
b95af2b6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
49 deletions
+53
-49
src/Convert/Logic.hs
+2
-5
src/Convert/PackedArray.hs
+11
-13
src/Convert/Traverse.hs
+14
-3
src/Language/SystemVerilog/AST.hs
+8
-8
src/Language/SystemVerilog/Parser/Parse.y
+8
-7
src/Language/SystemVerilog/Parser/ParseDecl.hs
+10
-13
No files found.
src/Convert/Logic.hs
View file @
59efba06
...
@@ -39,9 +39,6 @@ regIdents :: ModuleItem -> Writer RegIdents ()
...
@@ -39,9 +39,6 @@ regIdents :: ModuleItem -> Writer RegIdents ()
regIdents
(
AlwaysC
_
stmt
)
=
collectStmtLHSsM
idents
stmt
regIdents
(
AlwaysC
_
stmt
)
=
collectStmtLHSsM
idents
stmt
where
where
idents
::
LHS
->
Writer
RegIdents
()
idents
::
LHS
->
Writer
RegIdents
()
idents
(
LHS
vx
)
=
tell
$
Set
.
singleton
vx
idents
(
LHSIdent
vx
)
=
tell
$
Set
.
singleton
vx
idents
(
LHSBit
vx
_
)
=
tell
$
Set
.
singleton
vx
idents
_
=
return
()
-- the collector recurses for us
idents
(
LHSRange
vx
_
)
=
tell
$
Set
.
singleton
vx
idents
(
LHSConcat
lhss
)
=
mapM
idents
lhss
>>=
\
_
->
return
()
idents
(
LHSDot
lhs
_
)
=
idents
lhs
regIdents
_
=
return
()
regIdents
_
=
return
()
src/Convert/PackedArray.hs
View file @
59efba06
...
@@ -95,11 +95,9 @@ collectExpr (IdentRange i _) = recordSeqUsage i
...
@@ -95,11 +95,9 @@ collectExpr (IdentRange i _) = recordSeqUsage i
collectExpr
(
IdentBit
i
_
)
=
recordIdxUsage
i
collectExpr
(
IdentBit
i
_
)
=
recordIdxUsage
i
collectExpr
_
=
return
()
collectExpr
_
=
return
()
collectLHS
::
LHS
->
State
Info
()
collectLHS
::
LHS
->
State
Info
()
collectLHS
(
LHS
i
)
=
recordSeqUsage
i
collectLHS
(
LHSIdent
i
)
=
recordSeqUsage
i
collectLHS
(
LHSRange
i
_
)
=
recordSeqUsage
i
collectLHS
(
LHSBit
(
LHSIdent
i
)
_
)
=
recordIdxUsage
i
collectLHS
(
LHSBit
i
_
)
=
recordIdxUsage
i
collectLHS
_
=
return
()
-- the collect recurses for us
collectLHS
(
LHSConcat
lhss
)
=
mapM
collectLHS
lhss
>>=
\
_
->
return
()
collectLHS
(
LHSDot
lhs
_
)
=
collectLHS
lhs
-- VCS doesn't like port declarations inside of `generate` blocks, so we hoist
-- VCS doesn't like port declarations inside of `generate` blocks, so we hoist
-- them out with this function. This obviously isn't ideal, but it's a
-- them out with this function. This obviously isn't ideal, but it's a
...
@@ -167,8 +165,8 @@ unflattener writeToFlatVariant arr (t, (majorHi, majorLo)) =
...
@@ -167,8 +165,8 @@ unflattener writeToFlatVariant arr (t, (majorHi, majorLo)) =
(
BinOp
Mul
(
Ident
index
)
size
))
(
BinOp
Mul
(
Ident
index
)
size
))
,
GenModuleItem
$
(
uncurry
Assign
)
$
,
GenModuleItem
$
(
uncurry
Assign
)
$
if
not
writeToFlatVariant
if
not
writeToFlatVariant
then
(
LHSBit
arrUnflat
$
Ident
index
,
IdentRange
arr
origRange
)
then
(
LHSBit
(
LHSIdent
arrUnflat
)
$
Ident
index
,
IdentRange
arr
origRange
)
else
(
LHSRange
arr
origRange
,
IdentBit
arrUnflat
$
Ident
index
)
else
(
LHSRange
(
LHSIdent
arr
)
origRange
,
IdentBit
arrUnflat
$
Ident
index
)
]
]
]
]
where
where
...
@@ -257,18 +255,18 @@ rewriteModuleItem info =
...
@@ -257,18 +255,18 @@ rewriteModuleItem info =
rewriteExpr
other
=
other
rewriteExpr
other
=
other
rewriteLHS
::
LHS
->
LHS
rewriteLHS
::
LHS
->
LHS
rewriteLHS
(
LHS
x
)
=
LHS
(
rewriteAsgnIdent
x
)
rewriteLHS
(
LHSIdent
x
)
=
LHSIdent
(
rewriteAsgnIdent
x
)
rewriteLHS
(
LHSBit
x
e
)
=
LHSBit
(
rewriteAsgnIdent
x
)
e
rewriteLHS
(
LHSBit
l
e
)
=
LHSBit
(
rewriteLHS
l
)
e
rewriteLHS
(
LHSRange
x
r
)
=
LHSRange
(
rewriteAsgnIdent
x
)
r
rewriteLHS
(
LHSRange
l
r
)
=
LHSRange
(
rewriteLHS
l
)
r
rewriteLHS
(
LHSDot
l
x
)
=
LHSDot
(
rewriteLHS
l
)
x
rewriteLHS
(
LHSConcat
ls
)
=
LHSConcat
$
map
rewriteLHS
ls
rewriteLHS
(
LHSConcat
ls
)
=
LHSConcat
$
map
rewriteLHS
ls
rewriteLHS
(
LHSDot
lhs
x
)
=
LHSDot
(
rewriteLHS
lhs
)
x
rewriteStmt
::
Stmt
->
Stmt
rewriteStmt
::
Stmt
->
Stmt
rewriteStmt
(
AsgnBlk
lhs
expr
)
=
convertAssignment
AsgnBlk
lhs
expr
rewriteStmt
(
AsgnBlk
lhs
expr
)
=
convertAssignment
AsgnBlk
lhs
expr
rewriteStmt
(
Asgn
lhs
expr
)
=
convertAssignment
Asgn
lhs
expr
rewriteStmt
(
Asgn
lhs
expr
)
=
convertAssignment
Asgn
lhs
expr
rewriteStmt
other
=
other
rewriteStmt
other
=
other
convertAssignment
::
(
LHS
->
Expr
->
Stmt
)
->
LHS
->
Expr
->
Stmt
convertAssignment
::
(
LHS
->
Expr
->
Stmt
)
->
LHS
->
Expr
->
Stmt
convertAssignment
constructor
(
lhs
@
(
LHS
ident
))
(
expr
@
(
Repeat
_
exprs
))
=
convertAssignment
constructor
(
lhs
@
(
LHS
Ident
ident
))
(
expr
@
(
Repeat
_
exprs
))
=
if
Map
.
member
ident
typeDims
if
Map
.
member
ident
typeDims
then
For
inir
chkr
incr
assign
then
For
inir
chkr
incr
assign
else
constructor
(
rewriteLHS
lhs
)
expr
else
constructor
(
rewriteLHS
lhs
)
expr
...
@@ -276,7 +274,7 @@ rewriteModuleItem info =
...
@@ -276,7 +274,7 @@ rewriteModuleItem info =
(
_
,
(
a
,
b
))
=
typeDims
Map
.!
ident
(
_
,
(
a
,
b
))
=
typeDims
Map
.!
ident
index
=
prefix
$
ident
++
"_repeater_index"
index
=
prefix
$
ident
++
"_repeater_index"
assign
=
constructor
assign
=
constructor
(
LHSBit
(
prefix
ident
)
(
Ident
index
))
(
LHSBit
(
LHSIdent
$
prefix
ident
)
(
Ident
index
))
(
Concat
exprs
)
(
Concat
exprs
)
inir
=
(
index
,
b
)
inir
=
(
index
,
b
)
chkr
=
BinOp
Le
(
Ident
index
)
a
chkr
=
BinOp
Le
(
Ident
index
)
a
...
...
src/Convert/Traverse.hs
View file @
59efba06
...
@@ -142,8 +142,9 @@ traverseNestedStmtsM mapper = fullMapper
...
@@ -142,8 +142,9 @@ traverseNestedStmtsM mapper = fullMapper
traverseStmtLHSsM
::
Monad
m
=>
MapperM
m
LHS
->
MapperM
m
Stmt
traverseStmtLHSsM
::
Monad
m
=>
MapperM
m
LHS
->
MapperM
m
Stmt
traverseStmtLHSsM
mapper
=
traverseNestedStmtsM
stmtMapper
traverseStmtLHSsM
mapper
=
traverseNestedStmtsM
stmtMapper
where
where
stmtMapper
(
AsgnBlk
lhs
expr
)
=
mapper
lhs
>>=
\
lhs'
->
return
$
AsgnBlk
lhs'
expr
fullMapper
=
traverseNestedLHSsM
mapper
stmtMapper
(
Asgn
lhs
expr
)
=
mapper
lhs
>>=
\
lhs'
->
return
$
Asgn
lhs'
expr
stmtMapper
(
AsgnBlk
lhs
expr
)
=
fullMapper
lhs
>>=
\
lhs'
->
return
$
AsgnBlk
lhs'
expr
stmtMapper
(
Asgn
lhs
expr
)
=
fullMapper
lhs
>>=
\
lhs'
->
return
$
Asgn
lhs'
expr
stmtMapper
other
=
return
other
stmtMapper
other
=
return
other
traverseStmtLHSs
::
Mapper
LHS
->
Mapper
Stmt
traverseStmtLHSs
::
Mapper
LHS
->
Mapper
Stmt
...
@@ -285,7 +286,7 @@ traverseLHSsM mapper item =
...
@@ -285,7 +286,7 @@ traverseLHSsM mapper item =
traverseStmtsM
(
traverseStmtLHSsM
mapper
)
item
>>=
traverseModuleItemLHSsM
traverseStmtsM
(
traverseStmtLHSsM
mapper
)
item
>>=
traverseModuleItemLHSsM
where
where
traverseModuleItemLHSsM
(
Assign
lhs
expr
)
=
do
traverseModuleItemLHSsM
(
Assign
lhs
expr
)
=
do
lhs'
<-
mapper
lhs
lhs'
<-
traverseNestedLHSsM
mapper
lhs
return
$
Assign
lhs'
expr
return
$
Assign
lhs'
expr
traverseModuleItemLHSsM
other
=
return
other
traverseModuleItemLHSsM
other
=
return
other
...
@@ -294,6 +295,16 @@ traverseLHSs = unmonad traverseLHSsM
...
@@ -294,6 +295,16 @@ traverseLHSs = unmonad traverseLHSsM
collectLHSsM
::
Monad
m
=>
CollectorM
m
LHS
->
CollectorM
m
ModuleItem
collectLHSsM
::
Monad
m
=>
CollectorM
m
LHS
->
CollectorM
m
ModuleItem
collectLHSsM
=
collectify
traverseLHSsM
collectLHSsM
=
collectify
traverseLHSsM
traverseNestedLHSsM
::
Monad
m
=>
MapperM
m
LHS
->
MapperM
m
LHS
traverseNestedLHSsM
mapper
=
fullMapper
where
fullMapper
lhs
=
tl
lhs
>>=
mapper
tl
(
LHSIdent
x
)
=
return
$
LHSIdent
x
tl
(
LHSBit
l
e
)
=
fullMapper
l
>>=
\
l'
->
return
$
LHSBit
l'
e
tl
(
LHSRange
l
r
)
=
fullMapper
l
>>=
\
l'
->
return
$
LHSRange
l'
r
tl
(
LHSDot
l
x
)
=
fullMapper
l
>>=
\
l'
->
return
$
LHSDot
l'
x
tl
(
LHSConcat
lhss
)
=
mapM
fullMapper
lhss
>>=
return
.
LHSConcat
traverseDeclsM
::
Monad
m
=>
MapperM
m
Decl
->
MapperM
m
ModuleItem
traverseDeclsM
::
Monad
m
=>
MapperM
m
Decl
->
MapperM
m
ModuleItem
traverseDeclsM
mapper
item
=
do
traverseDeclsM
mapper
item
=
do
item'
<-
miMapperA
item
item'
<-
miMapperA
item
...
...
src/Language/SystemVerilog/AST.hs
View file @
59efba06
...
@@ -351,19 +351,19 @@ instance Show Expr where
...
@@ -351,19 +351,19 @@ instance Show Expr where
showPatternItem
(
Just
n
,
e
)
=
printf
"%s: %s"
n
(
show
e
)
showPatternItem
(
Just
n
,
e
)
=
printf
"%s: %s"
n
(
show
e
)
data
LHS
data
LHS
=
LHS
Identifier
=
LHS
Ident
Identifier
|
LHSBit
Identifier
Expr
|
LHSBit
LHS
Expr
|
LHSRange
Identifier
Range
|
LHSRange
LHS
Range
|
LHSDot
LHS
Identifier
|
LHSDot
LHS
Identifier
|
LHSConcat
[
LHS
]
|
LHSConcat
[
LHS
]
deriving
Eq
deriving
Eq
instance
Show
LHS
where
instance
Show
LHS
where
show
(
LHS
a
)
=
a
show
(
LHS
Ident
x
)
=
x
show
(
LHSBit
a
b
)
=
printf
"%s[%s]"
a
(
show
b
)
show
(
LHSBit
l
e
)
=
printf
"%s[%s]"
(
show
l
)
(
show
e
)
show
(
LHSRange
a
(
b
,
c
))
=
printf
"%s[%s:%s]"
a
(
show
b
)
(
show
c
)
show
(
LHSRange
l
(
a
,
b
))
=
printf
"%s[%s:%s]"
(
show
l
)
(
show
a
)
(
show
b
)
show
(
LHS
Concat
a
)
=
printf
"{%s}"
(
commas
$
map
show
a
)
show
(
LHS
Dot
l
x
)
=
printf
"%s.%s"
(
show
l
)
x
show
(
LHS
Dot
a
b
)
=
printf
"%s.%s"
(
show
a
)
b
show
(
LHS
Concat
lhss
)
=
printf
"{%s}"
(
commas
$
map
show
lhss
)
data
CaseKW
data
CaseKW
=
CaseN
=
CaseN
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
59efba06
...
@@ -230,6 +230,7 @@ ParamDecl(delim) :: { [ModuleItem] }
...
@@ -230,6 +230,7 @@ ParamDecl(delim) :: { [ModuleItem] }
PortDecls :: { ([Identifier], [ModuleItem]) }
PortDecls :: { ([Identifier], [ModuleItem]) }
: "(" DeclTokens(")") { parseDTsAsPortDecls $2 }
: "(" DeclTokens(")") { parseDTsAsPortDecls $2 }
| "(" ")" { ([], []) }
| {- empty -} { ([], []) }
| {- empty -} { ([], []) }
ModportItems :: { [(Identifier, [ModportDecl])] }
ModportItems :: { [(Identifier, [ModportDecl])] }
...
@@ -360,15 +361,15 @@ Range :: { Range }
...
@@ -360,15 +361,15 @@ Range :: { Range }
: "[" Expr ":" Expr "]" { ($2, $4) }
: "[" Expr ":" Expr "]" { ($2, $4) }
LHS :: { LHS }
LHS :: { LHS }
: Identifier { LHS
$1 }
: Identifier { LHSIdent
$1 }
| Identifier Range
{ LHSRange $1 $2 }
| LHS Range
{ LHSRange $1 $2 }
| Identifier "[" Expr "]"
{ LHSBit $1 $3 }
| LHS "[" Expr "]"
{ LHSBit $1 $3 }
| "{" LHSs "}" { LHSConcat $2
}
| LHS "." Identifier { LHSDot $1 $3
}
| LHS "." Identifier { LHSDot $1 $3
}
| "{" LHSs "}" { LHSConcat $2
}
LHSs :: { [LHS] }
LHSs :: { [LHS] }
: LHS
{ [$1] }
: LHS
{ [$1] }
| LHSs "," LHS { $1 ++ [$3] }
| LHSs "," LHS { $1 ++ [$3] }
Sense :: { Sense }
Sense :: { Sense }
: Sense1 { $1 }
: Sense1 { $1 }
...
...
src/Language/SystemVerilog/Parser/ParseDecl.hs
View file @
59efba06
...
@@ -151,26 +151,23 @@ parseDTsAsDeclOrAsgn tokens =
...
@@ -151,26 +151,23 @@ parseDTsAsDeclOrAsgn tokens =
DTAsgn
e
->
(
AsgnBlk
,
e
)
DTAsgn
e
->
(
AsgnBlk
,
e
)
DTAsgnNBlk
e
->
(
Asgn
,
e
)
DTAsgnNBlk
e
->
(
Asgn
,
e
)
_
->
error
$
"invalid block item decl or stmt: "
++
(
show
tokens
)
_
->
error
$
"invalid block item decl or stmt: "
++
(
show
tokens
)
(
lhs
,
[]
)
=
takeLHS
$
init
tokens
Just
lhs
=
foldl
takeLHSStep
Nothing
$
init
tokens
isAsgnToken
::
DeclToken
->
Bool
isAsgnToken
::
DeclToken
->
Bool
isAsgnToken
(
DTBit
_
)
=
True
isAsgnToken
(
DTBit
_
)
=
True
isAsgnToken
(
DTConcat
_
)
=
True
isAsgnToken
(
DTConcat
_
)
=
True
isAsgnToken
_
=
False
isAsgnToken
_
=
False
-- TODO: It looks like our LHS type doesn't represent the full set of possible
takeLHSStep
::
Maybe
LHS
->
DeclToken
->
Maybe
LHS
-- LHSs, i.e., `foo[0][0]` isn't representable. When this is addressed, we'll
takeLHSStep
(
Nothing
)
(
DTConcat
lhss
)
=
Just
$
LHSConcat
lhss
-- have to take another pass at this function. It will probably need to be
takeLHSStep
(
Nothing
)
(
DTIdent
x
)
=
Just
$
LHSIdent
x
-- recursive.
takeLHSStep
(
Just
curr
)
(
DTBit
e
)
=
Just
$
LHSBit
curr
e
takeLHS
::
[
DeclToken
]
->
(
LHS
,
[
DeclToken
])
takeLHSStep
(
Just
curr
)
(
DTRange
r
)
=
Just
$
LHSRange
curr
r
takeLHS
(
DTConcat
lhss
:
rest
)
=
(
LHSConcat
lhss
,
rest
)
takeLHSStep
(
Nothing
)
(
DTType
tf
)
=
takeLHS
(
DTIdent
x
:
DTBit
e
:
rest
)
=
(
LHSBit
x
e
,
rest
)
takeLHS
(
DTIdent
x
:
DTRange
r
:
rest
)
=
(
LHSRange
x
r
,
rest
)
takeLHS
(
DTIdent
x
:
rest
)
=
(
LHS
x
,
rest
)
takeLHS
(
DTType
tf
:
rest
)
=
case
tf
[]
of
case
tf
[]
of
InterfaceT
x
(
Just
y
)
[]
->
(
LHSDot
(
LHS
x
)
y
,
rest
)
InterfaceT
x
(
Just
y
)
[]
->
Just
$
LHSDot
(
LHSIdent
x
)
y
_
->
error
$
"unexpected type in assignment: "
++
(
show
tf
)
_
->
error
$
"unexpected type in assignment: "
++
(
show
tf
)
takeLHS
tokens
=
error
$
"missing LHS in assignment: "
++
(
show
tokens
)
takeLHSStep
(
maybeCurr
)
token
=
error
$
"unexpected token in LHS: "
++
show
(
maybeCurr
,
token
)
-- batches together seperate declaration lists
-- batches together seperate declaration lists
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment