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
5c263298
Commit
5c263298
authored
Feb 07, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify substitution avoids shadowing
parent
490d96ba
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
17 deletions
+39
-17
src/Convert/Cast.hs
+7
-4
src/Convert/ExprUtils.hs
+2
-0
src/Convert/Simplify.hs
+20
-12
src/Convert/TypeOf.hs
+2
-1
test/basic/simplify_scope.sv
+8
-0
No files found.
src/Convert/Cast.hs
View file @
5c263298
...
...
@@ -92,10 +92,13 @@ traverseStmtM stmt = do
return
stmt'
traverseExprM
::
Expr
->
ST
Expr
traverseExprM
(
Cast
(
Left
(
IntegerVector
_
sg
rs
))
e
)
=
do
e'
<-
traverseExprM
e
convertCastM
(
dimensionsSize
rs
)
e'
signed
where
signed
=
sg
==
Signed
traverseExprM
(
Cast
(
Left
(
IntegerVector
_
sg
rs
))
value
)
=
do
value'
<-
traverseExprM
value
size'
<-
traverseExprM
size
convertCastM
size'
value'
signed
where
signed
=
sg
==
Signed
size
=
dimensionsSize
rs
traverseExprM
other
=
traverseSinglyNestedExprsM
traverseExprM
other
...
...
src/Convert/ExprUtils.hs
View file @
5c263298
...
...
@@ -52,6 +52,8 @@ simplifyStep (Mux (Number n) e1 e2) =
Just
_
->
e1
Nothing
->
Mux
(
Number
n
)
e1
e2
simplifyStep
(
Call
(
Ident
"$clog2"
)
(
Args
[
SizDec
k
]
[]
))
=
simplifyStep
$
Call
(
Ident
"$clog2"
)
(
Args
[
RawNum
k
]
[]
)
simplifyStep
(
Call
(
Ident
"$clog2"
)
(
Args
[
Dec
k
]
[]
))
=
toDec
$
clog2
k
where
...
...
src/Convert/Simplify.hs
View file @
5c263298
...
...
@@ -32,22 +32,29 @@ convertDescription =
traverseDeclM
::
Decl
->
Scoper
Expr
Decl
traverseDeclM
decl
=
do
case
decl
of
Param
Localparam
_
x
e
->
when
(
isSimpleExpr
e
)
$
insertElem
x
e
decl'
<-
traverseDeclExprsM
traverseExprM
decl
case
decl'
of
Param
Localparam
UnknownType
x
e
->
insertExpr
x
e
Param
Localparam
(
Implicit
Signed
[(
RawNum
31
,
RawNum
0
)])
x
e
->
insertExpr
x
e
Param
Localparam
(
Implicit
sg
rs
)
x
e
->
insertExpr
x
$
Cast
(
Left
t
)
e
where
t
=
IntegerVector
TLogic
sg
rs
Param
Localparam
t
x
e
->
insertExpr
x
$
Cast
(
Left
t
)
e
_
->
return
()
let
mi
=
MIPackageItem
$
Decl
decl
mi'
<-
traverseModuleItemM
mi
let
MIPackageItem
(
Decl
decl'
)
=
mi'
return
decl'
insertExpr
::
Identifier
->
Expr
->
Scoper
Expr
()
insertExpr
ident
expr
=
do
expr'
<-
substituteExprM
expr
when
(
isSimpleExpr
expr'
)
$
insertElem
ident
expr'
isSimpleExpr
::
Expr
->
Bool
isSimpleExpr
Ident
{}
=
True
isSimpleExpr
Number
{}
=
True
isSimpleExpr
String
{}
=
True
isSimpleExpr
(
Dot
e
_
)
=
isSimpleExpr
e
isSimpleExpr
(
Bit
e
_
)
=
isSimpleExpr
e
isSimpleExpr
(
Range
e
_
_
)
=
isSimpleExpr
e
isSimpleExpr
(
Cast
Left
{}
e
)
=
isSimpleExpr
e
isSimpleExpr
_
=
False
traverseModuleItemM
::
ModuleItem
->
Scoper
Expr
ModuleItem
...
...
@@ -117,11 +124,12 @@ convertExpr info expr =
substitute
::
Scopes
Expr
->
Expr
->
Expr
substitute
scopes
expr
=
traverseNestedExprs
substitute'
expr
substitute'
expr
where
substitute'
::
Expr
->
Expr
substitute'
(
Ident
x
)
=
case
lookupElem
scopes
x
of
Nothing
->
Ident
x
Just
(
_
,
_
,
e
)
->
e
substitute'
other
=
other
substitute'
other
=
traverseSinglyNestedExprs
substitute'
other
src/Convert/TypeOf.hs
View file @
5c263298
...
...
@@ -115,7 +115,8 @@ traverseExprM (Cast (Right (Ident x)) expr) = do
else
elaborateSizeCast
(
Ident
x
)
expr'
traverseExprM
(
Cast
(
Right
size
)
expr
)
=
do
expr'
<-
traverseExprM
expr
elaborateSizeCast
size
expr'
size'
<-
traverseExprM
size
elaborateSizeCast
size'
expr'
traverseExprM
other
=
traverseExprTypesM
traverseTypeM
other
>>=
traverseSinglyNestedExprsM
traverseExprM
...
...
test/basic/simplify_scope.sv
0 → 100644
View file @
5c263298
module
top
;
localparam
A
=
1
;
localparam
B
=
A
;
if
(
A
)
begin
:
blk
localparam
A
=
1
'
sbx
;
initial
$
display
(
"%b"
,
$
clog2
(
B
+
1
+
1
))
;
end
endmodule
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