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
3597f4a6
Commit
3597f4a6
authored
Oct 19, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for methods (no conversion) and interface TFs
parent
39f0e9b4
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
103 additions
and
64 deletions
+103
-64
src/Convert/EmptyArgs.hs
+2
-2
src/Convert/Interface.hs
+14
-0
src/Convert/KWArgs.hs
+4
-4
src/Convert/NestPI.hs
+2
-2
src/Convert/Package.hs
+0
-8
src/Convert/Simplify.hs
+2
-2
src/Convert/SizeCast.hs
+1
-1
src/Convert/Struct.hs
+18
-14
src/Convert/Traverse.hs
+7
-5
src/Language/SystemVerilog/AST/Expr.hs
+3
-3
src/Language/SystemVerilog/AST/Stmt.hs
+2
-2
src/Language/SystemVerilog/Parser/Parse.y
+4
-7
src/Language/SystemVerilog/Parser/ParseDecl.hs
+26
-14
test/basic/interface_func.sv
+11
-0
test/basic/interface_func.v
+7
-0
No files found.
src/Convert/EmptyArgs.hs
View file @
3597f4a6
...
@@ -46,8 +46,8 @@ traverseFunctionsM (MIPackageItem (Function ml t f decls stmts)) = do
...
@@ -46,8 +46,8 @@ traverseFunctionsM (MIPackageItem (Function ml t f decls stmts)) = do
traverseFunctionsM
other
=
return
other
traverseFunctionsM
other
=
return
other
convertExpr
::
Idents
->
Expr
->
Expr
convertExpr
::
Idents
->
Expr
->
Expr
convertExpr
functions
(
Call
Nothing
func
(
Args
[]
[]
))
=
convertExpr
functions
(
Call
(
Ident
func
)
(
Args
[]
[]
))
=
Call
Nothing
func
(
Args
args
[]
)
Call
(
Ident
func
)
(
Args
args
[]
)
where
args
=
if
Set
.
member
func
functions
where
args
=
if
Set
.
member
func
functions
then
[
Just
$
Number
"0"
]
then
[
Just
$
Number
"0"
]
else
[]
else
[]
...
...
src/Convert/Interface.hs
View file @
3597f4a6
...
@@ -186,6 +186,7 @@ convertDescription _ _ other = other
...
@@ -186,6 +186,7 @@ convertDescription _ _ other = other
-- add a prefix to all standard identifiers in a module item
-- add a prefix to all standard identifiers in a module item
prefixModuleItems
::
Identifier
->
ModuleItem
->
ModuleItem
prefixModuleItems
::
Identifier
->
ModuleItem
->
ModuleItem
prefixModuleItems
prefix
=
prefixModuleItems
prefix
=
prefixMIPackageItem
.
traverseDecls
prefixDecl
.
traverseDecls
prefixDecl
.
traverseExprs
(
traverseNestedExprs
prefixExpr
)
.
traverseExprs
(
traverseNestedExprs
prefixExpr
)
.
traverseLHSs
(
traverseNestedLHSs
prefixLHS
)
traverseLHSs
(
traverseNestedLHSs
prefixLHS
)
...
@@ -200,6 +201,19 @@ prefixModuleItems prefix =
...
@@ -200,6 +201,19 @@ prefixModuleItems prefix =
prefixLHS
::
LHS
->
LHS
prefixLHS
::
LHS
->
LHS
prefixLHS
(
LHSIdent
x
)
=
LHSIdent
(
prefix
++
x
)
prefixLHS
(
LHSIdent
x
)
=
LHSIdent
(
prefix
++
x
)
prefixLHS
other
=
other
prefixLHS
other
=
other
prefixMIPackageItem
(
MIPackageItem
item
)
=
MIPackageItem
$
prefixPackageItem
prefix
item
prefixMIPackageItem
other
=
other
-- add a prefix to all standard identifiers in a package item
prefixPackageItem
::
Identifier
->
PackageItem
->
PackageItem
prefixPackageItem
prefix
(
Function
lifetime
t
x
decls
stmts
)
=
Function
lifetime
t
x'
decls
stmts
where
x'
=
prefix
++
x
prefixPackageItem
prefix
(
Task
lifetime
x
decls
stmts
)
=
Task
lifetime
x'
decls
stmts
where
x'
=
prefix
++
x
prefixPackageItem
_
other
=
other
lookupType
::
[
ModuleItem
]
->
Expr
->
(
Type
,
[
Range
])
lookupType
::
[
ModuleItem
]
->
Expr
->
(
Type
,
[
Range
])
lookupType
items
(
Ident
ident
)
=
lookupType
items
(
Ident
ident
)
=
...
...
src/Convert/KWArgs.hs
View file @
3597f4a6
...
@@ -44,11 +44,11 @@ collectTFDecls name decls =
...
@@ -44,11 +44,11 @@ collectTFDecls name decls =
getInput
_
=
Nothing
getInput
_
=
Nothing
convertExpr
::
TFs
->
Expr
->
Expr
convertExpr
::
TFs
->
Expr
->
Expr
convertExpr
_
(
orig
@
(
Call
Nothing
_
(
Args
_
[]
)))
=
orig
convertExpr
_
(
orig
@
(
Call
_
(
Args
_
[]
)))
=
orig
convertExpr
tfs
(
Call
Nothing
func
(
Args
pnArgs
kwArgs
))
=
convertExpr
tfs
(
Call
(
Ident
func
)
(
Args
pnArgs
kwArgs
))
=
case
tfs
Map
.!?
func
of
case
tfs
Map
.!?
func
of
Nothing
->
Call
Nothing
func
(
Args
pnArgs
kwArgs
)
Nothing
->
Call
(
Ident
func
)
(
Args
pnArgs
kwArgs
)
Just
ordered
->
Call
Nothing
func
(
Args
args
[]
)
Just
ordered
->
Call
(
Ident
func
)
(
Args
args
[]
)
where
where
args
=
pnArgs
++
(
map
snd
$
sortOn
position
kwArgs
)
args
=
pnArgs
++
(
map
snd
$
sortOn
position
kwArgs
)
position
(
x
,
_
)
=
elemIndex
x
ordered
position
(
x
,
_
)
=
elemIndex
x
ordered
...
...
src/Convert/NestPI.hs
View file @
3597f4a6
...
@@ -82,12 +82,12 @@ collectPIsM _ = return ()
...
@@ -82,12 +82,12 @@ collectPIsM _ = return ()
-- writes down the names of subroutine invocations
-- writes down the names of subroutine invocations
collectSubroutinesM
::
Stmt
->
Writer
Idents
()
collectSubroutinesM
::
Stmt
->
Writer
Idents
()
collectSubroutinesM
(
Subroutine
Nothing
f
_
)
=
tell
$
Set
.
singleton
f
collectSubroutinesM
(
Subroutine
(
Ident
f
)
_
)
=
tell
$
Set
.
singleton
f
collectSubroutinesM
_
=
return
()
collectSubroutinesM
_
=
return
()
-- writes down the names of function calls and identifiers
-- writes down the names of function calls and identifiers
collectIdentsM
::
Expr
->
Writer
Idents
()
collectIdentsM
::
Expr
->
Writer
Idents
()
collectIdentsM
(
Call
Nothing
x
_
)
=
tell
$
Set
.
singleton
x
collectIdentsM
(
Call
(
Ident
x
)
_
)
=
tell
$
Set
.
singleton
x
collectIdentsM
(
Ident
x
)
=
tell
$
Set
.
singleton
x
collectIdentsM
(
Ident
x
)
=
tell
$
Set
.
singleton
x
collectIdentsM
_
=
return
()
collectIdentsM
_
=
return
()
...
...
src/Convert/Package.hs
View file @
3597f4a6
...
@@ -154,22 +154,14 @@ traverseModuleItem existingItemNames packages (MIPackageItem (Import x y)) =
...
@@ -154,22 +154,14 @@ traverseModuleItem existingItemNames packages (MIPackageItem (Import x y)) =
items
=
map
snd
$
filter
(
filterer
.
fst
)
$
packageItems
items
=
map
snd
$
filter
(
filterer
.
fst
)
$
packageItems
traverseModuleItem
_
_
item
=
traverseModuleItem
_
_
item
=
(
traverseExprs
$
traverseNestedExprs
traverseExpr
)
$
(
traverseExprs
$
traverseNestedExprs
traverseExpr
)
$
(
traverseStmts
traverseStmt
)
$
(
traverseTypes
$
traverseNestedTypes
traverseType
)
$
(
traverseTypes
$
traverseNestedTypes
traverseType
)
$
item
item
where
where
traverseExpr
::
Expr
->
Expr
traverseExpr
::
Expr
->
Expr
traverseExpr
(
PSIdent
x
y
)
=
Ident
$
x
++
"_"
++
y
traverseExpr
(
PSIdent
x
y
)
=
Ident
$
x
++
"_"
++
y
traverseExpr
(
Call
(
Just
ps
)
f
args
)
=
Call
Nothing
(
ps
++
"_"
++
f
)
args
traverseExpr
other
=
other
traverseExpr
other
=
other
traverseStmt
::
Stmt
->
Stmt
traverseStmt
(
Subroutine
(
Just
ps
)
f
args
)
=
Subroutine
Nothing
(
ps
++
"_"
++
f
)
args
traverseStmt
other
=
other
traverseType
::
Type
->
Type
traverseType
::
Type
->
Type
traverseType
(
Alias
(
Just
ps
)
xx
rs
)
=
traverseType
(
Alias
(
Just
ps
)
xx
rs
)
=
Alias
Nothing
(
ps
++
"_"
++
xx
)
rs
Alias
Nothing
(
ps
++
"_"
++
xx
)
rs
...
...
src/Convert/Simplify.hs
View file @
3597f4a6
...
@@ -56,13 +56,13 @@ convertExpr info (DimFn f v e) =
...
@@ -56,13 +56,13 @@ convertExpr info (DimFn f v e) =
DimFn
f
v
e'
DimFn
f
v
e'
where
where
e'
=
simplify
$
substitute
info
e
e'
=
simplify
$
substitute
info
e
convertExpr
info
(
Call
Nothing
"$clog2"
(
Args
[
Just
e
]
[]
))
=
convertExpr
info
(
Call
(
Ident
"$clog2"
)
(
Args
[
Just
e
]
[]
))
=
if
clog2'
==
clog2
if
clog2'
==
clog2
then
clog2
then
clog2
else
clog2'
else
clog2'
where
where
e'
=
simplify
$
substitute
info
e
e'
=
simplify
$
substitute
info
e
clog2
=
Call
Nothing
"$clog2"
(
Args
[
Just
e'
]
[]
)
clog2
=
Call
(
Ident
"$clog2"
)
(
Args
[
Just
e'
]
[]
)
clog2'
=
simplify
clog2
clog2'
=
simplify
clog2
convertExpr
info
(
Mux
cc
aa
bb
)
=
convertExpr
info
(
Mux
cc
aa
bb
)
=
if
before
==
after
if
before
==
after
...
...
src/Convert/SizeCast.hs
View file @
3597f4a6
...
@@ -65,7 +65,7 @@ traverseExprM =
...
@@ -65,7 +65,7 @@ traverseExprM =
lift
$
tell
$
Set
.
singleton
(
s
,
sg
)
lift
$
tell
$
Set
.
singleton
(
s
,
sg
)
let
f
=
castFnName
s
sg
let
f
=
castFnName
s
sg
let
args
=
Args
[
Just
e
]
[]
let
args
=
Args
[
Just
e
]
[]
return
$
Call
Nothing
f
args
return
$
Call
(
Ident
f
)
args
_
->
return
$
Cast
(
Right
s
)
e
_
->
return
$
Cast
(
Right
s
)
e
convertExprM
other
=
return
other
convertExprM
other
=
return
other
...
...
src/Convert/Struct.hs
View file @
3597f4a6
...
@@ -51,10 +51,10 @@ convertDescription (description @ Part{}) =
...
@@ -51,10 +51,10 @@ convertDescription (description @ Part{}) =
traverseExprsM
traverseExprM
>>=
traverseExprsM
traverseExprM
>>=
traverseAsgnsM
traverseAsgnM
traverseAsgnsM
traverseAsgnM
traverseStmtM
::
Stmt
->
State
Types
Stmt
traverseStmtM
::
Stmt
->
State
Types
Stmt
traverseStmtM
(
Subroutine
Nothing
f
args
)
=
do
traverseStmtM
(
Subroutine
expr
args
)
=
do
stateTypes
<-
get
stateTypes
<-
get
return
$
uncurry
(
Subroutine
Nothing
)
$
return
$
Subroutine
expr
$
convertCall
structs
stateTypes
f
args
convertCall
structs
stateTypes
expr
args
traverseStmtM
stmt
=
traverseStmtM
stmt
=
traverseStmtLHSsM
traverseLHSM
stmt
>>=
traverseStmtLHSsM
traverseLHSM
stmt
>>=
traverseStmtExprsM
traverseExprM
>>=
traverseStmtExprsM
traverseExprM
>>=
...
@@ -152,7 +152,7 @@ convertType structs t1 =
...
@@ -152,7 +152,7 @@ convertType structs t1 =
-- writes down the names of called functions
-- writes down the names of called functions
collectCallsM
::
Expr
->
Writer
Idents
()
collectCallsM
::
Expr
->
Writer
Idents
()
collectCallsM
(
Call
Nothing
f
_
)
=
tell
$
Set
.
singleton
f
collectCallsM
(
Call
(
Ident
f
)
_
)
=
tell
$
Set
.
singleton
f
collectCallsM
_
=
return
()
collectCallsM
_
=
return
()
collectTFArgsM
::
ModuleItem
->
Writer
Types
()
collectTFArgsM
::
ModuleItem
->
Writer
Types
()
...
@@ -328,8 +328,8 @@ convertAsgn structs types (lhs, expr) =
...
@@ -328,8 +328,8 @@ convertAsgn structs types (lhs, expr) =
show
(
Set
.
toList
extraNames
)
++
" that are not in "
++
show
(
Set
.
toList
extraNames
)
++
" that are not in "
++
show
structTf
show
structTf
else
if
Map
.
member
structTf
structs
then
else
if
Map
.
member
structTf
structs
then
Call
Nothing
Call
(
packerFnName
structTf
)
(
Ident
$
packerFnName
structTf
)
(
Args
(
map
(
Just
.
snd
)
items
)
[]
)
(
Args
(
map
(
Just
.
snd
)
items
)
[]
)
else
else
Pattern
items
Pattern
items
...
@@ -464,14 +464,15 @@ convertAsgn structs types (lhs, expr) =
...
@@ -464,14 +464,15 @@ convertAsgn structs types (lhs, expr) =
(
_
,
[]
)
->
Implicit
Unspecified
[]
(
_
,
[]
)
->
Implicit
Unspecified
[]
(
tf
,
rs
)
->
tf
$
tail
rs
(
tf
,
rs
)
->
tf
$
tail
rs
(
_
,
i'
)
=
convertSubExpr
i
(
_
,
i'
)
=
convertSubExpr
i
convertSubExpr
(
Call
Nothing
f
args
)
=
convertSubExpr
(
Call
e
args
)
=
(
retType
,
uncurry
(
Call
Nothing
)
$
convertCall
structs
types
f
args
)
(
retType
,
Call
e
$
convertCall
structs
types
e'
args
)
where
where
retType
=
case
Map
.
lookup
f
types
of
(
_
,
e'
)
=
convertSubExpr
e
retType
=
case
e'
of
Ident
f
->
case
Map
.
lookup
f
types
of
Nothing
->
Implicit
Unspecified
[]
Nothing
->
Implicit
Unspecified
[]
Just
t
->
t
Just
t
->
t
convertSubExpr
(
Call
(
Just
x
)
f
args
)
=
_
->
Implicit
Unspecified
[]
(
Implicit
Unspecified
[]
,
Call
(
Just
x
)
f
args
)
convertSubExpr
(
String
s
)
=
(
Implicit
Unspecified
[]
,
String
s
)
convertSubExpr
(
String
s
)
=
(
Implicit
Unspecified
[]
,
String
s
)
convertSubExpr
(
Number
n
)
=
(
Implicit
Unspecified
[]
,
Number
n
)
convertSubExpr
(
Number
n
)
=
(
Implicit
Unspecified
[]
,
Number
n
)
convertSubExpr
(
Time
n
)
=
(
Implicit
Unspecified
[]
,
Time
n
)
convertSubExpr
(
Time
n
)
=
(
Implicit
Unspecified
[]
,
Time
n
)
...
@@ -536,10 +537,13 @@ convertAsgn structs types (lhs, expr) =
...
@@ -536,10 +537,13 @@ convertAsgn structs types (lhs, expr) =
where
fieldMap
=
Map
.
fromList
$
map
swap
fields
where
fieldMap
=
Map
.
fromList
$
map
swap
fields
-- attempts to convert based on the assignment-like contexts of TF arguments
-- attempts to convert based on the assignment-like contexts of TF arguments
convertCall
::
Structs
->
Types
->
Identifier
->
Args
->
(
Identifier
,
Args
)
convertCall
::
Structs
->
Types
->
Expr
->
Args
->
Args
convertCall
structs
types
f
(
Args
pnArgs
kwArgs
)
=
convertCall
structs
types
fn
(
Args
pnArgs
kwArgs
)
=
(
f
,
args
)
case
fn
of
Ident
_
->
args
_
->
Args
pnArgs
kwArgs
where
where
Ident
f
=
fn
idxs
=
map
show
([
0
..
]
::
[
Int
])
idxs
=
map
show
([
0
..
]
::
[
Int
])
args
=
Args
args
=
Args
(
map
snd
$
map
convertArg
$
zip
idxs
pnArgs
)
(
map
snd
$
map
convertArg
$
zip
idxs
pnArgs
)
...
...
src/Convert/Traverse.hs
View file @
3597f4a6
...
@@ -257,7 +257,7 @@ traverseSinglyNestedStmtsM fullMapper = cs
...
@@ -257,7 +257,7 @@ traverseSinglyNestedStmtsM fullMapper = cs
return
$
If
u
e
s1'
s2'
return
$
If
u
e
s1'
s2'
cs
(
Timing
event
stmt
)
=
fullMapper
stmt
>>=
return
.
Timing
event
cs
(
Timing
event
stmt
)
=
fullMapper
stmt
>>=
return
.
Timing
event
cs
(
Return
expr
)
=
return
$
Return
expr
cs
(
Return
expr
)
=
return
$
Return
expr
cs
(
Subroutine
ps
f
exprs
)
=
return
$
Subroutine
ps
f
exprs
cs
(
Subroutine
expr
exprs
)
=
return
$
Subroutine
expr
exprs
cs
(
Trigger
blocks
x
)
=
return
$
Trigger
blocks
x
cs
(
Trigger
blocks
x
)
=
return
$
Trigger
blocks
x
cs
(
Assertion
a
)
=
cs
(
Assertion
a
)
=
traverseAssertionStmtsM
fullMapper
a
>>=
return
.
Assertion
traverseAssertionStmtsM
fullMapper
a
>>=
return
.
Assertion
...
@@ -455,11 +455,12 @@ traverseNestedExprsM mapper = exprMapper
...
@@ -455,11 +455,12 @@ traverseNestedExprsM mapper = exprMapper
e'
<-
exprMapper
e
e'
<-
exprMapper
e
l'
<-
mapM
exprMapper
l
l'
<-
mapM
exprMapper
l
return
$
Stream
o
e'
l'
return
$
Stream
o
e'
l'
em
(
Call
ps
f
(
Args
l
p
))
=
do
em
(
Call
e
(
Args
l
p
))
=
do
e'
<-
exprMapper
e
l'
<-
mapM
maybeExprMapper
l
l'
<-
mapM
maybeExprMapper
l
pes
<-
mapM
maybeExprMapper
$
map
snd
p
pes
<-
mapM
maybeExprMapper
$
map
snd
p
let
p'
=
zip
(
map
fst
p
)
pes
let
p'
=
zip
(
map
fst
p
)
pes
return
$
Call
ps
f
(
Args
l'
p'
)
return
$
Call
e'
(
Args
l'
p'
)
em
(
UniOp
o
e
)
=
em
(
UniOp
o
e
)
=
exprMapper
e
>>=
return
.
UniOp
o
exprMapper
e
>>=
return
.
UniOp
o
em
(
BinOp
o
e1
e2
)
=
do
em
(
BinOp
o
e1
e2
)
=
do
...
@@ -711,11 +712,12 @@ traverseStmtExprsM exprMapper = flatStmtMapper
...
@@ -711,11 +712,12 @@ traverseStmtExprsM exprMapper = flatStmtMapper
flatStmtMapper
(
If
u
cc
s1
s2
)
=
flatStmtMapper
(
If
u
cc
s1
s2
)
=
exprMapper
cc
>>=
\
cc'
->
return
$
If
u
cc'
s1
s2
exprMapper
cc
>>=
\
cc'
->
return
$
If
u
cc'
s1
s2
flatStmtMapper
(
Timing
event
stmt
)
=
return
$
Timing
event
stmt
flatStmtMapper
(
Timing
event
stmt
)
=
return
$
Timing
event
stmt
flatStmtMapper
(
Subroutine
ps
f
(
Args
l
p
))
=
do
flatStmtMapper
(
Subroutine
e
(
Args
l
p
))
=
do
e'
<-
exprMapper
e
l'
<-
mapM
maybeExprMapper
l
l'
<-
mapM
maybeExprMapper
l
pes
<-
mapM
maybeExprMapper
$
map
snd
p
pes
<-
mapM
maybeExprMapper
$
map
snd
p
let
p'
=
zip
(
map
fst
p
)
pes
let
p'
=
zip
(
map
fst
p
)
pes
return
$
Subroutine
ps
f
(
Args
l'
p'
)
return
$
Subroutine
e'
(
Args
l'
p'
)
flatStmtMapper
(
Return
expr
)
=
flatStmtMapper
(
Return
expr
)
=
exprMapper
expr
>>=
return
.
Return
exprMapper
expr
>>=
return
.
Return
flatStmtMapper
(
Trigger
blocks
x
)
=
return
$
Trigger
blocks
x
flatStmtMapper
(
Trigger
blocks
x
)
=
return
$
Trigger
blocks
x
...
...
src/Language/SystemVerilog/AST/Expr.hs
View file @
3597f4a6
...
@@ -46,7 +46,7 @@ data Expr
...
@@ -46,7 +46,7 @@ data Expr
|
Repeat
Expr
[
Expr
]
|
Repeat
Expr
[
Expr
]
|
Concat
[
Expr
]
|
Concat
[
Expr
]
|
Stream
StreamOp
Expr
[
Expr
]
|
Stream
StreamOp
Expr
[
Expr
]
|
Call
(
Maybe
Identifier
)
Identifie
r
Args
|
Call
Exp
r
Args
|
UniOp
UniOp
Expr
|
UniOp
UniOp
Expr
|
BinOp
BinOp
Expr
Expr
|
BinOp
BinOp
Expr
Expr
|
Mux
Expr
Expr
Expr
|
Mux
Expr
Expr
Expr
...
@@ -75,7 +75,7 @@ instance Show Expr where
...
@@ -75,7 +75,7 @@ instance Show Expr where
show
(
BinOp
o
a
b
)
=
printf
"(%s %s %s)"
(
show
a
)
(
show
o
)
(
show
b
)
show
(
BinOp
o
a
b
)
=
printf
"(%s %s %s)"
(
show
a
)
(
show
o
)
(
show
b
)
show
(
Dot
e
n
)
=
printf
"%s.%s"
(
show
e
)
n
show
(
Dot
e
n
)
=
printf
"%s.%s"
(
show
e
)
n
show
(
Mux
c
a
b
)
=
printf
"(%s ? %s : %s)"
(
show
c
)
(
show
a
)
(
show
b
)
show
(
Mux
c
a
b
)
=
printf
"(%s ? %s : %s)"
(
show
c
)
(
show
a
)
(
show
b
)
show
(
Call
ps
f
l
)
=
printf
"%s%s%s"
(
maybe
""
(
++
"::"
)
ps
)
f
(
show
l
)
show
(
Call
e
l
)
=
printf
"%s%s"
(
show
e
)
(
show
l
)
show
(
Cast
tore
e
)
=
printf
"%s'(%s)"
(
showEither
tore
)
(
show
e
)
show
(
Cast
tore
e
)
=
printf
"%s'(%s)"
(
showEither
tore
)
(
show
e
)
show
(
DimsFn
f
v
)
=
printf
"%s(%s)"
(
show
f
)
(
showEither
v
)
show
(
DimsFn
f
v
)
=
printf
"%s(%s)"
(
show
f
)
(
showEither
v
)
show
(
DimFn
f
v
e
)
=
printf
"%s(%s, %s)"
(
show
f
)
(
showEither
v
)
(
show
e
)
show
(
DimFn
f
v
e
)
=
printf
"%s(%s, %s)"
(
show
f
)
(
showEither
v
)
(
show
e
)
...
@@ -184,7 +184,7 @@ simplify (orig @ (Repeat (Number n) exprs)) =
...
@@ -184,7 +184,7 @@ simplify (orig @ (Repeat (Number n) exprs)) =
simplify
(
Concat
[
expr
])
=
expr
simplify
(
Concat
[
expr
])
=
expr
simplify
(
Concat
exprs
)
=
simplify
(
Concat
exprs
)
=
Concat
$
filter
(
/=
Concat
[]
)
exprs
Concat
$
filter
(
/=
Concat
[]
)
exprs
simplify
(
orig
@
(
Call
Nothing
"$clog2"
(
Args
[
Just
(
Number
n
)]
[]
)))
=
simplify
(
orig
@
(
Call
(
Ident
"$clog2"
)
(
Args
[
Just
(
Number
n
)]
[]
)))
=
case
readNumber
n
of
case
readNumber
n
of
Nothing
->
orig
Nothing
->
orig
Just
x
->
Number
$
show
$
clog2
x
Just
x
->
Number
$
show
$
clog2
x
...
...
src/Language/SystemVerilog/AST/Stmt.hs
View file @
3597f4a6
...
@@ -48,7 +48,7 @@ data Stmt
...
@@ -48,7 +48,7 @@ data Stmt
|
If
(
Maybe
UniquePriority
)
Expr
Stmt
Stmt
|
If
(
Maybe
UniquePriority
)
Expr
Stmt
Stmt
|
Timing
Timing
Stmt
|
Timing
Timing
Stmt
|
Return
Expr
|
Return
Expr
|
Subroutine
(
Maybe
Identifier
)
Identifie
r
Args
|
Subroutine
Exp
r
Args
|
Trigger
Bool
Identifier
|
Trigger
Bool
Identifier
|
Assertion
Assertion
|
Assertion
Assertion
|
Continue
|
Continue
...
@@ -84,7 +84,7 @@ instance Show Stmt where
...
@@ -84,7 +84,7 @@ instance Show Stmt where
where
showInit
(
l
,
e
)
=
showAssign
(
l
,
AsgnOpEq
,
e
)
where
showInit
(
l
,
e
)
=
showAssign
(
l
,
AsgnOpEq
,
e
)
showAssign
::
(
LHS
,
AsgnOp
,
Expr
)
->
String
showAssign
::
(
LHS
,
AsgnOp
,
Expr
)
->
String
showAssign
(
l
,
op
,
e
)
=
printf
"%s %s %s"
(
show
l
)
(
show
op
)
(
show
e
)
showAssign
(
l
,
op
,
e
)
=
printf
"%s %s %s"
(
show
l
)
(
show
op
)
(
show
e
)
show
(
Subroutine
ps
x
a
)
=
printf
"%s%s%s;"
(
maybe
""
(
++
"::"
)
ps
)
x
aStr
show
(
Subroutine
e
a
)
=
printf
"%s%s;"
(
show
e
)
aStr
where
aStr
=
if
a
==
Args
[]
[]
then
""
else
show
a
where
aStr
=
if
a
==
Args
[]
[]
then
""
else
show
a
show
(
AsgnBlk
o
v
e
)
=
printf
"%s %s %s;"
(
show
v
)
(
show
o
)
(
show
e
)
show
(
AsgnBlk
o
v
e
)
=
printf
"%s %s %s;"
(
show
v
)
(
show
o
)
(
show
e
)
show
(
Asgn
t
v
e
)
=
printf
"%s <= %s%s;"
(
show
v
)
(
maybe
""
showPad
t
)
(
show
e
)
show
(
Asgn
t
v
e
)
=
printf
"%s <= %s%s;"
(
show
v
)
(
maybe
""
showPad
t
)
(
show
e
)
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
3597f4a6
...
@@ -592,7 +592,6 @@ DeclTokens(delim) :: { [DeclToken] }
...
@@ -592,7 +592,6 @@ DeclTokens(delim) :: { [DeclToken] }
DeclToken :: { DeclToken }
DeclToken :: { DeclToken }
: DeclOrStmtToken { $1 }
: DeclOrStmtToken { $1 }
| ParameterBindings { DTParams $1 }
| ParameterBindings { DTParams $1 }
| PortBindings { DTInstance $1 }
DeclOrStmtTokens(delim) :: { [DeclToken] }
DeclOrStmtTokens(delim) :: { [DeclToken] }
: DeclOrStmtToken delim { [$1] }
: DeclOrStmtToken delim { [$1] }
...
@@ -612,6 +611,7 @@ DeclOrStmtToken :: { DeclToken }
...
@@ -612,6 +611,7 @@ DeclOrStmtToken :: { DeclToken }
| LHSConcat { DTConcat $1 }
| LHSConcat { DTConcat $1 }
| PartialType { DTType $1 }
| PartialType { DTType $1 }
| "." Identifier { DTDot $2 }
| "." Identifier { DTDot $2 }
| PortBindings { DTInstance $1 }
| Signing { DTSigning $1 }
| Signing { DTSigning $1 }
| Lifetime { DTLifetime $1 }
| Lifetime { DTLifetime $1 }
| Identifier "::" Identifier { DTPSIdent $1 $3 }
| Identifier "::" Identifier { DTPSIdent $1 $3 }
...
@@ -904,8 +904,8 @@ StmtAsgn :: { Stmt }
...
@@ -904,8 +904,8 @@ StmtAsgn :: { Stmt }
: LHS AsgnOp Expr ";" { AsgnBlk $2 $1 $3 }
: LHS AsgnOp Expr ";" { AsgnBlk $2 $1 $3 }
| LHS IncOrDecOperator ";" { AsgnBlk (AsgnOp $2) $1 (Number "1") }
| LHS IncOrDecOperator ";" { AsgnBlk (AsgnOp $2) $1 (Number "1") }
| LHS "<=" opt(DelayOrEventControl) Expr ";" { Asgn $3 $1 $4 }
| LHS "<=" opt(DelayOrEventControl) Expr ";" { Asgn $3 $1 $4 }
|
Identifier ";" { Subroutine (Nothing) $1
(Args [] []) }
|
LHS ";" { Subroutine (lhsToExpr $1)
(Args [] []) }
|
Identifier "::" Identifier ";" { Subroutine (Just $1) $3 (Args [] [])
}
|
LHS CallArgs ";" { Subroutine (lhsToExpr $1) $2
}
StmtNonAsgn :: { Stmt }
StmtNonAsgn :: { Stmt }
: StmtBlock(BlockKWSeq, "end" ) { $1 }
: StmtBlock(BlockKWSeq, "end" ) { $1 }
| StmtBlock(BlockKWPar, "join") { $1 }
| StmtBlock(BlockKWPar, "join") { $1 }
...
@@ -920,8 +920,6 @@ StmtNonBlock :: { Stmt }
...
@@ -920,8 +920,6 @@ StmtNonBlock :: { Stmt }
| Unique "if" "(" Expr ")" Stmt %prec NoElse { If $1 $4 $6 Null }
| Unique "if" "(" Expr ")" Stmt %prec NoElse { If $1 $4 $6 Null }
| "for" "(" ForInit ForCond ForStep ")" Stmt { For $3 $4 $5 $7 }
| "for" "(" ForInit ForCond ForStep ")" Stmt { For $3 $4 $5 $7 }
| Unique CaseKW "(" Expr ")" Cases "endcase" { Case $1 $2 $4 (fst $6) (snd $6) }
| Unique CaseKW "(" Expr ")" Cases "endcase" { Case $1 $2 $4 (fst $6) (snd $6) }
| Identifier CallArgs ";" { Subroutine (Nothing) $1 $2 }
| Identifier "::" Identifier CallArgs ";" { Subroutine (Just $1) $3 $4 }
| TimingControl Stmt { Timing $1 $2 }
| TimingControl Stmt { Timing $1 $2 }
| "return" Expr ";" { Return $2 }
| "return" Expr ";" { Return $2 }
| "return" ";" { Return Nil }
| "return" ";" { Return Nil }
...
@@ -1102,8 +1100,7 @@ Expr :: { Expr }
...
@@ -1102,8 +1100,7 @@ Expr :: { Expr }
| String { String $1 }
| String { String $1 }
| Number { Number $1 }
| Number { Number $1 }
| Time { Time $1 }
| Time { Time $1 }
| Identifier CallArgs { Call (Nothing) $1 $2 }
| Expr CallArgs { Call $1 $2 }
| Identifier "::" Identifier CallArgs { Call (Just $1) $3 $4 }
| DimsFn "(" TypeOrExpr ")" { DimsFn $1 $3 }
| DimsFn "(" TypeOrExpr ")" { DimsFn $1 $3 }
| DimFn "(" TypeOrExpr ")" { DimFn $1 $3 (Number "1") }
| DimFn "(" TypeOrExpr ")" { DimFn $1 $3 (Number "1") }
| DimFn "(" TypeOrExpr "," Expr ")" { DimFn $1 $3 $5 }
| DimFn "(" TypeOrExpr "," Expr ")" { DimFn $1 $3 $5 }
...
...
src/Language/SystemVerilog/Parser/ParseDecl.hs
View file @
3597f4a6
...
@@ -38,8 +38,8 @@ module Language.SystemVerilog.Parser.ParseDecl
...
@@ -38,8 +38,8 @@ module Language.SystemVerilog.Parser.ParseDecl
,
parseDTsAsDeclsOrAsgns
,
parseDTsAsDeclsOrAsgns
)
where
)
where
import
Data.List
(
elemIndex
,
findIndex
,
findIndices
)
import
Data.List
(
elemIndex
,
findIndex
,
findIndices
,
partition
)
import
Data.Maybe
(
fromJust
,
mapMaybe
)
import
Data.Maybe
(
mapMaybe
)
import
Language.SystemVerilog.AST
import
Language.SystemVerilog.AST
...
@@ -202,22 +202,34 @@ parseDTsAsDecl tokens =
...
@@ -202,22 +202,34 @@ parseDTsAsDecl tokens =
-- [PUBLIC]: parser for single block item declarations or assign or arg-less
-- [PUBLIC]: parser for single block item declarations or assign or arg-less
-- subroutine call statetments
-- subroutine call statetments
parseDTsAsDeclOrAsgn
::
[
DeclToken
]
->
([
Decl
],
[
Stmt
])
parseDTsAsDeclOrAsgn
::
[
DeclToken
]
->
([
Decl
],
[
Stmt
])
parseDTsAsDeclOrAsgn
[
DTIdent
f
]
=
(
[]
,
[
Subroutine
(
Nothing
)
f
(
Args
[]
[]
)])
parseDTsAsDeclOrAsgn
[
DTIdent
f
]
=
(
[]
,
[
Subroutine
(
Ident
f
)
(
Args
[]
[]
)])
parseDTsAsDeclOrAsgn
[
DTPSIdent
p
f
]
=
(
[]
,
[
Subroutine
(
Just
p
)
f
(
Args
[]
[]
)])
parseDTsAsDeclOrAsgn
[
DTPSIdent
p
f
]
=
(
[]
,
[
Subroutine
(
PSIdent
p
f
)
(
Args
[]
[]
)])
parseDTsAsDeclOrAsgn
tokens
=
parseDTsAsDeclOrAsgn
tokens
=
if
(
is
Asgn
(
last
tokens
)
||
tripLookahead
tokens
)
&&
l
hs
/=
Nothing
if
(
is
Stmt
(
last
tokens
)
||
tripLookahead
tokens
)
&&
maybeL
hs
/=
Nothing
then
(
[]
,
[
constructor
(
fromJust
lhs
)
expr
])
then
(
[]
,
[
stmt
])
else
(
parseDTsAsDecl
tokens
,
[]
)
else
(
parseDTsAsDecl
tokens
,
[]
)
where
where
(
constructor
,
expr
)
=
case
last
tokens
of
stmt
=
case
last
tokens
of
DTAsgn
op
e
->
(
AsgnBlk
op
,
e
)
DTAsgn
op
e
->
AsgnBlk
op
lhs
e
DTAsgnNBlk
mt
e
->
(
Asgn
mt
,
e
)
DTAsgnNBlk
mt
e
->
Asgn
mt
lhs
e
DTInstance
args
->
Subroutine
(
lhsToExpr
lhs
)
(
instanceToArgs
args
)
_
->
error
$
"invalid block item decl or stmt: "
++
(
show
tokens
)
_
->
error
$
"invalid block item decl or stmt: "
++
(
show
tokens
)
lhs
=
takeLHS
$
init
tokens
maybeLhs
=
takeLHS
$
init
tokens
isAsgn
::
DeclToken
->
Bool
Just
lhs
=
maybeLhs
isAsgn
(
DTAsgnNBlk
_
_
)
=
True
isStmt
::
DeclToken
->
Bool
isAsgn
(
DTAsgn
_
_
)
=
True
isStmt
(
DTAsgnNBlk
{})
=
True
isAsgn
_
=
False
isStmt
(
DTAsgn
{})
=
True
isStmt
(
DTInstance
{})
=
True
isStmt
_
=
False
-- converts port bindings to call args
instanceToArgs
::
[
PortBinding
]
->
Args
instanceToArgs
bindings
=
Args
pnArgs
kwArgs
where
(
pnBindings
,
kwBindings
)
=
partition
(
null
.
fst
)
bindings
pnArgs
=
map
snd
pnBindings
kwArgs
=
kwBindings
-- [PUBLIC]: parser for comma-separated declarations or assignment lists; this
-- [PUBLIC]: parser for comma-separated declarations or assignment lists; this
-- is only used for `for` loop initialization lists
-- is only used for `for` loop initialization lists
...
...
test/basic/interface_func.sv
0 → 100644
View file @
3597f4a6
interface
Foo
;
function
bar
;
input
integer
x
;
return
x
*
x
;
endfunction
endinterface
module
top
;
Foo
foo
()
;
initial
$
display
(
foo
.
bar
(
3
))
;
endmodule
test/basic/interface_func.v
0 → 100644
View file @
3597f4a6
module
top
;
function
bar
;
input
integer
x
;
bar
=
x
*
x
;
endfunction
initial
$
display
(
bar
(
3
))
;
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