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
46be0edb
Commit
46be0edb
authored
Jul 24, 2021
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify cast scoper lookup and removal
parent
1311e449
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
25 deletions
+22
-25
src/Convert/Cast.hs
+22
-25
No files found.
src/Convert/Cast.hs
View file @
46be0edb
...
@@ -30,6 +30,7 @@ module Convert.Cast (convert) where
...
@@ -30,6 +30,7 @@ module Convert.Cast (convert) where
import
Control.Monad.Writer.Strict
import
Control.Monad.Writer.Strict
import
Data.List
(
isPrefixOf
)
import
Data.List
(
isPrefixOf
)
import
Data.Maybe
(
isJust
)
import
Convert.ExprUtils
import
Convert.ExprUtils
import
Convert.Scoper
import
Convert.Scoper
...
@@ -46,9 +47,9 @@ convertDescription description =
...
@@ -46,9 +47,9 @@ convertDescription description =
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
description
description
type
S
T
=
Scoper
Expr
type
S
C
=
Scoper
()
traverseDeclM
::
Decl
->
S
T
Decl
traverseDeclM
::
Decl
->
S
C
Decl
traverseDeclM
decl
=
do
traverseDeclM
decl
=
do
decl'
<-
case
decl
of
decl'
<-
case
decl
of
Variable
d
t
x
a
e
->
do
Variable
d
t
x
a
e
->
do
...
@@ -59,16 +60,16 @@ traverseDeclM decl = do
...
@@ -59,16 +60,16 @@ traverseDeclM decl = do
if
isPrefixOf
"sv2v_cast_"
x
&&
details
/=
Nothing
if
isPrefixOf
"sv2v_cast_"
x
&&
details
/=
Nothing
then
return
$
Variable
Local
t
DuplicateTag
[]
Nil
then
return
$
Variable
Local
t
DuplicateTag
[]
Nil
else
do
else
do
insertElem
x
Nil
insertElem
x
()
return
$
Variable
d
t
x
a
e'
return
$
Variable
d
t
x
a
e'
Net
d
n
s
t
x
a
e
->
do
Net
d
n
s
t
x
a
e
->
do
enterStmt
enterStmt
e'
<-
traverseExprM
e
e'
<-
traverseExprM
e
exitStmt
exitStmt
insertElem
x
Nil
insertElem
x
()
return
$
Net
d
n
s
t
x
a
e'
return
$
Net
d
n
s
t
x
a
e'
Param
_
_
x
_
->
Param
_
_
x
_
->
insertElem
x
Nil
>>
return
decl
insertElem
x
()
>>
return
decl
ParamType
_
_
_
->
return
decl
ParamType
_
_
_
->
return
decl
CommentDecl
_
->
return
decl
CommentDecl
_
->
return
decl
traverseDeclExprsM
traverseExprM
decl'
traverseDeclExprsM
traverseExprM
decl'
...
@@ -81,23 +82,23 @@ dropDuplicateCaster (MIPackageItem (Function _ _ DuplicateTag _ _)) =
...
@@ -81,23 +82,23 @@ dropDuplicateCaster (MIPackageItem (Function _ _ DuplicateTag _ _)) =
Generate
[]
Generate
[]
dropDuplicateCaster
other
=
other
dropDuplicateCaster
other
=
other
traverseModuleItemM
::
ModuleItem
->
S
T
ModuleItem
traverseModuleItemM
::
ModuleItem
->
S
C
ModuleItem
traverseModuleItemM
(
Genvar
x
)
=
traverseModuleItemM
(
Genvar
x
)
=
insertElem
x
Nil
>>
return
(
Genvar
x
)
insertElem
x
()
>>
return
(
Genvar
x
)
traverseModuleItemM
item
=
traverseModuleItemM
item
=
traverseExprsM
traverseExprM
item
traverseExprsM
traverseExprM
item
traverseGenItemM
::
GenItem
->
S
T
GenItem
traverseGenItemM
::
GenItem
->
S
C
GenItem
traverseGenItemM
=
traverseGenItemExprsM
traverseExprM
traverseGenItemM
=
traverseGenItemExprsM
traverseExprM
traverseStmtM
::
Stmt
->
S
T
Stmt
traverseStmtM
::
Stmt
->
S
C
Stmt
traverseStmtM
stmt
=
do
traverseStmtM
stmt
=
do
enterStmt
enterStmt
stmt'
<-
traverseStmtExprsM
traverseExprM
stmt
stmt'
<-
traverseStmtExprsM
traverseExprM
stmt
exitStmt
exitStmt
return
stmt'
return
stmt'
traverseExprM
::
Expr
->
S
T
Expr
traverseExprM
::
Expr
->
S
C
Expr
traverseExprM
(
Cast
(
Left
(
IntegerVector
_
sg
rs
))
value
)
=
do
traverseExprM
(
Cast
(
Left
(
IntegerVector
_
sg
rs
))
value
)
=
do
value'
<-
traverseExprM
value
value'
<-
traverseExprM
value
size'
<-
traverseExprM
size
size'
<-
traverseExprM
size
...
@@ -108,7 +109,7 @@ traverseExprM (Cast (Left (IntegerVector _ sg rs)) value) = do
...
@@ -108,7 +109,7 @@ traverseExprM (Cast (Left (IntegerVector _ sg rs)) value) = do
traverseExprM
other
=
traverseExprM
other
=
traverseSinglyNestedExprsM
traverseExprM
other
traverseSinglyNestedExprsM
traverseExprM
other
convertCastM
::
Expr
->
Expr
->
Bool
->
S
T
Expr
convertCastM
::
Expr
->
Expr
->
Bool
->
S
C
Expr
convertCastM
(
Number
size
)
(
Number
value
)
signed
=
convertCastM
(
Number
size
)
(
Number
value
)
signed
=
return
$
Number
$
return
$
Number
$
case
numberToInteger
size
of
case
numberToInteger
size
of
...
@@ -132,7 +133,7 @@ convertCastM size value signed = do
...
@@ -132,7 +133,7 @@ convertCastM size value signed = do
return
$
Call
(
Ident
name
)
(
Args
[
value'
]
[]
)
return
$
Call
(
Ident
name
)
(
Args
[
value'
]
[]
)
else
do
else
do
name
<-
castDeclName
0
name
<-
castDeclName
0
insertElem
name
Nil
insertElem
name
()
useVar
<-
withinStmt
useVar
<-
withinStmt
injectDecl
$
castDecl
useVar
name
value'
size
signed
injectDecl
$
castDecl
useVar
name
value'
size
signed
return
$
Ident
name
return
$
Ident
name
...
@@ -191,7 +192,7 @@ castDecl useVar name value size signed =
...
@@ -191,7 +192,7 @@ castDecl useVar name value size signed =
else
Param
Localparam
t
name
value
else
Param
Localparam
t
name
value
where
t
=
castType
size
signed
where
t
=
castType
size
signed
castDeclName
::
Int
->
S
T
String
castDeclName
::
Int
->
S
C
String
castDeclName
counter
=
do
castDeclName
counter
=
do
details
<-
lookupElemM
name
details
<-
lookupElemM
name
if
details
==
Nothing
if
details
==
Nothing
...
@@ -204,19 +205,15 @@ castDeclName counter = do
...
@@ -204,19 +205,15 @@ castDeclName counter = do
prefix
=
"sv2v_tmp_cast"
prefix
=
"sv2v_tmp_cast"
-- track whether procedural casts should use variables
-- track whether procedural casts should use variables
pattern
WithinStmt
::
Identifier
withinStmtKey
::
Identifier
pattern
WithinStmt
=
":within_stmt:"
withinStmtKey
=
":within_stmt:"
withinStmt
::
ST
Bool
withinStmt
::
SC
Bool
withinStmt
=
do
withinStmt
=
fmap
isJust
$
lookupElemM
withinStmtKey
details
<-
lookupElemM
WithinStmt
enterStmt
::
SC
()
return
$
case
details
of
Just
(
_
,
_
,
t
)
->
t
/=
Nil
Nothing
->
False
enterStmt
::
ST
()
enterStmt
=
do
enterStmt
=
do
inProcedure
<-
withinProcedureM
inProcedure
<-
withinProcedureM
when
inProcedure
$
insertElem
WithinStmt
(
RawNum
1
)
when
inProcedure
$
insertElem
withinStmtKey
(
)
exitStmt
::
S
T
()
exitStmt
::
S
C
()
exitStmt
=
do
exitStmt
=
do
inProcedure
<-
withinProcedureM
inProcedure
<-
withinProcedureM
when
inProcedure
$
insertElem
WithinStmt
Nil
when
inProcedure
$
removeElem
withinStmtKey
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