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
e1799de5
Commit
e1799de5
authored
Mar 04, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expr bits and ranges are recursive (as they should have been)
parent
59efba06
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
36 deletions
+36
-36
src/Convert/PackedArray.hs
+10
-10
src/Convert/Traverse.hs
+11
-10
src/Language/SystemVerilog/AST.hs
+8
-10
src/Language/SystemVerilog/Parser/Parse.y
+7
-6
No files found.
src/Convert/PackedArray.hs
View file @
e1799de5
...
@@ -90,9 +90,9 @@ recordSeqUsage i = modify $ \s -> s { sSeqUses = Set.insert i $ sSeqUses s }
...
@@ -90,9 +90,9 @@ recordSeqUsage i = modify $ \s -> s { sSeqUses = Set.insert i $ sSeqUses s }
recordIdxUsage
::
Identifier
->
State
Info
()
recordIdxUsage
::
Identifier
->
State
Info
()
recordIdxUsage
i
=
modify
$
\
s
->
s
{
sIdxUses
=
Set
.
insert
i
$
sIdxUses
s
}
recordIdxUsage
i
=
modify
$
\
s
->
s
{
sIdxUses
=
Set
.
insert
i
$
sIdxUses
s
}
collectExpr
::
Expr
->
State
Info
()
collectExpr
::
Expr
->
State
Info
()
collectExpr
(
Ident
i
)
=
recordSeqUsage
i
collectExpr
(
Ident
i
)
=
recordSeqUsage
i
collectExpr
(
IdentRange
i
_
)
=
recordSeqUsage
i
collectExpr
(
Range
(
Ident
i
)
_
)
=
recordSeqUsage
i
collectExpr
(
IdentBit
i
_
)
=
recordIdxUsage
i
collectExpr
(
Bit
(
Ident
i
)
_
)
=
recordIdxUsage
i
collectExpr
_
=
return
()
collectExpr
_
=
return
()
collectLHS
::
LHS
->
State
Info
()
collectLHS
::
LHS
->
State
Info
()
collectLHS
(
LHSIdent
i
)
=
recordSeqUsage
i
collectLHS
(
LHSIdent
i
)
=
recordSeqUsage
i
...
@@ -165,8 +165,8 @@ unflattener writeToFlatVariant arr (t, (majorHi, majorLo)) =
...
@@ -165,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
(
LHSIdent
arrUnflat
)
$
Ident
index
,
IdentRange
arr
origRange
)
then
(
LHSBit
(
LHSIdent
arrUnflat
)
$
Ident
index
,
Range
(
Ident
arr
)
origRange
)
else
(
LHSRange
(
LHSIdent
arr
)
origRange
,
IdentBit
arrUnflat
$
Ident
index
)
else
(
LHSRange
(
LHSIdent
arr
)
origRange
,
Bit
(
Ident
arrUnflat
)
(
Ident
index
)
)
]
]
]
]
where
where
...
@@ -240,12 +240,12 @@ rewriteModuleItem info =
...
@@ -240,12 +240,12 @@ rewriteModuleItem info =
rewriteAsgnIdent
=
rewriteIdent
True
rewriteAsgnIdent
=
rewriteIdent
True
rewriteExpr
::
Expr
->
Expr
rewriteExpr
::
Expr
->
Expr
rewriteExpr
(
Ident
i
)
=
Ident
(
rewriteReadIdent
i
)
rewriteExpr
(
Ident
i
)
=
Ident
(
rewriteReadIdent
i
)
rewriteExpr
(
IdentBit
i
e
)
=
IdentBit
(
rewriteReadIdent
i
)
e
rewriteExpr
(
Bit
(
Ident
i
)
e
)
=
Bit
(
Ident
$
rewriteReadIdent
i
)
e
rewriteExpr
(
IdentRange
i
(
r
@
(
s
,
e
)))
=
rewriteExpr
(
Range
(
Ident
i
)
(
r
@
(
s
,
e
)))
=
if
Map
.
member
i
typeDims
if
Map
.
member
i
typeDims
then
IdentRange
i
r'
then
Range
(
Ident
i
)
r'
else
IdentRange
i
r
else
Range
(
Ident
i
)
r
where
where
(
a
,
b
)
=
head
$
snd
$
typeRanges
$
fst
$
typeDims
Map
.!
i
(
a
,
b
)
=
head
$
snd
$
typeRanges
$
fst
$
typeDims
Map
.!
i
size
=
BinOp
Add
(
BinOp
Sub
a
b
)
(
Number
"1"
)
size
=
BinOp
Add
(
BinOp
Sub
a
b
)
(
Number
"1"
)
...
...
src/Convert/Traverse.hs
View file @
e1799de5
...
@@ -160,12 +160,15 @@ traverseNestedExprsM mapper = exprMapper
...
@@ -160,12 +160,15 @@ traverseNestedExprsM mapper = exprMapper
em
(
Number
s
)
=
return
$
Number
s
em
(
Number
s
)
=
return
$
Number
s
em
(
ConstBool
b
)
=
return
$
ConstBool
b
em
(
ConstBool
b
)
=
return
$
ConstBool
b
em
(
Ident
i
)
=
return
$
Ident
i
em
(
Ident
i
)
=
return
$
Ident
i
em
(
IdentRange
i
(
e1
,
e2
))
=
do
em
(
Range
e
(
e1
,
e2
))
=
do
e'
<-
exprMapper
e
e1'
<-
exprMapper
e1
e2'
<-
exprMapper
e2
return
$
Range
e'
(
e1'
,
e2'
)
em
(
Bit
e1
e2
)
=
do
e1'
<-
exprMapper
e1
e1'
<-
exprMapper
e1
e2'
<-
exprMapper
e2
e2'
<-
exprMapper
e2
return
$
IdentRange
i
(
e1'
,
e2'
)
return
$
Bit
e1'
e2'
em
(
IdentBit
i
e
)
=
exprMapper
e
>>=
return
.
IdentBit
i
em
(
Repeat
e
l
)
=
do
em
(
Repeat
e
l
)
=
do
e'
<-
exprMapper
e
e'
<-
exprMapper
e
l'
<-
mapM
exprMapper
l
l'
<-
mapM
exprMapper
l
...
@@ -185,16 +188,14 @@ traverseNestedExprsM mapper = exprMapper
...
@@ -185,16 +188,14 @@ traverseNestedExprsM mapper = exprMapper
e2'
<-
exprMapper
e2
e2'
<-
exprMapper
e2
e3'
<-
exprMapper
e3
e3'
<-
exprMapper
e3
return
$
Mux
e1'
e2'
e3'
return
$
Mux
e1'
e2'
e3'
em
(
Bit
e
n
)
=
exprMapper
e
>>=
\
e'
->
return
$
Bit
e'
n
em
(
Cast
t
e
)
=
em
(
Cast
t
e
)
=
exprMapper
e
>>=
return
.
Cast
t
exprMapper
e
>>=
return
.
Cast
t
em
(
Struct
Access
e
x
)
=
em
(
Access
e
x
)
=
exprMapper
e
>>=
\
e'
->
return
$
Struct
Access
e'
x
exprMapper
e
>>=
\
e'
->
return
$
Access
e'
x
em
(
Struct
Pattern
l
)
=
do
em
(
Pattern
l
)
=
do
let
names
=
map
fst
l
let
names
=
map
fst
l
exprs
<-
mapM
exprMapper
$
map
snd
l
exprs
<-
mapM
exprMapper
$
map
snd
l
return
$
Struct
Pattern
$
zip
names
exprs
return
$
Pattern
$
zip
names
exprs
traverseExprsM
::
Monad
m
=>
MapperM
m
Expr
->
MapperM
m
ModuleItem
traverseExprsM
::
Monad
m
=>
MapperM
m
Expr
->
MapperM
m
ModuleItem
...
...
src/Language/SystemVerilog/AST.hs
View file @
e1799de5
...
@@ -240,18 +240,17 @@ data Expr
...
@@ -240,18 +240,17 @@ data Expr
|
Number
String
|
Number
String
|
ConstBool
Bool
|
ConstBool
Bool
|
Ident
Identifier
|
Ident
Identifier
|
IdentRange
Identifie
r
Range
|
Range
Exp
r
Range
|
IdentBit
Identifie
r
Expr
|
Bit
Exp
r
Expr
|
Repeat
Expr
[
Expr
]
|
Repeat
Expr
[
Expr
]
|
Concat
[
Expr
]
|
Concat
[
Expr
]
|
Call
Identifier
[
Expr
]
|
Call
Identifier
[
Expr
]
|
UniOp
UniOp
Expr
|
UniOp
UniOp
Expr
|
BinOp
BinOp
Expr
Expr
|
BinOp
BinOp
Expr
Expr
|
Mux
Expr
Expr
Expr
|
Mux
Expr
Expr
Expr
|
Bit
Expr
Int
|
Cast
Type
Expr
|
Cast
Type
Expr
|
StructAccess
Expr
Identifier
|
Access
Expr
Identifier
|
StructPattern
[(
Maybe
Identifier
,
Expr
)]
|
Pattern
[(
Maybe
Identifier
,
Expr
)]
deriving
(
Eq
,
Ord
)
deriving
(
Eq
,
Ord
)
data
UniOp
data
UniOp
...
@@ -331,18 +330,17 @@ instance Show Expr where
...
@@ -331,18 +330,17 @@ instance Show Expr where
Number
a
->
a
Number
a
->
a
ConstBool
a
->
printf
"1'b%s"
(
if
a
then
"1"
else
"0"
)
ConstBool
a
->
printf
"1'b%s"
(
if
a
then
"1"
else
"0"
)
Ident
a
->
a
Ident
a
->
a
IdentBit
a
b
->
printf
"%s[%s]"
a
(
show
b
)
Bit
a
b
->
printf
"%s[%s]"
(
show
a
)
(
show
b
)
IdentRange
a
(
b
,
c
)
->
printf
"%s[%s:%s]"
a
(
show
b
)
(
show
c
)
Range
a
(
b
,
c
)
->
printf
"%s[%s:%s]"
(
show
a
)
(
show
b
)
(
show
c
)
Repeat
a
b
->
printf
"{%s {%s}}"
(
show
a
)
(
commas
$
map
show
b
)
Repeat
a
b
->
printf
"{%s {%s}}"
(
show
a
)
(
commas
$
map
show
b
)
Concat
a
->
printf
"{%s}"
(
commas
$
map
show
a
)
Concat
a
->
printf
"{%s}"
(
commas
$
map
show
a
)
Call
a
b
->
printf
"%s(%s)"
a
(
commas
$
map
show
b
)
Call
a
b
->
printf
"%s(%s)"
a
(
commas
$
map
show
b
)
UniOp
a
b
->
printf
"(%s %s)"
(
show
a
)
(
show
b
)
UniOp
a
b
->
printf
"(%s %s)"
(
show
a
)
(
show
b
)
BinOp
a
b
c
->
printf
"(%s %s %s)"
(
show
b
)
(
show
a
)
(
show
c
)
BinOp
a
b
c
->
printf
"(%s %s %s)"
(
show
b
)
(
show
a
)
(
show
c
)
Mux
a
b
c
->
printf
"(%s ? %s : %s)"
(
show
a
)
(
show
b
)
(
show
c
)
Mux
a
b
c
->
printf
"(%s ? %s : %s)"
(
show
a
)
(
show
b
)
(
show
c
)
Bit
a
b
->
printf
"(%s [%d])"
(
show
a
)
b
Cast
a
b
->
printf
"%s'(%s)"
(
show
a
)
(
show
b
)
Cast
a
b
->
printf
"%s'(%s)"
(
show
a
)
(
show
b
)
StructAccess
e
n
->
printf
"%s.%s"
(
show
e
)
n
Access
e
n
->
printf
"%s.%s"
(
show
e
)
n
StructPattern
l
->
printf
"'{
\n
%s
\n
}"
(
showPatternItems
l
)
Pattern
l
->
printf
"'{
\n
%s
\n
}"
(
showPatternItems
l
)
where
where
showPatternItems
::
[(
Maybe
Identifier
,
Expr
)]
->
String
showPatternItems
::
[(
Maybe
Identifier
,
Expr
)]
->
String
showPatternItems
l
=
indent
$
intercalate
",
\n
"
(
map
showPatternItem
l
)
showPatternItems
l
=
indent
$
intercalate
",
\n
"
(
map
showPatternItem
l
)
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
e1799de5
...
@@ -168,7 +168,7 @@ string { Token Lit_string _ _ }
...
@@ -168,7 +168,7 @@ string { Token Lit_string _ _ }
%left "+" "-"
%left "+" "-"
%left "*" "/" "%"
%left "*" "/" "%"
%left UPlus UMinus "!" "~" RedOps
%left UPlus UMinus "!" "~" RedOps
%left "."
%left "
(" ")" "[" "]" "
."
%%
%%
...
@@ -459,8 +459,8 @@ Expr :: { Expr }
...
@@ -459,8 +459,8 @@ Expr :: { Expr }
| Number { Number $1 }
| Number { Number $1 }
| Identifier "(" CallArgs ")" { Call $1 $3 }
| Identifier "(" CallArgs ")" { Call $1 $3 }
| Identifier { Ident $1 }
| Identifier { Ident $1 }
|
Identifier Range { Ident
Range $1 $2 }
|
Expr Range {
Range $1 $2 }
|
Identifier "[" Expr "]" { Ident
Bit $1 $3 }
|
Expr "[" Expr "]" {
Bit $1 $3 }
| "{" Expr "{" Exprs "}" "}" { Repeat $2 $4 }
| "{" Expr "{" Exprs "}" "}" { Repeat $2 $4 }
| "{" Exprs "}" { Concat $2 }
| "{" Exprs "}" { Concat $2 }
| Expr "?" Expr ":" Expr { Mux $1 $3 $5 }
| Expr "?" Expr ":" Expr { Mux $1 $3 $5 }
...
@@ -495,9 +495,10 @@ Expr :: { Expr }
...
@@ -495,9 +495,10 @@ Expr :: { Expr }
| "^" Expr %prec RedOps { UniOp RedXor $2 }
| "^" Expr %prec RedOps { UniOp RedXor $2 }
| "~^" Expr %prec RedOps { UniOp RedXnor $2 }
| "~^" Expr %prec RedOps { UniOp RedXnor $2 }
| "^~" Expr %prec RedOps { UniOp RedXnor $2 }
| "^~" Expr %prec RedOps { UniOp RedXnor $2 }
| Type "'" "(" Expr ")" { Cast $1 $4 }
| PartialType "'" "(" Expr ")" { Cast ($1 []) $4 }
| Expr "." Identifier { StructAccess $1 $3 }
| Identifier "'" "(" Expr ")" { Cast (Alias $1 []) $4 }
| "'" "{" PatternItems "}" { StructPattern $3 }
| Expr "." Identifier { Access $1 $3 }
| "'" "{" PatternItems "}" { Pattern $3 }
PatternItems :: { [(Maybe Identifier, Expr)] }
PatternItems :: { [(Maybe Identifier, Expr)] }
: PatternNamedItems { map (\(x,e) -> (Just x, e)) $1 }
: PatternNamedItems { map (\(x,e) -> (Just x, e)) $1 }
...
...
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