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 }
recordIdxUsage
::
Identifier
->
State
Info
()
recordIdxUsage
i
=
modify
$
\
s
->
s
{
sIdxUses
=
Set
.
insert
i
$
sIdxUses
s
}
collectExpr
::
Expr
->
State
Info
()
collectExpr
(
Ident
i
)
=
recordSeqUsage
i
collectExpr
(
IdentRange
i
_
)
=
recordSeqUsage
i
collectExpr
(
IdentBit
i
_
)
=
recordIdxUsage
i
collectExpr
(
Ident
i
)
=
recordSeqUsage
i
collectExpr
(
Range
(
Ident
i
)
_
)
=
recordSeqUsage
i
collectExpr
(
Bit
(
Ident
i
)
_
)
=
recordIdxUsage
i
collectExpr
_
=
return
()
collectLHS
::
LHS
->
State
Info
()
collectLHS
(
LHSIdent
i
)
=
recordSeqUsage
i
...
...
@@ -165,8 +165,8 @@ unflattener writeToFlatVariant arr (t, (majorHi, majorLo)) =
(
BinOp
Mul
(
Ident
index
)
size
))
,
GenModuleItem
$
(
uncurry
Assign
)
$
if
not
writeToFlatVariant
then
(
LHSBit
(
LHSIdent
arrUnflat
)
$
Ident
index
,
IdentRange
arr
origRange
)
else
(
LHSRange
(
LHSIdent
arr
)
origRange
,
IdentBit
arrUnflat
$
Ident
index
)
then
(
LHSBit
(
LHSIdent
arrUnflat
)
$
Ident
index
,
Range
(
Ident
arr
)
origRange
)
else
(
LHSRange
(
LHSIdent
arr
)
origRange
,
Bit
(
Ident
arrUnflat
)
(
Ident
index
)
)
]
]
where
...
...
@@ -240,12 +240,12 @@ rewriteModuleItem info =
rewriteAsgnIdent
=
rewriteIdent
True
rewriteExpr
::
Expr
->
Expr
rewriteExpr
(
Ident
i
)
=
Ident
(
rewriteReadIdent
i
)
rewriteExpr
(
IdentBit
i
e
)
=
IdentBit
(
rewriteReadIdent
i
)
e
rewriteExpr
(
IdentRange
i
(
r
@
(
s
,
e
)))
=
rewriteExpr
(
Ident
i
)
=
Ident
(
rewriteReadIdent
i
)
rewriteExpr
(
Bit
(
Ident
i
)
e
)
=
Bit
(
Ident
$
rewriteReadIdent
i
)
e
rewriteExpr
(
Range
(
Ident
i
)
(
r
@
(
s
,
e
)))
=
if
Map
.
member
i
typeDims
then
IdentRange
i
r'
else
IdentRange
i
r
then
Range
(
Ident
i
)
r'
else
Range
(
Ident
i
)
r
where
(
a
,
b
)
=
head
$
snd
$
typeRanges
$
fst
$
typeDims
Map
.!
i
size
=
BinOp
Add
(
BinOp
Sub
a
b
)
(
Number
"1"
)
...
...
src/Convert/Traverse.hs
View file @
e1799de5
...
...
@@ -160,12 +160,15 @@ traverseNestedExprsM mapper = exprMapper
em
(
Number
s
)
=
return
$
Number
s
em
(
ConstBool
b
)
=
return
$
ConstBool
b
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
e2'
<-
exprMapper
e2
return
$
IdentRange
i
(
e1'
,
e2'
)
em
(
IdentBit
i
e
)
=
exprMapper
e
>>=
return
.
IdentBit
i
return
$
Bit
e1'
e2'
em
(
Repeat
e
l
)
=
do
e'
<-
exprMapper
e
l'
<-
mapM
exprMapper
l
...
...
@@ -185,16 +188,14 @@ traverseNestedExprsM mapper = exprMapper
e2'
<-
exprMapper
e2
e3'
<-
exprMapper
e3
return
$
Mux
e1'
e2'
e3'
em
(
Bit
e
n
)
=
exprMapper
e
>>=
\
e'
->
return
$
Bit
e'
n
em
(
Cast
t
e
)
=
exprMapper
e
>>=
return
.
Cast
t
em
(
Struct
Access
e
x
)
=
exprMapper
e
>>=
\
e'
->
return
$
Struct
Access
e'
x
em
(
Struct
Pattern
l
)
=
do
em
(
Access
e
x
)
=
exprMapper
e
>>=
\
e'
->
return
$
Access
e'
x
em
(
Pattern
l
)
=
do
let
names
=
map
fst
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
...
...
src/Language/SystemVerilog/AST.hs
View file @
e1799de5
...
...
@@ -240,18 +240,17 @@ data Expr
|
Number
String
|
ConstBool
Bool
|
Ident
Identifier
|
IdentRange
Identifie
r
Range
|
IdentBit
Identifie
r
Expr
|
Range
Exp
r
Range
|
Bit
Exp
r
Expr
|
Repeat
Expr
[
Expr
]
|
Concat
[
Expr
]
|
Call
Identifier
[
Expr
]
|
UniOp
UniOp
Expr
|
BinOp
BinOp
Expr
Expr
|
Mux
Expr
Expr
Expr
|
Bit
Expr
Int
|
Cast
Type
Expr
|
StructAccess
Expr
Identifier
|
StructPattern
[(
Maybe
Identifier
,
Expr
)]
|
Access
Expr
Identifier
|
Pattern
[(
Maybe
Identifier
,
Expr
)]
deriving
(
Eq
,
Ord
)
data
UniOp
...
...
@@ -331,18 +330,17 @@ instance Show Expr where
Number
a
->
a
ConstBool
a
->
printf
"1'b%s"
(
if
a
then
"1"
else
"0"
)
Ident
a
->
a
IdentBit
a
b
->
printf
"%s[%s]"
a
(
show
b
)
IdentRange
a
(
b
,
c
)
->
printf
"%s[%s:%s]"
a
(
show
b
)
(
show
c
)
Bit
a
b
->
printf
"%s[%s]"
(
show
a
)
(
show
b
)
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
)
Concat
a
->
printf
"{%s}"
(
commas
$
map
show
a
)
Call
a
b
->
printf
"%s(%s)"
a
(
commas
$
map
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
)
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
)
StructAccess
e
n
->
printf
"%s.%s"
(
show
e
)
n
StructPattern
l
->
printf
"'{
\n
%s
\n
}"
(
showPatternItems
l
)
Access
e
n
->
printf
"%s.%s"
(
show
e
)
n
Pattern
l
->
printf
"'{
\n
%s
\n
}"
(
showPatternItems
l
)
where
showPatternItems
::
[(
Maybe
Identifier
,
Expr
)]
->
String
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 _ _ }
%left "+" "-"
%left "*" "/" "%"
%left UPlus UMinus "!" "~" RedOps
%left "."
%left "
(" ")" "[" "]" "
."
%%
...
...
@@ -459,8 +459,8 @@ Expr :: { Expr }
| Number { Number $1 }
| Identifier "(" CallArgs ")" { Call $1 $3 }
| Identifier { Ident $1 }
|
Identifier Range { Ident
Range $1 $2 }
|
Identifier "[" Expr "]" { Ident
Bit $1 $3 }
|
Expr Range {
Range $1 $2 }
|
Expr "[" Expr "]" {
Bit $1 $3 }
| "{" Expr "{" Exprs "}" "}" { Repeat $2 $4 }
| "{" Exprs "}" { Concat $2 }
| Expr "?" Expr ":" Expr { Mux $1 $3 $5 }
...
...
@@ -495,9 +495,10 @@ Expr :: { Expr }
| "^" Expr %prec RedOps { UniOp RedXor $2 }
| "~^" Expr %prec RedOps { UniOp RedXnor $2 }
| "^~" Expr %prec RedOps { UniOp RedXnor $2 }
| Type "'" "(" Expr ")" { Cast $1 $4 }
| Expr "." Identifier { StructAccess $1 $3 }
| "'" "{" PatternItems "}" { StructPattern $3 }
| PartialType "'" "(" Expr ")" { Cast ($1 []) $4 }
| Identifier "'" "(" Expr ")" { Cast (Alias $1 []) $4 }
| Expr "." Identifier { Access $1 $3 }
| "'" "{" PatternItems "}" { Pattern $3 }
PatternItems :: { [(Maybe Identifier, Expr)] }
: 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