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
2ee5b6e0
Commit
2ee5b6e0
authored
Feb 20, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
suport for in module instantiations
parent
5fae85e6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
8 deletions
+52
-8
Convert.hs
+2
-0
Convert/StarPort.hs
+37
-0
Language/SystemVerilog/AST.hs
+8
-5
Language/SystemVerilog/Parser/Parse.y
+4
-3
sv2v.cabal
+1
-0
No files found.
Convert.hs
View file @
2ee5b6e0
...
@@ -11,6 +11,7 @@ import Language.SystemVerilog.AST
...
@@ -11,6 +11,7 @@ import Language.SystemVerilog.AST
import
qualified
Convert.AlwaysKW
import
qualified
Convert.AlwaysKW
import
qualified
Convert.Logic
import
qualified
Convert.Logic
import
qualified
Convert.Typedef
import
qualified
Convert.Typedef
import
qualified
Convert.StarPort
type
Phase
=
AST
->
AST
type
Phase
=
AST
->
AST
...
@@ -19,6 +20,7 @@ phases =
...
@@ -19,6 +20,7 @@ phases =
[
Convert
.
AlwaysKW
.
convert
[
Convert
.
AlwaysKW
.
convert
,
Convert
.
Logic
.
convert
,
Convert
.
Logic
.
convert
,
Convert
.
Typedef
.
convert
,
Convert
.
Typedef
.
convert
,
Convert
.
StarPort
.
convert
]
]
run
::
Phase
run
::
Phase
...
...
Convert/StarPort.hs
0 → 100644
View file @
2ee5b6e0
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Conversion for `.*` in module instantiation
-}
module
Convert.StarPort
(
convert
)
where
import
Data.Maybe
import
qualified
Data.Map.Strict
as
Map
import
Language.SystemVerilog.AST
type
ModulePorts
=
Map
.
Map
String
[
String
]
convert
::
AST
->
AST
convert
descriptions
=
map
(
convertDescription
portsInfo
)
descriptions
where
portsInfo
=
Map
.
fromList
$
mapMaybe
getPorts
descriptions
getPorts
::
Description
->
Maybe
(
Identifier
,
[
Identifier
])
getPorts
(
Module
name
ports
_
)
=
Just
(
name
,
ports
)
getPorts
_
=
Nothing
convertDescription
::
ModulePorts
->
Description
->
Description
convertDescription
info
(
Module
name
ports
items
)
=
Module
name
ports
$
map
(
convertModuleItem
info
)
items
convertDescription
_
other
=
other
convertModuleItem
::
ModulePorts
->
ModuleItem
->
ModuleItem
convertModuleItem
info
(
Instance
m
p
x
Nothing
)
=
Instance
m
p
x
(
Just
portBindings
)
where
ports
=
case
Map
.
lookup
m
info
of
Nothing
->
error
$
"could not convert `.*` in instantiation of "
++
m
Just
l
->
l
portBindings
=
map
(
\
port
->
(
port
,
Just
$
Ident
port
))
ports
convertModuleItem
_
other
=
other
Language/SystemVerilog/AST.hs
View file @
2ee5b6e0
...
@@ -92,7 +92,7 @@ data ModuleItem
...
@@ -92,7 +92,7 @@ data ModuleItem
|
LocalNet
Type
Identifier
RangesOrAssignment
|
LocalNet
Type
Identifier
RangesOrAssignment
|
AlwaysC
AlwaysKW
Stmt
|
AlwaysC
AlwaysKW
Stmt
|
Assign
LHS
Expr
|
Assign
LHS
Expr
|
Instance
Identifier
[
PortBinding
]
Identifier
[
PortBinding
]
|
Instance
Identifier
[
PortBinding
]
Identifier
(
Maybe
[
PortBinding
])
-- `Nothing` represents `.*`
|
Function
(
Maybe
FuncRet
)
Identifier
[(
Bool
,
BlockItemDeclaration
)]
Stmt
|
Function
(
Maybe
FuncRet
)
Identifier
[(
Bool
,
BlockItemDeclaration
)]
Stmt
|
Genvar
Identifier
|
Genvar
Identifier
|
Generate
[
GenItem
]
|
Generate
[
GenItem
]
...
@@ -139,14 +139,17 @@ instance Show ModuleItem where
...
@@ -139,14 +139,17 @@ instance Show ModuleItem where
AlwaysC
k
b
->
printf
"%s %s"
(
show
k
)
(
show
b
)
AlwaysC
k
b
->
printf
"%s %s"
(
show
k
)
(
show
b
)
Assign
a
b
->
printf
"assign %s = %s;"
(
show
a
)
(
show
b
)
Assign
a
b
->
printf
"assign %s = %s;"
(
show
a
)
(
show
b
)
Instance
m
params
i
ports
Instance
m
params
i
ports
|
null
params
->
printf
"%s %s
%s;"
m
i
(
showPorts
show
ports
)
|
null
params
->
printf
"%s %s
%s;"
m
i
(
showMaybePorts
ports
)
|
otherwise
->
printf
"%s #%s %s
%s;"
m
(
showPorts
show
params
)
i
(
showPorts
show
ports
)
|
otherwise
->
printf
"%s #%s %s
%s;"
m
(
showPorts
params
)
i
(
showMaybePorts
ports
)
Function
t
x
i
b
->
printf
"function %s%s;
\n
%s
\n
%s
\n
endfunction"
(
showFuncRet
t
)
x
(
indent
$
unlines'
$
map
showFunctionItem
i
)
(
indent
$
show
b
)
Function
t
x
i
b
->
printf
"function %s%s;
\n
%s
\n
%s
\n
endfunction"
(
showFuncRet
t
)
x
(
indent
$
unlines'
$
map
showFunctionItem
i
)
(
indent
$
show
b
)
Genvar
x
->
printf
"genvar %s;"
x
Genvar
x
->
printf
"genvar %s;"
x
Generate
b
->
printf
"generate
\n
%s
\n
endgenerate"
(
indent
$
unlines'
$
map
show
b
)
Generate
b
->
printf
"generate
\n
%s
\n
endgenerate"
(
indent
$
unlines'
$
map
show
b
)
where
where
showPorts
::
(
Expr
->
String
)
->
[(
Identifier
,
Maybe
Expr
)]
->
String
showMaybePorts
::
Maybe
[(
Identifier
,
Maybe
Expr
)]
->
String
showPorts
s
ports
=
indentedParenList
[
if
i
==
""
then
show
(
fromJust
arg
)
else
printf
".%s(%s)"
i
(
if
isJust
arg
then
s
$
fromJust
arg
else
""
)
|
(
i
,
arg
)
<-
ports
]
showMaybePorts
Nothing
=
"(.*)"
showMaybePorts
(
Just
ports
)
=
showPorts
ports
showPorts
::
[(
Identifier
,
Maybe
Expr
)]
->
String
showPorts
ports
=
indentedParenList
[
if
i
==
""
then
show
(
fromJust
arg
)
else
printf
".%s(%s)"
i
(
if
isJust
arg
then
show
$
fromJust
arg
else
""
)
|
(
i
,
arg
)
<-
ports
]
showFunctionItem
::
(
Bool
,
BlockItemDeclaration
)
->
String
showFunctionItem
::
(
Bool
,
BlockItemDeclaration
)
->
String
showFunctionItem
(
b
,
item
)
=
prefix
++
(
show
item
)
showFunctionItem
(
b
,
item
)
=
prefix
++
(
show
item
)
where
prefix
=
if
b
then
"input "
else
""
where
prefix
=
if
b
then
"input "
else
""
...
...
Language/SystemVerilog/Parser/Parse.y
View file @
2ee5b6e0
...
@@ -260,11 +260,12 @@ AlwaysKW :: { AlwaysKW }
...
@@ -260,11 +260,12 @@ AlwaysKW :: { AlwaysKW }
| "always_ff" { AlwaysFF }
| "always_ff" { AlwaysFF }
| "always_latch" { AlwaysLatch }
| "always_latch" { AlwaysLatch }
ModuleInstantiations :: { [(Identifier, [PortBinding])] }
ModuleInstantiations :: { [(Identifier,
Maybe
[PortBinding])] }
: ModuleInstantiation { [$1] }
: ModuleInstantiation { [$1] }
| ModuleInstantiations "," ModuleInstantiation { $1 ++ [$3] }
| ModuleInstantiations "," ModuleInstantiation { $1 ++ [$3] }
ModuleInstantiation :: { (Identifier, [PortBinding]) }
ModuleInstantiation :: { (Identifier, Maybe [PortBinding]) }
: Identifier "(" Bindings ")" { ($1, $3) }
: Identifier "(" Bindings ")" { ($1, Just $3) }
| Identifier "(" ".*" ")" { ($1, Nothing) }
FunctionItems :: { [(Bool, BlockItemDeclaration)] }
FunctionItems :: { [(Bool, BlockItemDeclaration)] }
: "(" FunctionPortList ";" BlockItemDeclarations { (map ((,) True) $2) ++ (map ((,) False) $4) }
: "(" FunctionPortList ";" BlockItemDeclarations { (map ((,) True) $2) ++ (map ((,) False) $4) }
...
...
sv2v.cabal
View file @
2ee5b6e0
...
@@ -62,6 +62,7 @@ executable sv2v
...
@@ -62,6 +62,7 @@ executable sv2v
Convert
Convert
Convert.AlwaysKW
Convert.AlwaysKW
Convert.Logic
Convert.Logic
Convert.StarPort
Convert.Typedef
Convert.Typedef
Convert.Template.ModuleItem
Convert.Template.ModuleItem
ghc-options:
ghc-options:
...
...
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