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
2ca8a022
Commit
2ca8a022
authored
Sep 15, 2019
by
Zachary Snow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support and conversion for -> and <->
parent
c0e38f79
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
75 additions
and
0 deletions
+75
-0
src/Convert.hs
+2
-0
src/Convert/LogOp.hs
+28
-0
src/Language/SystemVerilog/AST/Op.hs
+4
-0
src/Language/SystemVerilog/Parser/Lex.x
+1
-0
src/Language/SystemVerilog/Parser/Parse.y
+4
-0
src/Language/SystemVerilog/Parser/Tokens.hs
+1
-0
sv2v.cabal
+1
-0
test/basic/log_op.sv
+16
-0
test/basic/log_op.v
+18
-0
No files found.
src/Convert.hs
View file @
2ca8a022
...
...
@@ -22,6 +22,7 @@ import qualified Convert.Interface
import
qualified
Convert.IntTypes
import
qualified
Convert.KWArgs
import
qualified
Convert.Logic
import
qualified
Convert.LogOp
import
qualified
Convert.NamedBlock
import
qualified
Convert.NestPI
import
qualified
Convert.Package
...
...
@@ -52,6 +53,7 @@ phases excludes =
,
Convert
.
EmptyArgs
.
convert
,
Convert
.
IntTypes
.
convert
,
Convert
.
KWArgs
.
convert
,
Convert
.
LogOp
.
convert
,
Convert
.
PackedArray
.
convert
,
Convert
.
DimensionQuery
.
convert
,
Convert
.
ParamType
.
convert
...
...
src/Convert/LogOp.hs
0 → 100644
View file @
2ca8a022
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Conversion for logical implication (->) and logical equality (<->) operators.
-
- We convert `a -> b` to `!a || b`, as per the definition of implication.
-
- We convert `a <-> b` to `!a = !b`. Note that we can't simply use `a = b` as
- `1 != 2`, but `1 <-> 2`.
-}
module
Convert.LogOp
(
convert
)
where
import
Convert.Traverse
import
Language.SystemVerilog.AST
convert
::
[
AST
]
->
[
AST
]
convert
=
map
$
traverseDescriptions
$
traverseModuleItems
$
traverseExprs
$
traverseNestedExprs
convertExpr
convertExpr
::
Expr
->
Expr
convertExpr
(
BinOp
LogEq
a
b
)
=
BinOp
Eq
(
UniOp
LogNot
a
)
(
UniOp
LogNot
b
)
convertExpr
(
BinOp
LogImp
a
b
)
=
BinOp
LogOr
(
UniOp
LogNot
a
)
b
convertExpr
other
=
other
src/Language/SystemVerilog/AST/Op.hs
View file @
2ca8a022
...
...
@@ -40,6 +40,8 @@ instance Show UniOp where
data
BinOp
=
LogAnd
|
LogOr
|
LogImp
|
LogEq
|
BitAnd
|
BitXor
|
BitXnor
...
...
@@ -69,6 +71,8 @@ data BinOp
instance
Show
BinOp
where
show
LogAnd
=
"&&"
show
LogOr
=
"||"
show
LogImp
=
"->"
show
LogEq
=
"<->"
show
BitAnd
=
"&"
show
BitXor
=
"^"
show
BitXnor
=
"~^"
...
...
src/Language/SystemVerilog/Parser/Lex.x
View file @
2ca8a022
...
...
@@ -458,6 +458,7 @@ tokens :-
"<<<" { tok Sym_lt_lt_lt }
"<<=" { tok Sym_lt_lt_eq }
">>=" { tok Sym_gt_gt_eq }
"<->" { tok Sym_lt_dash_gt }
"|->" { tok Sym_bar_dash_gt }
"|=>" { tok Sym_bar_eq_gt }
"[->" { tok Sym_brack_l_dash_gt }
...
...
src/Language/SystemVerilog/Parser/Parse.y
View file @
2ca8a022
...
...
@@ -366,6 +366,7 @@ time { Token Lit_time _ _ }
"<<<" { Token Sym_lt_lt_lt _ _ }
"<<=" { Token Sym_lt_lt_eq _ _ }
">>=" { Token Sym_gt_gt_eq _ _ }
"<->" { Token Sym_lt_dash_gt _ _ }
"|->" { Token Sym_bar_dash_gt _ _ }
"|=>" { Token Sym_bar_eq_gt _ _ }
"[->" { Token Sym_brack_l_dash_gt _ _ }
...
...
@@ -391,6 +392,7 @@ time { Token Lit_time _ _ }
%right "throughout"
%left "##"
%nonassoc "[*]" "[=]" "[->]"
%right "->" "<->"
%right "?" ":"
%left "||"
%left "&&"
...
...
@@ -1042,6 +1044,8 @@ Expr :: { Expr }
-- binary expressions
| Expr "||" Expr { BinOp LogOr $1 $3 }
| Expr "&&" Expr { BinOp LogAnd $1 $3 }
| Expr "->" Expr { BinOp LogImp $1 $3 }
| Expr "<->" Expr { BinOp LogEq $1 $3 }
| Expr "|" Expr { BinOp BitOr $1 $3 }
| Expr "^" Expr { BinOp BitXor $1 $3 }
| Expr "&" Expr { BinOp BitAnd $1 $3 }
...
...
src/Language/SystemVerilog/Parser/Tokens.hs
View file @
2ca8a022
...
...
@@ -366,6 +366,7 @@ data TokenName
|
Sym_lt_lt_lt
|
Sym_lt_lt_eq
|
Sym_gt_gt_eq
|
Sym_lt_dash_gt
|
Sym_bar_dash_gt
|
Sym_bar_eq_gt
|
Sym_pound_dash_pound
...
...
sv2v.cabal
View file @
2ca8a022
...
...
@@ -67,6 +67,7 @@ executable sv2v
Convert.IntTypes
Convert.KWArgs
Convert.Logic
Convert.LogOp
Convert.NamedBlock
Convert.NestPI
Convert.Package
...
...
test/basic/log_op.sv
0 → 100644
View file @
2ca8a022
module
top
;
function
log_imp
;
input
integer
a
;
input
integer
b
;
return
a
->
b
;
endfunction
function
log_eq
;
input
integer
a
;
input
integer
b
;
return
a
<->
b
;
endfunction
initial
for
(
integer
a
=
-
2
;
a
<=
2
;
a
++
)
for
(
integer
b
=
-
2
;
b
<=
2
;
b
++
)
$
display
(
log_imp
(
a
,
b
)
,
log_eq
(
a
,
b
))
;
endmodule
test/basic/log_op.v
0 → 100644
View file @
2ca8a022
module
top
;
function
log_imp
;
input
integer
a
;
input
integer
b
;
log_imp
=
!
a
||
b
;
endfunction
function
log_eq
;
input
integer
a
;
input
integer
b
;
log_eq
=
!
a
==
!
b
;
endfunction
initial
begin
:
foo
integer
a
,
b
;
for
(
a
=
-
2
;
a
<=
2
;
a
=
a
+
1
)
for
(
b
=
-
2
;
b
<=
2
;
b
=
b
+
1
)
$
display
(
log_imp
(
a
,
b
)
,
log_eq
(
a
,
b
))
;
end
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