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
Hide 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
import
Control.Monad.Writer.Strict
import
Data.List
(
isPrefixOf
)
import
Data.Maybe
(
isJust
)
import
Convert.ExprUtils
import
Convert.Scoper
...
...
@@ -46,9 +47,9 @@ convertDescription description =
traverseDeclM
traverseModuleItemM
traverseGenItemM
traverseStmtM
description
type
S
T
=
Scoper
Expr
type
S
C
=
Scoper
()
traverseDeclM
::
Decl
->
S
T
Decl
traverseDeclM
::
Decl
->
S
C
Decl
traverseDeclM
decl
=
do
decl'
<-
case
decl
of
Variable
d
t
x
a
e
->
do
...
...
@@ -59,16 +60,16 @@ traverseDeclM decl = do
if
isPrefixOf
"sv2v_cast_"
x
&&
details
/=
Nothing
then
return
$
Variable
Local
t
DuplicateTag
[]
Nil
else
do
insertElem
x
Nil
insertElem
x
()
return
$
Variable
d
t
x
a
e'
Net
d
n
s
t
x
a
e
->
do
enterStmt
e'
<-
traverseExprM
e
exitStmt
insertElem
x
Nil
insertElem
x
()
return
$
Net
d
n
s
t
x
a
e'
Param
_
_
x
_
->
insertElem
x
Nil
>>
return
decl
insertElem
x
()
>>
return
decl
ParamType
_
_
_
->
return
decl
CommentDecl
_
->
return
decl
traverseDeclExprsM
traverseExprM
decl'
...
...
@@ -81,23 +82,23 @@ dropDuplicateCaster (MIPackageItem (Function _ _ DuplicateTag _ _)) =
Generate
[]
dropDuplicateCaster
other
=
other
traverseModuleItemM
::
ModuleItem
->
S
T
ModuleItem
traverseModuleItemM
::
ModuleItem
->
S
C
ModuleItem
traverseModuleItemM
(
Genvar
x
)
=
insertElem
x
Nil
>>
return
(
Genvar
x
)
insertElem
x
()
>>
return
(
Genvar
x
)
traverseModuleItemM
item
=
traverseExprsM
traverseExprM
item
traverseGenItemM
::
GenItem
->
S
T
GenItem
traverseGenItemM
::
GenItem
->
S
C
GenItem
traverseGenItemM
=
traverseGenItemExprsM
traverseExprM
traverseStmtM
::
Stmt
->
S
T
Stmt
traverseStmtM
::
Stmt
->
S
C
Stmt
traverseStmtM
stmt
=
do
enterStmt
stmt'
<-
traverseStmtExprsM
traverseExprM
stmt
exitStmt
return
stmt'
traverseExprM
::
Expr
->
S
T
Expr
traverseExprM
::
Expr
->
S
C
Expr
traverseExprM
(
Cast
(
Left
(
IntegerVector
_
sg
rs
))
value
)
=
do
value'
<-
traverseExprM
value
size'
<-
traverseExprM
size
...
...
@@ -108,7 +109,7 @@ traverseExprM (Cast (Left (IntegerVector _ sg rs)) value) = do
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
=
return
$
Number
$
case
numberToInteger
size
of
...
...
@@ -132,7 +133,7 @@ convertCastM size value signed = do
return
$
Call
(
Ident
name
)
(
Args
[
value'
]
[]
)
else
do
name
<-
castDeclName
0
insertElem
name
Nil
insertElem
name
()
useVar
<-
withinStmt
injectDecl
$
castDecl
useVar
name
value'
size
signed
return
$
Ident
name
...
...
@@ -191,7 +192,7 @@ castDecl useVar name value size signed =
else
Param
Localparam
t
name
value
where
t
=
castType
size
signed
castDeclName
::
Int
->
S
T
String
castDeclName
::
Int
->
S
C
String
castDeclName
counter
=
do
details
<-
lookupElemM
name
if
details
==
Nothing
...
...
@@ -204,19 +205,15 @@ castDeclName counter = do
prefix
=
"sv2v_tmp_cast"
-- track whether procedural casts should use variables
pattern
WithinStmt
::
Identifier
pattern
WithinStmt
=
":within_stmt:"
withinStmt
::
ST
Bool
withinStmt
=
do
details
<-
lookupElemM
WithinStmt
return
$
case
details
of
Just
(
_
,
_
,
t
)
->
t
/=
Nil
Nothing
->
False
enterStmt
::
ST
()
withinStmtKey
::
Identifier
withinStmtKey
=
":within_stmt:"
withinStmt
::
SC
Bool
withinStmt
=
fmap
isJust
$
lookupElemM
withinStmtKey
enterStmt
::
SC
()
enterStmt
=
do
inProcedure
<-
withinProcedureM
when
inProcedure
$
insertElem
WithinStmt
(
RawNum
1
)
exitStmt
::
S
T
()
when
inProcedure
$
insertElem
withinStmtKey
(
)
exitStmt
::
S
C
()
exitStmt
=
do
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