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
9adb7522
Commit
9adb7522
authored
Jun 09, 2020
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve stmt representation
parent
2f5b746e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
45 deletions
+43
-45
src/Convert/Foreach.hs
+3
-3
src/Convert/Traverse.hs
+2
-6
src/Language/SystemVerilog/AST/ModuleItem.hs
+3
-3
src/Language/SystemVerilog/AST/Stmt.hs
+23
-24
src/Language/SystemVerilog/Parser/Parse.y
+12
-9
No files found.
src/Convert/Foreach.hs
View file @
9adb7522
...
@@ -22,9 +22,9 @@ convertStmt :: Stmt -> Stmt
...
@@ -22,9 +22,9 @@ convertStmt :: Stmt -> Stmt
convertStmt
(
Foreach
x
idxs
stmt
)
=
convertStmt
(
Foreach
x
idxs
stmt
)
=
(
foldl
(
.
)
id
$
map
toLoop
$
zip
[
1
..
]
idxs
)
stmt
(
foldl
(
.
)
id
$
map
toLoop
$
zip
[
1
..
]
idxs
)
stmt
where
where
toLoop
::
(
Int
,
Maybe
Identifier
)
->
(
Stmt
->
Stmt
)
toLoop
::
(
Int
,
Identifier
)
->
(
Stmt
->
Stmt
)
toLoop
(
_
,
Nothing
)
=
id
toLoop
(
_
,
""
)
=
id
toLoop
(
d
,
Just
i
)
=
toLoop
(
d
,
i
)
=
For
(
Left
[
idxDecl
])
cmp
[
incr
]
For
(
Left
[
idxDecl
])
cmp
[
incr
]
where
where
queryFn
f
=
DimFn
f
(
Right
$
Ident
x
)
(
Number
$
show
d
)
queryFn
f
=
DimFn
f
(
Right
$
Ident
x
)
(
Number
$
show
d
)
...
...
src/Convert/Traverse.hs
View file @
9adb7522
...
@@ -255,14 +255,10 @@ traverseSinglyNestedStmtsM fullMapper = cs
...
@@ -255,14 +255,10 @@ traverseSinglyNestedStmtsM fullMapper = cs
traverseAssertionStmtsM
::
Monad
m
=>
MapperM
m
Stmt
->
MapperM
m
Assertion
traverseAssertionStmtsM
::
Monad
m
=>
MapperM
m
Stmt
->
MapperM
m
Assertion
traverseAssertionStmtsM
mapper
=
assertionMapper
traverseAssertionStmtsM
mapper
=
assertionMapper
where
where
actionBlockMapper
(
ActionBlockIf
stmt
)
=
actionBlockMapper
(
ActionBlock
s1
s2
)
=
do
mapper
stmt
>>=
return
.
ActionBlockIf
actionBlockMapper
(
ActionBlockElse
Nothing
stmt
)
=
mapper
stmt
>>=
return
.
ActionBlockElse
Nothing
actionBlockMapper
(
ActionBlockElse
(
Just
s1
)
s2
)
=
do
s1'
<-
mapper
s1
s1'
<-
mapper
s1
s2'
<-
mapper
s2
s2'
<-
mapper
s2
return
$
ActionBlock
Else
(
Just
s1'
)
s2'
return
$
ActionBlock
s1'
s2'
assertionMapper
(
Assert
e
ab
)
=
assertionMapper
(
Assert
e
ab
)
=
actionBlockMapper
ab
>>=
return
.
Assert
e
actionBlockMapper
ab
>>=
return
.
Assert
e
assertionMapper
(
Assume
e
ab
)
=
assertionMapper
(
Assume
e
ab
)
=
...
...
src/Language/SystemVerilog/AST/ModuleItem.hs
View file @
9adb7522
...
@@ -63,10 +63,10 @@ instance Show ModuleItem where
...
@@ -63,10 +63,10 @@ instance Show ModuleItem where
showGate
kw
d
x
$
show
lhs
:
map
show
exprs
showGate
kw
d
x
$
show
lhs
:
map
show
exprs
show
(
NOutputGate
kw
d
x
lhss
expr
)
=
show
(
NOutputGate
kw
d
x
lhss
expr
)
=
showGate
kw
d
x
$
(
map
show
lhss
)
++
[
show
expr
]
showGate
kw
d
x
$
(
map
show
lhss
)
++
[
show
expr
]
show
(
AssertionItem
(
m
x
,
a
))
=
show
(
AssertionItem
(
x
,
a
))
=
if
mx
==
Nothing
if
null
x
then
show
a
then
show
a
else
printf
"%s : %s"
(
fromJust
mx
)
(
show
a
)
else
printf
"%s : %s"
x
(
show
a
)
show
(
Instance
m
params
i
r
ports
)
=
show
(
Instance
m
params
i
r
ports
)
=
if
null
params
if
null
params
then
printf
"%s %s%s%s;"
m
i
rStr
(
showPorts
ports
)
then
printf
"%s %s%s%s;"
m
i
rStr
(
showPorts
ports
)
...
...
src/Language/SystemVerilog/AST/Stmt.hs
View file @
9adb7522
...
@@ -43,7 +43,7 @@ data Stmt
...
@@ -43,7 +43,7 @@ data Stmt
|
RepeatL
Expr
Stmt
|
RepeatL
Expr
Stmt
|
DoWhile
Expr
Stmt
|
DoWhile
Expr
Stmt
|
Forever
Stmt
|
Forever
Stmt
|
Foreach
Identifier
[
Maybe
Identifier
]
Stmt
|
Foreach
Identifier
[
Identifier
]
Stmt
|
If
ViolationCheck
Expr
Stmt
Stmt
|
If
ViolationCheck
Expr
Stmt
Stmt
|
Timing
Timing
Stmt
|
Timing
Timing
Stmt
|
Return
Expr
|
Return
Expr
...
@@ -79,24 +79,25 @@ instance Show Stmt where
...
@@ -79,24 +79,25 @@ instance Show Stmt where
showInits
(
Right
asgns
)
=
commas
$
map
showInit
asgns
showInits
(
Right
asgns
)
=
commas
$
map
showInit
asgns
where
showInit
(
l
,
e
)
=
showAssign
(
l
,
AsgnOpEq
,
e
)
where
showInit
(
l
,
e
)
=
showAssign
(
l
,
AsgnOpEq
,
e
)
showAssign
::
(
LHS
,
AsgnOp
,
Expr
)
->
String
showAssign
::
(
LHS
,
AsgnOp
,
Expr
)
->
String
showAssign
(
l
,
op
,
e
)
=
printf
"%s %s %s"
(
show
l
)
(
show
op
)
(
show
e
)
showAssign
(
l
,
op
,
e
)
=
(
showPad
l
)
++
(
showPad
op
)
++
(
show
e
)
show
(
Subroutine
e
a
)
=
printf
"%s%s;"
(
show
e
)
aStr
show
(
Subroutine
e
a
)
=
printf
"%s%s;"
(
show
e
)
aStr
where
aStr
=
if
a
==
Args
[]
[]
then
""
else
show
a
where
aStr
=
if
a
==
Args
[]
[]
then
""
else
show
a
show
(
Asgn
o
t
v
e
)
=
printf
"%s %s %s%s;"
(
show
v
)
(
show
o
)
(
maybe
""
showPad
t
)
(
show
e
)
show
(
Asgn
o
t
v
e
)
=
printf
"%s %s %s%s;"
(
show
v
)
(
show
o
)
tStr
(
show
e
)
show
(
While
e
s
)
=
printf
"while (%s) %s"
(
show
e
)
(
show
s
)
where
tStr
=
maybe
""
showPad
t
show
(
RepeatL
e
s
)
=
printf
"repeat (%s) %s"
(
show
e
)
(
show
s
)
show
(
If
u
c
s
Null
)
=
printf
"%sif (%s)%s"
(
showPad
u
)
(
show
c
)
(
showBranch
s
)
show
(
DoWhile
e
s
)
=
printf
"do %s while (%s);"
(
show
s
)
(
show
e
)
show
(
If
u
c
s1
s2
)
=
printf
"%sif (%s)%s
\n
else%s"
(
showPad
u
)
(
show
c
)
(
showBlockedBranch
s1
)
(
showElseBranch
s2
)
show
(
Forever
s
)
=
printf
"forever %s"
(
show
s
)
show
(
While
e
s
)
=
printf
"while (%s) %s"
(
show
e
)
(
show
s
)
show
(
Foreach
x
i
s
)
=
printf
"foreach (%s [ %s ]) %s"
x
(
commas
$
map
(
maybe
""
id
)
i
)
(
show
s
)
show
(
RepeatL
e
s
)
=
printf
"repeat (%s) %s"
(
show
e
)
(
show
s
)
show
(
If
u
a
b
Null
)
=
printf
"%sif (%s)%s"
(
showPad
u
)
(
show
a
)
(
showBranch
b
)
show
(
DoWhile
e
s
)
=
printf
"do %s while (%s);"
(
show
s
)
(
show
e
)
show
(
If
u
a
b
c
)
=
printf
"%sif (%s)%s
\n
else%s"
(
showPad
u
)
(
show
a
)
(
showBlockedBranch
b
)
(
showElseBranch
c
)
show
(
Forever
s
)
=
printf
"forever %s"
(
show
s
)
show
(
Return
e
)
=
printf
"return %s;"
(
show
e
)
show
(
Foreach
x
i
s
)
=
printf
"foreach (%s [ %s ]) %s"
x
(
commas
i
)
(
show
s
)
show
(
Timing
t
s
)
=
printf
"%s%s"
(
show
t
)
(
showShortBranch
s
)
show
(
Return
e
)
=
printf
"return %s;"
(
show
e
)
show
(
Trigger
b
x
)
=
printf
"->%s %s;"
(
if
b
then
""
else
">"
)
x
show
(
Timing
t
s
)
=
printf
"%s%s"
(
show
t
)
(
showShortBranch
s
)
show
(
Assertion
a
)
=
show
a
show
(
Trigger
b
x
)
=
printf
"->%s %s;"
(
if
b
then
""
else
">"
)
x
show
(
Continue
)
=
"continue;"
show
(
Assertion
a
)
=
show
a
show
(
Break
)
=
"break;"
show
(
Continue
)
=
"continue;"
show
(
Null
)
=
";"
show
(
Break
)
=
"break;"
show
(
Null
)
=
";"
show
(
CommentStmt
c
)
=
show
(
CommentStmt
c
)
=
if
elem
'
\n
'
c
if
elem
'
\n
'
c
then
"// "
++
show
c
then
"// "
++
show
c
...
@@ -183,14 +184,12 @@ instance Show Sense where
...
@@ -183,14 +184,12 @@ instance Show Sense where
show
(
SenseStar
)
=
"*"
show
(
SenseStar
)
=
"*"
data
ActionBlock
data
ActionBlock
=
ActionBlockIf
Stmt
=
ActionBlock
Stmt
Stmt
|
ActionBlockElse
(
Maybe
Stmt
)
Stmt
deriving
Eq
deriving
Eq
instance
Show
ActionBlock
where
instance
Show
ActionBlock
where
show
(
ActionBlockIf
Null
)
=
";"
show
(
ActionBlock
s
Null
)
=
printf
" %s"
(
show
s
)
show
(
ActionBlockIf
s
)
=
printf
" %s"
(
show
s
)
show
(
ActionBlock
Null
s
)
=
printf
" else %s"
(
show
s
)
show
(
ActionBlockElse
Nothing
s
)
=
printf
" else %s"
(
show
s
)
show
(
ActionBlock
s1
s2
)
=
printf
" %s else %s"
(
show
s1
)
(
show
s2
)
show
(
ActionBlockElse
(
Just
s1
)
s2
)
=
printf
" %s else %s"
(
show
s1
)
(
show
s2
)
data
PropExpr
data
PropExpr
=
PropExpr
SeqExpr
=
PropExpr
SeqExpr
...
@@ -228,7 +227,7 @@ instance Show SeqExpr where
...
@@ -228,7 +227,7 @@ instance Show SeqExpr where
show
(
SeqExprDelay
me
e
s
)
=
printf
"%s##%s %s"
(
maybe
""
showPad
me
)
(
show
e
)
(
show
s
)
show
(
SeqExprDelay
me
e
s
)
=
printf
"%s##%s %s"
(
maybe
""
showPad
me
)
(
show
e
)
(
show
s
)
show
(
SeqExprFirstMatch
e
a
)
=
printf
"first_match(%s, %s)"
(
show
e
)
(
show
a
)
show
(
SeqExprFirstMatch
e
a
)
=
printf
"first_match(%s, %s)"
(
show
e
)
(
show
a
)
type
AssertionItem
=
(
Maybe
Identifier
,
Assertion
)
type
AssertionItem
=
(
Identifier
,
Assertion
)
type
AssertionExpr
=
Either
PropertySpec
Expr
type
AssertionExpr
=
Either
PropertySpec
Expr
data
Assertion
data
Assertion
=
Assert
AssertionExpr
ActionBlock
=
Assert
AssertionExpr
ActionBlock
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
9adb7522
...
@@ -690,8 +690,8 @@ ProceduralAssertionStatement :: { Assertion }
...
@@ -690,8 +690,8 @@ ProceduralAssertionStatement :: { Assertion }
|
ImmediateAssertionStatement
{
$
1
}
|
ImmediateAssertionStatement
{
$
1
}
ConcurrentAssertionItem
::
{
AssertionItem
}
ConcurrentAssertionItem
::
{
AssertionItem
}
:
Identifier
":"
ConcurrentAssertionStatement
{
(
Just
$
1
,
$
3
)
}
:
Identifier
":"
ConcurrentAssertionStatement
{
(
$
1
,
$
3
)
}
|
ConcurrentAssertionStatement
{
(
Nothing
,
$
1
)
}
|
ConcurrentAssertionStatement
{
(
""
,
$
1
)
}
ConcurrentAssertionStatement
::
{
Assertion
}
ConcurrentAssertionStatement
::
{
Assertion
}
:
"assert"
"property"
"("
PropertySpec
")"
ActionBlock
{
Assert
(
Left
$
4
)
$
6
}
:
"assert"
"property"
"("
PropertySpec
")"
ActionBlock
{
Assert
(
Left
$
4
)
$
6
}
|
"assume"
"property"
"("
PropertySpec
")"
ActionBlock
{
Assume
(
Left
$
4
)
$
6
}
|
"assume"
"property"
"("
PropertySpec
")"
ActionBlock
{
Assume
(
Left
$
4
)
$
6
}
...
@@ -739,9 +739,9 @@ SeqMatchItem :: { SeqMatchItem }
...
@@ -739,9 +739,9 @@ SeqMatchItem :: { SeqMatchItem }
|
Identifier
CallArgs
{
Right
(
$
1
,
$
2
)
}
|
Identifier
CallArgs
{
Right
(
$
1
,
$
2
)
}
ActionBlock
::
{
ActionBlock
}
ActionBlock
::
{
ActionBlock
}
:
Stmt
%
prec
NoElse
{
ActionBlock
If
$
1
}
:
Stmt
%
prec
NoElse
{
ActionBlock
$
1
Null
}
|
"else"
Stmt
{
ActionBlock
Else
(
Nothing
)
$
2
}
|
"else"
Stmt
{
ActionBlock
Null
$
2
}
|
Stmt
"else"
Stmt
{
ActionBlock
Else
(
Just
$
1
)
$
3
}
|
Stmt
"else"
Stmt
{
ActionBlock
$
1
$
3
}
AttributeInstances
::
{
[
Attr
]
}
AttributeInstances
::
{
[
Attr
]
}
:
{- empty -}
{
[]
}
:
{- empty -}
{
[]
}
...
@@ -1029,11 +1029,14 @@ ForStepAssignment :: { (LHS, AsgnOp, Expr) }
...
@@ -1029,11 +1029,14 @@ ForStepAssignment :: { (LHS, AsgnOp, Expr) }
|
IncOrDecOperator
LHS
{
(
$
2
,
AsgnOp
$
1
,
Number
"1"
)
}
|
IncOrDecOperator
LHS
{
(
$
2
,
AsgnOp
$
1
,
Number
"1"
)
}
|
LHS
IncOrDecOperator
{
(
$
1
,
AsgnOp
$
2
,
Number
"1"
)
}
|
LHS
IncOrDecOperator
{
(
$
1
,
AsgnOp
$
2
,
Number
"1"
)
}
IdxVars
::
{
[
Maybe
Identifier
]
}
IdxVars
::
{
[
Identifier
]
}
:
"["
IdxVarsInside
"]"
{
$
2
}
:
"["
IdxVarsInside
"]"
{
$
2
}
IdxVarsInside
::
{
[
Maybe
Identifier
]
}
IdxVarsInside
::
{
[
Identifier
]
}
:
opt
(
Identifier
)
{
[
$
1
]
}
:
IdxVar
{
[
$
1
]
}
|
opt
(
Identifier
)
","
IdxVarsInside
{
$
1
:
$
3
}
|
IdxVar
","
IdxVarsInside
{
$
1
:
$
3
}
IdxVar
::
{
Identifier
}
:
{- empty -}
{
""
}
|
Identifier
{
$
1
}
DeclsAndStmts
::
{
([
Decl
],
[
Stmt
])
}
DeclsAndStmts
::
{
([
Decl
],
[
Stmt
])
}
:
StmtTrace
DeclOrStmt
DeclsAndStmts
{
combineDeclsAndStmts
$
2
$
3
}
:
StmtTrace
DeclOrStmt
DeclsAndStmts
{
combineDeclsAndStmts
$
2
$
3
}
...
...
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